Skip to content

Commit

Permalink
fix(partition): update signature to match docs
Browse files Browse the repository at this point in the history
  • Loading branch information
manbearwiz committed Aug 30, 2017
1 parent d926435 commit 4f10751
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
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);
}
2 changes: 1 addition & 1 deletion src/operators/partition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ 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

0 comments on commit 4f10751

Please sign in to comment.