Skip to content

Commit

Permalink
fix(partition): update TypeScript signature to match docs and filter …
Browse files Browse the repository at this point in the history
…operator (#2819)

* fix(partition): update signature to match docs

* style(partition): don't exceed max line length
  • Loading branch information
manbearwiz authored and benlesh committed Sep 19, 2017
1 parent 3d79250 commit 755df9b
Show file tree
Hide file tree
Showing 3 changed files with 17 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);
}
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

0 comments on commit 755df9b

Please sign in to comment.