diff --git a/spec/asynciterable-operators/filter-spec.ts b/spec/asynciterable-operators/filter-spec.ts index 6b86262d..b8c74fb7 100644 --- a/spec/asynciterable-operators/filter-spec.ts +++ b/spec/asynciterable-operators/filter-spec.ts @@ -34,6 +34,26 @@ test('AsyncIterable#filter with index', async t => { t.end(); }); +test('AsyncIterable#filter with typeguard', async t => { + const xs = of( + new String('8'), 5, + new String('7'), 4, + new String('6'), 9, + new String('2'), 1, + new String('0') + ); + const ys = filter(xs, (x): x is string => x instanceof String); + + const it = ys[Symbol.asyncIterator](); + await hasNext(t, it, new String('8')); + await hasNext(t, it, new String('7')); + await hasNext(t, it, new String('6')); + await hasNext(t, it, new String('2')); + await hasNext(t, it, new String('0')); + await noNext(t, it); + t.end(); +}); + test('AsyncIterable#filter throws part way through', async t => { const xs = of(8, 5, 7, 4, 6, 9, 2, 1, 0); const err = new Error(); diff --git a/spec/iterable-operators/filter-spec.ts b/spec/iterable-operators/filter-spec.ts index ef3a2b46..3941da49 100644 --- a/spec/iterable-operators/filter-spec.ts +++ b/spec/iterable-operators/filter-spec.ts @@ -33,6 +33,26 @@ test('Iterable#filter with index', t => { t.end(); }); +test('Iterable#filter with typeguard', t => { + const xs = [ + new String('8'), 5, + new String('7'), 4, + new String('6'), 9, + new String('2'), 1, + new String('0') + ]; + const ys = filter(xs, (x): x is string => x instanceof String); + + const it = ys[Symbol.iterator](); + hasNext(t, it, new String('8')); + hasNext(t, it, new String('7')); + hasNext(t, it, new String('6')); + hasNext(t, it, new String('2')); + hasNext(t, it, new String('0')); + noNext(t, it); + t.end(); +}); + test('Iterable#filter throws part way through', t => { const xs = [8, 5, 7, 4, 6, 9, 2, 1, 0]; const err = new Error(); diff --git a/spec/tape-async.d.ts b/spec/tape-async.d.ts index 760049cb..a28f2e90 100644 --- a/spec/tape-async.d.ts +++ b/spec/tape-async.d.ts @@ -1,4 +1,4 @@ -declare module "tape-async" { +declare module 'tape-async' { import * as tape from 'tape'; export = tape; } diff --git a/src/add/asynciterable-operators/every.ts b/src/add/asynciterable-operators/every.ts index 04168bee..4bfb453c 100644 --- a/src/add/asynciterable-operators/every.ts +++ b/src/add/asynciterable-operators/every.ts @@ -1,12 +1,13 @@ import { AsyncIterableX } from '../../asynciterable'; import { every } from '../../asynciterable/every'; +import { booleanAsyncPredicate } from '../../internal/predicates'; /** * @ignore */ export function everyProto( this: AsyncIterableX, - comparer: (value: T, index: number) => boolean | Promise): Promise { + comparer: booleanAsyncPredicate): Promise { return every(this, comparer); } diff --git a/src/add/asynciterable-operators/filter.ts b/src/add/asynciterable-operators/filter.ts index bedabc81..0705bd4b 100644 --- a/src/add/asynciterable-operators/filter.ts +++ b/src/add/asynciterable-operators/filter.ts @@ -1,12 +1,13 @@ import { AsyncIterableX } from '../../asynciterable'; import { filter } from '../../asynciterable/filter'; +import { booleanAsyncPredicate } from '../../internal/predicates'; /** * @ignore */ export function filterProto( this: AsyncIterable, - predicate: (value: TSource, index: number) => Promise | boolean, + predicate: booleanAsyncPredicate, thisArg?: any): AsyncIterableX { return filter(this, predicate, thisArg); } diff --git a/src/add/asynciterable-operators/find.ts b/src/add/asynciterable-operators/find.ts index b63300c0..f4334c6f 100644 --- a/src/add/asynciterable-operators/find.ts +++ b/src/add/asynciterable-operators/find.ts @@ -1,12 +1,13 @@ import { AsyncIterableX } from '../../asynciterable'; import { find } from '../../asynciterable/find'; +import { booleanAsyncPredicate } from '../../internal/predicates'; /** * @ignore */ export function findProto( this: AsyncIterableX, - predicate: (value: T, index: number) => boolean | Promise, + predicate: booleanAsyncPredicate, thisArg?: any): Promise { return find(this, predicate, thisArg); } diff --git a/src/add/asynciterable-operators/first.ts b/src/add/asynciterable-operators/first.ts index 6ef58c4b..31497f8d 100644 --- a/src/add/asynciterable-operators/first.ts +++ b/src/add/asynciterable-operators/first.ts @@ -1,12 +1,13 @@ import { AsyncIterableX } from '../../asynciterable'; import { first } from '../../asynciterable/first'; +import { booleanAsyncPredicate } from '../../internal/predicates'; /** * @ignore */ export function firstProto( this: AsyncIterableX, - fn?: (value: T) => boolean | Promise): Promise { + fn?: booleanAsyncPredicate): Promise { return first(this, fn); } diff --git a/src/add/asynciterable-operators/last.ts b/src/add/asynciterable-operators/last.ts index 7b7f2016..8a4e13fb 100644 --- a/src/add/asynciterable-operators/last.ts +++ b/src/add/asynciterable-operators/last.ts @@ -1,12 +1,13 @@ import { AsyncIterableX } from '../../asynciterable'; import { last } from '../../asynciterable/last'; +import { booleanAsyncPredicate } from '../../internal/predicates'; /** * @ignore */ export function lastProto( this: AsyncIterableX, - selector: (value: T) => boolean | Promise = async () => true): Promise { + selector?: booleanAsyncPredicate): Promise { return last(this, selector); } diff --git a/src/add/asynciterable-operators/partition.ts b/src/add/asynciterable-operators/partition.ts index 610b4242..69456d33 100644 --- a/src/add/asynciterable-operators/partition.ts +++ b/src/add/asynciterable-operators/partition.ts @@ -1,12 +1,13 @@ import { AsyncIterableX } from '../../asynciterable'; import { partition } from '../../asynciterable/partition'; +import { booleanAsyncPredicate } from '../../internal/predicates'; /** * @ignore */ export function partitionProto( this: AsyncIterableX, - fn: (value: T, index: number) => boolean, + fn: booleanAsyncPredicate, thisArg?: any): AsyncIterableX[] { return partition(this, fn, thisArg); } diff --git a/src/add/asynciterable-operators/single.ts b/src/add/asynciterable-operators/single.ts index 8818bdf2..81ad560c 100644 --- a/src/add/asynciterable-operators/single.ts +++ b/src/add/asynciterable-operators/single.ts @@ -1,12 +1,13 @@ import { AsyncIterableX } from '../../asynciterable'; import { single } from '../../asynciterable/single'; +import { booleanAsyncPredicate } from '../../internal/predicates'; /** * @ignore */ export function singleProto( this: AsyncIterableX, - selector: (value: T) => boolean | Promise = async () => true): Promise { + selector?: booleanAsyncPredicate): Promise { return single(this, selector); } diff --git a/src/add/asynciterable-operators/skipwhile.ts b/src/add/asynciterable-operators/skipwhile.ts index d2b81f24..f2e159e2 100644 --- a/src/add/asynciterable-operators/skipwhile.ts +++ b/src/add/asynciterable-operators/skipwhile.ts @@ -1,12 +1,13 @@ import { AsyncIterableX } from '../../asynciterable'; import { skipWhile } from '../../asynciterable/skipwhile'; +import { booleanAsyncPredicate } from '../../internal/predicates'; /** * @ignore */ export function skipWhileProto( this: AsyncIterableX, - predicate: (value: TSource, index: number) => boolean | Promise): AsyncIterableX { + predicate: booleanAsyncPredicate): AsyncIterableX { return skipWhile(this, predicate); } diff --git a/src/add/asynciterable-operators/some.ts b/src/add/asynciterable-operators/some.ts index 383818e9..b6a28e1c 100644 --- a/src/add/asynciterable-operators/some.ts +++ b/src/add/asynciterable-operators/some.ts @@ -1,12 +1,13 @@ import { AsyncIterableX } from '../../asynciterable'; import { some } from '../../asynciterable/some'; +import { booleanAsyncPredicate } from '../../internal/predicates'; /** * @ignore */ export function someProto( this: AsyncIterableX, - comparer: (value: T, index: number) => boolean | Promise): Promise { + comparer: booleanAsyncPredicate): Promise { return some(this, comparer); } diff --git a/src/add/asynciterable-operators/takewhile.ts b/src/add/asynciterable-operators/takewhile.ts index 5ffea243..e3713679 100644 --- a/src/add/asynciterable-operators/takewhile.ts +++ b/src/add/asynciterable-operators/takewhile.ts @@ -1,12 +1,13 @@ import { AsyncIterableX } from '../../asynciterable'; import { takeWhile } from '../../asynciterable/takewhile'; +import { booleanAsyncPredicate } from '../../internal/predicates'; /** * @ignore */ export function takeWhileProto( this: AsyncIterableX, - predicate: (value: TSource, index: number) => boolean | Promise): AsyncIterableX { + predicate: booleanAsyncPredicate): AsyncIterableX { return takeWhile(this, predicate); } diff --git a/src/asynciterable/every.ts b/src/asynciterable/every.ts index dce83cad..851613f8 100644 --- a/src/asynciterable/every.ts +++ b/src/asynciterable/every.ts @@ -1,6 +1,8 @@ +import { booleanAsyncPredicate } from '../internal/predicates'; + export async function every( source: AsyncIterable, - comparer: (value: T, index: number) => boolean | Promise): Promise { + comparer: booleanAsyncPredicate): Promise { let i = 0; for await (let item of source) { if (!await comparer(item, i++)) { return false; } diff --git a/src/asynciterable/filter.ts b/src/asynciterable/filter.ts index 4d50fd74..75537f59 100644 --- a/src/asynciterable/filter.ts +++ b/src/asynciterable/filter.ts @@ -1,13 +1,14 @@ import { AsyncIterableX } from '../asynciterable'; import { bindCallback } from '../internal/bindcallback'; +import { booleanAsyncPredicate } from '../internal/predicates'; class FilterAsyncIterable extends AsyncIterableX { private _source: Iterable> | AsyncIterable; - private _predicate: (value: TSource, index: number) => Promise | boolean; + private _predicate: booleanAsyncPredicate; constructor( source: Iterable> | AsyncIterable, - predicate: (value: TSource, index: number) => Promise | boolean) { + predicate: booleanAsyncPredicate) { super(); this._source = source; this._predicate = predicate; @@ -25,7 +26,7 @@ class FilterAsyncIterable extends AsyncIterableX { export function filter( source: Iterable> | AsyncIterable, - predicate: (value: TSource, index: number) => Promise | boolean, + predicate: booleanAsyncPredicate, thisArg?: any): AsyncIterableX { return new FilterAsyncIterable(source, bindCallback(predicate, thisArg, 2)); } diff --git a/src/asynciterable/find.ts b/src/asynciterable/find.ts index 07da3e48..9a5940be 100644 --- a/src/asynciterable/find.ts +++ b/src/asynciterable/find.ts @@ -1,8 +1,9 @@ import { bindCallback } from '../internal/bindcallback'; +import { booleanAsyncPredicate } from '../internal/predicates'; export async function find( source: AsyncIterable, - predicate: (value: T, index: number) => boolean | Promise, + predicate: booleanAsyncPredicate, thisArg?: any): Promise { const fn = bindCallback(predicate, thisArg, 2); let i = 0; diff --git a/src/asynciterable/first.ts b/src/asynciterable/first.ts index 5f8e3f14..7384057f 100644 --- a/src/asynciterable/first.ts +++ b/src/asynciterable/first.ts @@ -1,8 +1,11 @@ +import { booleanAsyncPredicate } from '../internal/predicates'; + export async function first( source: AsyncIterable, - predicate: (value: T) => boolean | Promise = async () => true): Promise { + predicate: booleanAsyncPredicate = async () => true): Promise { + let i = 0; for await (let item of source) { - if (await predicate(item)) { + if (await predicate(item, i++)) { return item; } } diff --git a/src/asynciterable/last.ts b/src/asynciterable/last.ts index b07ff619..c65849a3 100644 --- a/src/asynciterable/last.ts +++ b/src/asynciterable/last.ts @@ -1,9 +1,11 @@ +import { booleanAsyncPredicate } from '../internal/predicates'; + export async function last( source: AsyncIterable, - fn: (value: T) => boolean | Promise = async () => true): Promise { - let result: T | undefined; + fn: booleanAsyncPredicate = async () => true): Promise { + let i = 0, result: T | undefined; for await (let item of source) { - if (await fn(item)) { + if (await fn(item, i++)) { result = item; } } diff --git a/src/asynciterable/partition.ts b/src/asynciterable/partition.ts index af7f489f..0be4a021 100644 --- a/src/asynciterable/partition.ts +++ b/src/asynciterable/partition.ts @@ -1,9 +1,10 @@ import { AsyncIterableX } from '../asynciterable'; import { filter } from './filter'; +import { booleanAsyncPredicate } from '../internal/predicates'; export function partition( source: AsyncIterable, - predicate: (value: TSource, index: number) => boolean | Promise, + predicate: booleanAsyncPredicate, thisArg?: any): AsyncIterableX[] { return [ filter(source, predicate, thisArg), diff --git a/src/asynciterable/single.ts b/src/asynciterable/single.ts index d67ecb29..ad76b21e 100644 --- a/src/asynciterable/single.ts +++ b/src/asynciterable/single.ts @@ -1,13 +1,16 @@ +import { booleanAsyncPredicate } from '../internal/predicates'; + export async function single( source: AsyncIterable, - selector: (value: T) => boolean | Promise = () => true): Promise { + selector: booleanAsyncPredicate = () => true): Promise { let result: T | undefined; let hasResult = false; + let i = 0; for await (let item of source) { - if (hasResult && await selector(item)) { + if (hasResult && await selector(item, i++)) { throw new Error('More than one element was found'); } - if (await selector(item)) { + if (await selector(item, i++)) { result = item; hasResult = true; } diff --git a/src/asynciterable/skipwhile.ts b/src/asynciterable/skipwhile.ts index d45420f0..f5e1376f 100644 --- a/src/asynciterable/skipwhile.ts +++ b/src/asynciterable/skipwhile.ts @@ -1,12 +1,13 @@ import { AsyncIterableX } from '../asynciterable'; +import { booleanAsyncPredicate } from '../internal/predicates'; class SkipWhileAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; - private _predicate: (value: TSource, index: number) => boolean | Promise; + private _predicate: booleanAsyncPredicate; constructor( source: AsyncIterable, - predicate: (value: TSource, index: number) => boolean | Promise) { + predicate: booleanAsyncPredicate) { super(); this._source = source; this._predicate = predicate; @@ -23,6 +24,6 @@ class SkipWhileAsyncIterable extends AsyncIterableX { export function skipWhile( source: AsyncIterable, - predicate: (value: TSource, index: number) => boolean | Promise): AsyncIterableX { + predicate: booleanAsyncPredicate): AsyncIterableX { return new SkipWhileAsyncIterable(source, predicate); } diff --git a/src/asynciterable/some.ts b/src/asynciterable/some.ts index 58a67784..7533c3fb 100644 --- a/src/asynciterable/some.ts +++ b/src/asynciterable/some.ts @@ -1,6 +1,8 @@ +import { booleanAsyncPredicate } from '../internal/predicates'; + export async function some( source: AsyncIterable, - comparer: (value: T, index: number) => boolean | Promise): Promise { + comparer: booleanAsyncPredicate): Promise { let i = 0; for await (let item of source) { if (await comparer(item, i++)) { return true; } diff --git a/src/asynciterable/takewhile.ts b/src/asynciterable/takewhile.ts index 3908f3a0..d50c8849 100644 --- a/src/asynciterable/takewhile.ts +++ b/src/asynciterable/takewhile.ts @@ -1,12 +1,13 @@ import { AsyncIterableX } from '../asynciterable'; +import { booleanAsyncPredicate } from '../internal/predicates'; class TakeWhileAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; - private _predicate: (value: TSource, index: number) => boolean | Promise; + private _predicate: booleanAsyncPredicate; constructor( source: AsyncIterable, - predicate: (value: TSource, index: number) => boolean | Promise) { + predicate: booleanAsyncPredicate) { super(); this._source = source; this._predicate = predicate; @@ -23,6 +24,6 @@ class TakeWhileAsyncIterable extends AsyncIterableX { export function takeWhile( source: AsyncIterable, - predicate: (value: TSource, index: number) => boolean| Promise): AsyncIterableX { + predicate: booleanAsyncPredicate): AsyncIterableX { return new TakeWhileAsyncIterable(source, predicate); } diff --git a/src/internal/predicates.ts b/src/internal/predicates.ts new file mode 100644 index 00000000..4276a96f --- /dev/null +++ b/src/internal/predicates.ts @@ -0,0 +1,8 @@ +export type booleanPredicate = +{ (value: T, index: number): boolean } | +{ (value: T, index: number): value is T }; + +export type booleanAsyncPredicate = +{ (value: T, index: number): boolean } | +{ (value: T, index: number): value is T } | +{ (value: T, index: number): Promise } ; diff --git a/src/iterable/every.ts b/src/iterable/every.ts index 6dd816e9..577ea46c 100644 --- a/src/iterable/every.ts +++ b/src/iterable/every.ts @@ -1,3 +1,4 @@ +import { booleanPredicate } from '../internal/predicates'; /** * Determines whether every element of a sequence satisfy a condition. * @param {Iterable} source Source sequence. @@ -7,7 +8,7 @@ */ export function every( source: Iterable, - comparer: (value: T, index: number) => boolean): boolean { + comparer: booleanPredicate): boolean { let i = 0; for (let item of source) { if (!comparer(item, i++)) { return false; } diff --git a/src/iterable/filter.ts b/src/iterable/filter.ts index 0c84ccdb..de3d93ac 100644 --- a/src/iterable/filter.ts +++ b/src/iterable/filter.ts @@ -1,5 +1,6 @@ import { IterableX } from '../iterable'; import { bindCallback } from '../internal/bindcallback'; +import { booleanPredicate } from '../internal/predicates'; class FilterIterable extends IterableX { private _source: Iterable; @@ -30,7 +31,7 @@ class FilterIterable extends IterableX { */ export function filter( source: Iterable, - predicate: (value: T, index: number) => boolean, + predicate: booleanPredicate, thisArg?: any): IterableX { return new FilterIterable(source, bindCallback(predicate, thisArg, 2)); } diff --git a/src/iterable/filterasync.ts b/src/iterable/filterasync.ts index 291ada72..1592190a 100644 --- a/src/iterable/filterasync.ts +++ b/src/iterable/filterasync.ts @@ -1,5 +1,6 @@ import { AsyncIterableX } from '../asynciterable'; import { bindCallback } from '../internal/bindcallback'; +import { booleanAsyncPredicate } from '../internal/predicates'; class FilterIterable extends AsyncIterableX { private _source: Iterable> | AsyncIterable; @@ -32,7 +33,7 @@ class FilterIterable extends AsyncIterableX { */ export function filterAsync( source: Iterable> | AsyncIterable, - predicate: (value: TSource, index: number) => boolean | Promise, + predicate: booleanAsyncPredicate, thisArg?: any): AsyncIterableX { return new FilterIterable(source, bindCallback(predicate, thisArg, 2)); } diff --git a/src/iterable/find.ts b/src/iterable/find.ts index 0818da65..5b742d36 100644 --- a/src/iterable/find.ts +++ b/src/iterable/find.ts @@ -1,4 +1,5 @@ import { bindCallback } from '../internal/bindcallback'; +import { booleanPredicate } from '../internal/predicates'; /** * Returns the value of the first element in the sequence that satisfies the provided testing function. @@ -11,7 +12,7 @@ import { bindCallback } from '../internal/bindcallback'; */ export function find( source: Iterable, - predicate: (value: T, index: number) => boolean, + predicate: booleanPredicate, thisArg?: any): T | undefined { if (typeof predicate !== 'function') { throw new TypeError(); } const f = bindCallback(predicate, thisArg, 2); diff --git a/src/iterable/findindex.ts b/src/iterable/findindex.ts index c70a3fbd..819b1279 100644 --- a/src/iterable/findindex.ts +++ b/src/iterable/findindex.ts @@ -1,6 +1,7 @@ import { bindCallback } from '../internal/bindcallback'; +import { booleanPredicate } from '../internal/predicates'; -export function findIndex(source: Iterable, fn: (value: T, index: number) => boolean, thisArg?: any): number { +export function findIndex(source: Iterable, fn: booleanPredicate, thisArg?: any): number { if (typeof fn !== 'function') { throw new TypeError(); } const f = bindCallback(fn, thisArg, 2); let i = 0; diff --git a/src/iterable/first.ts b/src/iterable/first.ts index 1e00f50a..6aa807b8 100644 --- a/src/iterable/first.ts +++ b/src/iterable/first.ts @@ -1,3 +1,5 @@ +import { booleanPredicate } from '../internal/predicates'; + /** * Returns the first element in a sequence that satisfies a specified condition if provided, else * the first element in the sequence. @@ -9,9 +11,10 @@ */ export function first( source: Iterable, - selector: (value: T) => boolean = () => true): T | undefined { + selector: booleanPredicate = () => true): T | undefined { + let i = 0; for (let item of source) { - if (selector(item)) { + if (selector(item, i++)) { return item; } } diff --git a/src/iterable/last.ts b/src/iterable/last.ts index 0b7b28f1..b59644b7 100644 --- a/src/iterable/last.ts +++ b/src/iterable/last.ts @@ -1,7 +1,9 @@ -export function last(source: Iterable, fn: (value: T) => boolean = () => true): T | undefined { - let result: T | undefined; +import { booleanPredicate } from '../internal/predicates'; + +export function last(source: Iterable, fn: booleanPredicate = () => true): T | undefined { + let i = 0, result: T | undefined; for (let item of source) { - if (fn(item)) { + if (fn(item, i++)) { result = item; } } diff --git a/src/iterable/single.ts b/src/iterable/single.ts index 30c1562e..411f2b96 100644 --- a/src/iterable/single.ts +++ b/src/iterable/single.ts @@ -1,11 +1,14 @@ -export function single(source: Iterable, fn: (value: T) => boolean = () => true): T | undefined { +import { booleanPredicate } from '../internal/predicates'; + +export function single(source: Iterable, fn: booleanPredicate = () => true): T | undefined { let result: T | undefined; let hasResult = false; + let i = 0; for (let item of source) { - if (hasResult && fn(item)) { + if (hasResult && fn(item, i++)) { throw new Error('More than one element was found'); } - if (fn(item)) { + if (fn(item, i++)) { result = item; hasResult = true; } diff --git a/src/iterable/skipwhile.ts b/src/iterable/skipwhile.ts index a57d5cac..cd947c12 100644 --- a/src/iterable/skipwhile.ts +++ b/src/iterable/skipwhile.ts @@ -1,10 +1,11 @@ import { IterableX } from '../iterable'; +import { booleanPredicate } from '../internal/predicates'; class SkipWhileIterable extends IterableX { private _source: Iterable; - private _predicate: (value: TSource, index: number) => boolean; + private _predicate: booleanPredicate; - constructor(source: Iterable, predicate: (value: TSource, index: number) => boolean) { + constructor(source: Iterable, predicate: booleanPredicate) { super(); this._source = source; this._predicate = predicate; @@ -21,6 +22,6 @@ class SkipWhileIterable extends IterableX { export function skipWhile( source: Iterable, - predicate: (value: TSource, index: number) => boolean): IterableX { + predicate: booleanPredicate): IterableX { return new SkipWhileIterable(source, predicate); } diff --git a/src/iterable/some.ts b/src/iterable/some.ts index 702f8022..6218fbdf 100644 --- a/src/iterable/some.ts +++ b/src/iterable/some.ts @@ -1,6 +1,8 @@ +import { booleanPredicate } from '../internal/predicates'; + export function some( source: Iterable, - comparer: (value: T, index: number) => boolean): boolean { + comparer: booleanPredicate): boolean { let i = 0; for (let item of source) { if (comparer(item, i++)) { return true; } diff --git a/src/iterable/takewhile.ts b/src/iterable/takewhile.ts index e184c331..9ef4aa95 100644 --- a/src/iterable/takewhile.ts +++ b/src/iterable/takewhile.ts @@ -1,8 +1,9 @@ import { IterableX } from '../iterable'; +import { booleanPredicate } from '../internal/predicates'; class TakeWhileIterable extends IterableX { private _source: Iterable; - private _predicate: (value: TSource, index: number) => boolean; + private _predicate: booleanPredicate; constructor(source: Iterable, predicate: (value: TSource, index: number) => boolean) { super(); @@ -21,6 +22,6 @@ class TakeWhileIterable extends IterableX { export function takeWhile( source: Iterable, - predicate: (value: TSource, index: number) => boolean): IterableX { + predicate: booleanPredicate): IterableX { return new TakeWhileIterable(source, predicate); }