Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(orderby): add piped orderby #190

Merged
merged 2 commits into from
Dec 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
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
);
};
}
4 changes: 4 additions & 0 deletions src/iterable/pipe/index.ts
Original file line number Diff line number Diff line change
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
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
);
};
}