Skip to content

Commit

Permalink
feat(orderby): add piped orderby (#190)
Browse files Browse the repository at this point in the history
* feat(orderby): add piped orderby

* build(gulp): fix gulp
  • Loading branch information
mattpodwysocki committed Dec 22, 2017
1 parent 131eb10 commit aaa527a
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -16,6 +16,7 @@
"lint:src": "tslint --fix --project -p tsconfig.json -c tslint.json \"src/**/*.ts\"",
"lint:spec": "tslint --fix --project -p spec/tsconfig.json -c tslint.json \"spec/**/*.ts\"",
"prepublishOnly": "echo \"Error: do 'npm run release' instead of 'npm publish'\" && exit 1",
"preinstall": "npm i rimraf && rimraf node_modules/tsickle",
"postinstall": "git apply --ignore-whitespace patches/tsickle+0.24.1.patch"
},
"author": "Matthew Podwysocki <matthewp@microsoft.com>",
Expand Down Expand Up @@ -61,7 +62,7 @@
"esdoc": "1.0.4",
"esdoc-standard-plugin": "1.0.0",
"google-closure-compiler": "20171203.0.0",
"gulp": "github:gulpjs/gulp#4.0",
"gulp": "github:gulpjs/gulp#6d71a658c61edb3090221579d8f97dbe086ba2ed",
"gulp-json-transform": "0.4.5",
"gulp-rename": "1.2.2",
"gulp-sourcemaps": "2.6.1",
Expand Down
4 changes: 4 additions & 0 deletions src/asynciterable/pipe/index.ts
Expand Up @@ -29,6 +29,8 @@ export { merge } from './merge';
export { mergeAll } from './mergeall';
export { minBy } from './minby';
export { onErrorResumeNext } from './onerrorresumenext';
export { orderBy } from './orderby';
export { orderByDescending } from './orderby';
export { pairwise } from './pairwise';
export { pluck } from './pluck';
export { publish } from './publish';
Expand All @@ -49,6 +51,8 @@ export { takeLast } from './takelast';
export { takeUntil } from './takeuntil';
export { takeWhile } from './takewhile';
export { tap } from './tap';
export { thenBy } from './orderby';
export { thenByDescending } from './orderby';
export { throttle } from './throttle';
export { timeInterval } from './timeinterval';
export { timeout } from './timeout';
Expand Down
53 changes: 53 additions & 0 deletions src/asynciterable/pipe/orderby.ts
@@ -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
);
};
}
4 changes: 4 additions & 0 deletions src/iterable/pipe/index.ts
Expand Up @@ -24,6 +24,8 @@ export { maxBy } from './maxby';
export { memoize } from './memoize';
export { minBy } from './minby';
export { onErrorResumeNext } from './onerrorresumenext';
export { orderBy } from './orderby';
export { orderByDescending } from './orderby';
export { pairwise } from './pairwise';
export { pluck } from './pluck';
export { publish } from './publish';
Expand All @@ -42,5 +44,7 @@ export { take } from './take';
export { takeLast } from './takelast';
export { takeWhile } from './takewhile';
export { tap } from './tap';
export { thenBy } from './orderby';
export { thenByDescending } from './orderby';
export { union } from './union';
export { zip } from './zip';
53 changes: 53 additions & 0 deletions src/iterable/pipe/orderby.ts
@@ -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
);
};
}

0 comments on commit aaa527a

Please sign in to comment.