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

fix(partition): update signature to match docs and filter operator #2819

Merged
merged 2 commits into from
Sep 19, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions spec/operators/partition-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ describe('Observable.prototype.partition', () => {
expectSubscriptions(e1.subscriptions).toBe([e1subs, e1subs]);
});

it('should partition an observable into two using a predicate that takes an index', () => {
const e1 = hot('--a-b---a------d--e---c--|');
const e1subs = '^ !';
const expected = ['--a-----a---------e------|',
'----b----------d------c--|'];

function predicate(value, index: number) {
return index % 2 === 0;
}

expectObservableArray(e1.partition(predicate), expected);
expectSubscriptions(e1.subscriptions).toBe([e1subs, e1subs]);
});

it('should partition an observable into two using a predicate and thisArg', () => {
const e1 = hot('--a-b---a------d--a---c--|');
const e1subs = '^ !';
Expand Down
2 changes: 1 addition & 1 deletion src/operator/partition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ import { partition as higherOrder } from '../operators/partition';
* @method partition
* @owner Observable
*/
export function partition<T>(this: Observable<T>, predicate: (value: T) => boolean, thisArg?: any): [Observable<T>, Observable<T>] {
export function partition<T>(this: Observable<T>, predicate: (value: T, index: number) => boolean, thisArg?: any): [Observable<T>, Observable<T>] {
return higherOrder(predicate, thisArg)(this);
}
3 changes: 2 additions & 1 deletion src/operators/partition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ import { UnaryFunction } from '../interfaces';
* @method partition
* @owner Observable
*/
export function partition<T>(predicate: (value: T) => boolean, thisArg?: any): UnaryFunction<Observable<T>, [Observable<T>, Observable<T>]> {
export function partition<T>(predicate: (value: T, index: number) => boolean,
thisArg?: any): UnaryFunction<Observable<T>, [Observable<T>, Observable<T>]> {
return (source: Observable<T>) => [
filter(predicate, thisArg)(source),
filter(not(predicate, thisArg) as any)(source)
Expand Down