Skip to content

Commit 755df9b

Browse files
manbearwizbenlesh
authored andcommitted
fix(partition): update TypeScript signature to match docs and filter operator (#2819)
* fix(partition): update signature to match docs * style(partition): don't exceed max line length
1 parent 3d79250 commit 755df9b

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

spec/operators/partition-spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ describe('Observable.prototype.partition', () => {
4545
expectSubscriptions(e1.subscriptions).toBe([e1subs, e1subs]);
4646
});
4747

48+
it('should partition an observable into two using a predicate that takes an index', () => {
49+
const e1 = hot('--a-b---a------d--e---c--|');
50+
const e1subs = '^ !';
51+
const expected = ['--a-----a---------e------|',
52+
'----b----------d------c--|'];
53+
54+
function predicate(value, index: number) {
55+
return index % 2 === 0;
56+
}
57+
58+
expectObservableArray(e1.partition(predicate), expected);
59+
expectSubscriptions(e1.subscriptions).toBe([e1subs, e1subs]);
60+
});
61+
4862
it('should partition an observable into two using a predicate and thisArg', () => {
4963
const e1 = hot('--a-b---a------d--a---c--|');
5064
const e1subs = '^ !';

src/operator/partition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ import { partition as higherOrder } from '../operators/partition';
4141
* @method partition
4242
* @owner Observable
4343
*/
44-
export function partition<T>(this: Observable<T>, predicate: (value: T) => boolean, thisArg?: any): [Observable<T>, Observable<T>] {
44+
export function partition<T>(this: Observable<T>, predicate: (value: T, index: number) => boolean, thisArg?: any): [Observable<T>, Observable<T>] {
4545
return higherOrder(predicate, thisArg)(this);
4646
}

src/operators/partition.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ import { UnaryFunction } from '../interfaces';
4444
* @method partition
4545
* @owner Observable
4646
*/
47-
export function partition<T>(predicate: (value: T) => boolean, thisArg?: any): UnaryFunction<Observable<T>, [Observable<T>, Observable<T>]> {
47+
export function partition<T>(predicate: (value: T, index: number) => boolean,
48+
thisArg?: any): UnaryFunction<Observable<T>, [Observable<T>, Observable<T>]> {
4849
return (source: Observable<T>) => [
4950
filter(predicate, thisArg)(source),
5051
filter(not(predicate, thisArg) as any)(source)

0 commit comments

Comments
 (0)