diff --git a/spec/operators/partition-spec.ts b/spec/operators/partition-spec.ts index 2c9736d7be..83bbd4221d 100644 --- a/spec/operators/partition-spec.ts +++ b/spec/operators/partition-spec.ts @@ -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 = '^ !'; diff --git a/src/operator/partition.ts b/src/operator/partition.ts index c5026eddb2..98edb1dd69 100644 --- a/src/operator/partition.ts +++ b/src/operator/partition.ts @@ -41,6 +41,6 @@ import { partition as higherOrder } from '../operators/partition'; * @method partition * @owner Observable */ -export function partition(this: Observable, predicate: (value: T) => boolean, thisArg?: any): [Observable, Observable] { +export function partition(this: Observable, predicate: (value: T, index: number) => boolean, thisArg?: any): [Observable, Observable] { return higherOrder(predicate, thisArg)(this); } diff --git a/src/operators/partition.ts b/src/operators/partition.ts index 0a6e846b4e..f31d18ff3f 100644 --- a/src/operators/partition.ts +++ b/src/operators/partition.ts @@ -44,7 +44,8 @@ import { UnaryFunction } from '../interfaces'; * @method partition * @owner Observable */ -export function partition(predicate: (value: T) => boolean, thisArg?: any): UnaryFunction, [Observable, Observable]> { +export function partition(predicate: (value: T, index: number) => boolean, + thisArg?: any): UnaryFunction, [Observable, Observable]> { return (source: Observable) => [ filter(predicate, thisArg)(source), filter(not(predicate, thisArg) as any)(source)