Skip to content

Commit

Permalink
Export some types.
Browse files Browse the repository at this point in the history
  • Loading branch information
dboikliev committed May 16, 2021
1 parent 306c010 commit ea50d69
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
6 changes: 4 additions & 2 deletions src/linq/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Linqable, extractSync } from './linqable'
import { Linqable, extractSync, OrderedLinqable, ToMapArgs } from './linqable'
import { Sequence } from './iterables/sequence'
import { elementsSymbol, ElementsWrapper, isWrapper } from './element-wrapper'
import { AsyncLinqable, extractAsync } from './linqableAsync'
import { AsyncLinqable, extractAsync, OrderedLinqableAsync } from './linqableAsync'
import { Unfold, UnfoldStep } from './iterables/unfold'
import { LinqMap, LinqSet } from './collections'

export type { Linqable, AsyncLinqable, OrderedLinqable, OrderedLinqableAsync, ToMapArgs, LinqMap, LinqSet }
export type SyncSource<T> = Iterable<T> | (() => Generator<T>)
export type AsyncSource<T> = AsyncIterable<T> | (() => AsyncGenerator<T>)

Expand Down
6 changes: 3 additions & 3 deletions src/linq/linqable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,10 @@ export class Linqable<TSource> implements Iterable<TSource>, ElementsWrapper<TSo

let accumulated = seed
if (typeof seed === 'undefined') {
let result = iterator.next()
const result = iterator.next()
if (!result.done) {
accumulated = result.value
let second = iterator.next()
const second = iterator.next()
index++
if (!second.done) {
accumulated = accumulator(result.value, second.value, index++) as TResult
Expand All @@ -316,7 +316,7 @@ export class Linqable<TSource> implements Iterable<TSource>, ElementsWrapper<TSo
accumulated = accumulator(accumulated, result.value, index++) as TResult
result = iterator.next()
}
return accumulated
return accumulated
}

scan<TResult = TSource>(accumulator: (accumulated: TResult, element: TSource, index: number) => TResult, seed?: TResult): Linqable<TResult> {
Expand Down
28 changes: 14 additions & 14 deletions src/linq/linqableAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,19 +207,19 @@ export class AsyncLinqable<TSource> implements AsyncIterable<TSource>, ElementsW
/**
* Orders elements based on a selector function.
* @param {function} selector - A function or a selector used for comparing the elements.
* @returns {OrderedLinqable<TSource>} An iterable of the ordered elements.
* @returns {OrderedLinqableAsync<TSource>} An iterable of the ordered elements.
*/
orderBy(selector: (element: TSource) => number | string): OrderedLinqable<TSource> {
return new OrderedLinqable(Ordered.from(this.elements, selector, true))
orderBy(selector: (element: TSource) => number | string): OrderedLinqableAsync<TSource> {
return new OrderedLinqableAsync(Ordered.from(this.elements, selector, true))
}

/**
* Orders elements based on a selector function in desceding order.
* @param {function} selector - A function or a selector used for comparing the elements.
* @returns {OrderedLinqable<TSource>} An iterable of the ordered elements.
* @returns {OrderedLinqableAsync<TSource>} An iterable of the ordered elements.
*/
orderByDescending(selector: (element: TSource) => number | string): OrderedLinqable<TSource> {
return new OrderedLinqable(Ordered.from(this.elements, selector, false))
orderByDescending(selector: (element: TSource) => number | string): OrderedLinqableAsync<TSource> {
return new OrderedLinqableAsync(Ordered.from(this.elements, selector, false))
}

/**
Expand Down Expand Up @@ -278,10 +278,10 @@ export class AsyncLinqable<TSource> implements AsyncIterable<TSource>, ElementsW

let accumulated = seed
if (typeof seed === 'undefined') {
let result = await iterator.next()
const result = await iterator.next()
if (!result.done) {
accumulated = result.value
let second = await iterator.next()
const second = await iterator.next()
index++
if (!second.done) {
accumulated = await accumulator(result.value, second.value, index++) as TResult
Expand Down Expand Up @@ -760,7 +760,7 @@ export class AsyncLinqable<TSource> implements AsyncIterable<TSource>, ElementsW
}
}

export class OrderedLinqable<TSource> extends AsyncLinqable<TSource> {
export class OrderedLinqableAsync<TSource> extends AsyncLinqable<TSource> {
constructor(elements: Ordered<TSource>) {
super(elements)
}
Expand All @@ -769,25 +769,25 @@ export class OrderedLinqable<TSource> extends AsyncLinqable<TSource> {
* Chains an additional ascending ordering based on the key returned by the selector function.
* @param selector - A function which returns a key which will be used for comparisons.
*/
thenBy(this: OrderedLinqable<TSource>, selector: (element: TSource) => string | number): OrderedLinqable<TSource> {
thenBy(this: OrderedLinqableAsync<TSource>, selector: (element: TSource) => string | number): OrderedLinqableAsync<TSource> {
return this.from(selector, true)
}

/**
* Chains an additional descending ordering based on the key returned by the selector function.
* @param selector - A function which returns a key which will be used for comparisons.
*/
thenByDescending(this: OrderedLinqable<TSource>, selector: (element: TSource) => string | number): OrderedLinqable<TSource> {
thenByDescending(this: OrderedLinqableAsync<TSource>, selector: (element: TSource) => string | number): OrderedLinqableAsync<TSource> {
return this.from(selector, false)
}

toString(): string {
return OrderedLinqable.name
return OrderedLinqableAsync.name
}

private from(selector: (element: TSource) => string | number, isAscending: boolean): OrderedLinqable<TSource> {
private from(selector: (element: TSource) => string | number, isAscending: boolean): OrderedLinqableAsync<TSource> {
const ordered = this.elements as Ordered<TSource>
return new OrderedLinqable(ordered.from(selector, isAscending))
return new OrderedLinqableAsync(ordered.from(selector, isAscending))
}
}

Expand Down

0 comments on commit ea50d69

Please sign in to comment.