From 4f107514c5cc0c867bc87b6727ebeaf373745649 Mon Sep 17 00:00:00 2001 From: Kevin Brey Date: Tue, 29 Aug 2017 23:55:16 -0500 Subject: [PATCH 1/2] fix(partition): update signature to match docs --- spec/operators/partition-spec.ts | 14 ++++++++++++++ src/operator/partition.ts | 2 +- src/operators/partition.ts | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) 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..5c13572c13 100644 --- a/src/operators/partition.ts +++ b/src/operators/partition.ts @@ -44,7 +44,7 @@ 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) From 2460114b746790cf1f9cc4fa513f263df8b14519 Mon Sep 17 00:00:00 2001 From: Kevin Brey Date: Wed, 30 Aug 2017 10:19:35 -0500 Subject: [PATCH 2/2] style(partition): don't exceed max line length --- src/operators/partition.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/operators/partition.ts b/src/operators/partition.ts index 5c13572c13..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, index: number) => 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)