Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(orderby): add piped orderby (#190)
* feat(orderby): add piped orderby * build(gulp): fix gulp
- Loading branch information
1 parent
131eb10
commit aaa527a
Showing
5 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; | ||
import { OrderedAsyncIterableX, OrderedAsyncIterableBaseX } from '../orderby'; | ||
import { sorter as defaultSorter } from '../../internal/sorter'; | ||
|
||
export function orderBy<TKey, TSource>( | ||
keySelector: (item: TSource) => TKey, | ||
comparer: (fst: TKey, snd: TKey) => number = defaultSorter | ||
): MonoTypeOperatorAsyncFunction<TSource> { | ||
return function orderByOperatorFunction(source: AsyncIterable<TSource>) { | ||
return new OrderedAsyncIterableX<TKey, TSource>(source, keySelector, comparer, false); | ||
}; | ||
} | ||
|
||
export function orderByDescending<TKey, TSource>( | ||
keySelector: (item: TSource) => TKey, | ||
comparer: (fst: TKey, snd: TKey) => number = defaultSorter | ||
): MonoTypeOperatorAsyncFunction<TSource> { | ||
return function orderByDescendingOperatorFunction(source: AsyncIterable<TSource>) { | ||
return new OrderedAsyncIterableX<TKey, TSource>(source, keySelector, comparer, true); | ||
}; | ||
} | ||
|
||
export function thenBy<TKey, TSource>( | ||
keySelector: (item: TSource) => TKey, | ||
comparer: (fst: TKey, snd: TKey) => number = defaultSorter | ||
): MonoTypeOperatorAsyncFunction<TSource> { | ||
return function thenByOperatorFunction(source: AsyncIterable<TSource>) { | ||
const orderSource = <OrderedAsyncIterableBaseX<TSource>>source; | ||
return new OrderedAsyncIterableX<TKey, TSource>( | ||
orderSource._source, | ||
keySelector, | ||
comparer, | ||
false, | ||
orderSource | ||
); | ||
}; | ||
} | ||
|
||
export function thenByDescending<TKey, TSource>( | ||
keySelector: (item: TSource) => TKey, | ||
comparer: (fst: TKey, snd: TKey) => number = defaultSorter | ||
): MonoTypeOperatorAsyncFunction<TSource> { | ||
return function thenByDescendingOperatorFunction(source: AsyncIterable<TSource>) { | ||
const orderSource = <OrderedAsyncIterableBaseX<TSource>>source; | ||
return new OrderedAsyncIterableX<TKey, TSource>( | ||
orderSource._source, | ||
keySelector, | ||
comparer, | ||
true, | ||
orderSource | ||
); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { MonoTypeOperatorFunction } from '../../interfaces'; | ||
import { OrderedIterableX, OrderedIterableBaseX } from '../orderby'; | ||
import { sorter as defaultSorter } from '../../internal/sorter'; | ||
|
||
export function orderBy<TKey, TSource>( | ||
keySelector: (item: TSource) => TKey, | ||
comparer: (fst: TKey, snd: TKey) => number = defaultSorter | ||
): MonoTypeOperatorFunction<TSource> { | ||
return function orderByOperatorFunction(source: Iterable<TSource>) { | ||
return new OrderedIterableX<TKey, TSource>(source, keySelector, comparer, false); | ||
}; | ||
} | ||
|
||
export function orderByDescending<TKey, TSource>( | ||
keySelector: (item: TSource) => TKey, | ||
comparer: (fst: TKey, snd: TKey) => number = defaultSorter | ||
): MonoTypeOperatorFunction<TSource> { | ||
return function orderByDescendingOperatorFunction(source: Iterable<TSource>) { | ||
return new OrderedIterableX<TKey, TSource>(source, keySelector, comparer, true); | ||
}; | ||
} | ||
|
||
export function thenBy<TKey, TSource>( | ||
keySelector: (item: TSource) => TKey, | ||
comparer: (fst: TKey, snd: TKey) => number = defaultSorter | ||
): MonoTypeOperatorFunction<TSource> { | ||
return function thenByOperatorFunction(source: Iterable<TSource>) { | ||
const orderSource = <OrderedIterableBaseX<TSource>>source; | ||
return new OrderedIterableX<TKey, TSource>( | ||
orderSource._source, | ||
keySelector, | ||
comparer, | ||
false, | ||
orderSource | ||
); | ||
}; | ||
} | ||
|
||
export function thenByDescending<TKey, TSource>( | ||
keySelector: (item: TSource) => TKey, | ||
comparer: (fst: TKey, snd: TKey) => number = defaultSorter | ||
): MonoTypeOperatorFunction<TSource> { | ||
return function thenByDescendingOperatorFunction(source: Iterable<TSource>) { | ||
const orderSource = <OrderedIterableBaseX<TSource>>source; | ||
return new OrderedIterableX<TKey, TSource>( | ||
orderSource._source, | ||
keySelector, | ||
comparer, | ||
true, | ||
orderSource | ||
); | ||
}; | ||
} |