From 94cad279d292aa9e281fcfb5b6c0056d2af2c1f5 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 10 Oct 2017 00:26:22 -0400 Subject: [PATCH 001/106] feat(pipe): add piped operators --- src/asynciterable/buffer.ts | 2 +- src/asynciterable/catchwith.ts | 2 +- src/asynciterable/pipe.ts | 29 +++++++++++++++++++++++++++++ src/asynciterable/pipe/buffer.ts | 12 ++++++++++++ src/asynciterable/pipe/catchwith.ts | 10 ++++++++++ src/interfaces.ts | 12 ++++++++++++ 6 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 src/asynciterable/pipe.ts create mode 100644 src/asynciterable/pipe/buffer.ts create mode 100644 src/asynciterable/pipe/catchwith.ts create mode 100644 src/interfaces.ts diff --git a/src/asynciterable/buffer.ts b/src/asynciterable/buffer.ts index 14c50af4..ca8f1c0a 100644 --- a/src/asynciterable/buffer.ts +++ b/src/asynciterable/buffer.ts @@ -1,6 +1,6 @@ import { AsyncIterableX } from '../asynciterable'; -class BufferAsyncIterable extends AsyncIterableX { +export class BufferAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; private _count: number; private _skip: number; diff --git a/src/asynciterable/catchwith.ts b/src/asynciterable/catchwith.ts index 2b53f826..45982f9d 100644 --- a/src/asynciterable/catchwith.ts +++ b/src/asynciterable/catchwith.ts @@ -1,7 +1,7 @@ import { AsyncIterableX } from '../asynciterable'; import { returnAsyncIterator } from '../internal/returniterator'; -class CatchWithAsyncIterable extends AsyncIterableX { +export class CatchWithAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; private _handler: (error: any) => AsyncIterable | Promise>; diff --git a/src/asynciterable/pipe.ts b/src/asynciterable/pipe.ts new file mode 100644 index 00000000..89d2b860 --- /dev/null +++ b/src/asynciterable/pipe.ts @@ -0,0 +1,29 @@ +import { OperatorAsyncFunction } from '../interfaces'; +import { AsyncIterableX } from '../asynciterable'; + +/* tslint:disable:max-line-length */ +export function pipe(source: AsyncIterable): AsyncIterableX; +export function pipe(source: AsyncIterable, op1: OperatorAsyncFunction): AsyncIterableX; +export function pipe(source: AsyncIterable, op1: OperatorAsyncFunction, op2: OperatorAsyncFunction): AsyncIterableX; +export function pipe(source: AsyncIterable, op1: OperatorAsyncFunction, op2: OperatorAsyncFunction, op3: OperatorAsyncFunction): AsyncIterableX; +export function pipe(source: AsyncIterable, op1: OperatorAsyncFunction, op2: OperatorAsyncFunction, op3: OperatorAsyncFunction, op4: OperatorAsyncFunction): AsyncIterableX; +export function pipe(source: AsyncIterable, op1: OperatorAsyncFunction, op2: OperatorAsyncFunction, op3: OperatorAsyncFunction, op4: OperatorAsyncFunction, op5: OperatorAsyncFunction): AsyncIterableX; +export function pipe(source: AsyncIterable, op1: OperatorAsyncFunction, op2: OperatorAsyncFunction, op3: OperatorAsyncFunction, op4: OperatorAsyncFunction, op5: OperatorAsyncFunction, op6: OperatorAsyncFunction): AsyncIterableX; +export function pipe(source: AsyncIterable, op1: OperatorAsyncFunction, op2: OperatorAsyncFunction, op3: OperatorAsyncFunction, op4: OperatorAsyncFunction, op5: OperatorAsyncFunction, op6: OperatorAsyncFunction, op7: OperatorAsyncFunction): AsyncIterableX; +export function pipe(source: AsyncIterable, op1: OperatorAsyncFunction, op2: OperatorAsyncFunction, op3: OperatorAsyncFunction, op4: OperatorAsyncFunction, op5: OperatorAsyncFunction, op6: OperatorAsyncFunction, op7: OperatorAsyncFunction, op8: OperatorAsyncFunction): AsyncIterableX; +export function pipe(source: AsyncIterable, op1: OperatorAsyncFunction, op2: OperatorAsyncFunction, op3: OperatorAsyncFunction, op4: OperatorAsyncFunction, op5: OperatorAsyncFunction, op6: OperatorAsyncFunction, op7: OperatorAsyncFunction, op8: OperatorAsyncFunction, op9: OperatorAsyncFunction): AsyncIterableX; +/* tslint:enable:max-line-length */ + +export function pipe( + source: AsyncIterable, + ...operations: OperatorAsyncFunction[]): AsyncIterableX { + if (operations.length === 0) { + return source as any; + } + + const piped = (input: AsyncIterable): AsyncIterableX => { + return operations.reduce((prev: any, fn: OperatorAsyncFunction) => fn(prev), input); + }; + + return piped(source); +} diff --git a/src/asynciterable/pipe/buffer.ts b/src/asynciterable/pipe/buffer.ts new file mode 100644 index 00000000..e733aad8 --- /dev/null +++ b/src/asynciterable/pipe/buffer.ts @@ -0,0 +1,12 @@ +import { OperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { BufferAsyncIterable } from '../buffer'; + +export function buffer( + count: number, + skip?: number): OperatorAsyncFunction { + if (skip == null) { skip = count; } + return function bufferOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new BufferAsyncIterable(source, count, skip!); + }; +} diff --git a/src/asynciterable/pipe/catchwith.ts b/src/asynciterable/pipe/catchwith.ts new file mode 100644 index 00000000..2063598b --- /dev/null +++ b/src/asynciterable/pipe/catchwith.ts @@ -0,0 +1,10 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { CatchWithAsyncIterable } from '../catchwith'; + +export function catchWith( + handler: (error: any) => AsyncIterable | Promise>): MonoTypeOperatorAsyncFunction { + return function catchWithOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new CatchWithAsyncIterable(source, handler); + }; +} diff --git a/src/interfaces.ts b/src/interfaces.ts new file mode 100644 index 00000000..887704b5 --- /dev/null +++ b/src/interfaces.ts @@ -0,0 +1,12 @@ +import { IterableX } from './iterable'; +import { AsyncIterableX } from './asynciterable'; + +export type UnaryFunction = (source: T) => R; + +export type OperatorFunction = UnaryFunction, IterableX>; + +export type OperatorAsyncFunction = UnaryFunction, AsyncIterableX>; + +export type MonoTypeOperatorFunction = OperatorFunction; + +export type MonoTypeOperatorAsyncFunction = OperatorAsyncFunction; From 336f46f05908feff9a99e664fa9d4fc433dfe88c Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 16 Oct 2017 23:19:22 -0400 Subject: [PATCH 002/106] feat(pipe): add through concat --- src/asynciterable/concat.ts | 93 +++++++++++++++++++++-------- src/asynciterable/concatall.ts | 24 ++++++++ src/asynciterable/pipe.ts | 91 ++++++++++++++++++++++++---- src/asynciterable/pipe/buffer.ts | 13 ++-- src/asynciterable/pipe/catchwith.ts | 7 ++- src/asynciterable/pipe/concat.ts | 0 6 files changed, 186 insertions(+), 42 deletions(-) create mode 100644 src/asynciterable/concatall.ts create mode 100644 src/asynciterable/pipe/concat.ts diff --git a/src/asynciterable/concat.ts b/src/asynciterable/concat.ts index 25d292a6..ebd3b516 100644 --- a/src/asynciterable/concat.ts +++ b/src/asynciterable/concat.ts @@ -1,23 +1,6 @@ import { AsyncIterableX } from '../asynciterable'; -class ConcatAllAsyncIterable extends AsyncIterableX { - private _source: AsyncIterable>; - - constructor(source: AsyncIterable>) { - super(); - this._source = source; - } - - async *[Symbol.asyncIterator]() { - for await (let outer of this._source) { - for await (let item of outer) { - yield item; - } - } - } -} - -class ConcatAsyncIterable extends AsyncIterableX { +export class ConcatAsyncIterable extends AsyncIterableX { private _source: Iterable>; constructor(source: Iterable>) { @@ -34,18 +17,46 @@ class ConcatAsyncIterable extends AsyncIterableX { } } -export function concatAll( - source: AsyncIterable> -): AsyncIterableX { - return new ConcatAllAsyncIterable(source); -} - export function _concatAll( source: Iterable> ): AsyncIterableX { return new ConcatAsyncIterable(source); } +/* tslint:disable:max-line-length */ +export function concat(source: AsyncIterable): AsyncIterableX; +export function concat( + source: AsyncIterable, + v2: AsyncIterable +): AsyncIterableX; +export function concat( + source: AsyncIterable, + v2: AsyncIterable, + v3: AsyncIterable +): AsyncIterableX; +export function concat( + source: AsyncIterable, + v2: AsyncIterable, + v3: AsyncIterable, + v4: AsyncIterable +): AsyncIterableX; +export function concat( + source: AsyncIterable, + v2: AsyncIterable, + v3: AsyncIterable, + v4: AsyncIterable, + v5: AsyncIterable +): AsyncIterable; +export function concat( + source: AsyncIterable, + v2: AsyncIterable, + v3: AsyncIterable, + v4: AsyncIterable, + v5: AsyncIterable, + v6: AsyncIterable +): AsyncIterable; +/* tslint:enable:max-line-length */ + export function concat( source: AsyncIterable, ...args: AsyncIterable[] @@ -53,6 +64,40 @@ export function concat( return new ConcatAsyncIterable([source, ...args]); } +/* tslint:disable:max-line-length */ +export function concatStatic(v1: AsyncIterable): AsyncIterableX; +export function concatStatic( + v1: AsyncIterable, + v2: AsyncIterable +): AsyncIterableX; +export function concatStatic( + v1: AsyncIterable, + v2: AsyncIterable, + v3: AsyncIterable +): AsyncIterableX; +export function concatStatic( + v1: AsyncIterable, + v2: AsyncIterable, + v3: AsyncIterable, + v4: AsyncIterable +): AsyncIterableX; +export function concatStatic( + v1: AsyncIterable, + v2: AsyncIterable, + v3: AsyncIterable, + v4: AsyncIterable, + v5: AsyncIterable +): AsyncIterable; +export function concatStatic( + v1: AsyncIterable, + v2: AsyncIterable, + v3: AsyncIterable, + v4: AsyncIterable, + v5: AsyncIterable, + v6: AsyncIterable +): AsyncIterable; +/* tslint:enable:max-line-length */ + export function concatStatic(...args: AsyncIterable[]): AsyncIterableX { return new ConcatAsyncIterable(args); } diff --git a/src/asynciterable/concatall.ts b/src/asynciterable/concatall.ts new file mode 100644 index 00000000..f7525d30 --- /dev/null +++ b/src/asynciterable/concatall.ts @@ -0,0 +1,24 @@ +import { AsyncIterableX } from '../asynciterable'; + +export class ConcatAllAsyncIterable extends AsyncIterableX { + private _source: AsyncIterable>; + + constructor(source: AsyncIterable>) { + super(); + this._source = source; + } + + async *[Symbol.asyncIterator]() { + for await (let outer of this._source) { + for await (let item of outer) { + yield item; + } + } + } +} + +export function concatAll( + source: AsyncIterable> +): AsyncIterableX { + return new ConcatAllAsyncIterable(source); +} diff --git a/src/asynciterable/pipe.ts b/src/asynciterable/pipe.ts index 89d2b860..b921905c 100644 --- a/src/asynciterable/pipe.ts +++ b/src/asynciterable/pipe.ts @@ -3,26 +3,93 @@ import { AsyncIterableX } from '../asynciterable'; /* tslint:disable:max-line-length */ export function pipe(source: AsyncIterable): AsyncIterableX; -export function pipe(source: AsyncIterable, op1: OperatorAsyncFunction): AsyncIterableX; -export function pipe(source: AsyncIterable, op1: OperatorAsyncFunction, op2: OperatorAsyncFunction): AsyncIterableX; -export function pipe(source: AsyncIterable, op1: OperatorAsyncFunction, op2: OperatorAsyncFunction, op3: OperatorAsyncFunction): AsyncIterableX; -export function pipe(source: AsyncIterable, op1: OperatorAsyncFunction, op2: OperatorAsyncFunction, op3: OperatorAsyncFunction, op4: OperatorAsyncFunction): AsyncIterableX; -export function pipe(source: AsyncIterable, op1: OperatorAsyncFunction, op2: OperatorAsyncFunction, op3: OperatorAsyncFunction, op4: OperatorAsyncFunction, op5: OperatorAsyncFunction): AsyncIterableX; -export function pipe(source: AsyncIterable, op1: OperatorAsyncFunction, op2: OperatorAsyncFunction, op3: OperatorAsyncFunction, op4: OperatorAsyncFunction, op5: OperatorAsyncFunction, op6: OperatorAsyncFunction): AsyncIterableX; -export function pipe(source: AsyncIterable, op1: OperatorAsyncFunction, op2: OperatorAsyncFunction, op3: OperatorAsyncFunction, op4: OperatorAsyncFunction, op5: OperatorAsyncFunction, op6: OperatorAsyncFunction, op7: OperatorAsyncFunction): AsyncIterableX; -export function pipe(source: AsyncIterable, op1: OperatorAsyncFunction, op2: OperatorAsyncFunction, op3: OperatorAsyncFunction, op4: OperatorAsyncFunction, op5: OperatorAsyncFunction, op6: OperatorAsyncFunction, op7: OperatorAsyncFunction, op8: OperatorAsyncFunction): AsyncIterableX; -export function pipe(source: AsyncIterable, op1: OperatorAsyncFunction, op2: OperatorAsyncFunction, op3: OperatorAsyncFunction, op4: OperatorAsyncFunction, op5: OperatorAsyncFunction, op6: OperatorAsyncFunction, op7: OperatorAsyncFunction, op8: OperatorAsyncFunction, op9: OperatorAsyncFunction): AsyncIterableX; +export function pipe( + source: AsyncIterable, + op1: OperatorAsyncFunction +): AsyncIterableX; +export function pipe( + source: AsyncIterable, + op1: OperatorAsyncFunction, + op2: OperatorAsyncFunction +): AsyncIterableX; +export function pipe( + source: AsyncIterable, + op1: OperatorAsyncFunction, + op2: OperatorAsyncFunction, + op3: OperatorAsyncFunction +): AsyncIterableX; +export function pipe( + source: AsyncIterable, + op1: OperatorAsyncFunction, + op2: OperatorAsyncFunction, + op3: OperatorAsyncFunction, + op4: OperatorAsyncFunction +): AsyncIterableX; +export function pipe( + source: AsyncIterable, + op1: OperatorAsyncFunction, + op2: OperatorAsyncFunction, + op3: OperatorAsyncFunction, + op4: OperatorAsyncFunction, + op5: OperatorAsyncFunction +): AsyncIterableX; +export function pipe( + source: AsyncIterable, + op1: OperatorAsyncFunction, + op2: OperatorAsyncFunction, + op3: OperatorAsyncFunction, + op4: OperatorAsyncFunction, + op5: OperatorAsyncFunction, + op6: OperatorAsyncFunction +): AsyncIterableX; +export function pipe( + source: AsyncIterable, + op1: OperatorAsyncFunction, + op2: OperatorAsyncFunction, + op3: OperatorAsyncFunction, + op4: OperatorAsyncFunction, + op5: OperatorAsyncFunction, + op6: OperatorAsyncFunction, + op7: OperatorAsyncFunction +): AsyncIterableX; +export function pipe( + source: AsyncIterable, + op1: OperatorAsyncFunction, + op2: OperatorAsyncFunction, + op3: OperatorAsyncFunction, + op4: OperatorAsyncFunction, + op5: OperatorAsyncFunction, + op6: OperatorAsyncFunction, + op7: OperatorAsyncFunction, + op8: OperatorAsyncFunction +): AsyncIterableX; +export function pipe( + source: AsyncIterable, + op1: OperatorAsyncFunction, + op2: OperatorAsyncFunction, + op3: OperatorAsyncFunction, + op4: OperatorAsyncFunction, + op5: OperatorAsyncFunction, + op6: OperatorAsyncFunction, + op7: OperatorAsyncFunction, + op8: OperatorAsyncFunction, + op9: OperatorAsyncFunction +): AsyncIterableX; /* tslint:enable:max-line-length */ export function pipe( - source: AsyncIterable, - ...operations: OperatorAsyncFunction[]): AsyncIterableX { + source: AsyncIterable, + ...operations: OperatorAsyncFunction[] +): AsyncIterableX { if (operations.length === 0) { return source as any; } const piped = (input: AsyncIterable): AsyncIterableX => { - return operations.reduce((prev: any, fn: OperatorAsyncFunction) => fn(prev), input); + return operations.reduce( + (prev: any, fn: OperatorAsyncFunction) => fn(prev), + input + ); }; return piped(source); diff --git a/src/asynciterable/pipe/buffer.ts b/src/asynciterable/pipe/buffer.ts index e733aad8..d70b9033 100644 --- a/src/asynciterable/pipe/buffer.ts +++ b/src/asynciterable/pipe/buffer.ts @@ -3,10 +3,15 @@ import { AsyncIterableX } from '../../asynciterable'; import { BufferAsyncIterable } from '../buffer'; export function buffer( - count: number, - skip?: number): OperatorAsyncFunction { - if (skip == null) { skip = count; } - return function bufferOperatorFunction(source: AsyncIterable): AsyncIterableX { + count: number, + skip?: number +): OperatorAsyncFunction { + if (skip == null) { + skip = count; + } + return function bufferOperatorFunction( + source: AsyncIterable + ): AsyncIterableX { return new BufferAsyncIterable(source, count, skip!); }; } diff --git a/src/asynciterable/pipe/catchwith.ts b/src/asynciterable/pipe/catchwith.ts index 2063598b..dce94839 100644 --- a/src/asynciterable/pipe/catchwith.ts +++ b/src/asynciterable/pipe/catchwith.ts @@ -3,8 +3,11 @@ import { AsyncIterableX } from '../../asynciterable'; import { CatchWithAsyncIterable } from '../catchwith'; export function catchWith( - handler: (error: any) => AsyncIterable | Promise>): MonoTypeOperatorAsyncFunction { - return function catchWithOperatorFunction(source: AsyncIterable): AsyncIterableX { + handler: (error: any) => AsyncIterable | Promise> +): MonoTypeOperatorAsyncFunction { + return function catchWithOperatorFunction( + source: AsyncIterable + ): AsyncIterableX { return new CatchWithAsyncIterable(source, handler); }; } diff --git a/src/asynciterable/pipe/concat.ts b/src/asynciterable/pipe/concat.ts new file mode 100644 index 00000000..e69de29b From a7e7ad795b29aa7598ccef7326fff16f2a76ee15 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 23 Oct 2017 13:13:36 -0400 Subject: [PATCH 003/106] feat(pipe): add through defaultIfEmpty --- src/asynciterable/debounce.ts | 2 +- src/asynciterable/defaultifempty.ts | 2 +- src/asynciterable/pipe/concat.ts | 39 ++++++++++++++++++++++++ src/asynciterable/pipe/concatall.ts | 9 ++++++ src/asynciterable/pipe/debounce.ts | 11 +++++++ src/asynciterable/pipe/defaultifempty.ts | 9 ++++++ 6 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 src/asynciterable/pipe/concatall.ts create mode 100644 src/asynciterable/pipe/debounce.ts create mode 100644 src/asynciterable/pipe/defaultifempty.ts diff --git a/src/asynciterable/debounce.ts b/src/asynciterable/debounce.ts index 74c85dca..4b205148 100644 --- a/src/asynciterable/debounce.ts +++ b/src/asynciterable/debounce.ts @@ -1,7 +1,7 @@ import { AsyncIterableX } from '../asynciterable'; import { forEach } from './foreach'; -class DebounceAsyncIterable extends AsyncIterableX { +export class DebounceAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; private _time: number; diff --git a/src/asynciterable/defaultifempty.ts b/src/asynciterable/defaultifempty.ts index ece366ce..75e74c61 100644 --- a/src/asynciterable/defaultifempty.ts +++ b/src/asynciterable/defaultifempty.ts @@ -1,6 +1,6 @@ import { AsyncIterableX } from '../asynciterable'; -class DefaultIfEmptyAsyncIterable extends AsyncIterableX { +export class DefaultIfEmptyAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; private _defaultValue: TSource; diff --git a/src/asynciterable/pipe/concat.ts b/src/asynciterable/pipe/concat.ts index e69de29b..f754c94c 100644 --- a/src/asynciterable/pipe/concat.ts +++ b/src/asynciterable/pipe/concat.ts @@ -0,0 +1,39 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { ConcatAsyncIterable } from '../concat'; + +/* tslint:disable:max-line-length */ +export function concat( + v2: AsyncIterable +): MonoTypeOperatorAsyncFunction; +export function concat( + v2: AsyncIterable, + v3: AsyncIterable +): MonoTypeOperatorAsyncFunction; +export function concat( + v2: AsyncIterable, + v3: AsyncIterable, + v4: AsyncIterable +): MonoTypeOperatorAsyncFunction; +export function concat( + v2: AsyncIterable, + v3: AsyncIterable, + v4: AsyncIterable, + v5: AsyncIterable +): MonoTypeOperatorAsyncFunction; +export function concat( + v2: AsyncIterable, + v3: AsyncIterable, + v4: AsyncIterable, + v5: AsyncIterable, + v6: AsyncIterable +): MonoTypeOperatorAsyncFunction; +/* tslint:enable:max-line-length */ + +export function concat( + ...args: AsyncIterable[] +): MonoTypeOperatorAsyncFunction { + return function concatOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new ConcatAsyncIterable([source, ...args]); + }; +} diff --git a/src/asynciterable/pipe/concatall.ts b/src/asynciterable/pipe/concatall.ts new file mode 100644 index 00000000..f979ba3a --- /dev/null +++ b/src/asynciterable/pipe/concatall.ts @@ -0,0 +1,9 @@ +import { OperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { ConcatAllAsyncIterable } from '../concatall'; + +export function concatAll(): OperatorAsyncFunction, T> { + return function concatAllOperatorFunction(source: AsyncIterable>): AsyncIterableX { + return new ConcatAllAsyncIterable(source); + }; +} diff --git a/src/asynciterable/pipe/debounce.ts b/src/asynciterable/pipe/debounce.ts new file mode 100644 index 00000000..93a74057 --- /dev/null +++ b/src/asynciterable/pipe/debounce.ts @@ -0,0 +1,11 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { DebounceAsyncIterable } from '../debounce'; + +export function debounce( + time: number +): MonoTypeOperatorAsyncFunction { + return function debounceOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new DebounceAsyncIterable(source, time); + }; +} diff --git a/src/asynciterable/pipe/defaultifempty.ts b/src/asynciterable/pipe/defaultifempty.ts new file mode 100644 index 00000000..f434fdc4 --- /dev/null +++ b/src/asynciterable/pipe/defaultifempty.ts @@ -0,0 +1,9 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { DefaultIfEmptyAsyncIterable } from '../defaultifempty'; + +export function defaultIfEmpty(defaultValue: T): MonoTypeOperatorAsyncFunction { + return function defaultIfEmptyOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new DefaultIfEmptyAsyncIterable(source, defaultValue); + }; +} From 152fc062f12a59af634e88382e823763f6ba4118 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 23 Oct 2017 13:27:02 -0400 Subject: [PATCH 004/106] feat(pipe): add through delay --- src/asynciterable/delay.ts | 2 +- src/asynciterable/pipe/delay.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/delay.ts diff --git a/src/asynciterable/delay.ts b/src/asynciterable/delay.ts index 646facbc..733be58b 100644 --- a/src/asynciterable/delay.ts +++ b/src/asynciterable/delay.ts @@ -1,7 +1,7 @@ import { AsyncIterableX } from '../asynciterable'; import { sleep } from './_sleep'; -class DelayAsyncIterable extends AsyncIterableX { +export class DelayAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; private _dueTime: number; diff --git a/src/asynciterable/pipe/delay.ts b/src/asynciterable/pipe/delay.ts new file mode 100644 index 00000000..b5bb5774 --- /dev/null +++ b/src/asynciterable/pipe/delay.ts @@ -0,0 +1,11 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { DelayAsyncIterable } from '../delay'; + +export function delay( + dueTime: number +): MonoTypeOperatorAsyncFunction { + return function delayOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new DelayAsyncIterable(source, dueTime); + }; +} From 8b071ad863290c395ca935cb958f9e5af8ba34f4 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 23 Oct 2017 13:34:20 -0400 Subject: [PATCH 005/106] feat(pipe): add through delayEach --- src/asynciterable/delayeach.ts | 2 +- src/asynciterable/pipe/delayeach.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/delayeach.ts diff --git a/src/asynciterable/delayeach.ts b/src/asynciterable/delayeach.ts index e73e8daa..ffaf6159 100644 --- a/src/asynciterable/delayeach.ts +++ b/src/asynciterable/delayeach.ts @@ -1,7 +1,7 @@ import { AsyncIterableX } from '../asynciterable'; import { sleep } from './_sleep'; -class DelayEachAsyncIterable extends AsyncIterableX { +export class DelayEachAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; private _dueTime: number; diff --git a/src/asynciterable/pipe/delayeach.ts b/src/asynciterable/pipe/delayeach.ts new file mode 100644 index 00000000..8f871727 --- /dev/null +++ b/src/asynciterable/pipe/delayeach.ts @@ -0,0 +1,11 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { DelayEachAsyncIterable } from '../delayeach'; + +export function delayEach( + dueTime: number +): MonoTypeOperatorAsyncFunction { + return function delayEachOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new DelayEachAsyncIterable(source, dueTime); + }; +} From 4a6b817bb4e243474c83cd06c439575e2fb9d090 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 23 Oct 2017 13:44:02 -0400 Subject: [PATCH 006/106] feat(pipe): add through distinct --- src/asynciterable/distinct.ts | 2 +- src/asynciterable/pipe/distinct.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/distinct.ts diff --git a/src/asynciterable/distinct.ts b/src/asynciterable/distinct.ts index 3de5eca0..d7405457 100644 --- a/src/asynciterable/distinct.ts +++ b/src/asynciterable/distinct.ts @@ -3,7 +3,7 @@ import { identityAsync } from '../internal/identity'; import { arrayIndexOfAsync } from '../internal/arrayindexof'; import { comparerAsync } from '../internal/comparer'; -class DistinctAsyncIterable extends AsyncIterableX { +export class DistinctAsyncIterable extends AsyncIterableX { private _source: Iterable> | AsyncIterable; private _keySelector: (value: TSource) => TKey | Promise; private _comparer: (x: TKey, y: TKey) => boolean | Promise; diff --git a/src/asynciterable/pipe/distinct.ts b/src/asynciterable/pipe/distinct.ts new file mode 100644 index 00000000..603f42dd --- /dev/null +++ b/src/asynciterable/pipe/distinct.ts @@ -0,0 +1,14 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { DistinctAsyncIterable } from '../distinct'; +import { identityAsync } from '../../internal/identity'; +import { comparerAsync } from '../../internal/comparer'; + +export function distinct( + keySelector: (value: TSource) => TKey | Promise = identityAsync, + comparer: (x: TKey, y: TKey) => boolean | Promise = comparerAsync +): MonoTypeOperatorAsyncFunction { + return function distinctOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new DistinctAsyncIterable(source, keySelector, comparer); + }; +} From 29f7eb80fd27eb68ff95d394319f8fd7d087f8f9 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 23 Oct 2017 13:51:00 -0400 Subject: [PATCH 007/106] feat(pipe): add through distinctUntilChanged --- src/asynciterable/distinctuntilchanged.ts | 2 +- src/asynciterable/pipe/distinctuntilchanged.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/distinctuntilchanged.ts diff --git a/src/asynciterable/distinctuntilchanged.ts b/src/asynciterable/distinctuntilchanged.ts index 95a95ef9..42f90970 100644 --- a/src/asynciterable/distinctuntilchanged.ts +++ b/src/asynciterable/distinctuntilchanged.ts @@ -2,7 +2,7 @@ import { AsyncIterableX } from '../asynciterable'; import { identityAsync } from '../internal/identity'; import { comparerAsync } from '../internal/comparer'; -class DistinctUntilChangedAsyncIterable extends AsyncIterableX { +export class DistinctUntilChangedAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; private _keySelector: (value: TSource) => TKey | Promise; private _comparer: (x: TKey, y: TKey) => boolean | Promise; diff --git a/src/asynciterable/pipe/distinctuntilchanged.ts b/src/asynciterable/pipe/distinctuntilchanged.ts new file mode 100644 index 00000000..a675e5e1 --- /dev/null +++ b/src/asynciterable/pipe/distinctuntilchanged.ts @@ -0,0 +1,14 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { DistinctUntilChangedAsyncIterable } from '../distinctuntilchanged'; +import { identityAsync } from '../../internal/identity'; +import { comparerAsync } from '../../internal/comparer'; + +export function distinctUntilChanged( + keySelector: (value: TSource) => TKey | Promise = identityAsync, + comparer: (first: TKey, second: TKey) => boolean | Promise = comparerAsync +): MonoTypeOperatorAsyncFunction { + return function distinctUntilChangedOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new DistinctUntilChangedAsyncIterable(source, keySelector, comparer); + }; +} From c19313df16e411638a57011477e156afebba88bf Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 23 Oct 2017 14:07:06 -0400 Subject: [PATCH 008/106] feat(pipe): add through doWhile --- src/asynciterable/pipe/dowhile.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/asynciterable/pipe/dowhile.ts diff --git a/src/asynciterable/pipe/dowhile.ts b/src/asynciterable/pipe/dowhile.ts new file mode 100644 index 00000000..1c9d73f5 --- /dev/null +++ b/src/asynciterable/pipe/dowhile.ts @@ -0,0 +1,12 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { concatStatic } from '../concat'; +import { _while } from '../while'; + +export function doWhile( + condition: () => boolean | Promise +): MonoTypeOperatorAsyncFunction { + return function doWhileOperatorFunction(source: AsyncIterable): AsyncIterableX { + return concatStatic(source, _while(condition, source)); + }; +} From 25c6f21bb38dcee4910047d1300d2c7dc16d2ddb Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 23 Oct 2017 14:10:31 -0400 Subject: [PATCH 009/106] feat(pipe): add through endwith --- src/asynciterable/endwith.ts | 2 +- src/asynciterable/pipe/endwith.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/endwith.ts diff --git a/src/asynciterable/endwith.ts b/src/asynciterable/endwith.ts index 49d2493a..5adf1627 100644 --- a/src/asynciterable/endwith.ts +++ b/src/asynciterable/endwith.ts @@ -1,6 +1,6 @@ import { AsyncIterableX } from '../asynciterable'; -class EndWithAsyncIterable extends AsyncIterableX { +export class EndWithAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; private _args: TSource[]; diff --git a/src/asynciterable/pipe/endwith.ts b/src/asynciterable/pipe/endwith.ts new file mode 100644 index 00000000..ad63f956 --- /dev/null +++ b/src/asynciterable/pipe/endwith.ts @@ -0,0 +1,11 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { EndWithAsyncIterable } from '../endwith'; + +export function endWith( + ...args: TSource[] +): MonoTypeOperatorAsyncFunction { + return function endsWithOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new EndWithAsyncIterable(source, args); + }; +} From 9d099e18852348a15d764231ae7ba9837f382fb6 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 23 Oct 2017 14:17:47 -0400 Subject: [PATCH 010/106] feat(pipe): add through except --- src/asynciterable/except.ts | 2 +- src/asynciterable/pipe/except.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/except.ts diff --git a/src/asynciterable/except.ts b/src/asynciterable/except.ts index af984735..d4691aec 100644 --- a/src/asynciterable/except.ts +++ b/src/asynciterable/except.ts @@ -2,7 +2,7 @@ import { AsyncIterableX } from '../asynciterable'; import { arrayIndexOfAsync } from '../internal/arrayindexof'; import { comparerAsync } from '../internal/comparer'; -class ExceptAsyncIterable extends AsyncIterableX { +export class ExceptAsyncIterable extends AsyncIterableX { private _first: AsyncIterable; private _second: AsyncIterable; private _comparer: (x: TSource, y: TSource) => boolean | Promise; diff --git a/src/asynciterable/pipe/except.ts b/src/asynciterable/pipe/except.ts new file mode 100644 index 00000000..09f60c14 --- /dev/null +++ b/src/asynciterable/pipe/except.ts @@ -0,0 +1,13 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { ExceptAsyncIterable } from '../except'; +import { comparerAsync } from '../../internal/comparer'; + +export function except( + second: AsyncIterable, + comparer: (x: TSource, y: TSource) => boolean | Promise = comparerAsync +): MonoTypeOperatorAsyncFunction { + return function exceptOperatorFunction(first: AsyncIterable): AsyncIterableX { + return new ExceptAsyncIterable(first, second, comparer); + }; +} From 883b77621be3738c11461afd3f534c9ef1f798f7 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 23 Oct 2017 14:21:34 -0400 Subject: [PATCH 011/106] feat(pipe): add through expand --- src/asynciterable/expand.ts | 2 +- src/asynciterable/pipe/expand.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/expand.ts diff --git a/src/asynciterable/expand.ts b/src/asynciterable/expand.ts index 1dae61b2..742f16bc 100644 --- a/src/asynciterable/expand.ts +++ b/src/asynciterable/expand.ts @@ -1,6 +1,6 @@ import { AsyncIterableX } from '../asynciterable'; -class ExpandAsyncIterable extends AsyncIterableX { +export class ExpandAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; private _selector: (value: TSource) => AsyncIterable | Promise>; diff --git a/src/asynciterable/pipe/expand.ts b/src/asynciterable/pipe/expand.ts new file mode 100644 index 00000000..61adfdb9 --- /dev/null +++ b/src/asynciterable/pipe/expand.ts @@ -0,0 +1,11 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { ExpandAsyncIterable } from '../expand'; + +export function expand( + selector: (value: TSource) => AsyncIterable | Promise> +): MonoTypeOperatorAsyncFunction { + return function expandOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new ExpandAsyncIterable(source, selector); + }; +} From 45fddafcd1e752421fea189f07a035359dd16fbc Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 23 Oct 2017 14:25:37 -0400 Subject: [PATCH 012/106] feat(pipe): add through filter --- src/asynciterable/filter.ts | 2 +- src/asynciterable/pipe/filter.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/filter.ts diff --git a/src/asynciterable/filter.ts b/src/asynciterable/filter.ts index a1e2af51..03632b12 100644 --- a/src/asynciterable/filter.ts +++ b/src/asynciterable/filter.ts @@ -1,7 +1,7 @@ import { AsyncIterableX } from '../asynciterable'; import { bindCallback } from '../internal/bindcallback'; -class FilterAsyncIterable extends AsyncIterableX { +export class FilterAsyncIterable extends AsyncIterableX { private _source: Iterable> | AsyncIterable; private _predicate: (value: TSource, index: number) => boolean | Promise; diff --git a/src/asynciterable/pipe/filter.ts b/src/asynciterable/pipe/filter.ts new file mode 100644 index 00000000..7743fa6e --- /dev/null +++ b/src/asynciterable/pipe/filter.ts @@ -0,0 +1,13 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { FilterAsyncIterable } from '../filter'; +import { bindCallback } from '../../internal/bindcallback'; + +export function filter( + predicate: (value: TSource, index: number) => boolean | Promise, + thisArg?: any +): MonoTypeOperatorAsyncFunction { + return function filterOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new FilterAsyncIterable(source, bindCallback(predicate, thisArg, 2)); + }; +} From 2fcd230895b8a1b472f091c0b75b9c9f953ef6e7 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 23 Oct 2017 20:35:39 -0400 Subject: [PATCH 013/106] feat(pipe): add through finally --- src/asynciterable/finally.ts | 2 +- src/asynciterable/pipe/finally.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/finally.ts diff --git a/src/asynciterable/finally.ts b/src/asynciterable/finally.ts index 1d2c50d0..b61cc96d 100644 --- a/src/asynciterable/finally.ts +++ b/src/asynciterable/finally.ts @@ -1,6 +1,6 @@ import { AsyncIterableX } from '../asynciterable'; -class FinalyAsyncIterable extends AsyncIterableX { +export class FinalyAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; private _action: () => void | Promise; diff --git a/src/asynciterable/pipe/finally.ts b/src/asynciterable/pipe/finally.ts new file mode 100644 index 00000000..fcbbe537 --- /dev/null +++ b/src/asynciterable/pipe/finally.ts @@ -0,0 +1,11 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { FinalyAsyncIterable } from '../finally'; + +export function _finally( + action: () => void | Promise +): MonoTypeOperatorAsyncFunction { + return function finallyOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new FinalyAsyncIterable(source, action); + }; +} From 60fde4bdec116d1dbab183d7eb0a38ac14743b6c Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 23 Oct 2017 20:47:28 -0400 Subject: [PATCH 014/106] feat(pipe): add through flatmap --- src/asynciterable/flatmap.ts | 2 +- src/asynciterable/pipe/flatmap.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/flatmap.ts diff --git a/src/asynciterable/flatmap.ts b/src/asynciterable/flatmap.ts index c170349d..20dcda98 100644 --- a/src/asynciterable/flatmap.ts +++ b/src/asynciterable/flatmap.ts @@ -1,7 +1,7 @@ import { AsyncIterableX } from '../asynciterable'; import { bindCallback } from '../internal/bindcallback'; -class FlatMapAsyncIterable extends AsyncIterableX { +export class FlatMapAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; private _selector: (value: TSource) => AsyncIterable | Promise>; diff --git a/src/asynciterable/pipe/flatmap.ts b/src/asynciterable/pipe/flatmap.ts new file mode 100644 index 00000000..14ba1438 --- /dev/null +++ b/src/asynciterable/pipe/flatmap.ts @@ -0,0 +1,13 @@ +import { OperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { FlatMapAsyncIterable } from '../flatmap'; +import { bindCallback } from '../../internal/bindcallback'; + +export function flatMap( + selector: (value: TSource) => AsyncIterable | Promise>, + thisArg?: any +): OperatorAsyncFunction { + return function flatMapOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new FlatMapAsyncIterable(source, bindCallback(selector, thisArg, 1)); + }; +} From 9c43e9d719fbd400ce5341b2cd8f41da8bc5a0fd Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 23 Oct 2017 20:52:21 -0400 Subject: [PATCH 015/106] feat(pipe): add through flatten --- src/asynciterable/flatten.ts | 2 +- src/asynciterable/pipe/flatten.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/flatten.ts diff --git a/src/asynciterable/flatten.ts b/src/asynciterable/flatten.ts index ede9054d..9ec740ac 100644 --- a/src/asynciterable/flatten.ts +++ b/src/asynciterable/flatten.ts @@ -1,7 +1,7 @@ import { AsyncIterableX } from '../asynciterable'; import { isAsyncIterable } from '../internal/isiterable'; -class FlattenAsyncIterable extends AsyncIterableX { +export class FlattenAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; private _depth: number; diff --git a/src/asynciterable/pipe/flatten.ts b/src/asynciterable/pipe/flatten.ts new file mode 100644 index 00000000..b92e3fba --- /dev/null +++ b/src/asynciterable/pipe/flatten.ts @@ -0,0 +1,9 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { FlattenAsyncIterable } from '../flatten'; + +export function flatten(depth: number = Infinity): MonoTypeOperatorAsyncFunction { + return function flattenOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new FlattenAsyncIterable(source, depth); + }; +} From dcac250d86fb72ea7cd7fc50dba3f7be59e07afa Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 23 Oct 2017 21:02:02 -0400 Subject: [PATCH 016/106] feat(pipe): add through groupby --- src/asynciterable/pipe/groupby.ts | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/asynciterable/pipe/groupby.ts diff --git a/src/asynciterable/pipe/groupby.ts b/src/asynciterable/pipe/groupby.ts new file mode 100644 index 00000000..f122ef69 --- /dev/null +++ b/src/asynciterable/pipe/groupby.ts @@ -0,0 +1,34 @@ +import { OperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { GroupByAsyncIterable, GroupedAsyncIterable, groupByResultIdentityAsync } from '../groupby'; +import { identityAsync } from '../../internal/identity'; + +export function groupBy( + keySelector: (value: TSource) => TKey | Promise +): OperatorAsyncFunction>; +export function groupBy( + keySelector: (value: TSource) => TKey | Promise, + elementSelector?: (value: TSource) => TValue | Promise +): OperatorAsyncFunction>; +export function groupBy( + keySelector: (value: TSource) => TKey | Promise, + elementSelector?: (value: TSource) => TValue | Promise, + resultSelector?: (key: TKey, values: Iterable) => TResult | Promise +): OperatorAsyncFunction; +export function groupBy( + keySelector: (value: TSource) => TKey | Promise, + elementSelector: (value: TSource) => TValue | Promise = identityAsync, + resultSelector: ( + key: TKey, + values: Iterable + ) => TResult | Promise = groupByResultIdentityAsync +): OperatorAsyncFunction { + return function groupByOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new GroupByAsyncIterable( + source, + keySelector, + elementSelector, + resultSelector + ); + }; +} From 3503a6dc049b62154a06c8dc7c3894a8d108ff1b Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 23 Oct 2017 21:07:51 -0400 Subject: [PATCH 017/106] feat(pipe): add through groupjoin --- src/asynciterable/groupjoin.ts | 2 +- src/asynciterable/pipe/groupjoin.ts | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/groupjoin.ts diff --git a/src/asynciterable/groupjoin.ts b/src/asynciterable/groupjoin.ts index 2b3e8444..6fd77c97 100644 --- a/src/asynciterable/groupjoin.ts +++ b/src/asynciterable/groupjoin.ts @@ -4,7 +4,7 @@ import { empty } from './empty'; import { from } from './from'; import { identity } from '../internal/identity'; -class GroupJoinAsyncIterable extends AsyncIterableX { +export class GroupJoinAsyncIterable extends AsyncIterableX { private _outer: AsyncIterable; private _inner: AsyncIterable; private _outerSelector: (value: TOuter) => TKey | Promise; diff --git a/src/asynciterable/pipe/groupjoin.ts b/src/asynciterable/pipe/groupjoin.ts new file mode 100644 index 00000000..18f1ef10 --- /dev/null +++ b/src/asynciterable/pipe/groupjoin.ts @@ -0,0 +1,20 @@ +import { OperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { GroupJoinAsyncIterable } from '../groupjoin'; + +export function groupJoin( + inner: AsyncIterable, + outerSelector: (value: TOuter) => TKey | Promise, + innerSelector: (value: TInner) => TKey | Promise, + resultSelector: (outer: TOuter, inner: AsyncIterable) => TResult | Promise +): OperatorAsyncFunction { + return function groupJoinOperatorFunction(outer: AsyncIterable): AsyncIterableX { + return new GroupJoinAsyncIterable( + outer, + inner, + outerSelector, + innerSelector, + resultSelector + ); + }; +} From 613c50e8055ad4daa64a4b57578b87ced1cd655e Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 23 Oct 2017 21:11:06 -0400 Subject: [PATCH 018/106] feat(pipe): add through ignoreelements --- src/asynciterable/ignoreelements.ts | 2 +- src/asynciterable/pipe/ignoreelements.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/ignoreelements.ts diff --git a/src/asynciterable/ignoreelements.ts b/src/asynciterable/ignoreelements.ts index f186e923..88419c67 100644 --- a/src/asynciterable/ignoreelements.ts +++ b/src/asynciterable/ignoreelements.ts @@ -1,6 +1,6 @@ import { AsyncIterableX } from '../asynciterable'; -class IgnoreElementsAsyncIterable extends AsyncIterableX { +export class IgnoreElementsAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; constructor(source: AsyncIterable) { diff --git a/src/asynciterable/pipe/ignoreelements.ts b/src/asynciterable/pipe/ignoreelements.ts new file mode 100644 index 00000000..d5b27b82 --- /dev/null +++ b/src/asynciterable/pipe/ignoreelements.ts @@ -0,0 +1,11 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { IgnoreElementsAsyncIterable } from '../ignoreelements'; + +export function ignoreElements(): MonoTypeOperatorAsyncFunction { + return function ignoreElementsOperatorFunction( + source: AsyncIterable + ): AsyncIterableX { + return new IgnoreElementsAsyncIterable(source); + }; +} From 94892c7b3304e42fe8fd7ebf93739236e8e0c969 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 23 Oct 2017 21:17:32 -0400 Subject: [PATCH 019/106] feat(pipe): add through innerjoin --- src/asynciterable/innerjoin.ts | 2 +- src/asynciterable/pipe/innerjoin.ts | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/innerjoin.ts diff --git a/src/asynciterable/innerjoin.ts b/src/asynciterable/innerjoin.ts index 139921b5..b3481c53 100644 --- a/src/asynciterable/innerjoin.ts +++ b/src/asynciterable/innerjoin.ts @@ -2,7 +2,7 @@ import { AsyncIterableX } from '../asynciterable'; import { createGrouping } from './_grouping'; import { identity } from '../internal/identity'; -class JoinAsyncIterable extends AsyncIterableX { +export class JoinAsyncIterable extends AsyncIterableX { private _outer: AsyncIterable; private _inner: AsyncIterable; private _outerSelector: (value: TOuter) => TKey | Promise; diff --git a/src/asynciterable/pipe/innerjoin.ts b/src/asynciterable/pipe/innerjoin.ts new file mode 100644 index 00000000..45ef09b7 --- /dev/null +++ b/src/asynciterable/pipe/innerjoin.ts @@ -0,0 +1,20 @@ +import { OperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { JoinAsyncIterable } from '../innerjoin'; + +export function innerJoin( + inner: AsyncIterable, + outerSelector: (value: TOuter) => TKey | Promise, + innerSelector: (value: TInner) => TKey | Promise, + resultSelector: (outer: TOuter, inner: TInner) => TResult | Promise +): OperatorAsyncFunction { + return function innerJoinOperatorFunction(outer: AsyncIterable): AsyncIterableX { + return new JoinAsyncIterable( + outer, + inner, + outerSelector, + innerSelector, + resultSelector + ); + }; +} From caf1bcb0f4cb0604ec66926b66320e3a9386f163 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 23 Oct 2017 23:03:45 -0400 Subject: [PATCH 020/106] feat(pipe): add through intersect --- src/asynciterable/intersect.ts | 2 +- src/asynciterable/pipe/intersect.ts | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/intersect.ts diff --git a/src/asynciterable/intersect.ts b/src/asynciterable/intersect.ts index 990b26aa..016a4b39 100644 --- a/src/asynciterable/intersect.ts +++ b/src/asynciterable/intersect.ts @@ -15,7 +15,7 @@ async function arrayRemove( return true; } -class IntersectAsyncIterable extends AsyncIterableX { +export class IntersectAsyncIterable extends AsyncIterableX { private _first: AsyncIterable; private _second: AsyncIterable; private _comparer: (x: TSource, y: TSource) => boolean | Promise; diff --git a/src/asynciterable/pipe/intersect.ts b/src/asynciterable/pipe/intersect.ts new file mode 100644 index 00000000..6648f037 --- /dev/null +++ b/src/asynciterable/pipe/intersect.ts @@ -0,0 +1,15 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { IntersectAsyncIterable } from '../intersect'; +import { comparerAsync } from '../../internal/comparer'; + +export function intersect( + second: AsyncIterable, + comparer: (x: TSource, y: TSource) => boolean | Promise = comparerAsync +): MonoTypeOperatorAsyncFunction { + return function intersectOperatorFunction( + first: AsyncIterable + ): AsyncIterableX { + return new IntersectAsyncIterable(first, second, comparer); + }; +} From fad4faa584139ef992032a22ea5c38e8266fe849 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 23 Oct 2017 23:08:50 -0400 Subject: [PATCH 021/106] feat(pipe): add through map --- src/asynciterable/map.ts | 2 +- src/asynciterable/pipe/map.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/map.ts diff --git a/src/asynciterable/map.ts b/src/asynciterable/map.ts index 79d45d5b..ef1dc71a 100644 --- a/src/asynciterable/map.ts +++ b/src/asynciterable/map.ts @@ -1,7 +1,7 @@ import { AsyncIterableX } from '../asynciterable'; import { bindCallback } from '../internal/bindcallback'; -class MapAsyncIterable extends AsyncIterableX { +export class MapAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; private _selector: (value: TSource, index: number) => Promise | TResult; diff --git a/src/asynciterable/pipe/map.ts b/src/asynciterable/pipe/map.ts new file mode 100644 index 00000000..b2b2673d --- /dev/null +++ b/src/asynciterable/pipe/map.ts @@ -0,0 +1,13 @@ +import { OperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { MapAsyncIterable } from '../map'; +import { bindCallback } from '../../internal/bindcallback'; + +export function map( + selector: (value: TSource, index: number) => Promise | TResult, + thisArg?: any +): OperatorAsyncFunction { + return function mapOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new MapAsyncIterable(source, bindCallback(selector, thisArg, 2)); + }; +} From c9fc03b709a66aca9ebcbb2036037aaabd173fc0 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 23 Oct 2017 23:25:16 -0400 Subject: [PATCH 022/106] feat(pipe): add through memoize --- src/asynciterable/memoize.ts | 3 ++- src/asynciterable/pipe/maxby.ts | 12 ++++++++++++ src/asynciterable/pipe/memoize.ts | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/maxby.ts create mode 100644 src/asynciterable/pipe/memoize.ts diff --git a/src/asynciterable/memoize.ts b/src/asynciterable/memoize.ts index 6257f3c5..7298f232 100644 --- a/src/asynciterable/memoize.ts +++ b/src/asynciterable/memoize.ts @@ -2,7 +2,7 @@ import { AsyncIterableX } from '../asynciterable'; import { IRefCountList, MaxRefCountList, RefCountList } from '../iterable/_refcountlist'; import { create } from './create'; -class MemoizeAsyncBuffer extends AsyncIterableX { +export class MemoizeAsyncBuffer extends AsyncIterableX { private _source: AsyncIterator; private _buffer: IRefCountList; private _error: any; @@ -58,6 +58,7 @@ class MemoizeAsyncBuffer extends AsyncIterableX { } } } + export function memoize( source: AsyncIterable, readerCount?: number diff --git a/src/asynciterable/pipe/maxby.ts b/src/asynciterable/pipe/maxby.ts new file mode 100644 index 00000000..81f98623 --- /dev/null +++ b/src/asynciterable/pipe/maxby.ts @@ -0,0 +1,12 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { extremaBy, defaultCompareAsync } from '../_extremaby'; + +export function maxBy( + keySelector: (x: TSource) => TKey | Promise, + comparer: (x: TKey, y: TKey) => number | Promise = defaultCompareAsync +): MonoTypeOperatorAsyncFunction { + return function maxByOperatorFunction(source: AsyncIterable): AsyncIterableX { + return extremaBy(source, keySelector, comparer); + }; +} diff --git a/src/asynciterable/pipe/memoize.ts b/src/asynciterable/pipe/memoize.ts new file mode 100644 index 00000000..0a929551 --- /dev/null +++ b/src/asynciterable/pipe/memoize.ts @@ -0,0 +1,19 @@ +import { OperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { memoize as memoizeStatic } from '../memoize'; + +export function memoize(readerCount?: number): OperatorAsyncFunction; +export function memoize( + readerCount?: number, + selector?: (value: AsyncIterable) => AsyncIterable +): OperatorAsyncFunction; +export function memoize( + readerCount: number = -1, + selector?: (value: AsyncIterable) => AsyncIterable +): OperatorAsyncFunction { + return function memoizeOperatorFunction( + source: AsyncIterable + ): AsyncIterableX { + return memoizeStatic(source, readerCount, selector); + }; +} From 4fcbb0f9ac239dd1ea2cc461ca1afa9f34a6c9b9 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 23 Oct 2017 23:30:59 -0400 Subject: [PATCH 023/106] feat(pipe): add through merge --- src/asynciterable/merge.ts | 2 +- src/asynciterable/pipe/merge.ts | 35 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/merge.ts diff --git a/src/asynciterable/merge.ts b/src/asynciterable/merge.ts index d3aa67fb..4ef37f8b 100644 --- a/src/asynciterable/merge.ts +++ b/src/asynciterable/merge.ts @@ -9,7 +9,7 @@ function wrapPromiseWithIndex(promise: Promise, index: number) { return promise.then(value => ({ value, index })) as Promise>; } -class MergeAsyncIterable extends AsyncIterableX { +export class MergeAsyncIterable extends AsyncIterableX { private _source: AsyncIterable[]; constructor(source: AsyncIterable[]) { diff --git a/src/asynciterable/pipe/merge.ts b/src/asynciterable/pipe/merge.ts new file mode 100644 index 00000000..a0042932 --- /dev/null +++ b/src/asynciterable/pipe/merge.ts @@ -0,0 +1,35 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { MergeAsyncIterable } from '../merge'; + +/* tslint:disable:max-line-length */ +export function merge(v2: AsyncIterable): MonoTypeOperatorAsyncFunction; +export function merge( + v2: AsyncIterable, + v3: AsyncIterable +): MonoTypeOperatorAsyncFunction; +export function merge( + v2: AsyncIterable, + v3: AsyncIterable, + v4: AsyncIterable +): MonoTypeOperatorAsyncFunction; +export function merge( + v2: AsyncIterable, + v3: AsyncIterable, + v4: AsyncIterable, + v5: AsyncIterable +): MonoTypeOperatorAsyncFunction; +export function merge( + v2: AsyncIterable, + v3: AsyncIterable, + v4: AsyncIterable, + v5: AsyncIterable, + v6: AsyncIterable +): MonoTypeOperatorAsyncFunction; +/* tslint:enable:max-line-length */ + +export function merge(...args: AsyncIterable[]): MonoTypeOperatorAsyncFunction { + return function mergeOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new MergeAsyncIterable([source, ...args]); + }; +} From 7fdf0b8ca097a903c075440083b5fabb25bdadf4 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 23 Oct 2017 23:35:33 -0400 Subject: [PATCH 024/106] feat(pipe): add through mergeAll --- src/asynciterable/pipe/mergeall.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/asynciterable/pipe/mergeall.ts diff --git a/src/asynciterable/pipe/mergeall.ts b/src/asynciterable/pipe/mergeall.ts new file mode 100644 index 00000000..12eaa0be --- /dev/null +++ b/src/asynciterable/pipe/mergeall.ts @@ -0,0 +1,11 @@ +import { OperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { flatMap } from '../flatmap'; + +export function mergeAll(): OperatorAsyncFunction, TSource> { + return function mergeAllOperatorFunction( + source: AsyncIterable> + ): AsyncIterableX { + return flatMap(source, source => source); + }; +} From 3e55e4f82427da7fc0c27aaf9f45a0be289e9a39 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 23 Oct 2017 23:51:15 -0400 Subject: [PATCH 025/106] feat(pipe): add through minby --- src/asynciterable/pipe/minby.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/asynciterable/pipe/minby.ts diff --git a/src/asynciterable/pipe/minby.ts b/src/asynciterable/pipe/minby.ts new file mode 100644 index 00000000..4935d9f4 --- /dev/null +++ b/src/asynciterable/pipe/minby.ts @@ -0,0 +1,12 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { extremaBy, defaultCompareAsync } from '../_extremaby'; + +export function minBy( + keySelector: (x: TSource) => TKey | Promise, + comparer: (x: TKey, y: TKey) => number | Promise = defaultCompareAsync +): MonoTypeOperatorAsyncFunction { + return function minByOperatorFunction(source: AsyncIterable): AsyncIterableX { + return extremaBy(source, keySelector, async (key, minValue) => -await comparer(key, minValue)); + }; +} From 3de02e0efad4a10ca4622514332795da2e0afbab Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 00:05:14 -0400 Subject: [PATCH 026/106] feat(pipe): add through onerrorresumenext --- src/asynciterable/onerrorresumenext.ts | 2 +- src/asynciterable/pipe/onerrorresumenext.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/onerrorresumenext.ts diff --git a/src/asynciterable/onerrorresumenext.ts b/src/asynciterable/onerrorresumenext.ts index 53612f09..cb2a0364 100644 --- a/src/asynciterable/onerrorresumenext.ts +++ b/src/asynciterable/onerrorresumenext.ts @@ -1,6 +1,6 @@ import { AsyncIterableX } from '../asynciterable'; -class OnErrorResumeNextAsyncIterable extends AsyncIterableX { +export class OnErrorResumeNextAsyncIterable extends AsyncIterableX { private _source: Iterable>; constructor(source: Iterable>) { diff --git a/src/asynciterable/pipe/onerrorresumenext.ts b/src/asynciterable/pipe/onerrorresumenext.ts new file mode 100644 index 00000000..37b14a44 --- /dev/null +++ b/src/asynciterable/pipe/onerrorresumenext.ts @@ -0,0 +1,11 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { OnErrorResumeNextAsyncIterable } from '../onerrorresumenext'; + +export function onErrorResumeNext( + ...args: AsyncIterable[] +): MonoTypeOperatorAsyncFunction { + return function onErrorResumeNextOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new OnErrorResumeNextAsyncIterable([source, ...args]); + }; +} From 7b2bf03d2b8b0b0c96590b1c4ca74c2094cd7ca3 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 00:30:47 -0400 Subject: [PATCH 027/106] feat(pipe): add through pairwise --- src/asynciterable/pairwise.ts | 2 +- src/asynciterable/pipe/pariwise.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/pariwise.ts diff --git a/src/asynciterable/pairwise.ts b/src/asynciterable/pairwise.ts index ac208b85..41dce2f6 100644 --- a/src/asynciterable/pairwise.ts +++ b/src/asynciterable/pairwise.ts @@ -1,6 +1,6 @@ import { AsyncIterableX } from '../asynciterable'; -class PairwiseAsyncIterable extends AsyncIterableX { +export class PairwiseAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; constructor(source: AsyncIterable) { diff --git a/src/asynciterable/pipe/pariwise.ts b/src/asynciterable/pipe/pariwise.ts new file mode 100644 index 00000000..71970e63 --- /dev/null +++ b/src/asynciterable/pipe/pariwise.ts @@ -0,0 +1,11 @@ +import { OperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { PairwiseAsyncIterable } from '../pairwise'; + +export function pairwise(): OperatorAsyncFunction { + return function pairwiseOperatorFunction( + source: AsyncIterable + ): AsyncIterableX { + return new PairwiseAsyncIterable(source); + }; +} From 7cb72c50738d26089b303937db42fe106a659d92 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 00:34:58 -0400 Subject: [PATCH 028/106] feat(pipe): add through pluck --- src/asynciterable/pipe/pluck.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/asynciterable/pipe/pluck.ts diff --git a/src/asynciterable/pipe/pluck.ts b/src/asynciterable/pipe/pluck.ts new file mode 100644 index 00000000..016648b8 --- /dev/null +++ b/src/asynciterable/pipe/pluck.ts @@ -0,0 +1,11 @@ +import { OperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { pluck as pluckStatic } from '../pluck'; + +export function pluck( + ...args: string[] +): OperatorAsyncFunction { + return function pluckOperatorFunction(source: AsyncIterable): AsyncIterableX { + return pluckStatic(source, ...args); + }; +} From 753c1cb7d63ecf02e801d017c8b23f09a3f1fb9c Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 13:19:51 -0400 Subject: [PATCH 029/106] feat(pipe): add through publish --- src/asynciterable/pipe/publish.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/asynciterable/pipe/publish.ts diff --git a/src/asynciterable/pipe/publish.ts b/src/asynciterable/pipe/publish.ts new file mode 100644 index 00000000..c381b12a --- /dev/null +++ b/src/asynciterable/pipe/publish.ts @@ -0,0 +1,17 @@ +import { OperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { publish as publishStatic } from '../publish'; + +export function publish(): OperatorAsyncFunction; +export function publish( + selector?: (value: AsyncIterable) => AsyncIterable +): OperatorAsyncFunction; +export function publish( + selector?: (value: AsyncIterable) => AsyncIterable +): OperatorAsyncFunction { + return function publishOperatorFunction( + source: AsyncIterable + ): AsyncIterableX { + return publishStatic(source, selector); + }; +} From bddb83764ef61cc4fc13feb10529a68a0ddcde8a Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 14:36:40 -0400 Subject: [PATCH 030/106] feat(pipe): add through repeat --- src/asynciterable/pipe/repeat.ts | 9 +++++++++ src/asynciterable/repeat.ts | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/repeat.ts diff --git a/src/asynciterable/pipe/repeat.ts b/src/asynciterable/pipe/repeat.ts new file mode 100644 index 00000000..84ffa25a --- /dev/null +++ b/src/asynciterable/pipe/repeat.ts @@ -0,0 +1,9 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { RepeatAsyncIterable } from '../repeat'; + +export function repeat(count: number = -1): MonoTypeOperatorAsyncFunction { + return function repeatOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new RepeatAsyncIterable(source, count); + }; +} diff --git a/src/asynciterable/repeat.ts b/src/asynciterable/repeat.ts index dacc1e85..0a602b0f 100644 --- a/src/asynciterable/repeat.ts +++ b/src/asynciterable/repeat.ts @@ -1,7 +1,7 @@ import { of } from './of'; import { AsyncIterableX } from '../asynciterable'; -class RepeatAsyncIterable extends AsyncIterableX { +export class RepeatAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; private _count: number; From c908085f10fe8e297f408ac29ee3a2b1b85ff0fa Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 15:43:51 -0400 Subject: [PATCH 031/106] feat(pipe): add through retry --- src/asynciterable/pipe/retry.ts | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/asynciterable/pipe/retry.ts diff --git a/src/asynciterable/pipe/retry.ts b/src/asynciterable/pipe/retry.ts new file mode 100644 index 00000000..00789c91 --- /dev/null +++ b/src/asynciterable/pipe/retry.ts @@ -0,0 +1,9 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { retry as retryStatic } from '../retry'; + +export function retry(count: number = -1): MonoTypeOperatorAsyncFunction { + return function retryOperatorFunction(source: AsyncIterable): AsyncIterableX { + return retryStatic(source, count); + }; +} From da5f342e034825e02b444eac0d5fec940cdbf95d Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 15:52:49 -0400 Subject: [PATCH 032/106] feat(pipe): add through reverse --- src/asynciterable/pipe/reverse.ts | 9 +++++++++ src/asynciterable/reverse.ts | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/reverse.ts diff --git a/src/asynciterable/pipe/reverse.ts b/src/asynciterable/pipe/reverse.ts new file mode 100644 index 00000000..93e50bab --- /dev/null +++ b/src/asynciterable/pipe/reverse.ts @@ -0,0 +1,9 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { ReverseAsyncIterable } from '../reverse'; + +export function reverse(): MonoTypeOperatorAsyncFunction { + return function reverseOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new ReverseAsyncIterable(source); + }; +} diff --git a/src/asynciterable/reverse.ts b/src/asynciterable/reverse.ts index e33f3a0b..c5c33ec6 100644 --- a/src/asynciterable/reverse.ts +++ b/src/asynciterable/reverse.ts @@ -1,6 +1,6 @@ import { AsyncIterableX } from '../asynciterable'; -class ReverseAsyncIterable extends AsyncIterableX { +export class ReverseAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; constructor(source: AsyncIterable) { From 8f321e1e328372531e1bd7b4e5f19b52dd758e54 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 15:56:29 -0400 Subject: [PATCH 033/106] feat(pipe): add through scan --- src/asynciterable/pipe/scan.ts | 19 +++++++++++++++++++ src/asynciterable/scan.ts | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/scan.ts diff --git a/src/asynciterable/pipe/scan.ts b/src/asynciterable/pipe/scan.ts new file mode 100644 index 00000000..f0cc45af --- /dev/null +++ b/src/asynciterable/pipe/scan.ts @@ -0,0 +1,19 @@ +import { OperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { ScanAsyncIterable } from '../scan'; + +export function scan( + accumulator: (acc: T, value: T, index: number) => T | Promise +): OperatorAsyncFunction; +export function scan( + accumulator: (acc: R, value: T, index: number) => R | Promise, + seed: R +): OperatorAsyncFunction; +export function scan( + accumulator: (acc: T | R, value: T, index: number) => R | Promise, + ...args: (T | R)[] +): OperatorAsyncFunction { + return function scanOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new ScanAsyncIterable(source, accumulator, ...args); + }; +} diff --git a/src/asynciterable/scan.ts b/src/asynciterable/scan.ts index 8e8b604b..51d08f63 100644 --- a/src/asynciterable/scan.ts +++ b/src/asynciterable/scan.ts @@ -1,6 +1,6 @@ import { AsyncIterableX } from '../asynciterable'; -class ScanAsyncIterable extends AsyncIterableX { +export class ScanAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; private _fn: (acc: T | R, x: T, index: number) => R | Promise; private _seed?: T | R; From 6e1f57721e5f4eee6cb5643794f4985f1e71c67c Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 15:59:45 -0400 Subject: [PATCH 034/106] feat(pipe): add through scanRight --- src/asynciterable/pipe/scanright.ts | 19 +++++++++++++++++++ src/asynciterable/scanright.ts | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/scanright.ts diff --git a/src/asynciterable/pipe/scanright.ts b/src/asynciterable/pipe/scanright.ts new file mode 100644 index 00000000..a4ca3674 --- /dev/null +++ b/src/asynciterable/pipe/scanright.ts @@ -0,0 +1,19 @@ +import { OperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { ScanRightAsyncIterable } from '../scanright'; + +export function scanRight( + accumulator: (acc: T, value: T, index: number) => T | Promise +): OperatorAsyncFunction; +export function scanRight( + accumulator: (acc: R, value: T, index: number) => R | Promise, + seed: R +): OperatorAsyncFunction; +export function scanRight( + accumulator: (acc: T | R, value: T, index: number) => R | Promise, + ...args: (T | R)[] +): OperatorAsyncFunction { + return function scanRightOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new ScanRightAsyncIterable(source, accumulator, ...args); + }; +} diff --git a/src/asynciterable/scanright.ts b/src/asynciterable/scanright.ts index b61d4027..f0b10c7a 100644 --- a/src/asynciterable/scanright.ts +++ b/src/asynciterable/scanright.ts @@ -1,7 +1,7 @@ import { AsyncIterableX } from '../asynciterable'; import { toArray } from './toarray'; -class ScanRightAsyncIterable extends AsyncIterableX { +export class ScanRightAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; private _fn: (acc: T | R, x: T, index: number) => R | Promise; private _seed?: T | R; From b52a2d1aa50375b51d938195310ac866dee860b0 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 16:06:49 -0400 Subject: [PATCH 035/106] feat(pipe): add through share --- src/asynciterable/pipe/share.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/asynciterable/pipe/share.ts diff --git a/src/asynciterable/pipe/share.ts b/src/asynciterable/pipe/share.ts new file mode 100644 index 00000000..1f42afe7 --- /dev/null +++ b/src/asynciterable/pipe/share.ts @@ -0,0 +1,21 @@ +import { OperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { share as shareStatic } from '../share'; + +export function share(): OperatorAsyncFunction; +export function share( + selector?: ( + value: AsyncIterable + ) => AsyncIterable | Promise> +): OperatorAsyncFunction; +export function share( + selector?: ( + value: AsyncIterable + ) => AsyncIterable | Promise> +): OperatorAsyncFunction { + return function shareOperatorFunction( + source: AsyncIterable + ): AsyncIterableX { + return shareStatic(source, selector); + }; +} From b1f1365e18c4263525600d2ec904e198f438b5cd Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 16:36:50 -0400 Subject: [PATCH 036/106] feat(pipe): add through skip --- src/asynciterable/pipe/skip.ts | 9 +++++++++ src/asynciterable/skip.ts | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/skip.ts diff --git a/src/asynciterable/pipe/skip.ts b/src/asynciterable/pipe/skip.ts new file mode 100644 index 00000000..5000b2f6 --- /dev/null +++ b/src/asynciterable/pipe/skip.ts @@ -0,0 +1,9 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { SkipAsyncIterable } from '../skip'; + +export function skip(count: number): MonoTypeOperatorAsyncFunction { + return function skipOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new SkipAsyncIterable(source, count); + }; +} diff --git a/src/asynciterable/skip.ts b/src/asynciterable/skip.ts index ecd468e3..f985030f 100644 --- a/src/asynciterable/skip.ts +++ b/src/asynciterable/skip.ts @@ -1,6 +1,6 @@ import { AsyncIterableX } from '../asynciterable'; -class SkipAsyncIterable extends AsyncIterableX { +export class SkipAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; private _count: number; From fb566f35c9a29c7ce36eeb0ab79aa693d6d1184f Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 16:40:22 -0400 Subject: [PATCH 037/106] feat(pipe): add through skipLast --- src/asynciterable/pipe/skiplast.ts | 11 +++++++++++ src/asynciterable/skiplast.ts | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/skiplast.ts diff --git a/src/asynciterable/pipe/skiplast.ts b/src/asynciterable/pipe/skiplast.ts new file mode 100644 index 00000000..4fb4b8e3 --- /dev/null +++ b/src/asynciterable/pipe/skiplast.ts @@ -0,0 +1,11 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { SkipLastAsyncIterable } from '../skiplast'; + +export function skipLast(count: number): MonoTypeOperatorAsyncFunction { + return function skipLastOperatorFunction( + source: AsyncIterable + ): AsyncIterableX { + return new SkipLastAsyncIterable(source, count); + }; +} diff --git a/src/asynciterable/skiplast.ts b/src/asynciterable/skiplast.ts index 62fc0a6f..e17b7d80 100644 --- a/src/asynciterable/skiplast.ts +++ b/src/asynciterable/skiplast.ts @@ -1,6 +1,6 @@ import { AsyncIterableX } from '../asynciterable'; -class SkipLastAsyncIterable extends AsyncIterableX { +export class SkipLastAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; private _count: number; From b8e0844a2d0eda99f069f8d7f53416ce703ec2d2 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 16:52:25 -0400 Subject: [PATCH 038/106] feat(pipe): add through skipUntil --- spec/asynciterable-operators/skipuntil-spec.ts | 8 ++++---- src/add/asynciterable-operators/skipuntil.ts | 2 +- src/asynciterable/pipe/skipuntil.ts | 13 +++++++++++++ src/asynciterable/skipuntil.ts | 10 +++++----- 4 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 src/asynciterable/pipe/skipuntil.ts diff --git a/spec/asynciterable-operators/skipuntil-spec.ts b/spec/asynciterable-operators/skipuntil-spec.ts index 96180ff6..62757a50 100644 --- a/spec/asynciterable-operators/skipuntil-spec.ts +++ b/spec/asynciterable-operators/skipuntil-spec.ts @@ -4,12 +4,12 @@ const { skipUntil } = Ix.asynciterable; import { hasNext, noNext, delayValue } from '../asynciterablehelpers'; test('AsyncIterable#skipUntil hits', async t => { - const xs = async function* () { + const xs = async function*() { yield await delayValue(1, 100); yield await delayValue(2, 300); yield await delayValue(3, 600); }; - const ys = skipUntil(xs(), delayValue(42, 200)); + const ys = skipUntil(xs(), () => delayValue(42, 200)); const it = ys[Symbol.asyncIterator](); await hasNext(t, it, 2); @@ -19,12 +19,12 @@ test('AsyncIterable#skipUntil hits', async t => { }); test('AsyncIterable#skipUntil misses', async t => { - const xs = async function* () { + const xs = async function*() { yield await delayValue(1, 400); yield await delayValue(2, 500); yield await delayValue(3, 600); }; - const ys = skipUntil(xs(), delayValue(42, 0)); + const ys = skipUntil(xs(), () => delayValue(42, 0)); const it = ys[Symbol.asyncIterator](); await hasNext(t, it, 1); diff --git a/src/add/asynciterable-operators/skipuntil.ts b/src/add/asynciterable-operators/skipuntil.ts index 1e09c2e3..4f62b440 100644 --- a/src/add/asynciterable-operators/skipuntil.ts +++ b/src/add/asynciterable-operators/skipuntil.ts @@ -6,7 +6,7 @@ import { skipUntil } from '../../asynciterable/skipuntil'; */ export function skipUntilProto( this: AsyncIterableX, - other: Promise + other: () => Promise ): AsyncIterableX { return skipUntil(this, other); } diff --git a/src/asynciterable/pipe/skipuntil.ts b/src/asynciterable/pipe/skipuntil.ts new file mode 100644 index 00000000..25c7b7ca --- /dev/null +++ b/src/asynciterable/pipe/skipuntil.ts @@ -0,0 +1,13 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { SkipUntilAsyncIterable } from '../skipuntil'; + +export function skipUntil( + other: () => Promise +): MonoTypeOperatorAsyncFunction { + return function skipUntilOperatorFunction( + source: AsyncIterable + ): AsyncIterableX { + return new SkipUntilAsyncIterable(source, other); + }; +} diff --git a/src/asynciterable/skipuntil.ts b/src/asynciterable/skipuntil.ts index 261a846b..8853eabe 100644 --- a/src/asynciterable/skipuntil.ts +++ b/src/asynciterable/skipuntil.ts @@ -1,10 +1,10 @@ import { AsyncIterableX } from '../asynciterable'; -class SkipUntilAsyncIterable extends AsyncIterableX { +export class SkipUntilAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; - private _other: Promise; + private _other: () => Promise; - constructor(source: AsyncIterable, other: Promise) { + constructor(source: AsyncIterable, other: () => Promise) { super(); this._source = source; this._other = other; @@ -12,7 +12,7 @@ class SkipUntilAsyncIterable extends AsyncIterableX { async *[Symbol.asyncIterator]() { let otherDone = false; - this._other.then(() => (otherDone = true)); + this._other().then(() => (otherDone = true)); for await (let item of this._source) { if (otherDone) { yield item; @@ -23,7 +23,7 @@ class SkipUntilAsyncIterable extends AsyncIterableX { export function skipUntil( source: AsyncIterable, - other: Promise + other: () => Promise ): AsyncIterableX { return new SkipUntilAsyncIterable(source, other); } From efefa9134ecc769452ddd9926465af3c766a30fc Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 17:01:31 -0400 Subject: [PATCH 039/106] feat(pipe): add through skipWhile --- src/asynciterable/pipe/skipwhile.ts | 17 +++++++++++++++++ src/asynciterable/skipwhile.ts | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/skipwhile.ts diff --git a/src/asynciterable/pipe/skipwhile.ts b/src/asynciterable/pipe/skipwhile.ts new file mode 100644 index 00000000..edb4886f --- /dev/null +++ b/src/asynciterable/pipe/skipwhile.ts @@ -0,0 +1,17 @@ +import { OperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { SkipWhileAsyncIterable } from '../skipwhile'; + +export function skipWhile( + predicate: (value: T, index: number) => value is S +): OperatorAsyncFunction; +export function skipWhile( + predicate: (value: T, index: number) => boolean | Promise +): OperatorAsyncFunction; +export function skipWhile( + predicate: (value: T, index: number) => boolean | Promise +): OperatorAsyncFunction { + return function skipWhileOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new SkipWhileAsyncIterable(source, predicate); + }; +} diff --git a/src/asynciterable/skipwhile.ts b/src/asynciterable/skipwhile.ts index f57a7913..7fed895e 100644 --- a/src/asynciterable/skipwhile.ts +++ b/src/asynciterable/skipwhile.ts @@ -1,6 +1,6 @@ import { AsyncIterableX } from '../asynciterable'; -class SkipWhileAsyncIterable extends AsyncIterableX { +export class SkipWhileAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; private _predicate: (value: TSource, index: number) => boolean | Promise; From 338f5e4ff88eda0131474ddec4dd4fe4806bfcda Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 17:07:51 -0400 Subject: [PATCH 040/106] feat(pipe): add through slice --- src/asynciterable/pipe/slice.ts | 12 ++++++++++++ src/asynciterable/slice.ts | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/slice.ts diff --git a/src/asynciterable/pipe/slice.ts b/src/asynciterable/pipe/slice.ts new file mode 100644 index 00000000..eeb84ba0 --- /dev/null +++ b/src/asynciterable/pipe/slice.ts @@ -0,0 +1,12 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { SliceAsyncIterable } from '../slice'; + +export function slice( + begin: number, + end: number = Infinity +): MonoTypeOperatorAsyncFunction { + return function sliceOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new SliceAsyncIterable(source, begin, end); + }; +} diff --git a/src/asynciterable/slice.ts b/src/asynciterable/slice.ts index 437c985f..8d0064c4 100644 --- a/src/asynciterable/slice.ts +++ b/src/asynciterable/slice.ts @@ -1,6 +1,6 @@ import { AsyncIterableX } from '../asynciterable'; -class SliceAsyncIterable extends AsyncIterableX { +export class SliceAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; private _begin: number; private _end: number; From 0d8a61a537163ca652244e9eddef920834799cc0 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 19:03:51 -0400 Subject: [PATCH 041/106] feat(pipe): add through startwith --- src/asynciterable/pipe/startwith.ts | 11 +++++++++++ src/asynciterable/startwith.ts | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/startwith.ts diff --git a/src/asynciterable/pipe/startwith.ts b/src/asynciterable/pipe/startwith.ts new file mode 100644 index 00000000..35cacc6d --- /dev/null +++ b/src/asynciterable/pipe/startwith.ts @@ -0,0 +1,11 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { StartWithAsyncIterable } from '../startwith'; + +export function startWith(...args: TSource[]): MonoTypeOperatorAsyncFunction { + return function startWithOperatorFunction( + source: AsyncIterable + ): AsyncIterableX { + return new StartWithAsyncIterable(source, args); + }; +} diff --git a/src/asynciterable/startwith.ts b/src/asynciterable/startwith.ts index caa01dc9..0f26b12b 100644 --- a/src/asynciterable/startwith.ts +++ b/src/asynciterable/startwith.ts @@ -1,6 +1,6 @@ import { AsyncIterableX } from '../asynciterable'; -class StartWithAsyncIterable extends AsyncIterableX { +export class StartWithAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; private _args: TSource[]; From 60dabc8c859854bac1299d7d8c5ac7327c5c090e Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 19:18:36 -0400 Subject: [PATCH 042/106] feat(pipe): add through take --- src/asynciterable/pipe/take.ts | 9 +++++++++ src/asynciterable/take.ts | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/take.ts diff --git a/src/asynciterable/pipe/take.ts b/src/asynciterable/pipe/take.ts new file mode 100644 index 00000000..bec0d3a2 --- /dev/null +++ b/src/asynciterable/pipe/take.ts @@ -0,0 +1,9 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { TakeAsyncIterable } from '../take'; + +export function take(count: number): MonoTypeOperatorAsyncFunction { + return function takeOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new TakeAsyncIterable(source, count); + }; +} diff --git a/src/asynciterable/take.ts b/src/asynciterable/take.ts index 2f4e4238..d712b5dc 100644 --- a/src/asynciterable/take.ts +++ b/src/asynciterable/take.ts @@ -1,6 +1,6 @@ import { AsyncIterableX } from '../asynciterable'; -class TakeAsyncIterable extends AsyncIterableX { +export class TakeAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; private _count: number; From 6ded104bdd5d7e78fd71ebc3387efdfca2f42a7c Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 19:21:01 -0400 Subject: [PATCH 043/106] feat(pipe): add through takelast --- src/asynciterable/pipe/takelast.ts | 11 +++++++++++ src/asynciterable/takelast.ts | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/takelast.ts diff --git a/src/asynciterable/pipe/takelast.ts b/src/asynciterable/pipe/takelast.ts new file mode 100644 index 00000000..053e40ac --- /dev/null +++ b/src/asynciterable/pipe/takelast.ts @@ -0,0 +1,11 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { TakeLastAsyncIterable } from '../takelast'; + +export function takeLast(count: number): MonoTypeOperatorAsyncFunction { + return function takeLastOperatorFunction( + source: AsyncIterable + ): AsyncIterableX { + return new TakeLastAsyncIterable(source, count); + }; +} diff --git a/src/asynciterable/takelast.ts b/src/asynciterable/takelast.ts index d2e91db5..4c095766 100644 --- a/src/asynciterable/takelast.ts +++ b/src/asynciterable/takelast.ts @@ -1,6 +1,6 @@ import { AsyncIterableX } from '../asynciterable'; -class TakeLastAsyncIterable extends AsyncIterableX { +export class TakeLastAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; private _count: number; From 30644d5c03e6d940624e9ae4e90bf4b079d95cd3 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 19:30:19 -0400 Subject: [PATCH 044/106] feat(pipe): add through takeuntil --- spec/asynciterable-operators/takeuntil-spec.ts | 8 ++++---- src/add/asynciterable-operators/takeuntil.ts | 2 +- src/asynciterable/pipe/takeuntil.ts | 13 +++++++++++++ src/asynciterable/takeuntil.ts | 10 +++++----- 4 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 src/asynciterable/pipe/takeuntil.ts diff --git a/spec/asynciterable-operators/takeuntil-spec.ts b/spec/asynciterable-operators/takeuntil-spec.ts index 6c719807..ecd0c952 100644 --- a/spec/asynciterable-operators/takeuntil-spec.ts +++ b/spec/asynciterable-operators/takeuntil-spec.ts @@ -4,12 +4,12 @@ const { takeUntil } = Ix.asynciterable; import { hasNext, noNext, delayValue } from '../asynciterablehelpers'; test('AsyncIterable#takeUntil hits', async t => { - const xs = async function* () { + const xs = async function*() { yield await delayValue(1, 100); yield await delayValue(2, 300); yield await delayValue(3, 1200); }; - const ys = takeUntil(xs(), delayValue(42, 500)); + const ys = takeUntil(xs(), () => delayValue(42, 500)); const it = ys[Symbol.asyncIterator](); await hasNext(t, it, 1); @@ -19,12 +19,12 @@ test('AsyncIterable#takeUntil hits', async t => { }); test('AsyncIterable#takeUntil misses', async t => { - const xs = async function* () { + const xs = async function*() { yield await delayValue(1, 100); yield await delayValue(2, 300); yield await delayValue(3, 600); }; - const ys = takeUntil(xs(), delayValue(42, 1200)); + const ys = takeUntil(xs(), () => delayValue(42, 1200)); const it = ys[Symbol.asyncIterator](); await hasNext(t, it, 1); diff --git a/src/add/asynciterable-operators/takeuntil.ts b/src/add/asynciterable-operators/takeuntil.ts index cc43da55..dc2a902c 100644 --- a/src/add/asynciterable-operators/takeuntil.ts +++ b/src/add/asynciterable-operators/takeuntil.ts @@ -6,7 +6,7 @@ import { takeUntil } from '../../asynciterable/takeuntil'; */ export function takeUntilProto( this: AsyncIterableX, - other: Promise + other: () => Promise ): AsyncIterableX { return takeUntil(this, other); } diff --git a/src/asynciterable/pipe/takeuntil.ts b/src/asynciterable/pipe/takeuntil.ts new file mode 100644 index 00000000..4f0863c6 --- /dev/null +++ b/src/asynciterable/pipe/takeuntil.ts @@ -0,0 +1,13 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { TakeUntilAsyncIterable } from '../takeuntil'; + +export function takeUntil( + other: () => Promise +): MonoTypeOperatorAsyncFunction { + return function takeUntilOperatorFunction( + source: AsyncIterable + ): AsyncIterableX { + return new TakeUntilAsyncIterable(source, other); + }; +} diff --git a/src/asynciterable/takeuntil.ts b/src/asynciterable/takeuntil.ts index 12129e71..07d3035f 100644 --- a/src/asynciterable/takeuntil.ts +++ b/src/asynciterable/takeuntil.ts @@ -1,10 +1,10 @@ import { AsyncIterableX } from '../asynciterable'; -class TakeUntilAsyncIterable extends AsyncIterableX { +export class TakeUntilAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; - private _other: Promise; + private _other: () => Promise; - constructor(source: AsyncIterable, other: Promise) { + constructor(source: AsyncIterable, other: () => Promise) { super(); this._source = source; this._other = other; @@ -12,7 +12,7 @@ class TakeUntilAsyncIterable extends AsyncIterableX { async *[Symbol.asyncIterator]() { let otherDone = false; - this._other.then(() => (otherDone = true)); + this._other().then(() => (otherDone = true)); for await (let item of this._source) { if (otherDone) { break; @@ -24,7 +24,7 @@ class TakeUntilAsyncIterable extends AsyncIterableX { export function takeUntil( source: AsyncIterable, - other: Promise + other: () => Promise ): AsyncIterableX { return new TakeUntilAsyncIterable(source, other); } From 977efa24eefe6b96732c95f2a58c3a863dc77c7c Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 19:35:54 -0400 Subject: [PATCH 045/106] feat(pipe): add through takewhile --- src/asynciterable/pipe/takewhile.ts | 17 +++++++++++++++++ src/asynciterable/takewhile.ts | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/takewhile.ts diff --git a/src/asynciterable/pipe/takewhile.ts b/src/asynciterable/pipe/takewhile.ts new file mode 100644 index 00000000..828c5a5e --- /dev/null +++ b/src/asynciterable/pipe/takewhile.ts @@ -0,0 +1,17 @@ +import { OperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { TakeWhileAsyncIterable } from '../takewhile'; + +export function takeWhile( + predicate: (value: T, index: number) => value is S +): OperatorAsyncFunction; +export function takeWhile( + predicate: (value: T, index: number) => boolean | Promise +): OperatorAsyncFunction; +export function takeWhile( + predicate: (value: T, index: number) => boolean | Promise +): OperatorAsyncFunction { + return function takeWhileOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new TakeWhileAsyncIterable(source, predicate); + }; +} diff --git a/src/asynciterable/takewhile.ts b/src/asynciterable/takewhile.ts index 58bac832..c0f84df5 100644 --- a/src/asynciterable/takewhile.ts +++ b/src/asynciterable/takewhile.ts @@ -1,6 +1,6 @@ import { AsyncIterableX } from '../asynciterable'; -class TakeWhileAsyncIterable extends AsyncIterableX { +export class TakeWhileAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; private _predicate: (value: TSource, index: number) => boolean | Promise; From 010b959cbe0883d978df0392968aba7c40d868b7 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 19:39:50 -0400 Subject: [PATCH 046/106] feat(pipe): add through tap --- src/asynciterable/pipe/tap.ts | 12 ++++++++++++ src/asynciterable/tap.ts | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/tap.ts diff --git a/src/asynciterable/pipe/tap.ts b/src/asynciterable/pipe/tap.ts new file mode 100644 index 00000000..35c0a04f --- /dev/null +++ b/src/asynciterable/pipe/tap.ts @@ -0,0 +1,12 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { TapAsyncIterable } from '../tap'; +import { PartialAsyncObserver } from '../../observer'; + +export function tap( + observer: PartialAsyncObserver +): MonoTypeOperatorAsyncFunction { + return function tapOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new TapAsyncIterable(source, observer); + }; +} diff --git a/src/asynciterable/tap.ts b/src/asynciterable/tap.ts index 6599ed81..a2e49c45 100644 --- a/src/asynciterable/tap.ts +++ b/src/asynciterable/tap.ts @@ -1,7 +1,7 @@ import { AsyncIterableX } from '../asynciterable'; import { PartialAsyncObserver } from '../observer'; -class TapAsyncIterable extends AsyncIterableX { +export class TapAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; private _observer: PartialAsyncObserver; From f44726d677cf0d1040450025d00db48c341fb9cf Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 19:42:34 -0400 Subject: [PATCH 047/106] feat(pipe): add through throttle --- src/asynciterable/pipe/throttle.ts | 11 +++++++++++ src/asynciterable/throttle.ts | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/throttle.ts diff --git a/src/asynciterable/pipe/throttle.ts b/src/asynciterable/pipe/throttle.ts new file mode 100644 index 00000000..7c3da4e4 --- /dev/null +++ b/src/asynciterable/pipe/throttle.ts @@ -0,0 +1,11 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { ThrottleAsyncIterable } from '../throttle'; + +export function throttle(time: number): MonoTypeOperatorAsyncFunction { + return function throttleOperatorFunction( + source: AsyncIterable + ): AsyncIterableX { + return new ThrottleAsyncIterable(source, time); + }; +} diff --git a/src/asynciterable/throttle.ts b/src/asynciterable/throttle.ts index 943ecac5..1a958ab8 100644 --- a/src/asynciterable/throttle.ts +++ b/src/asynciterable/throttle.ts @@ -1,6 +1,6 @@ import { AsyncIterableX } from '../asynciterable'; -class ThrottleAsyncIterable extends AsyncIterableX { +export class ThrottleAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; private _time: number; From 829e89e1be8ef8145d3e6de29873120375cde51a Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 19:45:57 -0400 Subject: [PATCH 048/106] feat(pipe): add through timeinterval --- src/asynciterable/pipe/timeinterval.ts | 11 +++++++++++ src/asynciterable/timeinterval.ts | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/timeinterval.ts diff --git a/src/asynciterable/pipe/timeinterval.ts b/src/asynciterable/pipe/timeinterval.ts new file mode 100644 index 00000000..8d8f90b1 --- /dev/null +++ b/src/asynciterable/pipe/timeinterval.ts @@ -0,0 +1,11 @@ +import { OperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { TimeIntervalAsyncIterable, TimeInterval } from '../timeinterval'; + +export function timeInterval(): OperatorAsyncFunction> { + return function timeIntervalOperatorFunction( + source: AsyncIterable + ): AsyncIterableX> { + return new TimeIntervalAsyncIterable(source); + }; +} diff --git a/src/asynciterable/timeinterval.ts b/src/asynciterable/timeinterval.ts index 85441d04..16993613 100644 --- a/src/asynciterable/timeinterval.ts +++ b/src/asynciterable/timeinterval.ts @@ -5,7 +5,7 @@ export interface TimeInterval { elapsed: number; } -class TimeIntervalAsyncIterable extends AsyncIterableX> { +export class TimeIntervalAsyncIterable extends AsyncIterableX> { private _source: AsyncIterable; constructor(source: AsyncIterable) { From bae08b415ebcd12d9ebbcdf42204c8957aa90b99 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 19:49:50 -0400 Subject: [PATCH 049/106] feat(pipe): add through timeout --- src/asynciterable/pipe/timeout.ts | 9 +++++++++ src/asynciterable/timeout.ts | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/timeout.ts diff --git a/src/asynciterable/pipe/timeout.ts b/src/asynciterable/pipe/timeout.ts new file mode 100644 index 00000000..af5c1162 --- /dev/null +++ b/src/asynciterable/pipe/timeout.ts @@ -0,0 +1,9 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { TimeoutAsyncIterable } from '../timeout'; + +export function timeout(dueTime: number): MonoTypeOperatorAsyncFunction { + return function timeoutOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new TimeoutAsyncIterable(source, dueTime); + }; +} diff --git a/src/asynciterable/timeout.ts b/src/asynciterable/timeout.ts index be036039..d56193d3 100644 --- a/src/asynciterable/timeout.ts +++ b/src/asynciterable/timeout.ts @@ -17,7 +17,7 @@ interface TimeoutOperation { value?: IteratorResult; } -class TimeoutAsyncIterable extends AsyncIterableX { +export class TimeoutAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; private _dueTime: number; From b42c22e287300bc04165a1939e7fe01b4f473833 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 19:51:47 -0400 Subject: [PATCH 050/106] feat(pipe): add through timestamp --- src/asynciterable/pipe/timestamp.ts | 11 +++++++++++ src/asynciterable/timestamp.ts | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/timestamp.ts diff --git a/src/asynciterable/pipe/timestamp.ts b/src/asynciterable/pipe/timestamp.ts new file mode 100644 index 00000000..b2b67ee2 --- /dev/null +++ b/src/asynciterable/pipe/timestamp.ts @@ -0,0 +1,11 @@ +import { OperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { TimestampAsyncIterable, Timestamp } from '../timestamp'; + +export function timestamp(): OperatorAsyncFunction> { + return function timestampOperatorFunction( + source: AsyncIterable + ): AsyncIterableX> { + return new TimestampAsyncIterable(source); + }; +} diff --git a/src/asynciterable/timestamp.ts b/src/asynciterable/timestamp.ts index 6f3a9e50..ab559695 100644 --- a/src/asynciterable/timestamp.ts +++ b/src/asynciterable/timestamp.ts @@ -5,7 +5,7 @@ export interface Timestamp { value: TSource; } -class TimestampAsyncIterable extends AsyncIterableX> { +export class TimestampAsyncIterable extends AsyncIterableX> { private _source: AsyncIterable; constructor(source: AsyncIterable) { From 236819d3e530cdfe3dd15e4b2f718f2c32974cfd Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 19:54:40 -0400 Subject: [PATCH 051/106] feat(pipe): add through union --- src/asynciterable/pipe/union.ts | 13 +++++++++++++ src/asynciterable/union.ts | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/asynciterable/pipe/union.ts diff --git a/src/asynciterable/pipe/union.ts b/src/asynciterable/pipe/union.ts new file mode 100644 index 00000000..fa343ec8 --- /dev/null +++ b/src/asynciterable/pipe/union.ts @@ -0,0 +1,13 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { UnionAsyncIterable } from '../union'; +import { comparerAsync } from '../../internal/comparer'; + +export function union( + right: AsyncIterable, + comparer: (x: TSource, y: TSource) => boolean | Promise = comparerAsync +): MonoTypeOperatorAsyncFunction { + return function unionOperatorFunction(left: AsyncIterable): AsyncIterableX { + return new UnionAsyncIterable(left, right, comparer); + }; +} diff --git a/src/asynciterable/union.ts b/src/asynciterable/union.ts index f185c725..00392a6c 100644 --- a/src/asynciterable/union.ts +++ b/src/asynciterable/union.ts @@ -2,7 +2,7 @@ import { AsyncIterableX } from '../asynciterable'; import { arrayIndexOfAsync } from '../internal/arrayindexof'; import { comparerAsync } from '../internal/comparer'; -class UnionAsyncIterable extends AsyncIterableX { +export class UnionAsyncIterable extends AsyncIterableX { private _left: AsyncIterable; private _right: AsyncIterable; private _comparer: (x: TSource, y: TSource) => boolean | Promise; From 0f497afddd827e96f189fd94d8c8e7055d7100ca Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 22:37:43 -0400 Subject: [PATCH 052/106] feat(pipe): add through buffer --- src/iterable/__modules.ts | 2 + src/iterable/buffer.ts | 2 +- src/iterable/pipe.ts | 93 +++++++++++++++++++++++++++++++++++++ src/iterable/pipe/buffer.ts | 15 ++++++ 4 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe.ts create mode 100644 src/iterable/pipe/buffer.ts diff --git a/src/iterable/__modules.ts b/src/iterable/__modules.ts index cbd95e16..d7bd53fe 100644 --- a/src/iterable/__modules.ts +++ b/src/iterable/__modules.ts @@ -67,6 +67,7 @@ import { thenBy } from './orderby'; import { thenByDescending } from './orderby'; import { pairwise } from './pairwise'; import { partition } from './partition'; +import { pipe } from './pipe'; import { pluck } from './pluck'; import { publish } from './publish'; import { range } from './range'; @@ -170,6 +171,7 @@ export default { thenByDescending, pairwise, partition, + pipe, pluck, publish, range, diff --git a/src/iterable/buffer.ts b/src/iterable/buffer.ts index 4e70cfc9..6ec446e2 100644 --- a/src/iterable/buffer.ts +++ b/src/iterable/buffer.ts @@ -1,6 +1,6 @@ import { IterableX } from '../iterable'; -class BufferIterable extends IterableX { +export class BufferIterable extends IterableX { private _source: Iterable; private _count: number; private _skip: number; diff --git a/src/iterable/pipe.ts b/src/iterable/pipe.ts new file mode 100644 index 00000000..48a28b79 --- /dev/null +++ b/src/iterable/pipe.ts @@ -0,0 +1,93 @@ +import { OperatorFunction } from '../interfaces'; +import { IterableX } from '../iterable'; + +/* tslint:disable:max-line-length */ +export function pipe(source: Iterable): IterableX; +export function pipe(source: Iterable, op1: OperatorFunction): IterableX; +export function pipe( + source: Iterable, + op1: OperatorFunction, + op2: OperatorFunction +): IterableX; +export function pipe( + source: Iterable, + op1: OperatorFunction, + op2: OperatorFunction, + op3: OperatorFunction +): IterableX; +export function pipe( + source: Iterable, + op1: OperatorFunction, + op2: OperatorFunction, + op3: OperatorFunction, + op4: OperatorFunction +): IterableX; +export function pipe( + source: Iterable, + op1: OperatorFunction, + op2: OperatorFunction, + op3: OperatorFunction, + op4: OperatorFunction, + op5: OperatorFunction +): IterableX; +export function pipe( + source: Iterable, + op1: OperatorFunction, + op2: OperatorFunction, + op3: OperatorFunction, + op4: OperatorFunction, + op5: OperatorFunction, + op6: OperatorFunction +): IterableX; +export function pipe( + source: Iterable, + op1: OperatorFunction, + op2: OperatorFunction, + op3: OperatorFunction, + op4: OperatorFunction, + op5: OperatorFunction, + op6: OperatorFunction, + op7: OperatorFunction +): IterableX; +export function pipe( + source: Iterable, + op1: OperatorFunction, + op2: OperatorFunction, + op3: OperatorFunction, + op4: OperatorFunction, + op5: OperatorFunction, + op6: OperatorFunction, + op7: OperatorFunction, + op8: OperatorFunction +): IterableX; +export function pipe( + source: Iterable, + op1: OperatorFunction, + op2: OperatorFunction, + op3: OperatorFunction, + op4: OperatorFunction, + op5: OperatorFunction, + op6: OperatorFunction, + op7: OperatorFunction, + op8: OperatorFunction, + op9: OperatorFunction +): IterableX; +/* tslint:enable:max-line-length */ + +export function pipe( + source: Iterable, + ...operations: OperatorFunction[] +): IterableX { + if (operations.length === 0) { + return source as any; + } + + const piped = (input: Iterable): IterableX => { + return operations.reduce( + (prev: any, fn: OperatorFunction) => fn(prev), + input + ); + }; + + return piped(source); +} diff --git a/src/iterable/pipe/buffer.ts b/src/iterable/pipe/buffer.ts new file mode 100644 index 00000000..57aeed18 --- /dev/null +++ b/src/iterable/pipe/buffer.ts @@ -0,0 +1,15 @@ +import { OperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { BufferIterable } from '../buffer'; + +export function buffer( + count: number, + skip?: number +): OperatorFunction { + if (skip == null) { + skip = count; + } + return function bufferOperatorFunction(source: Iterable): IterableX { + return new BufferIterable(source, count, skip!); + }; +} From f1b9e481b3df86e5fe39ea2a0089e4fb59c97ee6 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 22:51:59 -0400 Subject: [PATCH 053/106] feat(pipe): add through catch --- src/asynciterable/catch.ts | 4 ++-- src/asynciterable/pipe/catch.ts | 9 +++++++++ src/iterable/catch.ts | 2 +- src/iterable/pipe/catch.ts | 9 +++++++++ 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 src/asynciterable/pipe/catch.ts create mode 100644 src/iterable/pipe/catch.ts diff --git a/src/asynciterable/catch.ts b/src/asynciterable/catch.ts index aa1ea26d..51094b3f 100644 --- a/src/asynciterable/catch.ts +++ b/src/asynciterable/catch.ts @@ -1,7 +1,7 @@ import { AsyncIterableX } from '../asynciterable'; import { returnAsyncIterator } from '../internal/returniterator'; -class CatchAllAsyncIterable extends AsyncIterableX { +export class CatchAllAsyncIterable extends AsyncIterableX { private _source: Iterable>; constructor(source: Iterable>) { @@ -60,7 +60,7 @@ export function _catch( source: AsyncIterable, ...args: AsyncIterable[] ): AsyncIterableX { - return _catchAll([source].concat(args)); + return _catchAll([source, ...args]); } export function _catchStatic(...source: AsyncIterable[]): AsyncIterableX { diff --git a/src/asynciterable/pipe/catch.ts b/src/asynciterable/pipe/catch.ts new file mode 100644 index 00000000..2bacb84b --- /dev/null +++ b/src/asynciterable/pipe/catch.ts @@ -0,0 +1,9 @@ +import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { CatchAllAsyncIterable } from '../catch'; + +export function _catch(...args: AsyncIterable[]): MonoTypeOperatorAsyncFunction { + return function catchOperatorFunction(source: AsyncIterable): AsyncIterableX { + return new CatchAllAsyncIterable([source, ...args]); + }; +} diff --git a/src/iterable/catch.ts b/src/iterable/catch.ts index a68edb09..67ece6f0 100644 --- a/src/iterable/catch.ts +++ b/src/iterable/catch.ts @@ -1,7 +1,7 @@ import { IterableX } from '../iterable'; import { returnIterator } from '../internal/returniterator'; -class CatchIterable extends IterableX { +export class CatchIterable extends IterableX { private _source: Iterable>; constructor(source: Iterable>) { diff --git a/src/iterable/pipe/catch.ts b/src/iterable/pipe/catch.ts new file mode 100644 index 00000000..b99143da --- /dev/null +++ b/src/iterable/pipe/catch.ts @@ -0,0 +1,9 @@ +import { MonoTypeOperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { CatchIterable } from '../catch'; + +export function _catch(...args: Iterable[]): MonoTypeOperatorFunction { + return function catchOperatorFunction(source: Iterable): IterableX { + return new CatchIterable([source, ...args]); + }; +} From d03709fbf4199cff5c6b08615a5899fc0cbf4883 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 22:55:09 -0400 Subject: [PATCH 054/106] feat(pipe): add through catchWith --- src/iterable/catchwith.ts | 2 +- src/iterable/pipe/catchwith.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe/catchwith.ts diff --git a/src/iterable/catchwith.ts b/src/iterable/catchwith.ts index c5cb5b40..5cd6fc01 100644 --- a/src/iterable/catchwith.ts +++ b/src/iterable/catchwith.ts @@ -1,7 +1,7 @@ import { IterableX } from '../iterable'; import { returnIterator } from '../internal/returniterator'; -class CatchWithIterable extends IterableX { +export class CatchWithIterable extends IterableX { private _source: Iterable; private _handler: (error: any) => Iterable; diff --git a/src/iterable/pipe/catchwith.ts b/src/iterable/pipe/catchwith.ts new file mode 100644 index 00000000..26d472bf --- /dev/null +++ b/src/iterable/pipe/catchwith.ts @@ -0,0 +1,11 @@ +import { MonoTypeOperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { CatchWithIterable } from '../catchwith'; + +export function catchWith( + handler: (error: any) => Iterable +): MonoTypeOperatorFunction { + return function catchWithOperatorFunction(source: Iterable): IterableX { + return new CatchWithIterable(source, handler); + }; +} From 9096bbc4d970148eab7e7da52076bc5ed4c3c653 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 23:00:08 -0400 Subject: [PATCH 055/106] feat(pipe): add through concat --- src/iterable/pipe/concat.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/iterable/pipe/concat.ts diff --git a/src/iterable/pipe/concat.ts b/src/iterable/pipe/concat.ts new file mode 100644 index 00000000..62de83d3 --- /dev/null +++ b/src/iterable/pipe/concat.ts @@ -0,0 +1,35 @@ +import { MonoTypeOperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { ConcatIterable } from '../concat'; + +/* tslint:disable:max-line-length */ +export function concat(v2: Iterable): MonoTypeOperatorFunction; +export function concat( + v2: Iterable, + v3: Iterable +): MonoTypeOperatorFunction; +export function concat( + v2: Iterable, + v3: Iterable, + v4: Iterable +): MonoTypeOperatorFunction; +export function concat( + v2: Iterable, + v3: Iterable, + v4: Iterable, + v5: Iterable +): MonoTypeOperatorFunction; +export function concat( + v2: Iterable, + v3: Iterable, + v4: Iterable, + v5: Iterable, + v6: Iterable +): MonoTypeOperatorFunction; +/* tslint:enable:max-line-length */ + +export function concat(...args: Iterable[]): MonoTypeOperatorFunction { + return function concatOperatorFunction(source: Iterable): IterableX { + return new ConcatIterable([source, ...args]); + }; +} From 01eab693d8a33ebb721bcca482741d1a23b7c7a2 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 23:02:55 -0400 Subject: [PATCH 056/106] feat(pipe): add through concatall --- src/iterable/pipe/concatall.ts | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/iterable/pipe/concatall.ts diff --git a/src/iterable/pipe/concatall.ts b/src/iterable/pipe/concatall.ts new file mode 100644 index 00000000..97132d81 --- /dev/null +++ b/src/iterable/pipe/concatall.ts @@ -0,0 +1,9 @@ +import { OperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { ConcatIterable } from '../concat'; + +export function concatAll(): OperatorFunction, T> { + return function concatAllOperatorFunction(source: Iterable>): IterableX { + return new ConcatIterable(source); + }; +} From 3aa1000c1f404990e197c6e79e46d674a87c3063 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 23:05:15 -0400 Subject: [PATCH 057/106] feat(pipe): add through defaultifempty --- src/iterable/defaultifempty.ts | 2 +- src/iterable/pipe/defaultifempty.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe/defaultifempty.ts diff --git a/src/iterable/defaultifempty.ts b/src/iterable/defaultifempty.ts index b3b36a93..c8e147b8 100644 --- a/src/iterable/defaultifempty.ts +++ b/src/iterable/defaultifempty.ts @@ -1,6 +1,6 @@ import { IterableX } from '../iterable'; -class DefaultIfEmptyIterable extends IterableX { +export class DefaultIfEmptyIterable extends IterableX { private _source: Iterable; private _defaultValue: TSource; diff --git a/src/iterable/pipe/defaultifempty.ts b/src/iterable/pipe/defaultifempty.ts new file mode 100644 index 00000000..a763123d --- /dev/null +++ b/src/iterable/pipe/defaultifempty.ts @@ -0,0 +1,9 @@ +import { MonoTypeOperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { DefaultIfEmptyIterable } from '../defaultifempty'; + +export function defaultIfEmpty(defaultValue: T): MonoTypeOperatorFunction { + return function defaultIfEmptyOperatorFunction(source: Iterable): IterableX { + return new DefaultIfEmptyIterable(source, defaultValue); + }; +} From 4575fb741646b6dc2f4894a401ed7a5dd8843b77 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 23:08:53 -0400 Subject: [PATCH 058/106] feat(pipe): add through distinct --- src/iterable/distinct.ts | 2 +- src/iterable/pipe/distinct.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe/distinct.ts diff --git a/src/iterable/distinct.ts b/src/iterable/distinct.ts index afb4e696..fb964b20 100644 --- a/src/iterable/distinct.ts +++ b/src/iterable/distinct.ts @@ -3,7 +3,7 @@ import { identity } from '../internal/identity'; import { arrayIndexOf } from '../internal/arrayindexof'; import { comparer as defaultComparer } from '../internal/comparer'; -class DistinctIterable extends IterableX { +export class DistinctIterable extends IterableX { private _source: Iterable; private _keySelector: (value: TSource) => TKey; private _cmp: (x: TKey, y: TKey) => boolean; diff --git a/src/iterable/pipe/distinct.ts b/src/iterable/pipe/distinct.ts new file mode 100644 index 00000000..2e5a6594 --- /dev/null +++ b/src/iterable/pipe/distinct.ts @@ -0,0 +1,14 @@ +import { MonoTypeOperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { DistinctIterable } from '../distinct'; +import { identity } from '../../internal/identity'; +import { comparer as defaultComparer } from '../../internal/comparer'; + +export function distinct( + keySelector: (value: TSource) => TKey = identity, + comparer: (x: TKey, y: TKey) => boolean = defaultComparer +): MonoTypeOperatorFunction { + return function distinctOperatorFunction(source: Iterable): IterableX { + return new DistinctIterable(source, keySelector, comparer); + }; +} From 8aee9122cf71afe373a8b3fdcd25efded50d58e8 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 23:11:38 -0400 Subject: [PATCH 059/106] feat(pipe): add through distinctuntilchanged --- src/iterable/distinctuntilchanged.ts | 2 +- src/iterable/pipe/distinctuntilchanged.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe/distinctuntilchanged.ts diff --git a/src/iterable/distinctuntilchanged.ts b/src/iterable/distinctuntilchanged.ts index 787228f3..2fa39acb 100644 --- a/src/iterable/distinctuntilchanged.ts +++ b/src/iterable/distinctuntilchanged.ts @@ -2,7 +2,7 @@ import { IterableX } from '../iterable'; import { identity } from '../internal/identity'; import { comparer as defaultComparer } from '../internal/comparer'; -class DistinctUntilChangedIterable extends IterableX { +export class DistinctUntilChangedIterable extends IterableX { private _source: Iterable; private _keySelector: (value: TSource) => TKey; private _comparer: (x: TKey, y: TKey) => boolean; diff --git a/src/iterable/pipe/distinctuntilchanged.ts b/src/iterable/pipe/distinctuntilchanged.ts new file mode 100644 index 00000000..8324538e --- /dev/null +++ b/src/iterable/pipe/distinctuntilchanged.ts @@ -0,0 +1,16 @@ +import { MonoTypeOperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { DistinctUntilChangedIterable } from '../distinctuntilchanged'; +import { identity } from '../../internal/identity'; +import { comparer as defaultComparer } from '../../internal/comparer'; + +export function distinctUntilChanged( + keySelector: (value: TSource) => TKey = identity, + comparer: (first: TKey, second: TKey) => boolean = defaultComparer +): MonoTypeOperatorFunction { + return function distinctUntilChangedOperatorFunction( + source: Iterable + ): IterableX { + return new DistinctUntilChangedIterable(source, keySelector, comparer); + }; +} From b1ee24cb938941609ba132d22c0a1d29fbd58980 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 23:13:20 -0400 Subject: [PATCH 060/106] feat(pipe): add through dowhile --- src/iterable/pipe/dowhile.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/iterable/pipe/dowhile.ts diff --git a/src/iterable/pipe/dowhile.ts b/src/iterable/pipe/dowhile.ts new file mode 100644 index 00000000..9aa0148a --- /dev/null +++ b/src/iterable/pipe/dowhile.ts @@ -0,0 +1,10 @@ +import { MonoTypeOperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { concatStatic } from '../concat'; +import { _while } from '../while'; + +export function doWhile(condition: () => boolean): MonoTypeOperatorFunction { + return function doWhileOperatorFunction(source: Iterable): IterableX { + return concatStatic(source, _while(condition, source)); + }; +} From 35d84e96690ecad41415e1f30dc9182c6453e993 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 23:18:53 -0400 Subject: [PATCH 061/106] feat(pipe): add through endwith --- src/iterable/endwith.ts | 2 +- src/iterable/pipe/endwith.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe/endwith.ts diff --git a/src/iterable/endwith.ts b/src/iterable/endwith.ts index 2a1fa615..97fb2397 100644 --- a/src/iterable/endwith.ts +++ b/src/iterable/endwith.ts @@ -1,6 +1,6 @@ import { IterableX } from '../iterable'; -class EndWithIterable extends IterableX { +export class EndWithIterable extends IterableX { private _source: Iterable; private _args: TSource[]; diff --git a/src/iterable/pipe/endwith.ts b/src/iterable/pipe/endwith.ts new file mode 100644 index 00000000..a8b22f8e --- /dev/null +++ b/src/iterable/pipe/endwith.ts @@ -0,0 +1,9 @@ +import { MonoTypeOperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { EndWithIterable } from '../endwith'; + +export function endWith(...args: TSource[]): MonoTypeOperatorFunction { + return function endsWithOperatorFunction(source: Iterable): IterableX { + return new EndWithIterable(source, args); + }; +} From b1cf9e5ed9ecf8e374836ad617e2a697a965d146 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 23:28:02 -0400 Subject: [PATCH 062/106] feat(pipe): add through except --- src/iterable/except.ts | 2 +- src/iterable/pipe/except.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe/except.ts diff --git a/src/iterable/except.ts b/src/iterable/except.ts index 0fdb4b74..e4d272b7 100644 --- a/src/iterable/except.ts +++ b/src/iterable/except.ts @@ -2,7 +2,7 @@ import { IterableX } from '../iterable'; import { arrayIndexOf } from '../internal/arrayindexof'; import { comparer as defaultComparer } from '../internal/comparer'; -class ExceptIterable extends IterableX { +export class ExceptIterable extends IterableX { private _first: Iterable; private _second: Iterable; private _comparer: (x: TSource, y: TSource) => boolean; diff --git a/src/iterable/pipe/except.ts b/src/iterable/pipe/except.ts new file mode 100644 index 00000000..c1caafa8 --- /dev/null +++ b/src/iterable/pipe/except.ts @@ -0,0 +1,13 @@ +import { MonoTypeOperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { ExceptIterable } from '../except'; +import { comparer as defaultComparer } from '../../internal/comparer'; + +export function except( + second: Iterable, + comparer: (x: TSource, y: TSource) => boolean = defaultComparer +): MonoTypeOperatorFunction { + return function exceptOperatorFunction(first: Iterable): IterableX { + return new ExceptIterable(first, second, comparer); + }; +} From e63cf1a0dc25717bc8c05f3a5728171ed17c514f Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 23:30:43 -0400 Subject: [PATCH 063/106] feat(pipe): add through expand --- src/iterable/expand.ts | 2 +- src/iterable/pipe/expand.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe/expand.ts diff --git a/src/iterable/expand.ts b/src/iterable/expand.ts index 04032c75..2a864c2a 100644 --- a/src/iterable/expand.ts +++ b/src/iterable/expand.ts @@ -1,6 +1,6 @@ import { IterableX } from '../iterable'; -class ExpandIterable extends IterableX { +export class ExpandIterable extends IterableX { private _source: Iterable; private _fn: (value: TSource) => Iterable; diff --git a/src/iterable/pipe/expand.ts b/src/iterable/pipe/expand.ts new file mode 100644 index 00000000..6a59a4ba --- /dev/null +++ b/src/iterable/pipe/expand.ts @@ -0,0 +1,11 @@ +import { MonoTypeOperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { ExpandIterable } from '../expand'; + +export function expand( + selector: (value: TSource) => Iterable +): MonoTypeOperatorFunction { + return function expandOperatorFunction(source: Iterable): IterableX { + return new ExpandIterable(source, selector); + }; +} From da388186613759091493dcdf933d9e200764a0f8 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 24 Oct 2017 23:54:16 -0400 Subject: [PATCH 064/106] feat(pipe): add through filter --- src/asynciterable/pipe/filter.ts | 12 ++++++++++-- src/iterable/filter.ts | 2 +- src/iterable/pipe/filter.ts | 21 +++++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 src/iterable/pipe/filter.ts diff --git a/src/asynciterable/pipe/filter.ts b/src/asynciterable/pipe/filter.ts index 7743fa6e..d82b9571 100644 --- a/src/asynciterable/pipe/filter.ts +++ b/src/asynciterable/pipe/filter.ts @@ -1,12 +1,20 @@ -import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; +import { OperatorAsyncFunction } from '../../interfaces'; import { AsyncIterableX } from '../../asynciterable'; import { FilterAsyncIterable } from '../filter'; import { bindCallback } from '../../internal/bindcallback'; +export function filter( + predicate: (value: T, index: number) => value is S, + thisArg?: any +): OperatorAsyncFunction; +export function filter( + predicate: (value: T, index: number) => boolean | Promise, + thisArg?: any +): OperatorAsyncFunction; export function filter( predicate: (value: TSource, index: number) => boolean | Promise, thisArg?: any -): MonoTypeOperatorAsyncFunction { +): OperatorAsyncFunction { return function filterOperatorFunction(source: AsyncIterable): AsyncIterableX { return new FilterAsyncIterable(source, bindCallback(predicate, thisArg, 2)); }; diff --git a/src/iterable/filter.ts b/src/iterable/filter.ts index ac26775b..5b21c56a 100644 --- a/src/iterable/filter.ts +++ b/src/iterable/filter.ts @@ -1,7 +1,7 @@ import { IterableX } from '../iterable'; import { bindCallback } from '../internal/bindcallback'; -class FilterIterable extends IterableX { +export class FilterIterable extends IterableX { private _source: Iterable; private _predicate: (value: TSource, index: number) => boolean; diff --git a/src/iterable/pipe/filter.ts b/src/iterable/pipe/filter.ts new file mode 100644 index 00000000..7b330ebb --- /dev/null +++ b/src/iterable/pipe/filter.ts @@ -0,0 +1,21 @@ +import { OperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { FilterIterable } from '../filter'; +import { bindCallback } from '../../internal/bindcallback'; + +export function filter( + predicate: (value: T, index: number) => value is S, + thisArg?: any +): OperatorFunction; +export function filter( + predicate: (value: T, index: number) => boolean, + thisArg?: any +): OperatorFunction; +export function filter( + predicate: (value: TSource, index: number) => boolean, + thisArg?: any +): OperatorFunction { + return function filterOperatorFunction(source: Iterable): IterableX { + return new FilterIterable(source, bindCallback(predicate, thisArg, 2)); + }; +} From 80f029fc80c51cb5ea0e5ff2132845334cb2292a Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 00:22:25 -0400 Subject: [PATCH 065/106] feat(pipe): add through finally --- src/asynciterable/finally.ts | 4 ++-- src/asynciterable/pipe/finally.ts | 4 ++-- src/iterable/finally.ts | 4 ++-- src/iterable/pipe/finally.ts | 9 +++++++++ 4 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 src/iterable/pipe/finally.ts diff --git a/src/asynciterable/finally.ts b/src/asynciterable/finally.ts index b61cc96d..78c35163 100644 --- a/src/asynciterable/finally.ts +++ b/src/asynciterable/finally.ts @@ -1,6 +1,6 @@ import { AsyncIterableX } from '../asynciterable'; -export class FinalyAsyncIterable extends AsyncIterableX { +export class FinallyAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; private _action: () => void | Promise; @@ -25,5 +25,5 @@ export function _finally( source: AsyncIterable, action: () => void | Promise ): AsyncIterableX { - return new FinalyAsyncIterable(source, action); + return new FinallyAsyncIterable(source, action); } diff --git a/src/asynciterable/pipe/finally.ts b/src/asynciterable/pipe/finally.ts index fcbbe537..cdd492e3 100644 --- a/src/asynciterable/pipe/finally.ts +++ b/src/asynciterable/pipe/finally.ts @@ -1,11 +1,11 @@ import { MonoTypeOperatorAsyncFunction } from '../../interfaces'; import { AsyncIterableX } from '../../asynciterable'; -import { FinalyAsyncIterable } from '../finally'; +import { FinallyAsyncIterable } from '../finally'; export function _finally( action: () => void | Promise ): MonoTypeOperatorAsyncFunction { return function finallyOperatorFunction(source: AsyncIterable): AsyncIterableX { - return new FinalyAsyncIterable(source, action); + return new FinallyAsyncIterable(source, action); }; } diff --git a/src/iterable/finally.ts b/src/iterable/finally.ts index 29bb2199..8cb34f0c 100644 --- a/src/iterable/finally.ts +++ b/src/iterable/finally.ts @@ -1,6 +1,6 @@ import { IterableX } from '../iterable'; -class FinalyIterable extends IterableX { +export class FinallyIterable extends IterableX { private _source: Iterable; private _action: () => void; @@ -29,5 +29,5 @@ export function _finally( source: Iterable, action: () => void ): IterableX { - return new FinalyIterable(source, action); + return new FinallyIterable(source, action); } diff --git a/src/iterable/pipe/finally.ts b/src/iterable/pipe/finally.ts new file mode 100644 index 00000000..052a30d0 --- /dev/null +++ b/src/iterable/pipe/finally.ts @@ -0,0 +1,9 @@ +import { MonoTypeOperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { FinallyIterable } from '../finally'; + +export function _finally(action: () => void): MonoTypeOperatorFunction { + return function finallyOperatorFunction(source: Iterable): IterableX { + return new FinallyIterable(source, action); + }; +} From ecf76d872f9b09cca485a30719f8e8b050d2ce91 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 00:24:05 -0400 Subject: [PATCH 066/106] feat(pipe): add through flatmap --- src/iterable/flatmap.ts | 2 +- src/iterable/pipe/flatmap.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe/flatmap.ts diff --git a/src/iterable/flatmap.ts b/src/iterable/flatmap.ts index d5abb4e8..e7158223 100644 --- a/src/iterable/flatmap.ts +++ b/src/iterable/flatmap.ts @@ -1,7 +1,7 @@ import { IterableX } from '../iterable'; import { bindCallback } from '../internal/bindcallback'; -class FlatMapIterable extends IterableX { +export class FlatMapIterable extends IterableX { private _source: Iterable; private _fn: (value: TSource) => Iterable; diff --git a/src/iterable/pipe/flatmap.ts b/src/iterable/pipe/flatmap.ts new file mode 100644 index 00000000..91469846 --- /dev/null +++ b/src/iterable/pipe/flatmap.ts @@ -0,0 +1,13 @@ +import { OperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { FlatMapIterable } from '../flatmap'; +import { bindCallback } from '../../internal/bindcallback'; + +export function flatMap( + selector: (value: TSource) => Iterable, + thisArg?: any +): OperatorFunction { + return function flatMapOperatorFunction(source: Iterable): IterableX { + return new FlatMapIterable(source, bindCallback(selector, thisArg, 1)); + }; +} From 1c90a65a0d7a4a11deb911d485ed8d5aa46d54a0 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 00:25:42 -0400 Subject: [PATCH 067/106] feat(pipe): add through flatten --- src/iterable/flatten.ts | 2 +- src/iterable/pipe/flatten.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe/flatten.ts diff --git a/src/iterable/flatten.ts b/src/iterable/flatten.ts index 6cb7e22e..1b5fb0c9 100644 --- a/src/iterable/flatten.ts +++ b/src/iterable/flatten.ts @@ -1,7 +1,7 @@ import { IterableX } from '../iterable'; import { isIterable } from '../internal/isiterable'; -class FlattenIterable extends IterableX { +export class FlattenIterable extends IterableX { private _source: Iterable; private _depth: number; diff --git a/src/iterable/pipe/flatten.ts b/src/iterable/pipe/flatten.ts new file mode 100644 index 00000000..b703cf6f --- /dev/null +++ b/src/iterable/pipe/flatten.ts @@ -0,0 +1,9 @@ +import { MonoTypeOperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { FlattenIterable } from '../flatten'; + +export function flatten(depth: number = Infinity): MonoTypeOperatorFunction { + return function flattenOperatorFunction(source: Iterable): IterableX { + return new FlattenIterable(source, depth); + }; +} From d534118c2f58a32fd356a37b6a1f4a2fcdf76662 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 00:29:28 -0400 Subject: [PATCH 068/106] feat(pipe): add through groupjoin --- src/iterable/groupjoin.ts | 2 +- src/iterable/pipe/groupby.ts | 31 +++++++++++++++++++++++++++++++ src/iterable/pipe/groupjoin.ts | 20 ++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe/groupby.ts create mode 100644 src/iterable/pipe/groupjoin.ts diff --git a/src/iterable/groupjoin.ts b/src/iterable/groupjoin.ts index 2c6d945b..0e573b32 100644 --- a/src/iterable/groupjoin.ts +++ b/src/iterable/groupjoin.ts @@ -3,7 +3,7 @@ import { createGrouping } from './_grouping'; import { empty } from './empty'; import { identity } from '../internal/identity'; -class GroupJoinIterable extends IterableX { +export class GroupJoinIterable extends IterableX { private _outer: Iterable; private _inner: Iterable; private _outerSelector: (value: TOuter) => TKey; diff --git a/src/iterable/pipe/groupby.ts b/src/iterable/pipe/groupby.ts new file mode 100644 index 00000000..997fd9cf --- /dev/null +++ b/src/iterable/pipe/groupby.ts @@ -0,0 +1,31 @@ +import { OperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { GroupByIterable, GroupedIterable, groupByResultIdentity } from '../groupby'; +import { identity } from '../../internal/identity'; + +export function groupBy( + keySelector: (value: TSource) => TKey +): OperatorFunction>; +export function groupBy( + keySelector: (value: TSource) => TKey, + elementSelector?: (value: TSource) => TValue +): OperatorFunction>; +export function groupBy( + keySelector: (value: TSource) => TKey, + elementSelector?: (value: TSource) => TValue, + resultSelector?: (key: TKey, values: Iterable) => TResult +): OperatorFunction; +export function groupBy( + keySelector: (value: TSource) => TKey, + elementSelector: (value: TSource) => TValue = identity, + resultSelector: (key: TKey, values: Iterable) => TResult = groupByResultIdentity +): OperatorFunction { + return function groupByOperatorFunction(source: Iterable): IterableX { + return new GroupByIterable( + source, + keySelector, + elementSelector, + resultSelector + ); + }; +} diff --git a/src/iterable/pipe/groupjoin.ts b/src/iterable/pipe/groupjoin.ts new file mode 100644 index 00000000..074fccb9 --- /dev/null +++ b/src/iterable/pipe/groupjoin.ts @@ -0,0 +1,20 @@ +import { OperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { GroupJoinIterable } from '../groupjoin'; + +export function groupJoin( + inner: Iterable, + outerSelector: (value: TOuter) => TKey, + innerSelector: (value: TInner) => TKey, + resultSelector: (outer: TOuter, inner: Iterable) => TResult +): OperatorFunction { + return function groupJoinOperatorFunction(outer: Iterable): IterableX { + return new GroupJoinIterable( + outer, + inner, + outerSelector, + innerSelector, + resultSelector + ); + }; +} From 70fc2567d8aa6ae1cceded81e39636dc35615161 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 00:31:11 -0400 Subject: [PATCH 069/106] feat(pipe): add through ignorelements --- src/iterable/ignoreelements.ts | 2 +- src/iterable/pipe/ignoreelements.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe/ignoreelements.ts diff --git a/src/iterable/ignoreelements.ts b/src/iterable/ignoreelements.ts index 4da77a23..99b7c193 100644 --- a/src/iterable/ignoreelements.ts +++ b/src/iterable/ignoreelements.ts @@ -1,6 +1,6 @@ import { IterableX } from '../iterable'; -class IgnoreElementsIterable extends IterableX { +export class IgnoreElementsIterable extends IterableX { private _source: Iterable; constructor(source: Iterable) { diff --git a/src/iterable/pipe/ignoreelements.ts b/src/iterable/pipe/ignoreelements.ts new file mode 100644 index 00000000..a0f87a78 --- /dev/null +++ b/src/iterable/pipe/ignoreelements.ts @@ -0,0 +1,9 @@ +import { MonoTypeOperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { IgnoreElementsIterable } from '../ignoreelements'; + +export function ignoreElements(): MonoTypeOperatorFunction { + return function ignoreElementsOperatorFunction(source: Iterable): IterableX { + return new IgnoreElementsIterable(source); + }; +} From c8989cd18367627bc85a7f8e4396b4c0cd286464 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 00:32:59 -0400 Subject: [PATCH 070/106] feat(pipe): add through innerjoin --- src/iterable/innerjoin.ts | 2 +- src/iterable/pipe/innerjoin.ts | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe/innerjoin.ts diff --git a/src/iterable/innerjoin.ts b/src/iterable/innerjoin.ts index 53699f81..cd624b88 100644 --- a/src/iterable/innerjoin.ts +++ b/src/iterable/innerjoin.ts @@ -2,7 +2,7 @@ import { IterableX } from '../iterable'; import { createGrouping } from './_grouping'; import { identity } from '../internal/identity'; -class JoinIterable extends IterableX { +export class JoinIterable extends IterableX { private _outer: Iterable; private _inner: Iterable; private _outerSelector: (value: TOuter) => TKey; diff --git a/src/iterable/pipe/innerjoin.ts b/src/iterable/pipe/innerjoin.ts new file mode 100644 index 00000000..6c67b3c6 --- /dev/null +++ b/src/iterable/pipe/innerjoin.ts @@ -0,0 +1,20 @@ +import { OperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { JoinIterable } from '../innerjoin'; + +export function innerJoin( + inner: Iterable, + outerSelector: (value: TOuter) => TKey, + innerSelector: (value: TInner) => TKey, + resultSelector: (outer: TOuter, inner: TInner) => TResult +): OperatorFunction { + return function innerJoinOperatorFunction(outer: Iterable): IterableX { + return new JoinIterable( + outer, + inner, + outerSelector, + innerSelector, + resultSelector + ); + }; +} From 438b5c48ce86fdaa403560191ed52dc2c25d3de6 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 00:34:51 -0400 Subject: [PATCH 071/106] feat(pipe): add through intersect --- src/iterable/intersect.ts | 2 +- src/iterable/pipe/intersect.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe/intersect.ts diff --git a/src/iterable/intersect.ts b/src/iterable/intersect.ts index 71e0b781..389174c3 100644 --- a/src/iterable/intersect.ts +++ b/src/iterable/intersect.ts @@ -11,7 +11,7 @@ function arrayRemove(array: T[], item: T, comparer: (x: T, y: T) => boolean): return true; } -class IntersectIterable extends IterableX { +export class IntersectIterable extends IterableX { private _first: Iterable; private _second: Iterable; private _comparer: (x: TSource, y: TSource) => boolean; diff --git a/src/iterable/pipe/intersect.ts b/src/iterable/pipe/intersect.ts new file mode 100644 index 00000000..41ddf90d --- /dev/null +++ b/src/iterable/pipe/intersect.ts @@ -0,0 +1,13 @@ +import { MonoTypeOperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { IntersectIterable } from '../intersect'; +import { comparer as defaultComparer } from '../../internal/comparer'; + +export function intersect( + second: Iterable, + comparer: (x: TSource, y: TSource) => boolean = defaultComparer +): MonoTypeOperatorFunction { + return function intersectOperatorFunction(first: Iterable): IterableX { + return new IntersectIterable(first, second, comparer); + }; +} From 000fbfe2e6ccf191721a088b0ef189e8886d7606 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 00:36:23 -0400 Subject: [PATCH 072/106] feat(pipe): add through map --- src/iterable/map.ts | 2 +- src/iterable/pipe/map.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe/map.ts diff --git a/src/iterable/map.ts b/src/iterable/map.ts index c316106b..3ea2ca13 100644 --- a/src/iterable/map.ts +++ b/src/iterable/map.ts @@ -1,7 +1,7 @@ import { IterableX } from '../iterable'; import { bindCallback } from '../internal/bindcallback'; -class MapIterable extends IterableX { +export class MapIterable extends IterableX { private _source: Iterable; private _selector: (value: TSource, index: number) => TResult; diff --git a/src/iterable/pipe/map.ts b/src/iterable/pipe/map.ts new file mode 100644 index 00000000..1598423b --- /dev/null +++ b/src/iterable/pipe/map.ts @@ -0,0 +1,13 @@ +import { OperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { MapIterable } from '../map'; +import { bindCallback } from '../../internal/bindcallback'; + +export function map( + selector: (value: TSource, index: number) => TResult, + thisArg?: any +): OperatorFunction { + return function mapOperatorFunction(source: Iterable): IterableX { + return new MapIterable(source, bindCallback(selector, thisArg, 2)); + }; +} From 53ce45ac11bc200bcda6cac061201811bc692fb5 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 00:37:47 -0400 Subject: [PATCH 073/106] feat(pipe): add through maxby --- src/iterable/pipe/maxby.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/iterable/pipe/maxby.ts diff --git a/src/iterable/pipe/maxby.ts b/src/iterable/pipe/maxby.ts new file mode 100644 index 00000000..4467cc5a --- /dev/null +++ b/src/iterable/pipe/maxby.ts @@ -0,0 +1,12 @@ +import { MonoTypeOperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { extremaBy, defaultCompare } from '../_extremaby'; + +export function maxBy( + keySelector: (x: TSource) => TKey, + comparer: (x: TKey, y: TKey) => number = defaultCompare +): MonoTypeOperatorFunction { + return function maxByOperatorFunction(source: Iterable): IterableX { + return extremaBy(source, keySelector, comparer); + }; +} From 16be7467e0532e041544d0595995bf12052bd261 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 00:39:25 -0400 Subject: [PATCH 074/106] feat(pipe): add through memoie --- src/iterable/pipe/memoize.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/iterable/pipe/memoize.ts diff --git a/src/iterable/pipe/memoize.ts b/src/iterable/pipe/memoize.ts new file mode 100644 index 00000000..bd1a58fd --- /dev/null +++ b/src/iterable/pipe/memoize.ts @@ -0,0 +1,17 @@ +import { OperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { memoize as memoizeStatic } from '../memoize'; + +export function memoize(readerCount?: number): OperatorFunction; +export function memoize( + readerCount?: number, + selector?: (value: Iterable) => Iterable +): OperatorFunction; +export function memoize( + readerCount: number = -1, + selector?: (value: Iterable) => Iterable +): OperatorFunction { + return function memoizeOperatorFunction(source: Iterable): IterableX { + return memoizeStatic(source, readerCount, selector); + }; +} From f628703dd9a38166d432fbc16952a601651602fd Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 00:40:31 -0400 Subject: [PATCH 075/106] feat(pipe): add through minby --- src/iterable/pipe/minby.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/iterable/pipe/minby.ts diff --git a/src/iterable/pipe/minby.ts b/src/iterable/pipe/minby.ts new file mode 100644 index 00000000..5d612f61 --- /dev/null +++ b/src/iterable/pipe/minby.ts @@ -0,0 +1,12 @@ +import { MonoTypeOperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { extremaBy, defaultCompare } from '../_extremaby'; + +export function minBy( + keySelector: (x: TSource) => TKey, + comparer: (x: TKey, y: TKey) => number = defaultCompare +): MonoTypeOperatorFunction { + return function minByOperatorFunction(source: Iterable): IterableX { + return extremaBy(source, keySelector, (key, minValue) => -comparer(key, minValue)); + }; +} From b1c39ac0e58ff97352ea7255af7ec2e7a92eb35c Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 00:41:47 -0400 Subject: [PATCH 076/106] feat(pipe): add through onerrorresumenext --- src/iterable/onerrorresumenext.ts | 2 +- src/iterable/pipe/onerrorresumenext.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe/onerrorresumenext.ts diff --git a/src/iterable/onerrorresumenext.ts b/src/iterable/onerrorresumenext.ts index 37e3c576..82ffffca 100644 --- a/src/iterable/onerrorresumenext.ts +++ b/src/iterable/onerrorresumenext.ts @@ -1,6 +1,6 @@ import { IterableX } from '../iterable'; -class OnErrorResumeNextIterable extends IterableX { +export class OnErrorResumeNextIterable extends IterableX { private _source: Iterable>; constructor(source: Iterable>) { diff --git a/src/iterable/pipe/onerrorresumenext.ts b/src/iterable/pipe/onerrorresumenext.ts new file mode 100644 index 00000000..e605eb31 --- /dev/null +++ b/src/iterable/pipe/onerrorresumenext.ts @@ -0,0 +1,9 @@ +import { MonoTypeOperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { OnErrorResumeNextIterable } from '../onerrorresumenext'; + +export function onErrorResumeNext(...args: Iterable[]): MonoTypeOperatorFunction { + return function onErrorResumeNextOperatorFunction(source: Iterable): IterableX { + return new OnErrorResumeNextIterable([source, ...args]); + }; +} From b46c7f2ed3ba18d99bfb725c0c2b824c5355998c Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 00:45:59 -0400 Subject: [PATCH 077/106] feat(pipe): add through pairwise --- src/iterable/pairwise.ts | 2 +- src/iterable/pipe/pairwise.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe/pairwise.ts diff --git a/src/iterable/pairwise.ts b/src/iterable/pairwise.ts index cec41eb4..fe90538a 100644 --- a/src/iterable/pairwise.ts +++ b/src/iterable/pairwise.ts @@ -1,6 +1,6 @@ import { IterableX } from '../iterable'; -class PairwiseIterable extends IterableX { +export class PairwiseIterable extends IterableX { private _source: Iterable; constructor(source: Iterable) { diff --git a/src/iterable/pipe/pairwise.ts b/src/iterable/pipe/pairwise.ts new file mode 100644 index 00000000..dc4ca805 --- /dev/null +++ b/src/iterable/pipe/pairwise.ts @@ -0,0 +1,9 @@ +import { OperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { PairwiseIterable } from '../pairwise'; + +export function pairwise(): OperatorFunction { + return function pairwiseOperatorFunction(source: Iterable): IterableX { + return new PairwiseIterable(source); + }; +} From ab8ece67970aa5ff6721173978aba9b011de9fea Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 00:47:02 -0400 Subject: [PATCH 078/106] feat(pipe): add through pluck --- src/iterable/pipe/pluck.ts | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/iterable/pipe/pluck.ts diff --git a/src/iterable/pipe/pluck.ts b/src/iterable/pipe/pluck.ts new file mode 100644 index 00000000..aeccdc63 --- /dev/null +++ b/src/iterable/pipe/pluck.ts @@ -0,0 +1,9 @@ +import { OperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { pluck as pluckStatic } from '../pluck'; + +export function pluck(...args: string[]): OperatorFunction { + return function pluckOperatorFunction(source: Iterable): IterableX { + return pluckStatic(source, ...args); + }; +} From 75f971e22f01b2f79cedc5cc009bb65d3631466a Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 00:48:01 -0400 Subject: [PATCH 079/106] feat(pipe): add through publish --- src/iterable/pipe/publish.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/iterable/pipe/publish.ts diff --git a/src/iterable/pipe/publish.ts b/src/iterable/pipe/publish.ts new file mode 100644 index 00000000..4044c26c --- /dev/null +++ b/src/iterable/pipe/publish.ts @@ -0,0 +1,15 @@ +import { OperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { publish as publishStatic } from '../publish'; + +export function publish(): OperatorFunction; +export function publish( + selector?: (value: Iterable) => Iterable +): OperatorFunction; +export function publish( + selector?: (value: Iterable) => Iterable +): OperatorFunction { + return function publishOperatorFunction(source: Iterable): IterableX { + return publishStatic(source, selector); + }; +} From 054ae84a18d872e12f5839c688d150deef8c2277 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 00:49:00 -0400 Subject: [PATCH 080/106] feat(pipe): add through repeat --- src/iterable/pipe/repeat.ts | 9 +++++++++ src/iterable/repeat.ts | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe/repeat.ts diff --git a/src/iterable/pipe/repeat.ts b/src/iterable/pipe/repeat.ts new file mode 100644 index 00000000..c483646c --- /dev/null +++ b/src/iterable/pipe/repeat.ts @@ -0,0 +1,9 @@ +import { MonoTypeOperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { RepeatIterable } from '../repeat'; + +export function repeat(count: number = -1): MonoTypeOperatorFunction { + return function repeatOperatorFunction(source: Iterable): IterableX { + return new RepeatIterable(source, count); + }; +} diff --git a/src/iterable/repeat.ts b/src/iterable/repeat.ts index 6ce71621..29868c63 100644 --- a/src/iterable/repeat.ts +++ b/src/iterable/repeat.ts @@ -1,7 +1,7 @@ import { of } from './of'; import { IterableX } from '../iterable'; -class RepeatIterable extends IterableX { +export class RepeatIterable extends IterableX { private _source: Iterable; private _count: number; From b4c2b7a4f803e79da4d2402fa2b922dbcb963995 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 00:49:35 -0400 Subject: [PATCH 081/106] feat(pipe): add through retry --- src/iterable/pipe/retry.ts | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/iterable/pipe/retry.ts diff --git a/src/iterable/pipe/retry.ts b/src/iterable/pipe/retry.ts new file mode 100644 index 00000000..5f90f077 --- /dev/null +++ b/src/iterable/pipe/retry.ts @@ -0,0 +1,9 @@ +import { MonoTypeOperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { retry as retryStatic } from '../retry'; + +export function retry(count: number = -1): MonoTypeOperatorFunction { + return function retryOperatorFunction(source: Iterable): IterableX { + return retryStatic(source, count); + }; +} From b9a0b3cc8fcf7015c4df11bb12415732cf893292 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 00:50:50 -0400 Subject: [PATCH 082/106] feat(pipe): add through reverse --- src/iterable/pipe/reverse.ts | 9 +++++++++ src/iterable/reverse.ts | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe/reverse.ts diff --git a/src/iterable/pipe/reverse.ts b/src/iterable/pipe/reverse.ts new file mode 100644 index 00000000..a3262857 --- /dev/null +++ b/src/iterable/pipe/reverse.ts @@ -0,0 +1,9 @@ +import { MonoTypeOperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { ReverseIterable } from '../reverse'; + +export function reverse(): MonoTypeOperatorFunction { + return function reverseOperatorFunction(source: Iterable): IterableX { + return new ReverseIterable(source); + }; +} diff --git a/src/iterable/reverse.ts b/src/iterable/reverse.ts index 1ae796a6..206537f5 100644 --- a/src/iterable/reverse.ts +++ b/src/iterable/reverse.ts @@ -1,6 +1,6 @@ import { IterableX } from '../iterable'; -class ReverseIterator extends IterableX { +export class ReverseIterator extends IterableX { private _source: Iterable; constructor(source: Iterable) { From b4bfe6d0a60f3e8f943cc82dda5654fd26989a95 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 01:01:04 -0400 Subject: [PATCH 083/106] feat(pipe): add through scan --- src/iterable/pipe/scan.ts | 19 +++++++++++++++++++ src/iterable/scan.ts | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe/scan.ts diff --git a/src/iterable/pipe/scan.ts b/src/iterable/pipe/scan.ts new file mode 100644 index 00000000..2854378f --- /dev/null +++ b/src/iterable/pipe/scan.ts @@ -0,0 +1,19 @@ +import { OperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { ScanIterable } from '../scan'; + +export function scan( + accumulator: (acc: T, value: T, index: number) => T +): OperatorFunction; +export function scan( + accumulator: (acc: R, value: T, index: number) => R, + seed: R +): OperatorFunction; +export function scan( + accumulator: (acc: T | R, value: T, index: number) => R, + ...args: (T | R)[] +): OperatorFunction { + return function scanOperatorFunction(source: Iterable): IterableX { + return new ScanIterable(source, accumulator, ...args); + }; +} diff --git a/src/iterable/scan.ts b/src/iterable/scan.ts index 2e8d436b..302915d9 100644 --- a/src/iterable/scan.ts +++ b/src/iterable/scan.ts @@ -1,6 +1,6 @@ import { IterableX } from '../iterable'; -class ScanIterable extends IterableX { +export class ScanIterable extends IterableX { private _source: Iterable; private _fn: (acc: T | R, x: T, index: number) => R; private _seed?: T | R; From 15a8eb390bb9879b351603c2927642172cc74f01 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 01:02:41 -0400 Subject: [PATCH 084/106] feat(pipe): add through scanright --- src/iterable/pipe/scanright.ts | 19 +++++++++++++++++++ src/iterable/scanright.ts | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe/scanright.ts diff --git a/src/iterable/pipe/scanright.ts b/src/iterable/pipe/scanright.ts new file mode 100644 index 00000000..8b3b959c --- /dev/null +++ b/src/iterable/pipe/scanright.ts @@ -0,0 +1,19 @@ +import { OperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { ScanRightIterable } from '../scanright'; + +export function scanRight( + accumulator: (acc: T, value: T, index: number) => T +): OperatorFunction; +export function scanRight( + accumulator: (acc: R, value: T, index: number) => R, + seed: R +): OperatorFunction; +export function scanRight( + accumulator: (acc: T | R, value: T, index: number) => R, + ...args: (T | R)[] +): OperatorFunction { + return function scanRightOperatorFunction(source: Iterable): IterableX { + return new ScanRightIterable(source, accumulator, ...args); + }; +} diff --git a/src/iterable/scanright.ts b/src/iterable/scanright.ts index 53e13187..83c0efcd 100644 --- a/src/iterable/scanright.ts +++ b/src/iterable/scanright.ts @@ -1,7 +1,7 @@ import { IterableX } from '../iterable'; import { toArray } from './toarray'; -class ScanRightIterable extends IterableX { +export class ScanRightIterable extends IterableX { private _source: Iterable; private _fn: (acc: T | R, x: T, index: number) => R; private _seed?: T | R; From 8164e88312e11ad162714365a92a438fcb5183d8 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 01:16:39 -0400 Subject: [PATCH 085/106] feat(pipe): add through share --- src/iterable/pipe/share.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/iterable/pipe/share.ts diff --git a/src/iterable/pipe/share.ts b/src/iterable/pipe/share.ts new file mode 100644 index 00000000..50dbb06a --- /dev/null +++ b/src/iterable/pipe/share.ts @@ -0,0 +1,15 @@ +import { OperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { share as shareStatic } from '../share'; + +export function share(): OperatorFunction; +export function share( + selector?: (value: Iterable) => Iterable +): OperatorFunction; +export function share( + selector?: (value: Iterable) => Iterable +): OperatorFunction { + return function shareOperatorFunction(source: Iterable): IterableX { + return shareStatic(source, selector); + }; +} From 1b1e1169691c130ec5a3a9ed6aabd1bbbfef6ded Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 01:18:28 -0400 Subject: [PATCH 086/106] feat(pipe): add through skip --- src/iterable/pipe/skip.ts | 9 +++++++++ src/iterable/skip.ts | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe/skip.ts diff --git a/src/iterable/pipe/skip.ts b/src/iterable/pipe/skip.ts new file mode 100644 index 00000000..9275f20f --- /dev/null +++ b/src/iterable/pipe/skip.ts @@ -0,0 +1,9 @@ +import { MonoTypeOperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { SkipIterable } from '../skip'; + +export function skip(count: number): MonoTypeOperatorFunction { + return function skipOperatorFunction(source: Iterable): IterableX { + return new SkipIterable(source, count); + }; +} diff --git a/src/iterable/skip.ts b/src/iterable/skip.ts index e9e4c23b..d4b22d98 100644 --- a/src/iterable/skip.ts +++ b/src/iterable/skip.ts @@ -1,6 +1,6 @@ import { IterableX } from '../iterable'; -class SkipIterable extends IterableX { +export class SkipIterable extends IterableX { private _source: Iterable; private _count: number; From d148ba34459fc2d2928394cd93ed66f1ff3500cc Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 01:19:33 -0400 Subject: [PATCH 087/106] feat(pipe): add through skiplast --- src/iterable/pipe/skiplast.ts | 9 +++++++++ src/iterable/skiplast.ts | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe/skiplast.ts diff --git a/src/iterable/pipe/skiplast.ts b/src/iterable/pipe/skiplast.ts new file mode 100644 index 00000000..ae96221d --- /dev/null +++ b/src/iterable/pipe/skiplast.ts @@ -0,0 +1,9 @@ +import { MonoTypeOperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { SkipLastIterable } from '../skiplast'; + +export function skipLast(count: number): MonoTypeOperatorFunction { + return function skipLastOperatorFunction(source: Iterable): IterableX { + return new SkipLastIterable(source, count); + }; +} diff --git a/src/iterable/skiplast.ts b/src/iterable/skiplast.ts index acd5e6b2..cf1d8654 100644 --- a/src/iterable/skiplast.ts +++ b/src/iterable/skiplast.ts @@ -1,6 +1,6 @@ import { IterableX } from '../iterable'; -class SkipLastIterable extends IterableX { +export class SkipLastIterable extends IterableX { private _source: Iterable; private _count: number; From 610c39f7a9d43868b305e7cb89adc928d0a9a0df Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 01:21:18 -0400 Subject: [PATCH 088/106] feat(pipe): add through skipwhile --- src/iterable/pipe/skipwhile.ts | 17 +++++++++++++++++ src/iterable/skipwhile.ts | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe/skipwhile.ts diff --git a/src/iterable/pipe/skipwhile.ts b/src/iterable/pipe/skipwhile.ts new file mode 100644 index 00000000..644f21c9 --- /dev/null +++ b/src/iterable/pipe/skipwhile.ts @@ -0,0 +1,17 @@ +import { OperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { SkipWhileIterable } from '../skipwhile'; + +export function skipWhile( + predicate: (value: T, index: number) => value is S +): OperatorFunction; +export function skipWhile( + predicate: (value: T, index: number) => boolean +): OperatorFunction; +export function skipWhile( + predicate: (value: T, index: number) => boolean +): OperatorFunction { + return function skipWhileOperatorFunction(source: Iterable): IterableX { + return new SkipWhileIterable(source, predicate); + }; +} diff --git a/src/iterable/skipwhile.ts b/src/iterable/skipwhile.ts index c50cb292..5c77406d 100644 --- a/src/iterable/skipwhile.ts +++ b/src/iterable/skipwhile.ts @@ -1,6 +1,6 @@ import { IterableX } from '../iterable'; -class SkipWhileIterable extends IterableX { +export class SkipWhileIterable extends IterableX { private _source: Iterable; private _predicate: (value: TSource, index: number) => boolean; From 24e87ae4f0145d2eb61baa6d9c8b4b6f82b7fe27 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 01:22:32 -0400 Subject: [PATCH 089/106] feat(pipe): add through slice --- src/iterable/pipe/slice.ts | 12 ++++++++++++ src/iterable/slice.ts | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe/slice.ts diff --git a/src/iterable/pipe/slice.ts b/src/iterable/pipe/slice.ts new file mode 100644 index 00000000..7cede8cb --- /dev/null +++ b/src/iterable/pipe/slice.ts @@ -0,0 +1,12 @@ +import { MonoTypeOperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { SliceIterable } from '../slice'; + +export function slice( + begin: number, + end: number = Infinity +): MonoTypeOperatorFunction { + return function sliceOperatorFunction(source: Iterable): IterableX { + return new SliceIterable(source, begin, end); + }; +} diff --git a/src/iterable/slice.ts b/src/iterable/slice.ts index 20879722..9fabb944 100644 --- a/src/iterable/slice.ts +++ b/src/iterable/slice.ts @@ -1,6 +1,6 @@ import { IterableX } from '../iterable'; -class SliceIterable extends IterableX { +export class SliceIterable extends IterableX { private _source: Iterable; private _begin: number; private _end: number; From 2e76d23f4962557046dc4ec01694cd18f238eed4 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 01:23:30 -0400 Subject: [PATCH 090/106] feat(pipe): add through startwith --- src/iterable/pipe/startwith.ts | 9 +++++++++ src/iterable/startwith.ts | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe/startwith.ts diff --git a/src/iterable/pipe/startwith.ts b/src/iterable/pipe/startwith.ts new file mode 100644 index 00000000..ebbd057f --- /dev/null +++ b/src/iterable/pipe/startwith.ts @@ -0,0 +1,9 @@ +import { MonoTypeOperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { StartWithIterable } from '../startwith'; + +export function startWith(...args: TSource[]): MonoTypeOperatorFunction { + return function startWithOperatorFunction(source: Iterable): IterableX { + return new StartWithIterable(source, args); + }; +} diff --git a/src/iterable/startwith.ts b/src/iterable/startwith.ts index 6dd4df15..d68cc632 100644 --- a/src/iterable/startwith.ts +++ b/src/iterable/startwith.ts @@ -1,6 +1,6 @@ import { IterableX } from '../iterable'; -class StartWithIterable extends IterableX { +export class StartWithIterable extends IterableX { private _source: Iterable; private _args: TSource[]; From 7c5667c7a41dc3626a1be0f87adcc2906a3fb5c0 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 01:25:01 -0400 Subject: [PATCH 091/106] feat(pipe): add through take --- src/iterable/pipe/take.ts | 9 +++++++++ src/iterable/take.ts | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe/take.ts diff --git a/src/iterable/pipe/take.ts b/src/iterable/pipe/take.ts new file mode 100644 index 00000000..ce21e305 --- /dev/null +++ b/src/iterable/pipe/take.ts @@ -0,0 +1,9 @@ +import { MonoTypeOperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { TakeIterable } from '../take'; + +export function take(count: number): MonoTypeOperatorFunction { + return function takeOperatorFunction(source: Iterable): IterableX { + return new TakeIterable(source, count); + }; +} diff --git a/src/iterable/take.ts b/src/iterable/take.ts index 9b9db198..f2d510fa 100644 --- a/src/iterable/take.ts +++ b/src/iterable/take.ts @@ -1,6 +1,6 @@ import { IterableX } from '../iterable'; -class TakeIterable extends IterableX { +export class TakeIterable extends IterableX { private _source: Iterable; private _count: number; From 298bcc559ac4114595e459c4ef95e9cd9dfbb5e8 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 01:26:11 -0400 Subject: [PATCH 092/106] feat(pipe): add through takelast --- src/iterable/pipe/takelast.ts | 9 +++++++++ src/iterable/takelast.ts | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe/takelast.ts diff --git a/src/iterable/pipe/takelast.ts b/src/iterable/pipe/takelast.ts new file mode 100644 index 00000000..374f1a73 --- /dev/null +++ b/src/iterable/pipe/takelast.ts @@ -0,0 +1,9 @@ +import { MonoTypeOperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { TakeLastIterable } from '../takelast'; + +export function takeLast(count: number): MonoTypeOperatorFunction { + return function takeLastOperatorFunction(source: Iterable): IterableX { + return new TakeLastIterable(source, count); + }; +} diff --git a/src/iterable/takelast.ts b/src/iterable/takelast.ts index 2ec4ac5d..6c802bea 100644 --- a/src/iterable/takelast.ts +++ b/src/iterable/takelast.ts @@ -1,6 +1,6 @@ import { IterableX } from '../iterable'; -class TakeLastIterable extends IterableX { +export class TakeLastIterable extends IterableX { private _source: Iterable; private _count: number; From d1c99b567cd5df021de77ca4373f9c6db2ea1db5 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 01:27:22 -0400 Subject: [PATCH 093/106] feat(pipe): add through takewhile --- src/iterable/pipe/takewhile.ts | 17 +++++++++++++++++ src/iterable/takewhile.ts | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe/takewhile.ts diff --git a/src/iterable/pipe/takewhile.ts b/src/iterable/pipe/takewhile.ts new file mode 100644 index 00000000..a0708392 --- /dev/null +++ b/src/iterable/pipe/takewhile.ts @@ -0,0 +1,17 @@ +import { OperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { TakeWhileIterable } from '../takewhile'; + +export function takeWhile( + predicate: (value: T, index: number) => value is S +): OperatorFunction; +export function takeWhile( + predicate: (value: T, index: number) => boolean +): OperatorFunction; +export function takeWhile( + predicate: (value: T, index: number) => boolean +): OperatorFunction { + return function takeWhileOperatorFunction(source: Iterable): IterableX { + return new TakeWhileIterable(source, predicate); + }; +} diff --git a/src/iterable/takewhile.ts b/src/iterable/takewhile.ts index 78a5d321..d47d3dd7 100644 --- a/src/iterable/takewhile.ts +++ b/src/iterable/takewhile.ts @@ -1,6 +1,6 @@ import { IterableX } from '../iterable'; -class TakeWhileIterable extends IterableX { +export class TakeWhileIterable extends IterableX { private _source: Iterable; private _predicate: (value: TSource, index: number) => boolean; From d9fe714cc5772d108ee23fc40daedb31ea02d1b0 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 01:28:29 -0400 Subject: [PATCH 094/106] feat(pipe): add through tap --- src/iterable/pipe/tap.ts | 12 ++++++++++++ src/iterable/tap.ts | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe/tap.ts diff --git a/src/iterable/pipe/tap.ts b/src/iterable/pipe/tap.ts new file mode 100644 index 00000000..23b0744f --- /dev/null +++ b/src/iterable/pipe/tap.ts @@ -0,0 +1,12 @@ +import { MonoTypeOperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { TapIterable } from '../tap'; +import { PartialObserver } from '../../observer'; + +export function tap( + observer: PartialObserver +): MonoTypeOperatorFunction { + return function tapOperatorFunction(source: Iterable): IterableX { + return new TapIterable(source, observer); + }; +} diff --git a/src/iterable/tap.ts b/src/iterable/tap.ts index ca968c71..abe71f3e 100644 --- a/src/iterable/tap.ts +++ b/src/iterable/tap.ts @@ -1,7 +1,7 @@ import { IterableX } from '../iterable'; import { PartialObserver } from '../observer'; -class TapIterable extends IterableX { +export class TapIterable extends IterableX { private _source: Iterable; private _observer: PartialObserver; From 37e15af64fa7c685fd81a1f71d130b7b697d825c Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 01:29:48 -0400 Subject: [PATCH 095/106] feat(pipe): add through union --- src/iterable/pipe/union.ts | 13 +++++++++++++ src/iterable/union.ts | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/iterable/pipe/union.ts diff --git a/src/iterable/pipe/union.ts b/src/iterable/pipe/union.ts new file mode 100644 index 00000000..17dff899 --- /dev/null +++ b/src/iterable/pipe/union.ts @@ -0,0 +1,13 @@ +import { MonoTypeOperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { UnionIterable } from '../union'; +import { comparer as defaultComparer } from '../../internal/comparer'; + +export function union( + right: Iterable, + comparer: (x: TSource, y: TSource) => boolean = defaultComparer +): MonoTypeOperatorFunction { + return function unionOperatorFunction(left: Iterable): IterableX { + return new UnionIterable(left, right, comparer); + }; +} diff --git a/src/iterable/union.ts b/src/iterable/union.ts index 56132204..1e5c9fca 100644 --- a/src/iterable/union.ts +++ b/src/iterable/union.ts @@ -2,7 +2,7 @@ import { IterableX } from '../iterable'; import { arrayIndexOf } from '../internal/arrayindexof'; import { comparer as defaultComparer } from '../internal/comparer'; -class UnionIterable extends IterableX { +export class UnionIterable extends IterableX { private _left: Iterable; private _right: Iterable; private _comparer: (x: TSource, y: TSource) => boolean; From 3cb4080f5bf83c2495d42f08190f8a0a46e4d433 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 13:35:52 -0400 Subject: [PATCH 096/106] feat(pipe): add through pipe --- src/asynciterable/pipe/zip.ts | 79 +++++++++++++++++++++++++++++++++++ src/asynciterable/zip.ts | 2 +- src/iterable/pipe/zip.ts | 79 +++++++++++++++++++++++++++++++++++ src/iterable/reverse.ts | 4 +- src/iterable/zip.ts | 2 +- 5 files changed, 162 insertions(+), 4 deletions(-) create mode 100644 src/asynciterable/pipe/zip.ts create mode 100644 src/iterable/pipe/zip.ts diff --git a/src/asynciterable/pipe/zip.ts b/src/asynciterable/pipe/zip.ts new file mode 100644 index 00000000..de66a577 --- /dev/null +++ b/src/asynciterable/pipe/zip.ts @@ -0,0 +1,79 @@ +import { OperatorAsyncFunction } from '../../interfaces'; +import { AsyncIterableX } from '../../asynciterable'; +import { ZipAsyncIterable } from '../zip'; +import { identityAsync } from '../../internal/identity'; + +export function zip( + source: AsyncIterable, + source2: AsyncIterable +): OperatorAsyncFunction; +export function zip( + source2: AsyncIterable, + source3: AsyncIterable +): OperatorAsyncFunction; +export function zip( + source2: AsyncIterable, + source3: AsyncIterable, + source4: AsyncIterable +): OperatorAsyncFunction; +export function zip( + source2: AsyncIterable, + source3: AsyncIterable, + source4: AsyncIterable, + source5: AsyncIterable +): OperatorAsyncFunction; +export function zip( + source2: AsyncIterable, + source3: AsyncIterable, + source4: AsyncIterable, + source5: AsyncIterable, + source6: AsyncIterable +): OperatorAsyncFunction; + +export function zip( + project: (values: [T, T2]) => R | Promise, + source2: AsyncIterable +): OperatorAsyncFunction; +export function zip( + project: (values: [T, T2, T3]) => R | Promise, + source2: AsyncIterable, + source3: AsyncIterable +): OperatorAsyncFunction; +export function zip( + project: (values: [T, T2, T3, T4]) => R | Promise, + source2: AsyncIterable, + source3: AsyncIterable, + source4: AsyncIterable +): OperatorAsyncFunction; +export function zip( + project: (values: [T, T2, T3, T4, T5]) => R | Promise, + source2: AsyncIterable, + source3: AsyncIterable, + source4: AsyncIterable, + source5: AsyncIterable +): OperatorAsyncFunction; +export function zip( + project: (values: [T, T2, T3, T4, T5, T6]) => R | Promise, + source2: AsyncIterable, + source3: AsyncIterable, + source4: AsyncIterable, + source5: AsyncIterable, + source6: AsyncIterable +): OperatorAsyncFunction; + +export function zip(...sources: AsyncIterable[]): OperatorAsyncFunction; +export function zip( + project: (values: T[]) => R | Promise, + ...sources: AsyncIterable[] +): OperatorAsyncFunction; +/* tslint:enable:max-line-length */ +export function zip(...sources: any[]): OperatorAsyncFunction { + return function zipOperatorFunction(source: AsyncIterable): AsyncIterableX { + let fn = sources.shift() as (values: any[]) => R | Promise; + if (typeof fn !== 'function') { + sources.push(fn); + fn = identityAsync; + } + return new ZipAsyncIterable([source, ...sources] as AsyncIterable[], fn); + }; +} diff --git a/src/asynciterable/zip.ts b/src/asynciterable/zip.ts index 34972f68..b034bf74 100644 --- a/src/asynciterable/zip.ts +++ b/src/asynciterable/zip.ts @@ -2,7 +2,7 @@ import { AsyncIterableX } from '../asynciterable'; import { identityAsync } from '../internal/identity'; import { returnAsyncIterator } from '../internal/returniterator'; -class ZipAsyncIterable extends AsyncIterableX { +export class ZipAsyncIterable extends AsyncIterableX { private _sources: AsyncIterable[]; private _fn: (values: any[]) => TResult | Promise; diff --git a/src/iterable/pipe/zip.ts b/src/iterable/pipe/zip.ts new file mode 100644 index 00000000..cfa65e77 --- /dev/null +++ b/src/iterable/pipe/zip.ts @@ -0,0 +1,79 @@ +import { OperatorFunction } from '../../interfaces'; +import { IterableX } from '../../iterable'; +import { ZipIterable } from '../zip'; +import { identity } from '../../internal/identity'; + +export function zip( + source: Iterable, + source2: Iterable +): OperatorFunction; +export function zip( + source2: Iterable, + source3: Iterable +): OperatorFunction; +export function zip( + source2: Iterable, + source3: Iterable, + source4: Iterable +): OperatorFunction; +export function zip( + source2: Iterable, + source3: Iterable, + source4: Iterable, + source5: Iterable +): OperatorFunction; +export function zip( + source2: Iterable, + source3: Iterable, + source4: Iterable, + source5: Iterable, + source6: Iterable +): OperatorFunction; + +export function zip( + project: (values: [T, T2]) => R, + source2: Iterable +): OperatorFunction; +export function zip( + project: (values: [T, T2, T3]) => R, + source2: Iterable, + source3: Iterable +): OperatorFunction; +export function zip( + project: (values: [T, T2, T3, T4]) => R, + source2: Iterable, + source3: Iterable, + source4: Iterable +): OperatorFunction; +export function zip( + project: (values: [T, T2, T3, T4, T5]) => R, + source2: Iterable, + source3: Iterable, + source4: Iterable, + source5: Iterable +): OperatorFunction; +export function zip( + project: (values: [T, T2, T3, T4, T5, T6]) => R, + source2: Iterable, + source3: Iterable, + source4: Iterable, + source5: Iterable, + source6: Iterable +): OperatorFunction; + +export function zip(...sources: Iterable[]): OperatorFunction; +export function zip( + project: (values: T[]) => R, + ...sources: Iterable[] +): OperatorFunction; +/* tslint:enable:max-line-length */ +export function zip(...sources: any[]): OperatorFunction { + return function zipOperatorFunction(source: Iterable): IterableX { + let fn = sources.shift() as (values: any[]) => R; + if (typeof fn !== 'function') { + sources.push(fn); + fn = identity; + } + return new ZipIterable([source, ...sources] as Iterable[], fn); + }; +} diff --git a/src/iterable/reverse.ts b/src/iterable/reverse.ts index 206537f5..32308e09 100644 --- a/src/iterable/reverse.ts +++ b/src/iterable/reverse.ts @@ -1,6 +1,6 @@ import { IterableX } from '../iterable'; -export class ReverseIterator extends IterableX { +export class ReverseIterable extends IterableX { private _source: Iterable; constructor(source: Iterable) { @@ -18,5 +18,5 @@ export class ReverseIterator extends IterableX { } export function reverse(source: Iterable): IterableX { - return new ReverseIterator(source); + return new ReverseIterable(source); } diff --git a/src/iterable/zip.ts b/src/iterable/zip.ts index c0314323..c32f23a7 100644 --- a/src/iterable/zip.ts +++ b/src/iterable/zip.ts @@ -2,7 +2,7 @@ import { IterableX } from '../iterable'; import { identity } from '../internal/identity'; import { returnIterator } from '../internal/returniterator'; -class ZipIterable extends IterableX { +export class ZipIterable extends IterableX { private _sources: Iterable[]; private _fn: (values: any[]) => TResult; From df6b7b9c117deee9e9199988640d1790dc95cfa9 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Wed, 25 Oct 2017 17:04:21 -0400 Subject: [PATCH 097/106] feat(pipe): moving pipe and forEach to core --- spec/asynciterable-operators/foreach-spec.ts | 11 ++- .../asynciterable-operators/ignoreelements.ts | 17 ++-- spec/iterable-operators/foreach-spec.ts | 7 +- .../iterable-operators/ignoreelements-spec.ts | 8 +- src/Ix.ts | 2 - src/add/asynciterable-operators/foreach.ts | 20 ----- src/add/iterable-operators/foreach.ts | 17 ---- src/asynciterable.ts | 87 +++++++++++++++++++ src/asynciterable/__modules.ts | 2 - src/asynciterable/debounce.ts | 10 ++- src/asynciterable/foreach.ts | 13 --- src/iterable.ts | 84 ++++++++++++++++++ src/iterable/__modules.ts | 2 - src/iterable/foreach.ts | 19 ---- 14 files changed, 205 insertions(+), 94 deletions(-) delete mode 100644 src/add/asynciterable-operators/foreach.ts delete mode 100644 src/add/iterable-operators/foreach.ts delete mode 100644 src/asynciterable/foreach.ts delete mode 100644 src/iterable/foreach.ts diff --git a/spec/asynciterable-operators/foreach-spec.ts b/spec/asynciterable-operators/foreach-spec.ts index 487b52af..f90fd2a6 100644 --- a/spec/asynciterable-operators/foreach-spec.ts +++ b/spec/asynciterable-operators/foreach-spec.ts @@ -1,12 +1,13 @@ import * as Ix from '../Ix'; -import * as test from 'tape'; -const { forEach } = Ix.asynciterable; +import * as test from 'tape'; const { range } = Ix.asynciterable; test('AsyncIterable#forEach', async t => { let n = 0; - await forEach(range(5, 3), async x => { n += x; }); + await range(5, 3).forEach(async x => { + n += x; + }); t.equal(5 + 6 + 7, n); t.end(); @@ -15,7 +16,9 @@ test('AsyncIterable#forEach', async t => { test('AsyncIterable#forEach with index', async t => { let n = 0; - await forEach(range(5, 3), async (x, i) => { n += x * i; }); + await range(5, 3).forEach(async (x, i) => { + n += x * i; + }); t.equal(5 * 0 + 6 * 1 + 7 * 2, n); t.end(); diff --git a/spec/asynciterable-operators/ignoreelements.ts b/spec/asynciterable-operators/ignoreelements.ts index 194eb6c2..bf87eb3c 100644 --- a/spec/asynciterable-operators/ignoreelements.ts +++ b/spec/asynciterable-operators/ignoreelements.ts @@ -1,6 +1,5 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; -const { forEach } = Ix.asynciterable; const { ignoreElements } = Ix.asynciterable; const { range } = Ix.asynciterable; const { take } = Ix.asynciterable; @@ -8,10 +7,18 @@ const { tap } = Ix.asynciterable; test('Iterable#ignoreElements has side effects', async t => { let n = 0; - await forEach( - take(ignoreElements(tap(range(0, 10), { next: async () => { n++; } })), 5), - async () => { /* tslint:disable-next-line:no-empty */ } - ); + await take( + ignoreElements( + tap(range(0, 10), { + next: async () => { + n++; + } + }) + ), + 5 + ).forEach(async () => { + /* tslint:disable-next-line:no-empty */ + }); t.equal(10, n); t.end(); diff --git a/spec/iterable-operators/foreach-spec.ts b/spec/iterable-operators/foreach-spec.ts index f3e4a3df..16874026 100644 --- a/spec/iterable-operators/foreach-spec.ts +++ b/spec/iterable-operators/foreach-spec.ts @@ -1,12 +1,11 @@ import * as Ix from '../Ix'; -import * as test from 'tape'; -const { forEach } = Ix.iterable; +import * as test from 'tape'; const { range } = Ix.iterable; test('Iterable#forEach', t => { let n = 0; - forEach(range(5, 3), x => n += x); + range(5, 3).forEach(x => (n += x)); t.equal(5 + 6 + 7, n); t.end(); @@ -15,7 +14,7 @@ test('Iterable#forEach', t => { test('Iterable#forEach with index', t => { let n = 0; - forEach(range(5, 3), (x, i) => n += x * i); + range(5, 3).forEach((x, i) => (n += x * i)); t.equal(5 * 0 + 6 * 1 + 7 * 2, n); t.end(); diff --git a/spec/iterable-operators/ignoreelements-spec.ts b/spec/iterable-operators/ignoreelements-spec.ts index e8e9c0d1..6b617719 100644 --- a/spec/iterable-operators/ignoreelements-spec.ts +++ b/spec/iterable-operators/ignoreelements-spec.ts @@ -1,6 +1,5 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; -const { forEach } = Ix.iterable; const { ignoreElements } = Ix.iterable; const { range } = Ix.iterable; const { take } = Ix.iterable; @@ -8,10 +7,9 @@ const { tap } = Ix.iterable; test('Iterable#ignoreElements has side effects', t => { let n = 0; - forEach( - take(ignoreElements(tap(range(0, 10), { next: () => n++})), 5), - () => { /* tslint:disable-next-line:no-empty */ } - ); + take(ignoreElements(tap(range(0, 10), { next: () => n++ })), 5).forEach(() => { + /* tslint:disable-next-line:no-empty */ + }); t.equal(10, n); t.end(); diff --git a/src/Ix.ts b/src/Ix.ts index bc76927a..3e3aaa30 100644 --- a/src/Ix.ts +++ b/src/Ix.ts @@ -79,7 +79,6 @@ import './add/iterable-operators/findindex'; import './add/iterable-operators/first'; import './add/iterable-operators/flatmap'; import './add/iterable-operators/flatten'; -import './add/iterable-operators/foreach'; import './add/iterable-operators/groupby'; import './add/iterable-operators/groupjoin'; import './add/iterable-operators/ignoreelements'; @@ -172,7 +171,6 @@ import './add/asynciterable-operators/findindex'; import './add/asynciterable-operators/first'; import './add/asynciterable-operators/flatmap'; import './add/asynciterable-operators/flatten'; -import './add/asynciterable-operators/foreach'; import './add/asynciterable-operators/groupby'; import './add/asynciterable-operators/groupjoin'; import './add/asynciterable-operators/ignoreelements'; diff --git a/src/add/asynciterable-operators/foreach.ts b/src/add/asynciterable-operators/foreach.ts deleted file mode 100644 index 5e9658ab..00000000 --- a/src/add/asynciterable-operators/foreach.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { AsyncIterableX } from '../../asynciterable'; -import { forEach } from '../../asynciterable/foreach'; - -/** - * @ignore - */ -export function forEachproto( - this: AsyncIterableX, - action: (value: T, index: number) => void | Promise -): Promise { - return forEach(this, action); -} - -AsyncIterableX.prototype.forEach = forEachproto; - -declare module '../../asynciterable' { - interface AsyncIterableX { - forEach: typeof forEachproto; - } -} diff --git a/src/add/iterable-operators/foreach.ts b/src/add/iterable-operators/foreach.ts deleted file mode 100644 index dc950672..00000000 --- a/src/add/iterable-operators/foreach.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { IterableX } from '../../iterable'; -import { forEach } from '../../iterable/foreach'; - -/** - * @ignore - */ -export function forEachproto(this: IterableX, fn: (value: T, index: number) => void): void { - return forEach(this, fn); -} - -IterableX.prototype.forEach = forEachproto; - -declare module '../../iterable' { - interface IterableX { - forEach: typeof forEachproto; - } -} diff --git a/src/asynciterable.ts b/src/asynciterable.ts index 9acb069c..694bde6e 100644 --- a/src/asynciterable.ts +++ b/src/asynciterable.ts @@ -1,6 +1,93 @@ +import { OperatorAsyncFunction } from './interfaces'; +import { bindCallback } from './internal/bindcallback'; + /** * This clas serves as the base for all operations which support [Symbol.asyncIterator]. */ export abstract class AsyncIterableX implements AsyncIterable { abstract [Symbol.asyncIterator](): AsyncIterator; + + async forEach( + projection: (value: T, index: number) => void | Promise, + thisArg?: any + ): Promise { + const fn = bindCallback(projection, thisArg, 2); + let i = 0; + for await (let item of this) { + await fn(item, i++); + } + } + + pipe(): AsyncIterableX; + pipe(op1: OperatorAsyncFunction): AsyncIterableX; + pipe(op1: OperatorAsyncFunction, op2: OperatorAsyncFunction): AsyncIterableX; + pipe( + op1: OperatorAsyncFunction, + op2: OperatorAsyncFunction, + op3: OperatorAsyncFunction + ): AsyncIterableX; + pipe( + op1: OperatorAsyncFunction, + op2: OperatorAsyncFunction, + op3: OperatorAsyncFunction, + op4: OperatorAsyncFunction + ): AsyncIterableX; + pipe( + op1: OperatorAsyncFunction, + op2: OperatorAsyncFunction, + op3: OperatorAsyncFunction, + op4: OperatorAsyncFunction, + op5: OperatorAsyncFunction + ): AsyncIterableX; + pipe( + op1: OperatorAsyncFunction, + op2: OperatorAsyncFunction, + op3: OperatorAsyncFunction, + op4: OperatorAsyncFunction, + op5: OperatorAsyncFunction, + op6: OperatorAsyncFunction + ): AsyncIterableX; + pipe( + op1: OperatorAsyncFunction, + op2: OperatorAsyncFunction, + op3: OperatorAsyncFunction, + op4: OperatorAsyncFunction, + op5: OperatorAsyncFunction, + op6: OperatorAsyncFunction, + op7: OperatorAsyncFunction + ): AsyncIterableX; + pipe( + op1: OperatorAsyncFunction, + op2: OperatorAsyncFunction, + op3: OperatorAsyncFunction, + op4: OperatorAsyncFunction, + op5: OperatorAsyncFunction, + op6: OperatorAsyncFunction, + op7: OperatorAsyncFunction, + op8: OperatorAsyncFunction + ): AsyncIterableX; + pipe( + op1: OperatorAsyncFunction, + op2: OperatorAsyncFunction, + op3: OperatorAsyncFunction, + op4: OperatorAsyncFunction, + op5: OperatorAsyncFunction, + op6: OperatorAsyncFunction, + op7: OperatorAsyncFunction, + op8: OperatorAsyncFunction, + op9: OperatorAsyncFunction + ): AsyncIterableX; + /* tslint:enable:max-line-length */ + + pipe(...operations: OperatorAsyncFunction[]): AsyncIterableX { + if (operations.length === 0) { + return this as any; + } + + const piped = (input: AsyncIterable): AsyncIterableX => { + return operations.reduce((prev: any, fn: OperatorAsyncFunction) => fn(prev), input); + }; + + return piped(this); + } } diff --git a/src/asynciterable/__modules.ts b/src/asynciterable/__modules.ts index d52d783f..79759b7e 100644 --- a/src/asynciterable/__modules.ts +++ b/src/asynciterable/__modules.ts @@ -41,7 +41,6 @@ import { first } from './first'; import { flatMap } from './flatmap'; import { flatten } from './flatten'; import { _for } from './for'; -import { forEach } from './foreach'; import { from } from './from'; import { fromEvent } from './fromevent'; import { fromEventPattern } from './fromeventpattern'; @@ -158,7 +157,6 @@ export default { flatMap, flatten, _for, - forEach, from, fromEvent, fromEventPattern, diff --git a/src/asynciterable/debounce.ts b/src/asynciterable/debounce.ts index 4b205148..abf1ece9 100644 --- a/src/asynciterable/debounce.ts +++ b/src/asynciterable/debounce.ts @@ -1,5 +1,13 @@ import { AsyncIterableX } from '../asynciterable'; -import { forEach } from './foreach'; + +async function forEach( + source: AsyncIterable, + fn: (item: T) => void | Promise +): Promise { + for await (const item of source) { + await fn(item); + } +} export class DebounceAsyncIterable extends AsyncIterableX { private _source: AsyncIterable; diff --git a/src/asynciterable/foreach.ts b/src/asynciterable/foreach.ts deleted file mode 100644 index fa55179d..00000000 --- a/src/asynciterable/foreach.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { bindCallback } from '../internal/bindcallback'; - -export async function forEach( - source: AsyncIterable, - projection: (value: TSource, index: number) => void | Promise, - thisArg?: any -): Promise { - const fn = bindCallback(projection, thisArg, 2); - let i = 0; - for await (let item of source) { - await fn(item, i++); - } -} diff --git a/src/iterable.ts b/src/iterable.ts index fc517558..9c0b0142 100644 --- a/src/iterable.ts +++ b/src/iterable.ts @@ -1,6 +1,90 @@ +import { OperatorFunction } from './interfaces'; +import { bindCallback } from './internal/bindcallback'; + /** * This clas serves as the base for all operations which support [Symbol.iterator]. */ export abstract class IterableX implements Iterable { abstract [Symbol.iterator](): Iterator; + + forEach(projection: (value: T, index: number) => void, thisArg?: any): void { + const fn = bindCallback(projection, thisArg, 2); + let i = 0; + for (let item of this) { + fn(item, i++); + } + } + + pipe(): IterableX; + pipe(op1: OperatorFunction): IterableX; + pipe(op1: OperatorFunction, op2: OperatorFunction): IterableX; + pipe( + op1: OperatorFunction, + op2: OperatorFunction, + op3: OperatorFunction + ): IterableX; + pipe( + op1: OperatorFunction, + op2: OperatorFunction, + op3: OperatorFunction, + op4: OperatorFunction + ): IterableX; + pipe( + op1: OperatorFunction, + op2: OperatorFunction, + op3: OperatorFunction, + op4: OperatorFunction, + op5: OperatorFunction + ): IterableX; + pipe( + op1: OperatorFunction, + op2: OperatorFunction, + op3: OperatorFunction, + op4: OperatorFunction, + op5: OperatorFunction, + op6: OperatorFunction + ): IterableX; + pipe( + op1: OperatorFunction, + op2: OperatorFunction, + op3: OperatorFunction, + op4: OperatorFunction, + op5: OperatorFunction, + op6: OperatorFunction, + op7: OperatorFunction + ): IterableX; + pipe( + op1: OperatorFunction, + op2: OperatorFunction, + op3: OperatorFunction, + op4: OperatorFunction, + op5: OperatorFunction, + op6: OperatorFunction, + op7: OperatorFunction, + op8: OperatorFunction + ): IterableX; + pipe( + op1: OperatorFunction, + op2: OperatorFunction, + op3: OperatorFunction, + op4: OperatorFunction, + op5: OperatorFunction, + op6: OperatorFunction, + op7: OperatorFunction, + op8: OperatorFunction, + op9: OperatorFunction + ): IterableX; + /* tslint:enable:max-line-length */ + + pipe(...operations: OperatorFunction[]): IterableX { + if (operations.length === 0) { + return this as any; + } + + const piped = (input: Iterable): IterableX => { + return operations.reduce((prev: any, fn: OperatorFunction) => fn(prev), input); + }; + + return piped(this); + } } diff --git a/src/iterable/__modules.ts b/src/iterable/__modules.ts index d7bd53fe..6d09e853 100644 --- a/src/iterable/__modules.ts +++ b/src/iterable/__modules.ts @@ -38,7 +38,6 @@ import { first } from './first'; import { flatMap } from './flatmap'; import { flatten } from './flatten'; import { _for } from './for'; -import { forEach } from './foreach'; import { from } from './from'; import { generate } from './generate'; import { groupBy } from './groupby'; @@ -142,7 +141,6 @@ export default { flatMap, flatten, _for, - forEach, from, generate, groupBy, diff --git a/src/iterable/foreach.ts b/src/iterable/foreach.ts deleted file mode 100644 index 3baa7993..00000000 --- a/src/iterable/foreach.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { bindCallback } from '../internal/bindcallback'; - -/** - * Iterates the sequence and invokes the given action for each value in the sequence. - * @param {Iterable} source Source sequence. - * @param {function:(value: T, index: number): void} callback Action to invoke for each element. - * @param {Object} [thisArg] Optional "this" binding for the callback. - */ -export function forEach( - source: Iterable, - callback: (value: TSource, index: number) => void, - thisArg?: any -): void { - let i = 0; - const fn = bindCallback(callback, thisArg, 2); - for (let item of source) { - fn(item, i++); - } -} From fec0e3667028fe93bb9c98ebfeedd4d313fb505b Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Thu, 26 Oct 2017 03:19:54 -0400 Subject: [PATCH 098/106] feat(pipe): adds of and from to base --- spec/asynciterable-operators/average-spec.ts | 2 +- .../asynciterable-operators/catchwith-spec.ts | 14 +- spec/asynciterable-operators/concat-spec.ts | 17 +- spec/asynciterable-operators/count-spec.ts | 6 +- .../defaultifempty-spec.ts | 2 +- .../distinctuntilchanged-spec.ts | 2 +- spec/asynciterable-operators/dowhile-spec.ts | 24 ++- .../asynciterable-operators/elementat-spec.ts | 2 +- spec/asynciterable-operators/every-spec.ts | 6 +- spec/asynciterable-operators/except-spec.ts | 2 +- spec/asynciterable-operators/expand-spec.ts | 10 +- spec/asynciterable-operators/filter-spec.ts | 28 ++- spec/asynciterable-operators/first-spec.ts | 2 +- spec/asynciterable-operators/flatmap-spec.ts | 8 +- spec/asynciterable-operators/flatten-spec.ts | 2 +- spec/asynciterable-operators/groupby-spec.ts | 9 +- .../asynciterable-operators/groupjoin-spec.ts | 36 +++- spec/asynciterable-operators/includes-spec.ts | 2 +- .../asynciterable-operators/innerjoin-spec.ts | 63 ++---- .../asynciterable-operators/intersect-spec.ts | 2 +- spec/asynciterable-operators/isempty-spec.ts | 2 +- spec/asynciterable-operators/last-spec.ts | 2 +- spec/asynciterable-operators/map-spec.ts | 17 +- spec/asynciterable-operators/max-spec.ts | 2 +- spec/asynciterable-operators/maxby-spec.ts | 2 +- spec/asynciterable-operators/memoize-spec.ts | 27 ++- spec/asynciterable-operators/merge-spec.ts | 2 +- spec/asynciterable-operators/min-spec.ts | 2 +- spec/asynciterable-operators/minby-spec.ts | 2 +- .../onerrorresumenext-spec.ts | 2 +- spec/asynciterable-operators/orderby-spec.ts | 14 +- spec/asynciterable-operators/pairwise-spec.ts | 2 +- .../asynciterable-operators/partition-spec.ts | 2 +- spec/asynciterable-operators/pluck-spec.ts | 28 +-- spec/asynciterable-operators/publish-spec.ts | 18 +- spec/asynciterable-operators/reduce-spec.ts | 2 +- .../reduceright-spec.ts | 2 +- spec/asynciterable-operators/repeat-spec.ts | 21 +- spec/asynciterable-operators/reverse-spec.ts | 2 +- .../sequenceequal-spec.ts | 6 +- spec/asynciterable-operators/single-spec.ts | 2 +- spec/asynciterable-operators/skip-spec.ts | 2 +- .../asynciterable-operators/skipwhile-spec.ts | 6 +- spec/asynciterable-operators/slice-spec.ts | 2 +- spec/asynciterable-operators/some-spec.ts | 6 +- spec/asynciterable-operators/sum-spec.ts | 2 +- spec/asynciterable-operators/take-spec.ts | 2 +- .../asynciterable-operators/takewhile-spec.ts | 6 +- spec/asynciterable-operators/toarray-spec.ts | 2 +- spec/asynciterable-operators/tomap-spec.ts | 2 +- .../toobservable-spec.ts | 4 +- spec/asynciterable-operators/toset-spec.ts | 2 +- spec/asynciterable-operators/union-spec.ts | 2 +- spec/asynciterable-operators/zip-spec.ts | 13 +- spec/asynciterable/from-spec.ts | 10 +- spec/asynciterable/if-spec.ts | 2 +- spec/asynciterable/of-spec.ts | 2 +- spec/asynciterable/race-spec.ts | 2 +- spec/asynciterable/while-spec.ts | 24 ++- spec/iterable-operators/pairwise-spec.ts | 2 +- spec/iterable-operators/partition-spec.ts | 2 +- spec/iterable-operators/pluck-spec.ts | 28 +-- spec/iterable-operators/reduce-spec.ts | 2 +- spec/iterable-operators/reduceright-spec.ts | 2 +- spec/iterable-operators/slice-spec.ts | 2 +- spec/iterable/from-spec.ts | 2 +- spec/iterable/of-spec.ts | 2 +- src/Ix.ts | 4 - src/add/asynciterable/from.ts | 8 - src/add/asynciterable/of.ts | 8 - src/add/iterable/from.ts | 8 - src/add/iterable/of.ts | 8 - src/asynciterable.ts | 197 +++++++++++++++++- src/asynciterable/__modules.ts | 4 - src/asynciterable/from.ts | 178 ---------------- src/asynciterable/groupjoin.ts | 3 +- src/asynciterable/of.ts | 20 -- src/asynciterable/ofentries.ts | 3 +- src/asynciterable/ofkeys.ts | 3 +- src/asynciterable/ofvalues.ts | 5 +- src/asynciterable/repeat.ts | 3 +- src/iterable.ts | 58 ++++++ src/iterable/__modules.ts | 4 - src/iterable/from.ts | 43 ---- src/iterable/of.ts | 18 -- src/iterable/repeat.ts | 3 +- 86 files changed, 581 insertions(+), 528 deletions(-) delete mode 100644 src/add/asynciterable/from.ts delete mode 100644 src/add/asynciterable/of.ts delete mode 100644 src/add/iterable/from.ts delete mode 100644 src/add/iterable/of.ts delete mode 100644 src/asynciterable/from.ts delete mode 100644 src/asynciterable/of.ts delete mode 100644 src/iterable/from.ts delete mode 100644 src/iterable/of.ts diff --git a/spec/asynciterable-operators/average-spec.ts b/spec/asynciterable-operators/average-spec.ts index 877d6f69..33e030c5 100644 --- a/spec/asynciterable-operators/average-spec.ts +++ b/spec/asynciterable-operators/average-spec.ts @@ -2,7 +2,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { average } = Ix.asynciterable; const { empty } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; test('Iterable#average empty', async (t: test.Test) => { const xs = empty(); diff --git a/spec/asynciterable-operators/catchwith-spec.ts b/spec/asynciterable-operators/catchwith-spec.ts index 17c03687..4665a089 100644 --- a/spec/asynciterable-operators/catchwith-spec.ts +++ b/spec/asynciterable-operators/catchwith-spec.ts @@ -1,7 +1,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { catchWith } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { range } = Ix.asynciterable; const { sequenceEqual } = Ix.asynciterable; const { single } = Ix.asynciterable; @@ -9,14 +9,22 @@ const { _throw } = Ix.asynciterable; test('AsyncIterable#catchWith error catches', async t => { const err = new Error(); - const res = await single(catchWith(_throw(err), async e => { t.same(err, e); return of(42); })); + const res = await single( + catchWith(_throw(err), async e => { + t.same(err, e); + return of(42); + }) + ); t.equal(42, res); t.end(); }); test('AsyncIterable#catchWith no error misses', async t => { const xs = range(0, 10); - const res = catchWith(xs, async e => { t.fail(); return of(42); }); + const res = catchWith(xs, async e => { + t.fail(); + return of(42); + }); t.true(await sequenceEqual(res, xs)); t.end(); }); diff --git a/spec/asynciterable-operators/concat-spec.ts b/spec/asynciterable-operators/concat-spec.ts index 1d7e817a..6931310d 100644 --- a/spec/asynciterable-operators/concat-spec.ts +++ b/spec/asynciterable-operators/concat-spec.ts @@ -3,7 +3,7 @@ import * as test from 'tape-async'; const { concat } = Ix.asynciterable; const { concatAll } = Ix.asynciterable; const { map } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { range } = Ix.asynciterable; const { sequenceEqual } = Ix.asynciterable; const { tap } = Ix.asynciterable; @@ -16,17 +16,14 @@ test('AsyncIterable#concat concatAll behavior', async t => { test('Iterable#concat concatAll order of effects', async t => { let i = 0; - const xss = tap(map(range(0, 3), x => range(0, x + 1)), { next: async () => { ++i; } }); + const xss = tap(map(range(0, 3), x => range(0, x + 1)), { + next: async () => { + ++i; + } + }); const res = map(concatAll(xss), x => i + ' - ' + x); - t.true(await sequenceEqual(res, of( - '1 - 0', - '2 - 0', - '2 - 1', - '3 - 0', - '3 - 1', - '3 - 2' - ))); + t.true(await sequenceEqual(res, of('1 - 0', '2 - 0', '2 - 1', '3 - 0', '3 - 1', '3 - 2'))); t.end(); }); diff --git a/spec/asynciterable-operators/count-spec.ts b/spec/asynciterable-operators/count-spec.ts index 2cb0f88b..1960d7f0 100644 --- a/spec/asynciterable-operators/count-spec.ts +++ b/spec/asynciterable-operators/count-spec.ts @@ -2,7 +2,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { count } = Ix.asynciterable; const { empty } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { _throw } = Ix.asynciterable; test('AsyncItearble#count some', async (t: test.Test) => { @@ -67,7 +67,9 @@ test('AsyncIterable#count predicate throws', async (t: test.Test) => { const xs = of(1, 2, 3, 4); try { - await count(xs, async () => { throw err; }); + await count(xs, async () => { + throw err; + }); } catch (e) { t.same(err, e); } diff --git a/spec/asynciterable-operators/defaultifempty-spec.ts b/spec/asynciterable-operators/defaultifempty-spec.ts index 4d4c816a..40e02ecf 100644 --- a/spec/asynciterable-operators/defaultifempty-spec.ts +++ b/spec/asynciterable-operators/defaultifempty-spec.ts @@ -2,7 +2,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { defaultIfEmpty } = Ix.asynciterable; const { empty } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { _throw } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; diff --git a/spec/asynciterable-operators/distinctuntilchanged-spec.ts b/spec/asynciterable-operators/distinctuntilchanged-spec.ts index 4dd62e10..092f5fde 100644 --- a/spec/asynciterable-operators/distinctuntilchanged-spec.ts +++ b/spec/asynciterable-operators/distinctuntilchanged-spec.ts @@ -1,7 +1,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { distinctUntilChanged } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { sequenceEqual } = Ix.asynciterable; test('Iterable#distinctUntilChanged no selector', async t => { diff --git a/spec/asynciterable-operators/dowhile-spec.ts b/spec/asynciterable-operators/dowhile-spec.ts index b838b884..fc704aca 100644 --- a/spec/asynciterable-operators/dowhile-spec.ts +++ b/spec/asynciterable-operators/dowhile-spec.ts @@ -2,7 +2,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { defer } = Ix.asynciterable; const { doWhile } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { sequenceEqual } = Ix.iterable; const { tap } = Ix.asynciterable; const { toArray } = Ix.asynciterable; @@ -10,7 +10,16 @@ const { toArray } = Ix.asynciterable; test('Iterable#doWhile some', async t => { let x = 5; const res = await toArray( - doWhile(defer(() => tap(of(x), { next: async () => { x--; } })), async () => x > 0) + doWhile( + defer(() => + tap(of(x), { + next: async () => { + x--; + } + }) + ), + async () => x > 0 + ) ); t.true(sequenceEqual(res, [5, 4, 3, 2, 1])); @@ -20,7 +29,16 @@ test('Iterable#doWhile some', async t => { test('Iterable#doWhile one', async t => { let x = 0; const res = await toArray( - doWhile(defer(() => tap(of(x), { next: async () => { x--; } })), async () => x > 0) + doWhile( + defer(() => + tap(of(x), { + next: async () => { + x--; + } + }) + ), + async () => x > 0 + ) ); t.true(sequenceEqual(res, [0])); diff --git a/spec/asynciterable-operators/elementat-spec.ts b/spec/asynciterable-operators/elementat-spec.ts index 5624db46..88306c0d 100644 --- a/spec/asynciterable-operators/elementat-spec.ts +++ b/spec/asynciterable-operators/elementat-spec.ts @@ -2,7 +2,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { elementAt } = Ix.asynciterable; const { empty } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; test('AsyncIterable#elementAt empty returns undefined', async (t: test.Test) => { const xs = empty(); diff --git a/spec/asynciterable-operators/every-spec.ts b/spec/asynciterable-operators/every-spec.ts index 0fe091e8..3c999e5a 100644 --- a/spec/asynciterable-operators/every-spec.ts +++ b/spec/asynciterable-operators/every-spec.ts @@ -1,7 +1,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { every } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { _throw } = Ix.asynciterable; test('AsyncIterable#every not all match', async (t: test.Test) => { @@ -39,7 +39,9 @@ test('AsyncIterable#every predicate throws', async (t: test.Test) => { const xs = of(1, 2, 3, 4); try { - await every(xs, async () => { throw err; }); + await every(xs, async () => { + throw err; + }); } catch (e) { t.same(err, e); } diff --git a/spec/asynciterable-operators/except-spec.ts b/spec/asynciterable-operators/except-spec.ts index d1004c99..4d897045 100644 --- a/spec/asynciterable-operators/except-spec.ts +++ b/spec/asynciterable-operators/except-spec.ts @@ -1,7 +1,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { except } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; import { hasNext, noNext } from '../asynciterablehelpers'; test('Iterable#except with default comparer', async t => { diff --git a/spec/asynciterable-operators/expand-spec.ts b/spec/asynciterable-operators/expand-spec.ts index 6ff68284..e93667ed 100644 --- a/spec/asynciterable-operators/expand-spec.ts +++ b/spec/asynciterable-operators/expand-spec.ts @@ -1,7 +1,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { expand } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { range } = Ix.asynciterable; const { sequenceEqual } = Ix.asynciterable; const { take } = Ix.asynciterable; @@ -14,13 +14,7 @@ test('Iterable#expand with single return behavior', async t => { test('Iterable#expand with range return behavior', async t => { const res = expand(of(3), async x => range(0, x)); - const exp = of( - 3, - 0, 1, 2, - 0, - 0, 1, - 0 - ); + const exp = of(3, 0, 1, 2, 0, 0, 1, 0); t.true(await sequenceEqual(res, exp)); t.end(); diff --git a/spec/asynciterable-operators/filter-spec.ts b/spec/asynciterable-operators/filter-spec.ts index b8c74fb7..30e5d3a9 100644 --- a/spec/asynciterable-operators/filter-spec.ts +++ b/spec/asynciterable-operators/filter-spec.ts @@ -2,7 +2,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { empty } = Ix.asynciterable; const { filter } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { _throw } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; @@ -36,10 +36,14 @@ test('AsyncIterable#filter with index', async t => { 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('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); @@ -57,7 +61,12 @@ test('AsyncIterable#filter with typeguard', async t => { 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(); - const ys = filter(xs, async x => { if (x === 4) { throw err; } return true; }); + const ys = filter(xs, async x => { + if (x === 4) { + throw err; + } + return true; + }); const it = ys[Symbol.asyncIterator](); await hasNext(t, it, 8); @@ -74,7 +83,12 @@ test('AsyncIterable#filter throws part way through', async t => { test('AsyncIterable#filter with index throws part way through', async t => { const xs = of(8, 5, 7, 4, 6, 9, 2, 1, 0); const err = new Error(); - const ys = filter(xs, async (x, i) => { if (i === 3) { throw err; } return true; }); + const ys = filter(xs, async (x, i) => { + if (i === 3) { + throw err; + } + return true; + }); const it = ys[Symbol.asyncIterator](); await hasNext(t, it, 8); diff --git a/spec/asynciterable-operators/first-spec.ts b/spec/asynciterable-operators/first-spec.ts index 9271e8d9..511670c9 100644 --- a/spec/asynciterable-operators/first-spec.ts +++ b/spec/asynciterable-operators/first-spec.ts @@ -1,7 +1,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { empty } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { first } = Ix.asynciterable; test('AsyncIterable#first empty returns undefined', async (t: test.Test) => { diff --git a/spec/asynciterable-operators/flatmap-spec.ts b/spec/asynciterable-operators/flatmap-spec.ts index 44aba2ed..2ce70f27 100644 --- a/spec/asynciterable-operators/flatmap-spec.ts +++ b/spec/asynciterable-operators/flatmap-spec.ts @@ -1,7 +1,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { flatMap } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { range } = Ix.asynciterable; const { _throw } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; @@ -24,7 +24,7 @@ test('Iterable#flatMap with range', async t => { test('Iterable#flatMap selector returns throw', async t => { const err = new Error(); const xs = of(1, 2, 3); - const ys = flatMap(xs, async x => x < 3 ? range(0, x) : _throw(err)); + const ys = flatMap(xs, async x => (x < 3 ? range(0, x) : _throw(err))); const it = ys[Symbol.asyncIterator](); hasNext(t, it, 0); @@ -56,7 +56,9 @@ test('Iterable#flatMap selector throws error', async t => { const err = new Error(); const xs = of(1, 2, 3); const ys = flatMap(xs, async x => { - if (x < 3) { return range(0, x); } + if (x < 3) { + return range(0, x); + } throw err; }); diff --git a/spec/asynciterable-operators/flatten-spec.ts b/spec/asynciterable-operators/flatten-spec.ts index 99d95159..06f2c211 100644 --- a/spec/asynciterable-operators/flatten-spec.ts +++ b/spec/asynciterable-operators/flatten-spec.ts @@ -1,7 +1,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { flatten } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { toArray } = Ix.asynciterable; function compareArrays(t: test.Test, fst: Iterable, snd: Iterable) { diff --git a/spec/asynciterable-operators/groupby-spec.ts b/spec/asynciterable-operators/groupby-spec.ts index 77e02301..91d5dda7 100644 --- a/spec/asynciterable-operators/groupby-spec.ts +++ b/spec/asynciterable-operators/groupby-spec.ts @@ -1,7 +1,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { empty } = Ix.asynciterable; -const { from } = Ix.asynciterable; +const { from } = Ix.AsyncIterable; const { groupBy } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; @@ -168,7 +168,12 @@ test('AsyncIterable#groupBy element selector', async t => { test('AsyncIterable#groupBy result selector', async t => { const xs = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; const xss = from(xs); - const ys = groupBy(xss, async x => x % 3, x => String.fromCharCode(97 + x), (k, v) => ({ k, v: from(v) })); + const ys = groupBy( + xss, + async x => x % 3, + x => String.fromCharCode(97 + x), + (k, v) => ({ k, v: from(v) }) + ); const it = ys[Symbol.asyncIterator](); diff --git a/spec/asynciterable-operators/groupjoin-spec.ts b/spec/asynciterable-operators/groupjoin-spec.ts index 2e74de94..abc1659b 100644 --- a/spec/asynciterable-operators/groupjoin-spec.ts +++ b/spec/asynciterable-operators/groupjoin-spec.ts @@ -1,7 +1,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { groupJoin } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { reduce } = Ix.asynciterable; const { _throw } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; @@ -14,7 +14,8 @@ test('AsyncIterable#groupJoin all groups have values', async t => { ys, async x => x % 3, async y => y % 3, - async (x, i) => x + ' - ' + await reduce(i, async (s, j) => s + j, '')); + async (x, i) => x + ' - ' + (await reduce(i, async (s, j) => s + j, '')) + ); const it = res[Symbol.asyncIterator](); await hasNext(t, it, '0 - 639'); @@ -32,7 +33,8 @@ test('AsyncIterable#groupJoin some groups have values', async t => { ys, async x => x % 3, async y => y % 3, - async (x, i) => x + ' - ' + await reduce(i, async (s, j) => s + j, '')); + async (x, i) => x + ' - ' + (await reduce(i, async (s, j) => s + j, '')) + ); const it = res[Symbol.asyncIterator](); await hasNext(t, it, '0 - 36'); @@ -51,7 +53,8 @@ test('AsyncIterable#groupJoin left throws', async t => { ys, async x => x % 3, async y => y % 3, - async (x, i) => x + ' - ' + await reduce(i, async (s, j) => s + j, '')); + async (x, i) => x + ' - ' + (await reduce(i, async (s, j) => s + j, '')) + ); const it = res[Symbol.asyncIterator](); try { @@ -71,7 +74,8 @@ test('AsyncIterable#groupJoin right throws', async t => { ys, async x => x % 3, async y => y % 3, - async (x, i) => x + ' - ' + await reduce(i, async (s, j) => s + j, '')); + async (x, i) => x + ' - ' + (await reduce(i, async (s, j) => s + j, '')) + ); const it = res[Symbol.asyncIterator](); try { @@ -89,9 +93,12 @@ test('AsyncIterable#groupJoin left selector throws', async t => { const res = groupJoin( xs, ys, - async x => { throw err; }, + async x => { + throw err; + }, async y => y % 3, - async (x, i) => x + ' - ' + await reduce(i, async (s, j) => s + j, '')); + async (x, i) => x + ' - ' + (await reduce(i, async (s, j) => s + j, '')) + ); const it = res[Symbol.asyncIterator](); try { @@ -110,8 +117,11 @@ test('AsyncIterable#groupJoin right selector throws', async t => { xs, ys, async x => x % 3, - async y => { throw err; }, - async (x, i) => x + ' - ' + await reduce(i, async (s, j) => s + j, '')); + async y => { + throw err; + }, + async (x, i) => x + ' - ' + (await reduce(i, async (s, j) => s + j, '')) + ); const it = res[Symbol.asyncIterator](); try { @@ -131,7 +141,13 @@ test('AsyncIterable#groupJoin result selector eventually throws', async t => { ys, async x => x % 3, async y => y % 3, - async (x, i) => { if (x === 1) { throw err; } return x + ' - ' + await reduce(i, async (s, j) => s + j, ''); }); + async (x, i) => { + if (x === 1) { + throw err; + } + return x + ' - ' + (await reduce(i, async (s, j) => s + j, '')); + } + ); const it = res[Symbol.asyncIterator](); await hasNext(t, it, '0 - 36'); diff --git a/spec/asynciterable-operators/includes-spec.ts b/spec/asynciterable-operators/includes-spec.ts index 2e765435..4219fe6a 100644 --- a/spec/asynciterable-operators/includes-spec.ts +++ b/spec/asynciterable-operators/includes-spec.ts @@ -1,6 +1,6 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { includes } = Ix.asynciterable; test('AsyncIterable#includes includes', async (t: test.Test) => { diff --git a/spec/asynciterable-operators/innerjoin-spec.ts b/spec/asynciterable-operators/innerjoin-spec.ts index 6b7eece5..1f561c11 100644 --- a/spec/asynciterable-operators/innerjoin-spec.ts +++ b/spec/asynciterable-operators/innerjoin-spec.ts @@ -1,19 +1,14 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { innerJoin } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { _throw } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; test('AsyncIterable#innerJoin normal', async t => { const xs = of(0, 1, 2); const ys = of(3, 6, 4); - const res = innerJoin( - xs, - ys, - async x => x % 3, - async y => y % 3, - async (x, y) => x + y); + const res = innerJoin(xs, ys, async x => x % 3, async y => y % 3, async (x, y) => x + y); const it = res[Symbol.asyncIterator](); await hasNext(t, it, 0 + 3); @@ -26,12 +21,7 @@ test('AsyncIterable#innerJoin normal', async t => { test('AsyncIterable#innerJoin reversed', async t => { const xs = of(3, 6, 4); const ys = of(0, 1, 2); - const res = innerJoin( - xs, - ys, - async x => x % 3, - async y => y % 3, - async (x, y) => x + y); + const res = innerJoin(xs, ys, async x => x % 3, async y => y % 3, async (x, y) => x + y); const it = res[Symbol.asyncIterator](); await hasNext(t, it, 3 + 0); @@ -44,12 +34,7 @@ test('AsyncIterable#innerJoin reversed', async t => { test('AsyncIterable#innerJoin only one group matches', async t => { const xs = of(0, 1, 2); const ys = of(3, 6); - const res = innerJoin( - xs, - ys, - async x => x % 3, - async y => y % 3, - async (x, y) => x + y); + const res = innerJoin(xs, ys, async x => x % 3, async y => y % 3, async (x, y) => x + y); const it = res[Symbol.asyncIterator](); await hasNext(t, it, 0 + 3); @@ -61,12 +46,7 @@ test('AsyncIterable#innerJoin only one group matches', async t => { test('AsyncIterable#innerJoin only one group matches reversed', async t => { const xs = of(3, 6); const ys = of(0, 1, 2); - const res = innerJoin( - xs, - ys, - async x => x % 3, - async y => y % 3, - async (x, y) => x + y); + const res = innerJoin(xs, ys, async x => x % 3, async y => y % 3, async (x, y) => x + y); const it = res[Symbol.asyncIterator](); await hasNext(t, it, 3 + 0); @@ -78,12 +58,7 @@ test('AsyncIterable#innerJoin only one group matches reversed', async t => { test('AsyncIterable#innerJoin left throws', async t => { const xs = _throw(new Error()); const ys = of(3, 6, 4); - const res = innerJoin( - xs, - ys, - async x => x % 3, - async y => y % 3, - async (x, y) => x + y); + const res = innerJoin(xs, ys, async x => x % 3, async y => y % 3, async (x, y) => x + y); const it = res[Symbol.asyncIterator](); try { @@ -97,12 +72,7 @@ test('AsyncIterable#innerJoin left throws', async t => { test('AsyncIterable#innerJoin right throws', async t => { const xs = of(0, 1, 2); const ys = _throw(new Error()); - const res = innerJoin( - xs, - ys, - async x => x % 3, - async y => y % 3, - async (x, y) => x + y); + const res = innerJoin(xs, ys, async x => x % 3, async y => y % 3, async (x, y) => x + y); const it = res[Symbol.asyncIterator](); try { @@ -119,9 +89,12 @@ test('AsyncIterable#innerJoin left selector throws', async t => { const res = innerJoin( xs, ys, - async x => { throw new Error(); }, + async x => { + throw new Error(); + }, async y => y % 3, - async (x, y) => x + y); + async (x, y) => x + y + ); const it = res[Symbol.asyncIterator](); try { @@ -139,8 +112,11 @@ test('AsyncIterable#innerJoin right selector throws', async t => { xs, ys, async x => x % 3, - async y => { throw new Error(); }, - async (x, y) => x + y); + async y => { + throw new Error(); + }, + async (x, y) => x + y + ); const it = res[Symbol.asyncIterator](); try { @@ -159,7 +135,10 @@ test('AsyncIterable#innerJoin result selector throws', async t => { ys, async x => x % 3, async y => y % 3, - async (x, y) => { throw new Error(); }); + async (x, y) => { + throw new Error(); + } + ); const it = res[Symbol.asyncIterator](); try { diff --git a/spec/asynciterable-operators/intersect-spec.ts b/spec/asynciterable-operators/intersect-spec.ts index ff9bdea4..71105ac0 100644 --- a/spec/asynciterable-operators/intersect-spec.ts +++ b/spec/asynciterable-operators/intersect-spec.ts @@ -1,6 +1,6 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { intersect } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; diff --git a/spec/asynciterable-operators/isempty-spec.ts b/spec/asynciterable-operators/isempty-spec.ts index 466ed1c9..c293c39e 100644 --- a/spec/asynciterable-operators/isempty-spec.ts +++ b/spec/asynciterable-operators/isempty-spec.ts @@ -2,7 +2,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { empty } = Ix.asynciterable; const { isEmpty } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; test('Iterable#isEmpty empty', async t => { t.true(await isEmpty(empty())); diff --git a/spec/asynciterable-operators/last-spec.ts b/spec/asynciterable-operators/last-spec.ts index cd1554a6..e8d9b698 100644 --- a/spec/asynciterable-operators/last-spec.ts +++ b/spec/asynciterable-operators/last-spec.ts @@ -2,7 +2,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { empty } = Ix.asynciterable; const { last } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; test('AsyncIterable#last empty returns undefined', async (t: test.Test) => { const xs = empty(); diff --git a/spec/asynciterable-operators/map-spec.ts b/spec/asynciterable-operators/map-spec.ts index 00446412..eb939c3f 100644 --- a/spec/asynciterable-operators/map-spec.ts +++ b/spec/asynciterable-operators/map-spec.ts @@ -1,8 +1,8 @@ import * as Ix from '../Ix'; -import * as test from 'tape'; +import * as test from 'tape'; const { empty } = Ix.asynciterable; const { map } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { sequenceEqual } = Ix.asynciterable; test('AsyncIterable#map single element', async t => { @@ -19,7 +19,7 @@ test('AsyncIterable#map maps property', t => { { name: 'Bob', custId: 29099 }, { name: 'Chris', custId: 39033 }, { name: null, custId: 30349 }, - { name: 'Frank', custId: 39030 }, + { name: 'Frank', custId: 39030 } ); const expected = of('Frank', 'Bob', 'Chris', null, 'Frank'); @@ -40,7 +40,7 @@ test('AsyncIterable#map map property using index', async t => { ); const expected = of('Frank', null, null); - t.true(await sequenceEqual(expected, map(source, (x, i) => i === 0 ? x.name : null))); + t.true(await sequenceEqual(expected, map(source, (x, i) => (i === 0 ? x.name : null)))); t.end(); }); @@ -50,17 +50,20 @@ test('AsyncIterable#map map property using index on last', async t => { { name: 'Bob', custId: 29099 }, { name: 'Chris', custId: 39033 }, { name: 'Bill', custId: 30349 }, - { name: 'Frank', custId: 39030 }, + { name: 'Frank', custId: 39030 } ); const expected = of(null, null, null, null, 'Frank'); - t.true(await sequenceEqual(expected, map(source, (x, i) => i === 4 ? x.name : null))); + t.true(await sequenceEqual(expected, map(source, (x, i) => (i === 4 ? x.name : null)))); t.end(); }); test('AsyncIterable#map execution is deferred', async t => { let fnCalled = false; - const source = of(() => { fnCalled = true; return 1; }); + const source = of(() => { + fnCalled = true; + return 1; + }); map(source, x => x()); diff --git a/spec/asynciterable-operators/max-spec.ts b/spec/asynciterable-operators/max-spec.ts index cd037a7b..9e43787e 100644 --- a/spec/asynciterable-operators/max-spec.ts +++ b/spec/asynciterable-operators/max-spec.ts @@ -1,7 +1,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { empty } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { max } = Ix.asynciterable; test('AsyncItearble#max laws', async (t: test.Test) => { diff --git a/spec/asynciterable-operators/maxby-spec.ts b/spec/asynciterable-operators/maxby-spec.ts index da9b68d5..c7cb58ab 100644 --- a/spec/asynciterable-operators/maxby-spec.ts +++ b/spec/asynciterable-operators/maxby-spec.ts @@ -2,7 +2,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { empty } = Ix.asynciterable; const { maxBy } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { sequenceEqual } = Ix.asynciterable; test('AsyncIterable#maxBy', async t => { diff --git a/spec/asynciterable-operators/memoize-spec.ts b/spec/asynciterable-operators/memoize-spec.ts index 6e8c1285..6feb06c4 100644 --- a/spec/asynciterable-operators/memoize-spec.ts +++ b/spec/asynciterable-operators/memoize-spec.ts @@ -1,8 +1,8 @@ import * as Ix from '../Ix'; -import * as test from 'tape'; +import * as test from 'tape'; const { concat } = Ix.asynciterable; const { every } = Ix.asynciterable; -const { from } = Ix.asynciterable; +const { from } = Ix.AsyncIterable; const { map } = Ix.asynciterable; const { memoize } = Ix.asynciterable; const { range } = Ix.asynciterable; @@ -12,7 +12,7 @@ const { tap } = Ix.asynciterable; const { _throw } = Ix.asynciterable; const { toArray } = Ix.asynciterable; const { zip } = Ix.asynciterable; -import { hasNext , noNext } from '../asynciterablehelpers'; +import { hasNext, noNext } from '../asynciterablehelpers'; async function* tick(t: (x: number) => void | Promise) { let i = 0; @@ -24,7 +24,11 @@ async function* tick(t: (x: number) => void | Promise) { test('AsyncIterable#memoize memoizes effects', async t => { let n = 0; - const rng = memoize(tick(async i => { n += i; })); + const rng = memoize( + tick(async i => { + n += i; + }) + ); const it1 = rng[Symbol.asyncIterator](); const it2 = rng[Symbol.asyncIterator](); @@ -167,7 +171,8 @@ test('AsyncIterable#memoize concat with error', async t => { }); function getRandom() { - let min = 0, max = Math.pow(2, 53) - 1; + let min = 0, + max = Math.pow(2, 53) - 1; return Math.floor(Math.random() * (max - min)) + min; } @@ -187,7 +192,11 @@ test('AsyncIterable#memoize with selector', async t => { let n = 0; const res = await toArray( memoize( - tap(range(0, 4), { next: async () => { n++; } }), + tap(range(0, 4), { + next: async () => { + n++; + } + }), undefined, xs => take(zip(async ([l, r]) => l + r, xs, xs), 4) ) @@ -202,7 +211,11 @@ test('AsyncIterable#memoize limited with selector', async t => { let n = 0; const res = await toArray( memoize( - tap(range(0, 4), { next: async () => { n++; } }), + tap(range(0, 4), { + next: async () => { + n++; + } + }), 2, xs => take(zip(async ([l, r]) => l + r, xs, xs), 4) ) diff --git a/spec/asynciterable-operators/merge-spec.ts b/spec/asynciterable-operators/merge-spec.ts index 7602584b..d65d83ec 100644 --- a/spec/asynciterable-operators/merge-spec.ts +++ b/spec/asynciterable-operators/merge-spec.ts @@ -2,7 +2,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { merge } = Ix.asynciterable; const { mergeAll } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { sequenceEqual } = Ix.asynciterable; test('AsyncIterable#merge mergeAll behavior', async t => { diff --git a/spec/asynciterable-operators/min-spec.ts b/spec/asynciterable-operators/min-spec.ts index 2abb600e..3d8c6c37 100644 --- a/spec/asynciterable-operators/min-spec.ts +++ b/spec/asynciterable-operators/min-spec.ts @@ -1,7 +1,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { empty } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { min } = Ix.asynciterable; test('AsyncItearble#min laws', async (t: test.Test) => { diff --git a/spec/asynciterable-operators/minby-spec.ts b/spec/asynciterable-operators/minby-spec.ts index 06df593a..a4659f11 100644 --- a/spec/asynciterable-operators/minby-spec.ts +++ b/spec/asynciterable-operators/minby-spec.ts @@ -2,7 +2,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { empty } = Ix.asynciterable; const { minBy } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { sequenceEqual } = Ix.asynciterable; test('AsyncIterable#minBy', async t => { diff --git a/spec/asynciterable-operators/onerrorresumenext-spec.ts b/spec/asynciterable-operators/onerrorresumenext-spec.ts index 67904fde..1f933497 100644 --- a/spec/asynciterable-operators/onerrorresumenext-spec.ts +++ b/spec/asynciterable-operators/onerrorresumenext-spec.ts @@ -1,7 +1,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { concat } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { onErrorResumeNext } = Ix.asynciterable; const { sequenceEqual } = Ix.asynciterable; const { _throw } = Ix.asynciterable; diff --git a/spec/asynciterable-operators/orderby-spec.ts b/spec/asynciterable-operators/orderby-spec.ts index b0988368..b9f6f45b 100644 --- a/spec/asynciterable-operators/orderby-spec.ts +++ b/spec/asynciterable-operators/orderby-spec.ts @@ -1,6 +1,6 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { orderBy, orderByDescending, thenBy, thenByDescending } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; @@ -20,7 +20,9 @@ test('AsyncIterable#orderBy normal ordering', async t => { test('AsyncIterable#orderBy normal ordering with thenBy throws', async t => { const err = new Error(); const xs = of(2, 6, 1, 5, 7, 8, 9, 3, 4, 0); - const ys = thenBy(orderBy(xs, x => x), () => { throw err; }); + const ys = thenBy(orderBy(xs, x => x), () => { + throw err; + }); const it = ys[Symbol.asyncIterator](); try { @@ -34,7 +36,9 @@ test('AsyncIterable#orderBy normal ordering with thenBy throws', async t => { test('AsyncIterable#orderBy selector throws', async t => { const err = new Error(); const xs = of(2, 6, 1, 5, 7, 8, 9, 3, 4, 0); - const ys = orderBy(xs, () => { throw err; }); + const ys = orderBy(xs, () => { + throw err; + }); const it = ys[Symbol.asyncIterator](); try { @@ -61,7 +65,9 @@ test('AsyncIterable#orderByDescending normal ordering', async t => { test('AsyncIterable#orderByDescending normal ordering with thenByDescending throws', async t => { const err = new Error(); const xs = of(2, 6, 1, 5, 7, 8, 9, 3, 4, 0); - const ys = thenByDescending(orderByDescending(xs, x => x), () => { throw err; }); + const ys = thenByDescending(orderByDescending(xs, x => x), () => { + throw err; + }); const it = ys[Symbol.asyncIterator](); try { diff --git a/spec/asynciterable-operators/pairwise-spec.ts b/spec/asynciterable-operators/pairwise-spec.ts index 061faa90..7001c649 100644 --- a/spec/asynciterable-operators/pairwise-spec.ts +++ b/spec/asynciterable-operators/pairwise-spec.ts @@ -1,7 +1,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { empty } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { pairwise } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; diff --git a/spec/asynciterable-operators/partition-spec.ts b/spec/asynciterable-operators/partition-spec.ts index d8999367..fcc611e2 100644 --- a/spec/asynciterable-operators/partition-spec.ts +++ b/spec/asynciterable-operators/partition-spec.ts @@ -1,7 +1,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { empty } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { partition } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; diff --git a/spec/asynciterable-operators/pluck-spec.ts b/spec/asynciterable-operators/pluck-spec.ts index 5bfd7d29..bc6d30a8 100644 --- a/spec/asynciterable-operators/pluck-spec.ts +++ b/spec/asynciterable-operators/pluck-spec.ts @@ -1,17 +1,11 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { pluck } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; test('Iterable#pluck simple prop', async t => { - const xs = of( - {prop: 1}, - {prop: 2}, - {prop: 3}, - {prop: 4}, - {prop: 5} - ); + const xs = of({ prop: 1 }, { prop: 2 }, { prop: 3 }, { prop: 4 }, { prop: 5 }); const ys = pluck(xs, 'prop'); const it = ys[Symbol.asyncIterator](); @@ -26,11 +20,11 @@ test('Iterable#pluck simple prop', async t => { test('Iterable#pluck nested prop', async t => { const xs = of( - {a: {b: {c: 1}}}, - {a: {b: {c: 2}}}, - {a: {b: {c: 3}}}, - {a: {b: {c: 4}}}, - {a: {b: {c: 5}}} + { a: { b: { c: 1 } } }, + { a: { b: { c: 2 } } }, + { a: { b: { c: 3 } } }, + { a: { b: { c: 4 } } }, + { a: { b: { c: 5 } } } ); const ys = pluck(xs, 'a', 'b', 'c'); @@ -46,11 +40,11 @@ test('Iterable#pluck nested prop', async t => { test('Iterable#pluck edge cases', async t => { const xs = of( - {a: {b: {c: 1}}}, - {a: {b: 2}}, - {a: {c: {c: 3}}}, + { a: { b: { c: 1 } } }, + { a: { b: 2 } }, + { a: { c: { c: 3 } } }, {}, - {a: {b: {c: 5}}} + { a: { b: { c: 5 } } } ); const ys = pluck(xs, 'a', 'b', 'c'); diff --git a/spec/asynciterable-operators/publish-spec.ts b/spec/asynciterable-operators/publish-spec.ts index ad2b5206..49614a74 100644 --- a/spec/asynciterable-operators/publish-spec.ts +++ b/spec/asynciterable-operators/publish-spec.ts @@ -1,7 +1,7 @@ import * as Ix from '../Ix'; -import * as test from 'tape'; +import * as test from 'tape'; const { concat } = Ix.asynciterable; -const { from } = Ix.asynciterable; +const { from } = Ix.AsyncIterable; const { map } = Ix.asynciterable; const { publish } = Ix.asynciterable; const { range } = Ix.asynciterable; @@ -11,7 +11,7 @@ const { take } = Ix.asynciterable; const { tap } = Ix.asynciterable; const { toArray } = Ix.asynciterable; const { zip } = Ix.asynciterable; -import { hasNext , noNext } from '../asynciterablehelpers'; +import { hasNext, noNext } from '../asynciterablehelpers'; async function* tick(t: (x: number) => void | Promise) { let i = 0; @@ -23,7 +23,11 @@ async function* tick(t: (x: number) => void | Promise) { test('AsyncIterable#publish starts at beginning', async t => { let n = 0; - const rng = publish(tick(async i => { n += i; })); + const rng = publish( + tick(async i => { + n += i; + }) + ); const it1 = rng[Symbol.asyncIterator](); const it2 = rng[Symbol.asyncIterator](); @@ -162,7 +166,11 @@ test('AsyncIterable#publish with selector', async t => { let n = 0; const res = await toArray( publish( - tap(range(0, 10), { next: async () => { n++; } }), + tap(range(0, 10), { + next: async () => { + n++; + } + }), xs => take(zip(async ([l, r]) => l + r, xs, xs), 4) ) ); diff --git a/spec/asynciterable-operators/reduce-spec.ts b/spec/asynciterable-operators/reduce-spec.ts index 190c07f1..9b1693d4 100644 --- a/spec/asynciterable-operators/reduce-spec.ts +++ b/spec/asynciterable-operators/reduce-spec.ts @@ -1,7 +1,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { empty } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { reduce } = Ix.asynciterable; test('Iterable#reduce no seed', async t => { diff --git a/spec/asynciterable-operators/reduceright-spec.ts b/spec/asynciterable-operators/reduceright-spec.ts index 475abd4d..a97ae52e 100644 --- a/spec/asynciterable-operators/reduceright-spec.ts +++ b/spec/asynciterable-operators/reduceright-spec.ts @@ -1,7 +1,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { empty } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { reduceRight } = Ix.asynciterable; test('AsyncIterable#reduceRight no seed', async t => { diff --git a/spec/asynciterable-operators/repeat-spec.ts b/spec/asynciterable-operators/repeat-spec.ts index 563f03fd..f9d7c1df 100644 --- a/spec/asynciterable-operators/repeat-spec.ts +++ b/spec/asynciterable-operators/repeat-spec.ts @@ -1,9 +1,9 @@ import * as Ix from '../Ix'; -import * as test from 'tape'; +import * as test from 'tape'; const { buffer } = Ix.iterable; const { every } = Ix.iterable; const { map } = Ix.iterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { repeat } = Ix.asynciterable; const { sum } = Ix.iterable; const { take } = Ix.asynciterable; @@ -12,7 +12,13 @@ const { toArray } = Ix.asynciterable; test('AsyncIterable#repeat infinite', async t => { let i = 0; - const xs = repeat(tap(of(1,2), { next: async () => { ++i; } })); + const xs = repeat( + tap(of(1, 2), { + next: async () => { + ++i; + } + }) + ); const res = await toArray(take(xs, 10)); t.equal(10, res.length); @@ -23,7 +29,14 @@ test('AsyncIterable#repeat infinite', async t => { test('AsyncIterable#repeat finite', async t => { let i = 0; - const xs = repeat(tap(of(1,2), { next: async () => { ++i; } }), 5); + const xs = repeat( + tap(of(1, 2), { + next: async () => { + ++i; + } + }), + 5 + ); const res = await toArray(take(xs, 10)); t.equal(10, res.length); diff --git a/spec/asynciterable-operators/reverse-spec.ts b/spec/asynciterable-operators/reverse-spec.ts index e3d39cd6..5b91c690 100644 --- a/spec/asynciterable-operators/reverse-spec.ts +++ b/spec/asynciterable-operators/reverse-spec.ts @@ -1,7 +1,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { empty } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { reverse } = Ix.asynciterable; const { _throw } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; diff --git a/spec/asynciterable-operators/sequenceequal-spec.ts b/spec/asynciterable-operators/sequenceequal-spec.ts index f4a38def..8d51428c 100644 --- a/spec/asynciterable-operators/sequenceequal-spec.ts +++ b/spec/asynciterable-operators/sequenceequal-spec.ts @@ -1,7 +1,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { empty } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { sequenceEqual } = Ix.asynciterable; const { _throw } = Ix.asynciterable; @@ -153,7 +153,9 @@ test('Itearble#sequenceEqual with custom comparer should be equal', async t => { test('Itearble#sequenceEqual with custom comparer throws', async t => { const err = new Error(); - const comparer = (x: number, y: number) => { throw err; }; + const comparer = (x: number, y: number) => { + throw err; + }; const xs = of(1, 2, -3, 4); const ys = of(1, -2, 3, 4); diff --git a/spec/asynciterable-operators/single-spec.ts b/spec/asynciterable-operators/single-spec.ts index d33e1d2e..5fccb535 100644 --- a/spec/asynciterable-operators/single-spec.ts +++ b/spec/asynciterable-operators/single-spec.ts @@ -1,7 +1,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { empty } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { single } = Ix.asynciterable; test('AsyncIterable#single no predicate empty returns undefined', async (t: test.Test) => { diff --git a/spec/asynciterable-operators/skip-spec.ts b/spec/asynciterable-operators/skip-spec.ts index fd91921b..33608cea 100644 --- a/spec/asynciterable-operators/skip-spec.ts +++ b/spec/asynciterable-operators/skip-spec.ts @@ -1,6 +1,6 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { skip } = Ix.asynciterable; const { _throw } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; diff --git a/spec/asynciterable-operators/skipwhile-spec.ts b/spec/asynciterable-operators/skipwhile-spec.ts index 7d954c64..a3794edc 100644 --- a/spec/asynciterable-operators/skipwhile-spec.ts +++ b/spec/asynciterable-operators/skipwhile-spec.ts @@ -1,6 +1,6 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { skipWhile } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; @@ -54,7 +54,9 @@ test('AsyncIterable#skipWhile skips some another run', async t => { test('AsyncIterable#skipWhile predicate throws', async t => { const err = new Error(); const xs = of(1, 2, 3, 4); - const ys = skipWhile(xs, () => { throw err; }); + const ys = skipWhile(xs, () => { + throw err; + }); const it = ys[Symbol.asyncIterator](); try { diff --git a/spec/asynciterable-operators/slice-spec.ts b/spec/asynciterable-operators/slice-spec.ts index 253fa1bc..1bb425ad 100644 --- a/spec/asynciterable-operators/slice-spec.ts +++ b/spec/asynciterable-operators/slice-spec.ts @@ -1,6 +1,6 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; -const { from } = Ix.asynciterable; +const { from } = Ix.AsyncIterable; const { slice } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; diff --git a/spec/asynciterable-operators/some-spec.ts b/spec/asynciterable-operators/some-spec.ts index 29963e47..a8fed2a7 100644 --- a/spec/asynciterable-operators/some-spec.ts +++ b/spec/asynciterable-operators/some-spec.ts @@ -1,6 +1,6 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { some } = Ix.asynciterable; const { _throw } = Ix.asynciterable; @@ -35,7 +35,9 @@ test('AsyncIterable#some predicate throws', async (t: test.Test) => { const xs = of(1, 2, 3, 4); try { - await some(xs, async () => { throw err; }); + await some(xs, async () => { + throw err; + }); } catch (e) { t.same(err, e); } diff --git a/spec/asynciterable-operators/sum-spec.ts b/spec/asynciterable-operators/sum-spec.ts index b5d6d5d5..02fc8aa4 100644 --- a/spec/asynciterable-operators/sum-spec.ts +++ b/spec/asynciterable-operators/sum-spec.ts @@ -1,7 +1,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { empty } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { sum } = Ix.asynciterable; test('AsyncIterable#sum laws', async t => { diff --git a/spec/asynciterable-operators/take-spec.ts b/spec/asynciterable-operators/take-spec.ts index ceb023a7..32eae5ec 100644 --- a/spec/asynciterable-operators/take-spec.ts +++ b/spec/asynciterable-operators/take-spec.ts @@ -1,6 +1,6 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { take } = Ix.asynciterable; const { _throw } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; diff --git a/spec/asynciterable-operators/takewhile-spec.ts b/spec/asynciterable-operators/takewhile-spec.ts index 69b3fc51..9f909f46 100644 --- a/spec/asynciterable-operators/takewhile-spec.ts +++ b/spec/asynciterable-operators/takewhile-spec.ts @@ -1,6 +1,6 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { takeWhile } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; @@ -51,7 +51,9 @@ test('AsyncIterable#takeWhile uses index', async t => { test('AsyncIterable#takeWhile predicate throws', async t => { const err = new Error(); const xs = of(1, 2, 3, 4); - const ys = takeWhile(xs, () => { throw err; }); + const ys = takeWhile(xs, () => { + throw err; + }); const it = ys[Symbol.asyncIterator](); try { diff --git a/spec/asynciterable-operators/toarray-spec.ts b/spec/asynciterable-operators/toarray-spec.ts index 07759f21..7ab1bfa8 100644 --- a/spec/asynciterable-operators/toarray-spec.ts +++ b/spec/asynciterable-operators/toarray-spec.ts @@ -1,7 +1,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { empty } = Ix.asynciterable; -const { from } = Ix.asynciterable; +const { from } = Ix.AsyncIterable; const { sequenceEqual } = Ix.iterable; const { toArray } = Ix.asynciterable; diff --git a/spec/asynciterable-operators/tomap-spec.ts b/spec/asynciterable-operators/tomap-spec.ts index fc3d4d89..633a152a 100644 --- a/spec/asynciterable-operators/tomap-spec.ts +++ b/spec/asynciterable-operators/tomap-spec.ts @@ -1,6 +1,6 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { toMap } = Ix.asynciterable; test('AsyncIterable#toMap stores values', async (t: test.Test) => { diff --git a/spec/asynciterable-operators/toobservable-spec.ts b/spec/asynciterable-operators/toobservable-spec.ts index 3e6d8e0c..8b4e25ad 100644 --- a/spec/asynciterable-operators/toobservable-spec.ts +++ b/spec/asynciterable-operators/toobservable-spec.ts @@ -1,7 +1,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { empty } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { _throw } = Ix.asynciterable; const { toObservable } = Ix.asynciterable; @@ -64,4 +64,4 @@ test('AsyncIterable#toObservable error', async t => { fail = true; } }); -}); \ No newline at end of file +}); diff --git a/spec/asynciterable-operators/toset-spec.ts b/spec/asynciterable-operators/toset-spec.ts index 1ffa8234..9726dea2 100644 --- a/spec/asynciterable-operators/toset-spec.ts +++ b/spec/asynciterable-operators/toset-spec.ts @@ -1,7 +1,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { empty } = Ix.asynciterable; -const { from } = Ix.asynciterable; +const { from } = Ix.AsyncIterable; const { sequenceEqual } = Ix.iterable; const { toSet } = Ix.asynciterable; diff --git a/spec/asynciterable-operators/union-spec.ts b/spec/asynciterable-operators/union-spec.ts index 6bd61152..42833978 100644 --- a/spec/asynciterable-operators/union-spec.ts +++ b/spec/asynciterable-operators/union-spec.ts @@ -1,6 +1,6 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { union } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; diff --git a/spec/asynciterable-operators/zip-spec.ts b/spec/asynciterable-operators/zip-spec.ts index a45b8ce5..0813fb54 100644 --- a/spec/asynciterable-operators/zip-spec.ts +++ b/spec/asynciterable-operators/zip-spec.ts @@ -1,6 +1,6 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { _throw } = Ix.asynciterable; const { zip } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; @@ -92,7 +92,16 @@ test('AsyncIterable#zip selector throws', async t => { const err = new Error(); const xs = of(1, 2, 3); const ys = of(4, 5, 6); - const res = zip(([x, y]) => { if (x > 0) { throw err; } return x * y; }, xs, ys); + const res = zip( + ([x, y]) => { + if (x > 0) { + throw err; + } + return x * y; + }, + xs, + ys + ); const it = res[Symbol.asyncIterator](); try { diff --git a/spec/asynciterable/from-spec.ts b/spec/asynciterable/from-spec.ts index 8de3baa7..7ac42c6d 100644 --- a/spec/asynciterable/from-spec.ts +++ b/spec/asynciterable/from-spec.ts @@ -1,10 +1,14 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; -const { from } = Ix.asynciterable; +const { from } = Ix.AsyncIterable; import { hasNext, noNext } from '../asynciterablehelpers'; test('AsyncIterable#from from promise list', async t => { - const xs: Iterable> = [Promise.resolve(1), Promise.resolve(2), Promise.resolve(3)]; + const xs: Iterable> = [ + Promise.resolve(1), + Promise.resolve(2), + Promise.resolve(3) + ]; const res = from(xs); const it = res[Symbol.asyncIterator](); @@ -198,4 +202,4 @@ test('AsyncIterable#fromObservable with error', async t => { } t.end(); -}); \ No newline at end of file +}); diff --git a/spec/asynciterable/if-spec.ts b/spec/asynciterable/if-spec.ts index 7fcec015..72578eee 100644 --- a/spec/asynciterable/if-spec.ts +++ b/spec/asynciterable/if-spec.ts @@ -2,7 +2,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { _if } = Ix.asynciterable; const { isEmpty } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { single } = Ix.asynciterable; test('AsyncIterable#if then and else', async t => { diff --git a/spec/asynciterable/of-spec.ts b/spec/asynciterable/of-spec.ts index 2de96988..7524cae3 100644 --- a/spec/asynciterable/of-spec.ts +++ b/spec/asynciterable/of-spec.ts @@ -1,6 +1,6 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; import { hasNext, noNext } from '../asynciterablehelpers'; test('AsyncIterable#of behavior', async (t: test.Test) => { diff --git a/spec/asynciterable/race-spec.ts b/spec/asynciterable/race-spec.ts index 7427a8dc..84c9dace 100644 --- a/spec/asynciterable/race-spec.ts +++ b/spec/asynciterable/race-spec.ts @@ -1,6 +1,6 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { race } = Ix.asynciterable; import { hasNext, noNext, delayValue } from '../asynciterablehelpers'; diff --git a/spec/asynciterable/while-spec.ts b/spec/asynciterable/while-spec.ts index 4ae0e368..954607ef 100644 --- a/spec/asynciterable/while-spec.ts +++ b/spec/asynciterable/while-spec.ts @@ -1,14 +1,23 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { defer } = Ix.asynciterable; -const { of } = Ix.asynciterable; +const { of } = Ix.AsyncIterable; const { tap } = Ix.asynciterable; const { _while } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; test('AsyncIterable#while some', async t => { let x = 5; - const res = _while(async () => x > 0, defer(async () => tap(of(x), { next: async () => { x--; } }))); + const res = _while( + async () => x > 0, + defer(async () => + tap(of(x), { + next: async () => { + x--; + } + }) + ) + ); const it = res[Symbol.asyncIterator](); await hasNext(t, it, 5); @@ -22,7 +31,16 @@ test('AsyncIterable#while some', async t => { test('AsyncIterable#while none', async t => { let x = 0; - const res = _while(async () => x > 0, defer(async () => tap(of(x), { next: async () => { x--; } }))); + const res = _while( + async () => x > 0, + defer(async () => + tap(of(x), { + next: async () => { + x--; + } + }) + ) + ); const it = res[Symbol.asyncIterator](); await noNext(t, it); diff --git a/spec/iterable-operators/pairwise-spec.ts b/spec/iterable-operators/pairwise-spec.ts index d0f7bf69..4ce32d9f 100644 --- a/spec/iterable-operators/pairwise-spec.ts +++ b/spec/iterable-operators/pairwise-spec.ts @@ -1,7 +1,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { empty } = Ix.iterable; -const { of } = Ix.iterable; +const { of } = Ix.Iterable; const { pairwise } = Ix.iterable; import { hasNext, noNext } from '../iterablehelpers'; diff --git a/spec/iterable-operators/partition-spec.ts b/spec/iterable-operators/partition-spec.ts index 745523c2..5b382c7f 100644 --- a/spec/iterable-operators/partition-spec.ts +++ b/spec/iterable-operators/partition-spec.ts @@ -1,7 +1,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { empty } = Ix.iterable; -const { of } = Ix.iterable; +const { of } = Ix.Iterable; const { partition } = Ix.iterable; import { hasNext, noNext } from '../iterablehelpers'; diff --git a/spec/iterable-operators/pluck-spec.ts b/spec/iterable-operators/pluck-spec.ts index 3ab647b6..804288e8 100644 --- a/spec/iterable-operators/pluck-spec.ts +++ b/spec/iterable-operators/pluck-spec.ts @@ -1,17 +1,11 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; -const { of } = Ix.iterable; +const { of } = Ix.Iterable; const { pluck } = Ix.iterable; import { hasNext, noNext } from '../iterablehelpers'; test('Iterable#pluck simple prop', t => { - const xs = of( - {prop: 1}, - {prop: 2}, - {prop: 3}, - {prop: 4}, - {prop: 5} - ); + const xs = of({ prop: 1 }, { prop: 2 }, { prop: 3 }, { prop: 4 }, { prop: 5 }); const ys = pluck(xs, 'prop'); const it = ys[Symbol.iterator](); @@ -26,11 +20,11 @@ test('Iterable#pluck simple prop', t => { test('Iterable#pluck nested prop', t => { const xs = of( - {a: {b: {c: 1}}}, - {a: {b: {c: 2}}}, - {a: {b: {c: 3}}}, - {a: {b: {c: 4}}}, - {a: {b: {c: 5}}} + { a: { b: { c: 1 } } }, + { a: { b: { c: 2 } } }, + { a: { b: { c: 3 } } }, + { a: { b: { c: 4 } } }, + { a: { b: { c: 5 } } } ); const ys = pluck(xs, 'a', 'b', 'c'); @@ -46,11 +40,11 @@ test('Iterable#pluck nested prop', t => { test('Iterable#pluck edge cases', t => { const xs = of( - {a: {b: {c: 1}}}, - {a: {b: 2}}, - {a: {c: {c: 3}}}, + { a: { b: { c: 1 } } }, + { a: { b: 2 } }, + { a: { c: { c: 3 } } }, {}, - {a: {b: {c: 5}}} + { a: { b: { c: 5 } } } ); const ys = pluck(xs, 'a', 'b', 'c'); diff --git a/spec/iterable-operators/reduce-spec.ts b/spec/iterable-operators/reduce-spec.ts index fc7a9031..3a01b27b 100644 --- a/spec/iterable-operators/reduce-spec.ts +++ b/spec/iterable-operators/reduce-spec.ts @@ -1,7 +1,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { empty } = Ix.iterable; -const { of } = Ix.iterable; +const { of } = Ix.Iterable; const { reduce } = Ix.iterable; test('Iterable#reduce no seed', t => { diff --git a/spec/iterable-operators/reduceright-spec.ts b/spec/iterable-operators/reduceright-spec.ts index 99b6b5d2..029ca0bc 100644 --- a/spec/iterable-operators/reduceright-spec.ts +++ b/spec/iterable-operators/reduceright-spec.ts @@ -1,7 +1,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { empty } = Ix.iterable; -const { of } = Ix.iterable; +const { of } = Ix.Iterable; const { reduceRight } = Ix.iterable; test('Iterable#reduceRight no seed', t => { diff --git a/spec/iterable-operators/slice-spec.ts b/spec/iterable-operators/slice-spec.ts index 8064d48d..3c3a87a3 100644 --- a/spec/iterable-operators/slice-spec.ts +++ b/spec/iterable-operators/slice-spec.ts @@ -1,6 +1,6 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; -const { from } = Ix.iterable; +const { from } = Ix.Iterable; const { slice } = Ix.iterable; import { hasNext, noNext } from '../iterablehelpers'; diff --git a/spec/iterable/from-spec.ts b/spec/iterable/from-spec.ts index 85d75bb9..c4fa8aa2 100644 --- a/spec/iterable/from-spec.ts +++ b/spec/iterable/from-spec.ts @@ -1,6 +1,6 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; -const { from } = Ix.iterable; +const { from } = Ix.Iterable; import { hasNext, noNext } from '../iterablehelpers'; test('Iterable#from from array/iterable', t => { diff --git a/spec/iterable/of-spec.ts b/spec/iterable/of-spec.ts index ac0daba0..f5f62521 100644 --- a/spec/iterable/of-spec.ts +++ b/spec/iterable/of-spec.ts @@ -1,6 +1,6 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; -const { of } = Ix.iterable; +const { of } = Ix.Iterable; import { hasNext, noNext } from '../iterablehelpers'; test('Iterable#of behavior', t => { diff --git a/src/Ix.ts b/src/Ix.ts index 3e3aaa30..73d459f6 100644 --- a/src/Ix.ts +++ b/src/Ix.ts @@ -47,8 +47,6 @@ import './add/iterable/create'; import './add/iterable/defer'; import './add/iterable/empty'; import './add/iterable/for'; -import './add/iterable/from'; -import './add/iterable/of'; import './add/iterable/range'; import './add/iterable/repeat'; import './add/iterable/throw'; @@ -136,10 +134,8 @@ import './add/asynciterable/create'; import './add/asynciterable/defer'; import './add/asynciterable/empty'; import './add/asynciterable/for'; -import './add/asynciterable/from'; import './add/asynciterable/fromevent'; import './add/asynciterable/fromeventpattern'; -import './add/asynciterable/of'; import './add/asynciterable/race'; import './add/asynciterable/range'; import './add/asynciterable/repeat'; diff --git a/src/add/asynciterable/from.ts b/src/add/asynciterable/from.ts deleted file mode 100644 index 14bb83ae..00000000 --- a/src/add/asynciterable/from.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { AsyncIterableX } from '../../asynciterable'; -import { from as fromStatic } from '../../asynciterable/from'; - -AsyncIterableX.from = fromStatic; - -declare module '../../asynciterable' { - namespace AsyncIterableX { export let from: typeof fromStatic; } -} diff --git a/src/add/asynciterable/of.ts b/src/add/asynciterable/of.ts deleted file mode 100644 index e15ce08c..00000000 --- a/src/add/asynciterable/of.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { AsyncIterableX } from '../../asynciterable'; -import { of as ofStatic } from '../../asynciterable/of'; - -AsyncIterableX.of = ofStatic; - -declare module '../../asynciterable' { - namespace AsyncIterableX { export let of: typeof ofStatic; } -} diff --git a/src/add/iterable/from.ts b/src/add/iterable/from.ts deleted file mode 100644 index 225f1a92..00000000 --- a/src/add/iterable/from.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { IterableX } from '../../iterable'; -import { from as fromStatic } from '../../iterable/from'; - -IterableX.from = fromStatic; - -declare module '../../iterable' { - namespace IterableX { export let from: typeof fromStatic; } -} diff --git a/src/add/iterable/of.ts b/src/add/iterable/of.ts deleted file mode 100644 index c1547714..00000000 --- a/src/add/iterable/of.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { IterableX } from '../../iterable'; -import { of as ofStatic } from '../../iterable/of'; - -IterableX.of = ofStatic; - -declare module '../../iterable' { - namespace IterableX { export let of: typeof ofStatic; } -} diff --git a/src/asynciterable.ts b/src/asynciterable.ts index 694bde6e..ccd40381 100644 --- a/src/asynciterable.ts +++ b/src/asynciterable.ts @@ -1,5 +1,10 @@ import { OperatorAsyncFunction } from './interfaces'; import { bindCallback } from './internal/bindcallback'; +import { identityAsync } from './internal/identity'; +import { toLength } from './internal/tolength'; +import { isIterable, isAsyncIterable } from './internal/isiterable'; +import { Observable } from './observer'; +import { AsyncIterable } from './Ix'; /** * This clas serves as the base for all operations which support [Symbol.asyncIterator]. @@ -77,7 +82,6 @@ export abstract class AsyncIterableX implements AsyncIterable { op8: OperatorAsyncFunction, op9: OperatorAsyncFunction ): AsyncIterableX; - /* tslint:enable:max-line-length */ pipe(...operations: OperatorAsyncFunction[]): AsyncIterableX { if (operations.length === 0) { @@ -90,4 +94,195 @@ export abstract class AsyncIterableX implements AsyncIterable { return piped(this); } + + static from( + source: AsyncIterableInput, + selector: (value: TSource, index: number) => TResult | Promise = identityAsync, + thisArg?: any + ): AsyncIterableX { + const fn = bindCallback(selector, thisArg, 2); + if (isIterable(source) || isAsyncIterable(source)) { + return new FromAsyncIterable(source, fn); + } + if (isPromise(source)) { + return new FromPromiseIterable(source, fn); + } + if (isObservable(source)) { + return new FromObservableAsyncIterable(source, fn); + } + if (isArrayLike(source)) { + return new FromArrayIterable(source, fn); + } + + throw new TypeError('Input type not supported'); + } + + static of(...args: TSource[]): AsyncIterableX { + return new OfAsyncIterable(args); + } +} + +class FromArrayIterable extends AsyncIterableX { + private _source: ArrayLike; + private _selector: (value: TSource, index: number) => TResult | Promise; + + constructor( + source: ArrayLike, + selector: (value: TSource, index: number) => TResult | Promise + ) { + super(); + this._source = source; + this._selector = selector; + } + + async *[Symbol.asyncIterator]() { + let i = 0; + const length = toLength((>this._source).length); + while (i < length) { + yield await this._selector(this._source[i], i++); + } + } +} + +class FromAsyncIterable extends AsyncIterableX { + private _source: Iterable> | AsyncIterable; + private _selector: (value: TSource, index: number) => TResult | Promise; + + constructor( + source: Iterable> | AsyncIterable, + selector: (value: TSource, index: number) => TResult | Promise + ) { + super(); + this._source = source; + this._selector = selector; + } + + async *[Symbol.asyncIterator]() { + let i = 0; + for await (let item of >this._source) { + yield await this._selector(item, i++); + } + } +} + +class FromPromiseIterable extends AsyncIterableX { + private _source: PromiseLike; + private _selector: (value: TSource, index: number) => TResult | Promise; + + constructor( + source: PromiseLike, + selector: (value: TSource, index: number) => TResult | Promise + ) { + super(); + this._source = source; + this._selector = selector; + } + + async *[Symbol.asyncIterator]() { + const item = await this._source; + yield await this._selector(item, 0); + } +} + +class AsyncObserver { + public values: TSource[]; + public hasError: boolean; + public hasCompleted: boolean; + public errorValue: any; + public closed: boolean; + + constructor() { + this.values = []; + this.hasCompleted = false; + this.hasError = false; + this.errorValue = null; + this.closed = false; + } + + next(value: TSource) { + if (!this.closed) { + this.values.push(value); + } + } + + error(err: any) { + if (!this.closed) { + this.closed = true; + this.hasError = true; + this.errorValue = err; + } + } + + complete() { + if (!this.closed) { + this.closed = true; + } + } +} + +class FromObservableAsyncIterable extends AsyncIterableX { + private _observable: Observable; + private _selector: (value: TSource, index: number) => TResult | Promise; + + constructor( + observable: Observable, + selector: (value: TSource, index: number) => TResult | Promise + ) { + super(); + this._observable = observable; + this._selector = selector; + } + + async *[Symbol.asyncIterator]() { + const observer = new AsyncObserver(); + const subscription = this._observable.subscribe(observer); + + let i = 0; + while (1) { + if (observer.values.length > 0) { + yield await this._selector(observer.values.shift()!, i++); + } else if (observer.closed) { + subscription.unsubscribe(); + if (observer.hasError) { + throw observer.errorValue; + } else { + break; + } + } + } + } +} + +export type AsyncIterableInput = + | Iterable> + | AsyncIterable + | ArrayLike + | PromiseLike + | Observable; + +function isPromise(x: any): x is PromiseLike { + return x != null && Object(x) === x && typeof x['then'] === 'function'; +} + +function isObservable(x: any): x is Observable { + return x != null && Object(x) === x && typeof x['subscribe'] === 'function'; +} + +function isArrayLike(x: any): x is ArrayLike { + return x != null && Object(x) === x && typeof x['length'] === 'number'; +} + +class OfAsyncIterable extends AsyncIterableX { + private _args: TSource[]; + + constructor(args: TSource[]) { + super(); + this._args = args; + } + + async *[Symbol.asyncIterator]() { + for (let item of this._args) { + yield item; + } + } } diff --git a/src/asynciterable/__modules.ts b/src/asynciterable/__modules.ts index 79759b7e..07e0ab3c 100644 --- a/src/asynciterable/__modules.ts +++ b/src/asynciterable/__modules.ts @@ -41,7 +41,6 @@ import { first } from './first'; import { flatMap } from './flatmap'; import { flatten } from './flatten'; import { _for } from './for'; -import { from } from './from'; import { fromEvent } from './fromevent'; import { fromEventPattern } from './fromeventpattern'; import { generate } from './generate'; @@ -63,7 +62,6 @@ import { merge } from './merge'; import { mergeAll } from './mergeall'; import { min } from './min'; import { minBy } from './minby'; -import { of } from './of'; import { ofEntries } from './ofentries'; import { ofKeys } from './ofkeys'; import { ofValues } from './ofvalues'; @@ -157,7 +155,6 @@ export default { flatMap, flatten, _for, - from, fromEvent, fromEventPattern, generate, @@ -179,7 +176,6 @@ export default { mergeAll, min, minBy, - of, ofEntries, ofKeys, ofValues, diff --git a/src/asynciterable/from.ts b/src/asynciterable/from.ts deleted file mode 100644 index df21b314..00000000 --- a/src/asynciterable/from.ts +++ /dev/null @@ -1,178 +0,0 @@ -import { AsyncIterableX } from '../asynciterable'; -import { bindCallback } from '../internal/bindcallback'; -import { identityAsync } from '../internal/identity'; -import { toLength } from '../internal/tolength'; -import { isIterable, isAsyncIterable } from '../internal/isiterable'; -import { Observable } from '../observer'; - -class FromArrayIterable extends AsyncIterableX { - private _source: ArrayLike; - private _selector: (value: TSource, index: number) => TResult | Promise; - - constructor( - source: ArrayLike, - selector: (value: TSource, index: number) => TResult | Promise - ) { - super(); - this._source = source; - this._selector = selector; - } - - async *[Symbol.asyncIterator]() { - let i = 0; - const length = toLength((>this._source).length); - while (i < length) { - yield await this._selector(this._source[i], i++); - } - } -} - -class FromAsyncIterable extends AsyncIterableX { - private _source: Iterable> | AsyncIterable; - private _selector: (value: TSource, index: number) => TResult | Promise; - - constructor( - source: Iterable> | AsyncIterable, - selector: (value: TSource, index: number) => TResult | Promise - ) { - super(); - this._source = source; - this._selector = selector; - } - - async *[Symbol.asyncIterator]() { - let i = 0; - for await (let item of >this._source) { - yield await this._selector(item, i++); - } - } -} - -class FromPromiseIterable extends AsyncIterableX { - private _source: PromiseLike; - private _selector: (value: TSource, index: number) => TResult | Promise; - - constructor( - source: PromiseLike, - selector: (value: TSource, index: number) => TResult | Promise - ) { - super(); - this._source = source; - this._selector = selector; - } - - async *[Symbol.asyncIterator]() { - const item = await this._source; - yield await this._selector(item, 0); - } -} - -class AsyncObserver { - public values: TSource[]; - public hasError: boolean; - public hasCompleted: boolean; - public errorValue: any; - public closed: boolean; - - constructor() { - this.values = []; - this.hasCompleted = false; - this.hasError = false; - this.errorValue = null; - this.closed = false; - } - - next(value: TSource) { - if (!this.closed) { - this.values.push(value); - } - } - - error(err: any) { - if (!this.closed) { - this.closed = true; - this.hasError = true; - this.errorValue = err; - } - } - - complete() { - if (!this.closed) { - this.closed = true; - } - } -} - -class FromObservableAsyncIterable extends AsyncIterableX { - private _observable: Observable; - private _selector: (value: TSource, index: number) => TResult | Promise; - - constructor( - observable: Observable, - selector: (value: TSource, index: number) => TResult | Promise - ) { - super(); - this._observable = observable; - this._selector = selector; - } - - async *[Symbol.asyncIterator]() { - const observer = new AsyncObserver(); - const subscription = this._observable.subscribe(observer); - - let i = 0; - while (1) { - if (observer.values.length > 0) { - yield await this._selector(observer.values.shift()!, i++); - } else if (observer.closed) { - subscription.unsubscribe(); - if (observer.hasError) { - throw observer.errorValue; - } else { - break; - } - } - } - } -} - -export type AsyncIterableInput = - | Iterable> - | AsyncIterable - | ArrayLike - | PromiseLike - | Observable; - -function isPromise(x: any): x is PromiseLike { - return x != null && Object(x) === x && typeof x['then'] === 'function'; -} - -function isObservable(x: any): x is Observable { - return x != null && Object(x) === x && typeof x['subscribe'] === 'function'; -} - -function isArrayLike(x: any): x is ArrayLike { - return x != null && Object(x) === x && typeof x['length'] === 'number'; -} - -export function from( - source: AsyncIterableInput, - selector: (value: TSource, index: number) => TResult | Promise = identityAsync, - thisArg?: any -): AsyncIterableX { - const fn = bindCallback(selector, thisArg, 2); - if (isIterable(source) || isAsyncIterable(source)) { - return new FromAsyncIterable(source, fn); - } - if (isPromise(source)) { - return new FromPromiseIterable(source, fn); - } - if (isObservable(source)) { - return new FromObservableAsyncIterable(source, fn); - } - if (isArrayLike(source)) { - return new FromArrayIterable(source, fn); - } - - throw new TypeError('Input type not supported'); -} diff --git a/src/asynciterable/groupjoin.ts b/src/asynciterable/groupjoin.ts index 6fd77c97..f1f310ec 100644 --- a/src/asynciterable/groupjoin.ts +++ b/src/asynciterable/groupjoin.ts @@ -1,7 +1,6 @@ import { AsyncIterableX } from '../asynciterable'; import { createGrouping } from './_grouping'; import { empty } from './empty'; -import { from } from './from'; import { identity } from '../internal/identity'; export class GroupJoinAsyncIterable extends AsyncIterableX { @@ -36,7 +35,7 @@ export class GroupJoinAsyncIterable extends Async const innerElements = map.has(outerKey) ? >map.get(outerKey) : empty(); - yield await this._resultSelector(outerElement, from(innerElements)); + yield await this._resultSelector(outerElement, AsyncIterableX.from(innerElements)); } } } diff --git a/src/asynciterable/of.ts b/src/asynciterable/of.ts deleted file mode 100644 index 692d8bad..00000000 --- a/src/asynciterable/of.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { AsyncIterableX } from '../asynciterable'; - -class OfAsyncIterable extends AsyncIterableX { - private _args: TSource[]; - - constructor(args: TSource[]) { - super(); - this._args = args; - } - - async *[Symbol.asyncIterator]() { - for (let item of this._args) { - yield item; - } - } -} - -export function of(...args: TSource[]): AsyncIterableX { - return new OfAsyncIterable(args); -} diff --git a/src/asynciterable/ofentries.ts b/src/asynciterable/ofentries.ts index a55c6b9d..0a6dfe56 100644 --- a/src/asynciterable/ofentries.ts +++ b/src/asynciterable/ofentries.ts @@ -1,5 +1,4 @@ import { AsyncIterableX } from '../asynciterable'; -import { from } from './from'; function makeTuple(x: TFirst, y: TSecond): [TFirst, TSecond] { return [x, y]; @@ -14,7 +13,7 @@ class OfEntriesAsyncIterable extends AsyncIterableX<[string, TSource]> } [Symbol.asyncIterator]() { - return from(Object.keys(this._source), key => makeTuple(key, this._source[key]))[ + return AsyncIterableX.from(Object.keys(this._source), key => makeTuple(key, this._source[key]))[ Symbol.asyncIterator ](); } diff --git a/src/asynciterable/ofkeys.ts b/src/asynciterable/ofkeys.ts index 945f89d0..1254babd 100644 --- a/src/asynciterable/ofkeys.ts +++ b/src/asynciterable/ofkeys.ts @@ -1,5 +1,4 @@ import { AsyncIterableX } from '../asynciterable'; -import { from } from './from'; class OfKeysAsyncIterable extends AsyncIterableX { private _source: { [key: string]: TSource }; @@ -10,7 +9,7 @@ class OfKeysAsyncIterable extends AsyncIterableX { } [Symbol.asyncIterator]() { - return from(Object.keys(this._source))[Symbol.asyncIterator](); + return AsyncIterableX.from(Object.keys(this._source))[Symbol.asyncIterator](); } } diff --git a/src/asynciterable/ofvalues.ts b/src/asynciterable/ofvalues.ts index 199358d5..02ac9e60 100644 --- a/src/asynciterable/ofvalues.ts +++ b/src/asynciterable/ofvalues.ts @@ -1,5 +1,4 @@ import { AsyncIterableX } from '../asynciterable'; -import { from } from './from'; class OfValuesAsyncIterable extends AsyncIterableX { private _source: { [key: string]: TSource }; @@ -10,7 +9,9 @@ class OfValuesAsyncIterable extends AsyncIterableX { } [Symbol.asyncIterator]() { - return from(Object.keys(this._source), key => this._source[key])[Symbol.asyncIterator](); + return AsyncIterableX.from(Object.keys(this._source), key => this._source[key])[ + Symbol.asyncIterator + ](); } } diff --git a/src/asynciterable/repeat.ts b/src/asynciterable/repeat.ts index 0a602b0f..404c8062 100644 --- a/src/asynciterable/repeat.ts +++ b/src/asynciterable/repeat.ts @@ -1,4 +1,3 @@ -import { of } from './of'; import { AsyncIterableX } from '../asynciterable'; export class RepeatAsyncIterable extends AsyncIterableX { @@ -36,5 +35,5 @@ export function repeat( } export function repeatStatic(value: TSource, count: number = -1): AsyncIterableX { - return new RepeatAsyncIterable(of(value), count); + return new RepeatAsyncIterable(AsyncIterableX.of(value), count); } diff --git a/src/iterable.ts b/src/iterable.ts index 9c0b0142..4b03c01c 100644 --- a/src/iterable.ts +++ b/src/iterable.ts @@ -1,5 +1,8 @@ import { OperatorFunction } from './interfaces'; import { bindCallback } from './internal/bindcallback'; +import { identity } from './internal/identity'; +import { toLength } from './internal/tolength'; +import { isIterable } from './internal/isiterable'; /** * This clas serves as the base for all operations which support [Symbol.iterator]. @@ -87,4 +90,59 @@ export abstract class IterableX implements Iterable { return piped(this); } + + static from( + source: Iterable | ArrayLike, + fn: (value: TSource, index: number) => TResult = identity, + thisArg?: any + ): IterableX { + return new FromIterable(source, bindCallback(fn, thisArg, 2)); + } + + static of(...args: TSource[]): IterableX { + return new OfIterable(args); + } +} + +class FromIterable extends IterableX { + private _source: Iterable | ArrayLike; + private _fn: (value: TSource, index: number) => TResult; + + constructor( + source: Iterable | ArrayLike, + fn: (value: TSource, index: number) => TResult + ) { + super(); + this._source = source; + this._fn = fn; + } + + *[Symbol.iterator]() { + const iterable = isIterable(this._source); + let i = 0; + if (iterable) { + for (let item of >this._source) { + yield this._fn(item, i++); + } + } else { + let length = toLength((>this._source).length); + while (i < length) { + let val = (>this._source)[i]; + yield this._fn(val, i++); + } + } + } +} + +class OfIterable extends IterableX { + private _args: TSource[]; + + constructor(args: TSource[]) { + super(); + this._args = args; + } + + *[Symbol.iterator]() { + yield* this._args; + } } diff --git a/src/iterable/__modules.ts b/src/iterable/__modules.ts index 6d09e853..8939f539 100644 --- a/src/iterable/__modules.ts +++ b/src/iterable/__modules.ts @@ -38,7 +38,6 @@ import { first } from './first'; import { flatMap } from './flatmap'; import { flatten } from './flatten'; import { _for } from './for'; -import { from } from './from'; import { generate } from './generate'; import { groupBy } from './groupby'; import { groupJoin } from './groupjoin'; @@ -55,7 +54,6 @@ import { maxBy } from './maxby'; import { memoize } from './memoize'; import { min } from './min'; import { minBy } from './minby'; -import { of } from './of'; import { ofEntries } from './ofentries'; import { ofKeys } from './ofkeys'; import { ofValues } from './ofvalues'; @@ -141,7 +139,6 @@ export default { flatMap, flatten, _for, - from, generate, groupBy, groupJoin, @@ -158,7 +155,6 @@ export default { memoize, min, minBy, - of, ofEntries, ofKeys, ofValues, diff --git a/src/iterable/from.ts b/src/iterable/from.ts deleted file mode 100644 index c4e8f4fb..00000000 --- a/src/iterable/from.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { IterableX } from '../iterable'; -import { bindCallback } from '../internal/bindcallback'; -import { identity } from '../internal/identity'; -import { toLength } from '../internal/tolength'; -import { isIterable } from '../internal/isiterable'; - -class FromIterable extends IterableX { - private _source: Iterable | ArrayLike; - private _fn: (value: TSource, index: number) => TResult; - - constructor( - source: Iterable | ArrayLike, - fn: (value: TSource, index: number) => TResult - ) { - super(); - this._source = source; - this._fn = fn; - } - - *[Symbol.iterator]() { - const iterable = isIterable(this._source); - let i = 0; - if (iterable) { - for (let item of >this._source) { - yield this._fn(item, i++); - } - } else { - let length = toLength((>this._source).length); - while (i < length) { - let val = (>this._source)[i]; - yield this._fn(val, i++); - } - } - } -} - -export function from( - source: Iterable | ArrayLike, - fn: (value: TSource, index: number) => TResult = identity, - thisArg?: any -): IterableX { - return new FromIterable(source, bindCallback(fn, thisArg, 2)); -} diff --git a/src/iterable/of.ts b/src/iterable/of.ts deleted file mode 100644 index ae9b6c65..00000000 --- a/src/iterable/of.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { IterableX } from '../iterable'; - -class OfIterable extends IterableX { - private _args: TSource[]; - - constructor(args: TSource[]) { - super(); - this._args = args; - } - - *[Symbol.iterator]() { - yield* this._args; - } -} - -export function of(...args: TSource[]): IterableX { - return new OfIterable(args); -} diff --git a/src/iterable/repeat.ts b/src/iterable/repeat.ts index 29868c63..17c244ec 100644 --- a/src/iterable/repeat.ts +++ b/src/iterable/repeat.ts @@ -1,4 +1,3 @@ -import { of } from './of'; import { IterableX } from '../iterable'; export class RepeatIterable extends IterableX { @@ -33,5 +32,5 @@ export function repeat(source: Iterable, count: number = -1): } export function repeatStatic(value: TSource, count: number = -1): IterableX { - return new RepeatIterable(of(value), count); + return new RepeatIterable(IterableX.of(value), count); } From 88e0591e570be9270ba6cdaa7611ebffc91f2f3b Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Thu, 26 Oct 2017 10:20:14 -0400 Subject: [PATCH 099/106] feat(pipe): fix build --- spec/asynciterable/from-spec.ts | 2 +- src/asynciterable.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/asynciterable/from-spec.ts b/spec/asynciterable/from-spec.ts index 7ac42c6d..fed4c0d7 100644 --- a/spec/asynciterable/from-spec.ts +++ b/spec/asynciterable/from-spec.ts @@ -19,7 +19,7 @@ test('AsyncIterable#from from promise list', async t => { t.end(); }); -async function* getData() { +async function* getData(): AsyncIterable { yield 1; yield 2; yield 3; diff --git a/src/asynciterable.ts b/src/asynciterable.ts index ccd40381..c6f3965c 100644 --- a/src/asynciterable.ts +++ b/src/asynciterable.ts @@ -254,8 +254,8 @@ class FromObservableAsyncIterable extends AsyncItera } export type AsyncIterableInput = - | Iterable> | AsyncIterable + | Iterable> | ArrayLike | PromiseLike | Observable; From aa8490596ae236b4a6c106e06bb44e032ce0fcaa Mon Sep 17 00:00:00 2001 From: OJ Kwon Date: Fri, 27 Oct 2017 12:17:25 -0700 Subject: [PATCH 100/106] style(lint): update code lint friendly (#116) --- package.json | 4 ++-- src/asynciterable.ts | 4 +++- src/iterable.ts | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index c2567ade..5627395b 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,8 @@ "release": "./npm-release.sh", "doc": "shx rm -rf ./doc && esdoc", "commitmsg": "validate-commit-msg", - "lint:src": "tslint --fix --type-check -p tsconfig.json -c tslint.json \"src/**/*.ts\"", - "lint:spec": "tslint --fix --type-check -p spec/tsconfig.json -c tslint.json \"spec/**/*.ts\"", + "lint:src": "tslint --fix --project -p tsconfig.json -c tslint.json \"src/**/*.ts\"", + "lint:spec": "tslint --fix --project -p spec/tsconfig.json -c tslint.json \"spec/**/*.ts\"", "prepublishOnly": "echo \"Error: do 'npm run release' instead of 'npm publish'\" && exit 1" }, "author": "Matthew Podwysocki ", diff --git a/src/asynciterable.ts b/src/asynciterable.ts index c6f3965c..5e46ef6f 100644 --- a/src/asynciterable.ts +++ b/src/asynciterable.ts @@ -101,6 +101,7 @@ export abstract class AsyncIterableX implements AsyncIterable { thisArg?: any ): AsyncIterableX { const fn = bindCallback(selector, thisArg, 2); + /* tslint:disable */ if (isIterable(source) || isAsyncIterable(source)) { return new FromAsyncIterable(source, fn); } @@ -113,11 +114,12 @@ export abstract class AsyncIterableX implements AsyncIterable { if (isArrayLike(source)) { return new FromArrayIterable(source, fn); } - + /* tslint:enable */ throw new TypeError('Input type not supported'); } static of(...args: TSource[]): AsyncIterableX { + //tslint:disable-next-line return new OfAsyncIterable(args); } } diff --git a/src/iterable.ts b/src/iterable.ts index 4b03c01c..04eaec50 100644 --- a/src/iterable.ts +++ b/src/iterable.ts @@ -96,10 +96,12 @@ export abstract class IterableX implements Iterable { fn: (value: TSource, index: number) => TResult = identity, thisArg?: any ): IterableX { + //tslint:disable-next-line return new FromIterable(source, bindCallback(fn, thisArg, 2)); } static of(...args: TSource[]): IterableX { + //tslint:disable-next-line return new OfIterable(args); } } From 35773d7ff21165db02fd8f45db1f01c775f4a51f Mon Sep 17 00:00:00 2001 From: Paul Taylor Date: Fri, 27 Oct 2017 14:38:12 -0700 Subject: [PATCH 101/106] feat(from): make from on non-iterables coerce to iterables (#117) --- spec/asynciterable/from-spec.ts | 20 ++++++++++++++++++++ spec/iterable/from-spec.ts | 20 ++++++++++++++++++++ src/asynciterable.ts | 19 ++++++++++--------- src/internal/isiterable.ts | 7 +++++++ src/iterable.ts | 20 ++++++++++++++------ 5 files changed, 71 insertions(+), 15 deletions(-) diff --git a/spec/asynciterable/from-spec.ts b/spec/asynciterable/from-spec.ts index fed4c0d7..130c6e8e 100644 --- a/spec/asynciterable/from-spec.ts +++ b/spec/asynciterable/from-spec.ts @@ -126,6 +126,26 @@ test('AsyncIterable#from from promise with selector', async t => { t.end(); }); +test('AsyncIterable#from from non-iterable', async t => { + const xs = {}; + const res = from(xs); + + const it = res[Symbol.asyncIterator](); + await hasNext(t, it, xs); + await noNext(t, it); + t.end(); +}); + +test('AsyncIterable#from from array-like with selector', async t => { + const xs = {}; + const res = from(xs, (x, i) => [x, i]); + + const it = res[Symbol.asyncIterator](); + await hasNext(t, it, [xs, 0]); + await noNext(t, it); + t.end(); +}); + interface Observer { next: (value: T) => void; error: (err: any) => void; diff --git a/spec/iterable/from-spec.ts b/spec/iterable/from-spec.ts index c4fa8aa2..69cf5ae5 100644 --- a/spec/iterable/from-spec.ts +++ b/spec/iterable/from-spec.ts @@ -59,3 +59,23 @@ test('Iterable#from from array-like with selector', t => { noNext(t, it); t.end(); }); + +test('Iterable#from from non-iterable', t => { + const xs = {}; + const res = from(xs); + + const it = res[Symbol.iterator](); + hasNext(t, it, xs); + noNext(t, it); + t.end(); +}); + +test('Iterable#from from non-iterable with selector', t => { + const xs = {}; + const res = from(xs, (x, i) => [x, i]); + + const it = res[Symbol.iterator](); + hasNext(t, it, [xs, 0]); + noNext(t, it); + t.end(); +}); diff --git a/src/asynciterable.ts b/src/asynciterable.ts index 5e46ef6f..494f66de 100644 --- a/src/asynciterable.ts +++ b/src/asynciterable.ts @@ -2,9 +2,8 @@ import { OperatorAsyncFunction } from './interfaces'; import { bindCallback } from './internal/bindcallback'; import { identityAsync } from './internal/identity'; import { toLength } from './internal/tolength'; -import { isIterable, isAsyncIterable } from './internal/isiterable'; +import { isArrayLike, isIterable, isAsyncIterable } from './internal/isiterable'; import { Observable } from './observer'; -import { AsyncIterable } from './Ix'; /** * This clas serves as the base for all operations which support [Symbol.asyncIterator]. @@ -89,14 +88,17 @@ export abstract class AsyncIterableX implements AsyncIterable { } const piped = (input: AsyncIterable): AsyncIterableX => { - return operations.reduce((prev: any, fn: OperatorAsyncFunction) => fn(prev), input); + return operations.reduce( + (prev: any, fn: OperatorAsyncFunction) => fn(prev), + input as any + ); }; return piped(this); } static from( - source: AsyncIterableInput, + source: AsyncIterableInput | TSource, selector: (value: TSource, index: number) => TResult | Promise = identityAsync, thisArg?: any ): AsyncIterableX { @@ -114,8 +116,11 @@ export abstract class AsyncIterableX implements AsyncIterable { if (isArrayLike(source)) { return new FromArrayIterable(source, fn); } + return new FromAsyncIterable( + new OfAsyncIterable([source as TSource]), + fn + ); /* tslint:enable */ - throw new TypeError('Input type not supported'); } static of(...args: TSource[]): AsyncIterableX { @@ -270,10 +275,6 @@ function isObservable(x: any): x is Observable { return x != null && Object(x) === x && typeof x['subscribe'] === 'function'; } -function isArrayLike(x: any): x is ArrayLike { - return x != null && Object(x) === x && typeof x['length'] === 'number'; -} - class OfAsyncIterable extends AsyncIterableX { private _args: TSource[]; diff --git a/src/internal/isiterable.ts b/src/internal/isiterable.ts index db8cbaf7..85a741ef 100644 --- a/src/internal/isiterable.ts +++ b/src/internal/isiterable.ts @@ -1,3 +1,10 @@ +/** + * @ignore + */ +export function isArrayLike(x: any): x is ArrayLike { + return x != null && Object(x) === x && typeof x['length'] === 'number'; +} + /** * @ignore */ diff --git a/src/iterable.ts b/src/iterable.ts index 04eaec50..34ccc19d 100644 --- a/src/iterable.ts +++ b/src/iterable.ts @@ -2,7 +2,7 @@ import { OperatorFunction } from './interfaces'; import { bindCallback } from './internal/bindcallback'; import { identity } from './internal/identity'; import { toLength } from './internal/tolength'; -import { isIterable } from './internal/isiterable'; +import { isArrayLike, isIterable } from './internal/isiterable'; /** * This clas serves as the base for all operations which support [Symbol.iterator]. @@ -85,19 +85,27 @@ export abstract class IterableX implements Iterable { } const piped = (input: Iterable): IterableX => { - return operations.reduce((prev: any, fn: OperatorFunction) => fn(prev), input); + return operations.reduce((prev: any, fn: OperatorFunction) => fn(prev), input as any); }; return piped(this); } static from( - source: Iterable | ArrayLike, - fn: (value: TSource, index: number) => TResult = identity, + source: Iterable | ArrayLike | TSource, + selector: (value: TSource, index: number) => TResult = identity, thisArg?: any ): IterableX { - //tslint:disable-next-line - return new FromIterable(source, bindCallback(fn, thisArg, 2)); + const fn = bindCallback(selector, thisArg, 2); + /* tslint:disable */ + if (isIterable(source)) { + return new FromIterable(source, fn); + } + if (isArrayLike(source)) { + return new FromIterable(source, fn); + } + return new FromIterable(new OfIterable([source as TSource]), fn); + /* tslint:enable */ } static of(...args: TSource[]): IterableX { From e05ec2477ce1dd559d0c9b91f6b53618e1cac373 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Fri, 27 Oct 2017 20:46:17 -0400 Subject: [PATCH 102/106] feat(pipe): add to __modules --- src/asynciterable/__modules.ts | 128 +++++++++++++++++- .../pipe/{pariwise.ts => pairwise.ts} | 0 src/iterable/__modules.ts | 100 +++++++++++++- 3 files changed, 226 insertions(+), 2 deletions(-) rename src/asynciterable/pipe/{pariwise.ts => pairwise.ts} (100%) diff --git a/src/asynciterable/__modules.ts b/src/asynciterable/__modules.ts index 07e0ab3c..fe596ccf 100644 --- a/src/asynciterable/__modules.ts +++ b/src/asynciterable/__modules.ts @@ -6,6 +6,8 @@ import { AsyncIterableX } from '../asynciterable'; import { GroupedAsyncIterable } from './groupby'; import { OrderedAsyncIterableX } from './orderby'; import { OrderedAsyncIterableBaseX } from './orderby'; +import { TimeInterval } from './timeinterval'; +import { Timestamp } from './timestamp'; import { asyncify } from './asyncify'; import { asyncifyErrback } from './asyncifyerrback'; @@ -102,6 +104,9 @@ import { takeUntil } from './takeuntil'; import { takeWhile } from './takewhile'; import { tap } from './tap'; import { throttle } from './throttle'; +import { timeInterval } from './timeinterval'; +import { timeout } from './timeout'; +import { timestamp } from './timestamp'; import { _throw } from './throw'; import { toArray } from './toarray'; import { toMap } from './tomap'; @@ -111,6 +116,64 @@ import { union } from './union'; import { _while } from './while'; import { zip } from './zip'; +import { buffer as bufferPipe } from './pipe/buffer'; +import { _catch as catchPipe } from './pipe/catch'; +import { catchWith as catchWithPipe } from './pipe/catchwith'; +import { concat as concatPipe } from './pipe/concat'; +import { concatAll as concatAllPipe } from './pipe/concatall'; +import { debounce as debouncePipe } from './pipe/debounce'; +import { defaultIfEmpty as defaultIfEmptyPipe } from './pipe/defaultifempty'; +import { delay as delayPipe } from './pipe/delay'; +import { delayEach as delayEachPipe } from './pipe/delayeach'; +import { distinct as distinctPipe } from './pipe/distinct'; +import { distinctUntilChanged as distinctUntilChangedPipe } from './pipe/distinctuntilchanged'; +import { doWhile as doWhilePipe } from './pipe/dowhile'; +import { endWith as endWithPipe } from './pipe/endwith'; +import { except as exceptPipe } from './pipe/except'; +import { expand as expandPipe } from './pipe/expand'; +import { filter as filterPipe } from './pipe/filter'; +import { _finally as finallyPipe } from './pipe/finally'; +import { flatMap as flatMapPipe } from './pipe/flatmap'; +import { flatten as flattenPipe } from './pipe/flatten'; +import { groupBy as groupByPipe } from './pipe/groupby'; +import { groupJoin as groupJoinPipe } from './pipe/groupjoin'; +import { ignoreElements as ignoreElementsPipe } from './pipe/ignoreelements'; +import { innerJoin as innerJoinPipe } from './pipe/innerjoin'; +import { intersect as intersectPipe } from './pipe/intersect'; +import { map as mapPipe } from './pipe/map'; +import { maxBy as maxByPipe } from './pipe/maxby'; +import { memoize as memoizePipe } from './pipe/memoize'; +import { merge as mergePipe } from './pipe/merge'; +import { mergeAll as mergeAllPipe } from './pipe/mergeall'; +import { minBy as minByPipe } from './pipe/minby'; +import { onErrorResumeNext as onErrorResumeNextPipe } from './pipe/onerrorresumenext'; +import { pairwise as pairwisePipe } from './pipe/pairwise'; +import { pluck as pluckPipe } from './pipe/pluck'; +import { publish as publishPipe } from './pipe/publish'; +import { repeat as repeatPipe } from './pipe/repeat'; +import { retry as retryPipe } from './pipe/retry'; +import { reverse as reversePipe } from './pipe/reverse'; +import { scan as scanPipe } from './pipe/scan'; +import { scanRight as scanRightPipe } from './pipe/scanright'; +import { share as sharePipe } from './pipe/share'; +import { skip as skipPipe } from './pipe/skip'; +import { skipLast as skipLastPipe } from './pipe/skiplast'; +import { skipUntil as skipUntilPipe } from './pipe/skipuntil'; +import { skipWhile as skipWhilePipe } from './pipe/skipwhile'; +import { slice as slicePipe } from './pipe/slice'; +import { startWith as startWithPipe } from './pipe/startwith'; +import { take as takePipe } from './pipe/take'; +import { takeLast as takeLastPipe } from './pipe/takelast'; +import { takeUntil as takeUntilPipe } from './pipe/takeuntil'; +import { takeWhile as takeWhilePipe } from './pipe/takewhile'; +import { tap as tapPipe } from './pipe/tap'; +import { throttle as throttlePipe } from './pipe/throttle'; +import { timeInterval as timeIntervalPipe } from './pipe/timeinterval'; +import { timeout as timeoutPipe } from './pipe/timeout'; +import { timestamp as timestampPipe } from './pipe/timestamp'; +import { union as unionPipe } from './pipe/union'; +import { zip as zipPipe } from './pipe/zip'; + export type AsyncIterableX = AsyncIterableX; export type Observable = Observable; export type NextAsyncObserver = NextAsyncObserver; @@ -119,6 +182,8 @@ export type CompletionAsyncObserver = CompletionAsyncObserver; export type GroupedAsyncIterable = GroupedAsyncIterable; export type OrderedAsyncIterableX = OrderedAsyncIterableX; export type OrderedAsyncIterableBaseX = OrderedAsyncIterableBaseX; +export type TimeInterval = TimeInterval; +export type Timestamp = Timestamp; export default { asyncify, @@ -216,6 +281,9 @@ export default { takeWhile, tap, throttle, + timeInterval, + timestamp, + timeout, _throw, toArray, toMap, @@ -223,5 +291,63 @@ export default { toSet, union, _while, - zip + zip, + + bufferPipe, + catchPipe, + catchWithPipe, + concatPipe, + concatAllPipe, + debouncePipe, + defaultIfEmptyPipe, + delayPipe, + delayEachPipe, + distinctPipe, + distinctUntilChangedPipe, + doWhilePipe, + endWithPipe, + exceptPipe, + expandPipe, + filterPipe, + finallyPipe, + flatMapPipe, + flattenPipe, + groupByPipe, + groupJoinPipe, + ignoreElementsPipe, + innerJoinPipe, + intersectPipe, + mapPipe, + maxByPipe, + memoizePipe, + mergePipe, + mergeAllPipe, + minByPipe, + onErrorResumeNextPipe, + pairwisePipe, + pluckPipe, + publishPipe, + repeatPipe, + retryPipe, + reversePipe, + scanPipe, + scanRightPipe, + sharePipe, + skipPipe, + skipLastPipe, + skipUntilPipe, + skipWhilePipe, + slicePipe, + startWithPipe, + takePipe, + takeLastPipe, + takeUntilPipe, + takeWhilePipe, + tapPipe, + throttlePipe, + timeIntervalPipe, + timestampPipe, + timeoutPipe, + unionPipe, + zipPipe }; diff --git a/src/asynciterable/pipe/pariwise.ts b/src/asynciterable/pipe/pairwise.ts similarity index 100% rename from src/asynciterable/pipe/pariwise.ts rename to src/asynciterable/pipe/pairwise.ts diff --git a/src/iterable/__modules.ts b/src/iterable/__modules.ts index 8939f539..6f0c9582 100644 --- a/src/iterable/__modules.ts +++ b/src/iterable/__modules.ts @@ -98,6 +98,55 @@ import { union } from './union'; import { _while } from './while'; import { zip } from './zip'; +import { buffer as bufferPipe } from './pipe/buffer'; +import { _catch as catchPipe } from './pipe/catch'; +import { catchWith as catchWithPipe } from './pipe/catchwith'; +import { concat as concatPipe } from './pipe/concat'; +import { concatAll as concatAllPipe } from './pipe/concatall'; +import { defaultIfEmpty as defaultIfEmptyPipe } from './pipe/defaultifempty'; +import { distinct as distinctPipe } from './pipe/distinct'; +import { distinctUntilChanged as distinctUntilChangedPipe } from './pipe/distinctuntilchanged'; +import { doWhile as doWhilePipe } from './pipe/dowhile'; +import { endWith as endWithPipe } from './pipe/endwith'; +import { except as exceptPipe } from './pipe/except'; +import { expand as expandPipe } from './pipe/expand'; +import { filter as filterPipe } from './pipe/filter'; +import { _finally as finallyPipe } from './pipe/finally'; +import { flatMap as flatMapPipe } from './pipe/flatmap'; +import { flatten as flattenPipe } from './pipe/flatten'; +import { groupBy as groupByPipe } from './pipe/groupby'; +import { groupJoin as groupJoinPipe } from './pipe/groupjoin'; +import { ignoreElements as ignoreElementsPipe } from './pipe/ignoreelements'; +import { innerJoin as innerJoinPipe } from './pipe/innerjoin'; +import { intersect as intersectPipe } from './pipe/intersect'; +import { map as mapPipe } from './pipe/map'; +import { maxBy as maxByPipe } from './pipe/maxby'; +import { memoize as memoizePipe } from './pipe/memoize'; +import { merge as mergePipe } from './pipe/merge'; +import { mergeAll as mergeAllPipe } from './pipe/mergeall'; +import { minBy as minByPipe } from './pipe/minby'; +import { onErrorResumeNext as onErrorResumeNextPipe } from './pipe/onerrorresumenext'; +import { pairwise as pairwisePipe } from './pipe/pairwise'; +import { pluck as pluckPipe } from './pipe/pluck'; +import { publish as publishPipe } from './pipe/publish'; +import { repeat as repeatPipe } from './pipe/repeat'; +import { retry as retryPipe } from './pipe/retry'; +import { reverse as reversePipe } from './pipe/reverse'; +import { scan as scanPipe } from './pipe/scan'; +import { scanRight as scanRightPipe } from './pipe/scanright'; +import { share as sharePipe } from './pipe/share'; +import { skip as skipPipe } from './pipe/skip'; +import { skipLast as skipLastPipe } from './pipe/skiplast'; +import { skipWhile as skipWhilePipe } from './pipe/skipwhile'; +import { slice as slicePipe } from './pipe/slice'; +import { startWith as startWithPipe } from './pipe/startwith'; +import { take as takePipe } from './pipe/take'; +import { takeLast as takeLastPipe } from './pipe/takelast'; +import { takeWhile as takeWhilePipe } from './pipe/takewhile'; +import { tap as tapPipe } from './pipe/tap'; +import { union as unionPipe } from './pipe/union'; +import { zip as zipPipe } from './pipe/zip'; + export type IterableX = IterableX; export type Observable = Observable; export type NextObserver = NextObserver; @@ -197,5 +246,54 @@ export default { toSet, union, _while, - zip + zip, + + bufferPipe, + catchPipe, + catchWithPipe, + concatPipe, + concatAllPipe, + defaultIfEmptyPipe, + distinctPipe, + distinctUntilChangedPipe, + doWhilePipe, + endWithPipe, + exceptPipe, + expandPipe, + filterPipe, + finallyPipe, + flatMapPipe, + flattenPipe, + groupByPipe, + groupJoinPipe, + ignoreElementsPipe, + innerJoinPipe, + intersectPipe, + mapPipe, + maxByPipe, + memoizePipe, + mergePipe, + mergeAllPipe, + minByPipe, + onErrorResumeNextPipe, + pairwisePipe, + pluckPipe, + publishPipe, + repeatPipe, + retryPipe, + reversePipe, + scanPipe, + scanRightPipe, + sharePipe, + skipPipe, + skipLastPipe, + skipWhilePipe, + slicePipe, + startWithPipe, + takePipe, + takeLastPipe, + takeWhilePipe, + tapPipe, + unionPipe, + zipPipe }; From 2e147a7f837c425ab2e642250951f36b08b89a86 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Fri, 27 Oct 2017 21:01:17 -0400 Subject: [PATCH 103/106] feat(pipe): add to __modules --- src/iterable/__modules.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/iterable/__modules.ts b/src/iterable/__modules.ts index 6f0c9582..d9c87377 100644 --- a/src/iterable/__modules.ts +++ b/src/iterable/__modules.ts @@ -122,8 +122,6 @@ import { intersect as intersectPipe } from './pipe/intersect'; import { map as mapPipe } from './pipe/map'; import { maxBy as maxByPipe } from './pipe/maxby'; import { memoize as memoizePipe } from './pipe/memoize'; -import { merge as mergePipe } from './pipe/merge'; -import { mergeAll as mergeAllPipe } from './pipe/mergeall'; import { minBy as minByPipe } from './pipe/minby'; import { onErrorResumeNext as onErrorResumeNextPipe } from './pipe/onerrorresumenext'; import { pairwise as pairwisePipe } from './pipe/pairwise'; @@ -272,8 +270,6 @@ export default { mapPipe, maxByPipe, memoizePipe, - mergePipe, - mergeAllPipe, minByPipe, onErrorResumeNextPipe, pairwisePipe, From 4ecff97997594c4d40fde81840bc3360314cfe0e Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Sat, 28 Oct 2017 18:05:12 -0400 Subject: [PATCH 104/106] feat(pipe): adding piped tests --- spec/asynciterable-operators/buffer-spec.ts | 59 +++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/spec/asynciterable-operators/buffer-spec.ts b/spec/asynciterable-operators/buffer-spec.ts index 5189c31a..e9142a77 100644 --- a/spec/asynciterable-operators/buffer-spec.ts +++ b/spec/asynciterable-operators/buffer-spec.ts @@ -1,6 +1,7 @@ import * as Ix from '../Ix'; import * as test from 'tape-async'; const { buffer } = Ix.asynciterable; +const { bufferPipe } = Ix.asynciterable; const { empty } = Ix.asynciterable; const { range } = Ix.asynciterable; const { sequenceEqual } = Ix.iterable; @@ -19,6 +20,19 @@ test('AsyncIterable#buffer no skip non-full buffer', async t => { t.end(); }); +test('AsyncIterable#bufferPipe no skip non-full buffer', async t => { + const rng = range(0, 10); + + const res = await toArray(rng.pipe(bufferPipe(3))); + t.equal(4, res.length); + + t.true(sequenceEqual(res[0], [0, 1, 2])); + t.true(sequenceEqual(res[1], [3, 4, 5])); + t.true(sequenceEqual(res[2], [6, 7, 8])); + t.true(sequenceEqual(res[3], [9])); + t.end(); +}); + test('AsyncIterable#buffer no skip all full', async t => { const rng = range(0, 10); @@ -30,6 +44,17 @@ test('AsyncIterable#buffer no skip all full', async t => { t.end(); }); +test('AsyncIterable#bufferPipe no skip all full', async t => { + const rng = range(0, 10); + + const res = await toArray(rng.pipe(bufferPipe(5))); + t.equal(2, res.length); + + t.true(sequenceEqual(res[0], [0, 1, 2, 3, 4])); + t.true(sequenceEqual(res[1], [5, 6, 7, 8, 9])); + t.end(); +}); + test('AsyncIterable#buffer no skip empty buffer', async t => { const rng = empty(); @@ -38,6 +63,14 @@ test('AsyncIterable#buffer no skip empty buffer', async t => { t.end(); }); +test('AsyncIterable#bufferPipe no skip empty buffer', async t => { + const rng = empty(); + + const res = await toArray(rng.pipe(bufferPipe(5))); + t.equal(0, res.length); + t.end(); +}); + test('AsyncIterable#buffer skip non-full buffer', async t => { const rng = range(0, 10); @@ -52,6 +85,20 @@ test('AsyncIterable#buffer skip non-full buffer', async t => { t.end(); }); +test('AsyncIterable#bufferPipe skip non-full buffer', async t => { + const rng = range(0, 10); + + const res = await toArray(rng.pipe(bufferPipe(3, 2))); + t.equal(5, res.length); + + t.true(sequenceEqual(res[0], [0, 1, 2])); + t.true(sequenceEqual(res[1], [2, 3, 4])); + t.true(sequenceEqual(res[2], [4, 5, 6])); + t.true(sequenceEqual(res[3], [6, 7, 8])); + t.true(sequenceEqual(res[4], [8, 9])); + t.end(); +}); + test('AsyncIterable#buffer skip full buffer', async t => { const rng = range(0, 10); @@ -63,3 +110,15 @@ test('AsyncIterable#buffer skip full buffer', async t => { t.true(sequenceEqual(res[2], [8, 9])); t.end(); }); + +test('AsyncIterable#bufferPipe skip full buffer', async t => { + const rng = range(0, 10); + + const res = await toArray(rng.pipe(bufferPipe(3, 4))); + t.equal(3, res.length); + + t.true(sequenceEqual(res[0], [0, 1, 2])); + t.true(sequenceEqual(res[1], [4, 5, 6])); + t.true(sequenceEqual(res[2], [8, 9])); + t.end(); +}); From 7cc833c6c37cfb1caf1f158bf6389c54c8af23d4 Mon Sep 17 00:00:00 2001 From: Paul Taylor Date: Sun, 29 Oct 2017 07:51:26 -0700 Subject: [PATCH 105/106] fix pipe exports (#119) * build(gulpfile): allow building UMD intermediate step standalone for debugging * fix(ix): declare prototype pipe method type so it isn't minified away * fix(pipe): export pipe operators separately so they're not minified away * test(operators): add helper to test all three operator variants * fix(reduce): fix scan/reduce proto method argument checks * test(spec): execute iterable operator tests on all operator variants * test(spec): execute asynciterable operator tests on all operator variants * fix(ix): export OrderedIterableBase so thenBy method names are protected from Uglify * chore(lint): fix lint --- gulpfile.js | 18 +- spec/Ix.ts | 16 +- spec/asynciterable-operators/average-spec.ts | 14 +- spec/asynciterable-operators/buffer-spec.ts | 73 +-- spec/asynciterable-operators/catch-spec.ts | 10 +- .../asynciterable-operators/catchwith-spec.ts | 8 +- spec/asynciterable-operators/chain-spec.ts | 6 +- spec/asynciterable-operators/concat-spec.ts | 12 +- spec/asynciterable-operators/count-spec.ts | 18 +- spec/asynciterable-operators/debounce-spec.ts | 8 +- .../defaultifempty-spec.ts | 10 +- spec/asynciterable-operators/distinct-spec.ts | 8 +- .../distinctuntilchanged-spec.ts | 8 +- spec/asynciterable-operators/dowhile-spec.ts | 8 +- .../asynciterable-operators/elementat-spec.ts | 14 +- spec/asynciterable-operators/endwith-spec.ts | 6 +- spec/asynciterable-operators/every-spec.ts | 12 +- spec/asynciterable-operators/except-spec.ts | 8 +- spec/asynciterable-operators/expand-spec.ts | 8 +- spec/asynciterable-operators/filter-spec.ts | 18 +- spec/asynciterable-operators/finally-spec.ts | 8 +- spec/asynciterable-operators/first-spec.ts | 14 +- spec/asynciterable-operators/flatmap-spec.ts | 12 +- spec/asynciterable-operators/flatten-spec.ts | 11 +- spec/asynciterable-operators/groupby-spec.ts | 14 +- .../asynciterable-operators/groupjoin-spec.ts | 18 +- .../asynciterable-operators/ignoreelements.ts | 6 +- spec/asynciterable-operators/includes-spec.ts | 12 +- .../asynciterable-operators/innerjoin-spec.ts | 22 +- .../asynciterable-operators/intersect-spec.ts | 8 +- spec/asynciterable-operators/isempty-spec.ts | 8 +- spec/asynciterable-operators/last-spec.ts | 14 +- spec/asynciterable-operators/map-spec.ts | 20 +- spec/asynciterable-operators/max-spec.ts | 14 +- spec/asynciterable-operators/maxby-spec.ts | 8 +- spec/asynciterable-operators/memoize-spec.ts | 22 +- spec/asynciterable-operators/merge-spec.ts | 10 +- spec/asynciterable-operators/min-spec.ts | 14 +- spec/asynciterable-operators/minby-spec.ts | 8 +- .../onerrorresumenext-spec.ts | 8 +- spec/asynciterable-operators/orderby-spec.ts | 98 ++-- spec/asynciterable-operators/pairwise-spec.ts | 10 +- .../asynciterable-operators/partition-spec.ts | 12 +- spec/asynciterable-operators/pluck-spec.ts | 10 +- spec/asynciterable-operators/publish-spec.ts | 18 +- spec/asynciterable-operators/reduce-spec.ts | 12 +- .../reduceright-spec.ts | 12 +- spec/asynciterable-operators/repeat-spec.ts | 8 +- spec/asynciterable-operators/retry-spec.ts | 10 +- spec/asynciterable-operators/reverse-spec.ts | 12 +- spec/asynciterable-operators/scan-spec.ts | 8 +- .../asynciterable-operators/scanright-spec.ts | 8 +- .../sequenceequal-spec.ts | 36 +- spec/asynciterable-operators/share-spec.ts | 12 +- spec/asynciterable-operators/single-spec.ts | 18 +- spec/asynciterable-operators/skip-spec.ts | 12 +- spec/asynciterable-operators/skiplast-spec.ts | 8 +- .../asynciterable-operators/skipuntil-spec.ts | 8 +- .../asynciterable-operators/skipwhile-spec.ts | 16 +- spec/asynciterable-operators/slice-spec.ts | 14 +- spec/asynciterable-operators/some-spec.ts | 12 +- .../asynciterable-operators/startwith-spec.ts | 8 +- spec/asynciterable-operators/sum-spec.ts | 14 +- spec/asynciterable-operators/take-spec.ts | 12 +- spec/asynciterable-operators/takelast-spec.ts | 12 +- .../asynciterable-operators/takeuntil-spec.ts | 8 +- .../asynciterable-operators/takewhile-spec.ts | 14 +- spec/asynciterable-operators/tap-spec.ts | 12 +- spec/asynciterable-operators/throttle-spec.ts | 8 +- spec/asynciterable-operators/toarray-spec.ts | 8 +- spec/asynciterable-operators/tomap-spec.ts | 12 +- .../toobservable-spec.ts | 10 +- spec/asynciterable-operators/toset-spec.ts | 10 +- spec/asynciterable-operators/union-spec.ts | 8 +- spec/asynciterable-operators/zip-spec.ts | 18 +- spec/asynciterablehelpers.ts | 49 +- spec/iterable-operators/average-spec.ts | 14 +- spec/iterable-operators/buffer-spec.ts | 14 +- spec/iterable-operators/catch-spec.ts | 10 +- spec/iterable-operators/catchwith-spec.ts | 8 +- spec/iterable-operators/chain-spec.ts | 6 +- spec/iterable-operators/concat-spec.ts | 12 +- spec/iterable-operators/count-spec.ts | 12 +- .../iterable-operators/defaultifempty-spec.ts | 10 +- spec/iterable-operators/distinct-spec.ts | 8 +- .../distinctuntilchanged-spec.ts | 8 +- spec/iterable-operators/dowhile-spec.ts | 8 +- spec/iterable-operators/elementat-spec.ts | 14 +- spec/iterable-operators/endwith-spec.ts | 6 +- spec/iterable-operators/every-spec.ts | 8 +- spec/iterable-operators/except-spec.ts | 8 +- spec/iterable-operators/expand-spec.ts | 8 +- spec/iterable-operators/filter-spec.ts | 18 +- spec/iterable-operators/finally-spec.ts | 8 +- spec/iterable-operators/first-spec.ts | 14 +- spec/iterable-operators/flatmap-spec.ts | 12 +- spec/iterable-operators/flatten-spec.ts | 15 +- spec/iterable-operators/groupby-spec.ts | 14 +- spec/iterable-operators/groupjoin-spec.ts | 18 +- .../iterable-operators/ignoreelements-spec.ts | 6 +- spec/iterable-operators/includes-spec.ts | 12 +- spec/iterable-operators/innerjoin-spec.ts | 22 +- spec/iterable-operators/intersect-spec.ts | 8 +- spec/iterable-operators/isempty-spec.ts | 8 +- spec/iterable-operators/last-spec.ts | 14 +- spec/iterable-operators/map-spec.ts | 18 +- spec/iterable-operators/max-spec.ts | 14 +- spec/iterable-operators/maxby-spec.ts | 8 +- spec/iterable-operators/memoize-spec.ts | 22 +- spec/iterable-operators/min-spec.ts | 14 +- spec/iterable-operators/minby-spec.ts | 8 +- .../onerrorresumenext-spec.ts | 8 +- spec/iterable-operators/orderby-spec.ts | 48 +- spec/iterable-operators/pairwise-spec.ts | 10 +- spec/iterable-operators/partition-spec.ts | 12 +- spec/iterable-operators/pluck-spec.ts | 10 +- spec/iterable-operators/publish-spec.ts | 18 +- spec/iterable-operators/reduce-spec.ts | 12 +- spec/iterable-operators/reduceright-spec.ts | 12 +- spec/iterable-operators/repeat-spec.ts | 8 +- spec/iterable-operators/retry-spec.ts | 10 +- spec/iterable-operators/reverse-spec.ts | 12 +- spec/iterable-operators/scan-spec.ts | 8 +- spec/iterable-operators/scanright-spec.ts | 8 +- spec/iterable-operators/sequenceequal-spec.ts | 36 +- spec/iterable-operators/share-spec.ts | 12 +- spec/iterable-operators/single-spec.ts | 18 +- spec/iterable-operators/skip-spec.ts | 12 +- spec/iterable-operators/skiplast-spec.ts | 8 +- spec/iterable-operators/skipwhile-spec.ts | 16 +- spec/iterable-operators/slice-spec.ts | 14 +- spec/iterable-operators/some-spec.ts | 8 +- spec/iterable-operators/startwith-spec.ts | 8 +- spec/iterable-operators/sum-spec.ts | 14 +- spec/iterable-operators/take-spec.ts | 12 +- spec/iterable-operators/takelast-spec.ts | 12 +- spec/iterable-operators/takewhile-spec.ts | 14 +- spec/iterable-operators/tap-spec.ts | 12 +- spec/iterable-operators/toarray-spec.ts | 8 +- spec/iterable-operators/tomap-spec.ts | 12 +- spec/iterable-operators/toset-spec.ts | 10 +- spec/iterable-operators/union-spec.ts | 8 +- spec/iterable-operators/zip-spec.ts | 18 +- spec/iterablehelpers.ts | 49 +- src/Ix.internal.ts | 9 +- src/Ix.ts | 8 +- src/add/asynciterable-operators/reduce.ts | 4 +- .../asynciterable-operators/reduceright.ts | 4 +- src/add/asynciterable-operators/scan.ts | 4 +- src/add/asynciterable-operators/scanright.ts | 4 +- src/add/iterable-operators/reduceright.ts | 2 +- src/add/iterable-operators/scan.ts | 2 +- src/add/iterable-operators/scanright.ts | 2 +- src/asynciterable.ts | 128 ++--- src/asynciterable/__modules.ts | 459 ++++-------------- src/asynciterable/pipe/__modules.ts | 57 +++ src/iterable.ts | 126 ++--- src/iterable/__modules.ts | 385 ++++----------- src/iterable/pipe/__modules.ts | 46 ++ 159 files changed, 1483 insertions(+), 1732 deletions(-) create mode 100644 src/asynciterable/pipe/__modules.ts create mode 100644 src/iterable/pipe/__modules.ts diff --git a/gulpfile.js b/gulpfile.js index 26322f4e..fc03b292 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -29,7 +29,6 @@ const { Observable, Scheduler, Subject, ReplaySubject } = require(`rxjs`); const releasesRootDir = `targets`; const knownTargets = [`es5`, `es2015`, `esnext`]; const knownModules = [`cjs`, `esm`, `cls`, `umd`]; -const moduleFormatsToSkipCombosOf = { cls: true }; const metadataFiles = [`LICENSE`, `readme.md`, `CHANGELOG.md`]; const packageJSONFields = [ `version`, `license`, `description`, @@ -272,7 +271,7 @@ const compileUglifyJS = ((cache, commonConfig) => memoizeTask(cache, function ug compress: { unsafe: true, }, output: { comments: false, beautify: false }, mangle: { eval: true, safari10: true, // <-- Works around a Safari 10 bug: // https://github.com/mishoo/UglifyJS2/issues/1753 - properties: { reserved } + properties: { reserved: [`configurable`, `enumerable`, ...reserved] } } }, }) @@ -462,9 +461,10 @@ function gulpConcurrent(tasks, concurrency = 'parallel') { const buildConcurrent = (tasks) => () => gulpConcurrent(tasks)() .concat(Observable - .defer(() => Observable - .merge(...knownTargets.map((target) => - del(`${_dir(UMDSourceTargets[target], `cls`)}/**`))))); + .defer(() => modules.indexOf(`cls`) > -1 ? + Observable.empty() : + Observable.merge(...knownTargets.map((target) => + del(`${_dir(target, `cls`)}/**`))))); const testConcurrency = process.env.IS_APPVEYOR_CI ? 'series' : 'parallel'; @@ -479,7 +479,7 @@ function getTasks(name) { if (targets.indexOf(`ts`) !== -1) tasks.push(`${name}:ts`); if (targets.indexOf(`ix`) !== -1) tasks.push(`${name}:ix`); for (const [target, format] of combinations(targets, modules)) { - if (format in moduleFormatsToSkipCombosOf) { + if (format === `cls` && (name === `test` || modules.indexOf(`cls`) === -1)) { continue; } tasks.push(`${name}:${_task(target, format)}`); @@ -495,10 +495,10 @@ function _dir(target, format) { return path.join(releasesRootDir, ...(!format ? function* combinations(_targets, _modules) { - const targets = known(knownTargets, _targets || (_targets = [`all`])); - const modules = known(knownModules, _modules || (_modules = [`all`])); + const targets = known(knownTargets, _targets || [`all`]); + const modules = known(knownModules, _modules || [`all`]); - if (_targets[0] === `all` && _modules[0] === `all`) { + if (targets[0] === `all` && modules[0] === `all`) { yield [`ts`, ``]; yield [`ix`, ``]; } diff --git a/spec/Ix.ts b/spec/Ix.ts index 349404a4..e954bdc2 100644 --- a/spec/Ix.ts +++ b/spec/Ix.ts @@ -11,7 +11,17 @@ const targets = [`es5`, `es2015`, `esnext`]; const formats = [`cjs`, `esm`, `cls`, `umd`]; function throwInvalidImportError(name: string, value: string, values: string[]) { - throw new Error('Unrecognized ' + name + ' \'' + value + '\'. Please run tests with \'--' + name + ' \''); + throw new Error( + 'Unrecognized ' + + name + + " '" + + value + + "'. Please run tests with '--" + + name + + ' '" + ); } let modulePath = ``; @@ -28,10 +38,14 @@ import { Iterable as Iterable_ } from '../src/Ix'; import { AsyncSink as AsyncSink_ } from '../src/Ix'; import { AsyncIterable as AsyncIterable_ } from '../src/Ix'; import { iterable as iterable_ } from '../src/Ix.internal'; +import { iterablePipe as iterablePipe_ } from '../src/Ix.internal'; import { asynciterable as asynciterable_ } from '../src/Ix.internal'; +import { asynciterablePipe as asynciterablePipe_ } from '../src/Ix.internal'; export let Iterable: typeof Iterable_ = Ix.Iterable; export let AsyncSink: typeof AsyncSink_ = Ix.AsyncSink; export let AsyncIterable: typeof AsyncIterable_ = Ix.AsyncIterable; export let iterable: typeof iterable_ = IxInternal.iterable; +export let iterablePipe: typeof iterablePipe_ = IxInternal.iterablePipe; export let asynciterable: typeof asynciterable_ = IxInternal.asynciterable; +export let asynciterablePipe: typeof asynciterablePipe_ = IxInternal.asynciterablePipe; diff --git a/spec/asynciterable-operators/average-spec.ts b/spec/asynciterable-operators/average-spec.ts index 33e030c5..ca389aa8 100644 --- a/spec/asynciterable-operators/average-spec.ts +++ b/spec/asynciterable-operators/average-spec.ts @@ -1,10 +1,10 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { average } = Ix.asynciterable; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.average]); const { empty } = Ix.asynciterable; const { of } = Ix.AsyncIterable; -test('Iterable#average empty', async (t: test.Test) => { +test('Iterable#average empty', async (t, [average]) => { const xs = empty(); try { await average(xs); @@ -14,13 +14,13 @@ test('Iterable#average empty', async (t: test.Test) => { t.end(); }); -test('Iterable#average', async (t: test.Test) => { +test('Iterable#average', async (t, [average]) => { const res = await average(of(1, 2, 3)); t.equal(res, 2); t.end(); }); -test('Iterable#average with selector empty', async (t: test.Test) => { +test('Iterable#average with selector empty', async (t, [average]) => { const xs = empty(); try { await average(xs, async x => x * 2); @@ -30,13 +30,13 @@ test('Iterable#average with selector empty', async (t: test.Test) => { t.end(); }); -test('Iterable#average with selector', async (t: test.Test) => { +test('Iterable#average with selector', async (t, [average]) => { const res = await average(of(1, 2, 3), x => x * 2); t.equal(res, 4); t.end(); }); -test('Iterable#average laws', async (t: test.Test) => { +test('Iterable#average laws', async (t, [average]) => { const xs = of(1, 2, 3); t.equal(await average(xs), await average(xs, x => x)); t.end(); diff --git a/spec/asynciterable-operators/buffer-spec.ts b/spec/asynciterable-operators/buffer-spec.ts index e9142a77..94e8744b 100644 --- a/spec/asynciterable-operators/buffer-spec.ts +++ b/spec/asynciterable-operators/buffer-spec.ts @@ -1,13 +1,12 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { buffer } = Ix.asynciterable; -const { bufferPipe } = Ix.asynciterable; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.buffer]); const { empty } = Ix.asynciterable; const { range } = Ix.asynciterable; const { sequenceEqual } = Ix.iterable; const { toArray } = Ix.asynciterable; -test('AsyncIterable#buffer no skip non-full buffer', async t => { +test('AsyncIterable#buffer no skip non-full buffer', async (t, [buffer]) => { const rng = range(0, 10); const res = await toArray(buffer(rng, 3)); @@ -20,20 +19,7 @@ test('AsyncIterable#buffer no skip non-full buffer', async t => { t.end(); }); -test('AsyncIterable#bufferPipe no skip non-full buffer', async t => { - const rng = range(0, 10); - - const res = await toArray(rng.pipe(bufferPipe(3))); - t.equal(4, res.length); - - t.true(sequenceEqual(res[0], [0, 1, 2])); - t.true(sequenceEqual(res[1], [3, 4, 5])); - t.true(sequenceEqual(res[2], [6, 7, 8])); - t.true(sequenceEqual(res[3], [9])); - t.end(); -}); - -test('AsyncIterable#buffer no skip all full', async t => { +test('AsyncIterable#buffer no skip all full', async (t, [buffer]) => { const rng = range(0, 10); const res = await toArray(buffer(rng, 5)); @@ -44,18 +30,7 @@ test('AsyncIterable#buffer no skip all full', async t => { t.end(); }); -test('AsyncIterable#bufferPipe no skip all full', async t => { - const rng = range(0, 10); - - const res = await toArray(rng.pipe(bufferPipe(5))); - t.equal(2, res.length); - - t.true(sequenceEqual(res[0], [0, 1, 2, 3, 4])); - t.true(sequenceEqual(res[1], [5, 6, 7, 8, 9])); - t.end(); -}); - -test('AsyncIterable#buffer no skip empty buffer', async t => { +test('AsyncIterable#buffer no skip empty buffer', async (t, [buffer]) => { const rng = empty(); const res = await toArray(buffer(rng, 5)); @@ -63,15 +38,7 @@ test('AsyncIterable#buffer no skip empty buffer', async t => { t.end(); }); -test('AsyncIterable#bufferPipe no skip empty buffer', async t => { - const rng = empty(); - - const res = await toArray(rng.pipe(bufferPipe(5))); - t.equal(0, res.length); - t.end(); -}); - -test('AsyncIterable#buffer skip non-full buffer', async t => { +test('AsyncIterable#buffer skip non-full buffer', async (t, [buffer]) => { const rng = range(0, 10); const res = await toArray(buffer(rng, 3, 2)); @@ -85,21 +52,7 @@ test('AsyncIterable#buffer skip non-full buffer', async t => { t.end(); }); -test('AsyncIterable#bufferPipe skip non-full buffer', async t => { - const rng = range(0, 10); - - const res = await toArray(rng.pipe(bufferPipe(3, 2))); - t.equal(5, res.length); - - t.true(sequenceEqual(res[0], [0, 1, 2])); - t.true(sequenceEqual(res[1], [2, 3, 4])); - t.true(sequenceEqual(res[2], [4, 5, 6])); - t.true(sequenceEqual(res[3], [6, 7, 8])); - t.true(sequenceEqual(res[4], [8, 9])); - t.end(); -}); - -test('AsyncIterable#buffer skip full buffer', async t => { +test('AsyncIterable#buffer skip full buffer', async (t, [buffer]) => { const rng = range(0, 10); const res = await toArray(buffer(rng, 3, 4)); @@ -110,15 +63,3 @@ test('AsyncIterable#buffer skip full buffer', async t => { t.true(sequenceEqual(res[2], [8, 9])); t.end(); }); - -test('AsyncIterable#bufferPipe skip full buffer', async t => { - const rng = range(0, 10); - - const res = await toArray(rng.pipe(bufferPipe(3, 4))); - t.equal(3, res.length); - - t.true(sequenceEqual(res[0], [0, 1, 2])); - t.true(sequenceEqual(res[1], [4, 5, 6])); - t.true(sequenceEqual(res[2], [8, 9])); - t.end(); -}); diff --git a/spec/asynciterable-operators/catch-spec.ts b/spec/asynciterable-operators/catch-spec.ts index 07be28d5..f86b65a6 100644 --- a/spec/asynciterable-operators/catch-spec.ts +++ b/spec/asynciterable-operators/catch-spec.ts @@ -1,19 +1,19 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { _catch } = Ix.asynciterable; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable._catch]); const { concat } = Ix.asynciterable; const { range } = Ix.asynciterable; const { sequenceEqual } = Ix.asynciterable; const { _throw } = Ix.asynciterable; import { hasNext } from '../asynciterablehelpers'; -test('AsyncIterable#catch with no errors', async t => { +test('AsyncIterable#catch with no errors', async (t, [_catch]) => { const res = _catch(range(0, 5), range(5, 5)); t.true(await sequenceEqual(res, range(0, 5))); t.end(); }); -test('AsyncIterable#catch with concat error', async t => { +test('AsyncIterable#catch with concat error', async (t, [_catch]) => { const res = _catch( concat(range(0, 5), _throw(new Error())), range(5, 5) @@ -23,7 +23,7 @@ test('AsyncIterable#catch with concat error', async t => { t.end(); }); -test('AsyncIterable#catch still throws', async t => { +test('AsyncIterable#catch still throws', async (t, [_catch]) => { const e1 = new Error(); const er1 = _throw(e1); diff --git a/spec/asynciterable-operators/catchwith-spec.ts b/spec/asynciterable-operators/catchwith-spec.ts index 4665a089..797641a5 100644 --- a/spec/asynciterable-operators/catchwith-spec.ts +++ b/spec/asynciterable-operators/catchwith-spec.ts @@ -1,13 +1,13 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { catchWith } = Ix.asynciterable; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.catchWith]); const { of } = Ix.AsyncIterable; const { range } = Ix.asynciterable; const { sequenceEqual } = Ix.asynciterable; const { single } = Ix.asynciterable; const { _throw } = Ix.asynciterable; -test('AsyncIterable#catchWith error catches', async t => { +test('AsyncIterable#catchWith error catches', async (t, [catchWith]) => { const err = new Error(); const res = await single( catchWith(_throw(err), async e => { @@ -19,7 +19,7 @@ test('AsyncIterable#catchWith error catches', async t => { t.end(); }); -test('AsyncIterable#catchWith no error misses', async t => { +test('AsyncIterable#catchWith no error misses', async (t, [catchWith]) => { const xs = range(0, 10); const res = catchWith(xs, async e => { t.fail(); diff --git a/spec/asynciterable-operators/chain-spec.ts b/spec/asynciterable-operators/chain-spec.ts index 11fb64c2..e78895cd 100644 --- a/spec/asynciterable-operators/chain-spec.ts +++ b/spec/asynciterable-operators/chain-spec.ts @@ -1,10 +1,10 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.chain]); const { empty } = Ix.asynciterable; -const { chain } = Ix.asynciterable; import { noNext } from '../asynciterablehelpers'; -test('Itearble#chain calls function immediately', async t => { +test('Itearble#chain calls function immediately', async (t, [chain]) => { let called = false; const xs = chain(empty(), x => { called = true; return x; }); t.true(called); diff --git a/spec/asynciterable-operators/concat-spec.ts b/spec/asynciterable-operators/concat-spec.ts index 6931310d..531bdaf7 100644 --- a/spec/asynciterable-operators/concat-spec.ts +++ b/spec/asynciterable-operators/concat-spec.ts @@ -1,20 +1,20 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { concat } = Ix.asynciterable; -const { concatAll } = Ix.asynciterable; +import { testOperator } from '../asynciterablehelpers'; +const testConcat = testOperator([Ix.asynciterable.concat]); +const testConcatAll = testOperator([Ix.asynciterable.concatAll]); const { map } = Ix.asynciterable; const { of } = Ix.AsyncIterable; const { range } = Ix.asynciterable; const { sequenceEqual } = Ix.asynciterable; const { tap } = Ix.asynciterable; -test('AsyncIterable#concat concatAll behavior', async t => { +testConcatAll('AsyncIterable#concat concatAll behavior', async (t, [concatAll]) => { const res = concatAll(of(of(1, 2, 3), of(4, 5))); t.true(await sequenceEqual(res, of(1, 2, 3, 4, 5))); t.end(); }); -test('Iterable#concat concatAll order of effects', async t => { +testConcatAll('Iterable#concat concatAll order of effects', async (t, [concatAll]) => { let i = 0; const xss = tap(map(range(0, 3), x => range(0, x + 1)), { next: async () => { @@ -27,7 +27,7 @@ test('Iterable#concat concatAll order of effects', async t => { t.end(); }); -test('AsyncIterable#concat behavior', async t => { +testConcat('AsyncIterable#concat behavior', async (t, [concat]) => { const res = concat(of(1, 2, 3), of(4, 5)); t.true(await sequenceEqual(res, of(1, 2, 3, 4, 5))); t.end(); diff --git a/spec/asynciterable-operators/count-spec.ts b/spec/asynciterable-operators/count-spec.ts index 1960d7f0..8968c390 100644 --- a/spec/asynciterable-operators/count-spec.ts +++ b/spec/asynciterable-operators/count-spec.ts @@ -1,11 +1,11 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { count } = Ix.asynciterable; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.count]); const { empty } = Ix.asynciterable; const { of } = Ix.AsyncIterable; const { _throw } = Ix.asynciterable; -test('AsyncItearble#count some', async (t: test.Test) => { +test('AsyncItearble#count some', async (t, [count]) => { const xs = of(1, 2, 3, 4); const ys = await count(xs); @@ -14,7 +14,7 @@ test('AsyncItearble#count some', async (t: test.Test) => { t.end(); }); -test('AsyncIterable#count empty', async (t: test.Test) => { +test('AsyncIterable#count empty', async (t, [count]) => { const xs = empty(); const ys = await count(xs); @@ -23,7 +23,7 @@ test('AsyncIterable#count empty', async (t: test.Test) => { t.end(); }); -test('AsyncIterable#count throws', async (t: test.Test) => { +test('AsyncIterable#count throws', async (t, [count]) => { const err = new Error(); const xs = _throw(err); @@ -35,7 +35,7 @@ test('AsyncIterable#count throws', async (t: test.Test) => { t.end(); }); -test('AsyncIterable#count predicate some match', async (t: test.Test) => { +test('AsyncIterable#count predicate some match', async (t, [count]) => { const xs = of(1, 2, 3, 4); const ys = await count(xs, async x => x > 3); @@ -44,7 +44,7 @@ test('AsyncIterable#count predicate some match', async (t: test.Test) => { t.end(); }); -test('AsyncIterable#count predicate all match', async (t: test.Test) => { +test('AsyncIterable#count predicate all match', async (t, [count]) => { const xs = of(1, 2, 3, 4); const ys = await count(xs, async x => x > 0); @@ -53,7 +53,7 @@ test('AsyncIterable#count predicate all match', async (t: test.Test) => { t.end(); }); -test('AsyncIterable#count predicate none match', async (t: test.Test) => { +test('AsyncIterable#count predicate none match', async (t, [count]) => { const xs = of(1, 2, 3, 4); const ys = await count(xs, async x => x > 4); @@ -62,7 +62,7 @@ test('AsyncIterable#count predicate none match', async (t: test.Test) => { t.end(); }); -test('AsyncIterable#count predicate throws', async (t: test.Test) => { +test('AsyncIterable#count predicate throws', async (t, [count]) => { const err = new Error(); const xs = of(1, 2, 3, 4); diff --git a/spec/asynciterable-operators/debounce-spec.ts b/spec/asynciterable-operators/debounce-spec.ts index d5666718..227e4959 100644 --- a/spec/asynciterable-operators/debounce-spec.ts +++ b/spec/asynciterable-operators/debounce-spec.ts @@ -1,9 +1,9 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { debounce } = Ix.asynciterable; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.debounce]); import { hasNext, noNext, delayValue } from '../asynciterablehelpers'; -test('AsyncIterable#debounce none drop', async t => { +test('AsyncIterable#debounce none drop', async (t, [debounce]) => { const xs = async function*() { yield await delayValue(1, 100); yield await delayValue(2, 100); @@ -19,7 +19,7 @@ test('AsyncIterable#debounce none drop', async t => { t.end(); }); -test('AsyncIterable#debounce some drop', async t => { +test('AsyncIterable#debounce some drop', async (t, [debounce]) => { const xs = async function*() { yield await delayValue(1, 200); yield await delayValue(2, 200); diff --git a/spec/asynciterable-operators/defaultifempty-spec.ts b/spec/asynciterable-operators/defaultifempty-spec.ts index 40e02ecf..07b2a667 100644 --- a/spec/asynciterable-operators/defaultifempty-spec.ts +++ b/spec/asynciterable-operators/defaultifempty-spec.ts @@ -1,12 +1,12 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { defaultIfEmpty } = Ix.asynciterable; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.defaultIfEmpty]); const { empty } = Ix.asynciterable; const { of } = Ix.AsyncIterable; const { _throw } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; -test('AsyncIterable#defaultIfEmpty with empty', async t => { +test('AsyncIterable#defaultIfEmpty with empty', async (t, [defaultIfEmpty]) => { const xs = empty(); const ys = defaultIfEmpty(xs, 0); @@ -16,7 +16,7 @@ test('AsyncIterable#defaultIfEmpty with empty', async t => { t.end(); }); -test('AsyncIterable#defaultIfEmpty with no empty', async t => { +test('AsyncIterable#defaultIfEmpty with no empty', async (t, [defaultIfEmpty]) => { const xs = of(42); const ys = defaultIfEmpty(xs, 0); @@ -26,7 +26,7 @@ test('AsyncIterable#defaultIfEmpty with no empty', async t => { t.end(); }); -test('AsyncIterable#defaultIfEmpty throws', async t => { +test('AsyncIterable#defaultIfEmpty throws', async (t, [defaultIfEmpty]) => { const xs = _throw(new Error()); const ys = defaultIfEmpty(xs, 0); diff --git a/spec/asynciterable-operators/distinct-spec.ts b/spec/asynciterable-operators/distinct-spec.ts index a35f3ad1..0d043fe3 100644 --- a/spec/asynciterable-operators/distinct-spec.ts +++ b/spec/asynciterable-operators/distinct-spec.ts @@ -1,10 +1,10 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { distinct } = Ix.asynciterable; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.distinct]); const { range } = Ix.asynciterable; const { sequenceEqual } = Ix.asynciterable; -test('AsyncIterable#distinct selector', async t => { +test('AsyncIterable#distinct selector', async (t, [distinct]) => { const res = distinct(range(0, 10), x => x % 5); t.true(await sequenceEqual(res, range(0, 5))); t.end(); @@ -14,7 +14,7 @@ function testComparer(x: number, y: number): boolean { return x % 2 === y % 2; } -test('AsyncIterable#distinct with comparer', async t => { +test('AsyncIterable#distinct with comparer', async (t, [distinct]) => { const res = distinct(range(0, 10), x => x % 5, testComparer); t.true(await sequenceEqual(res, range(0, 2))); t.end(); diff --git a/spec/asynciterable-operators/distinctuntilchanged-spec.ts b/spec/asynciterable-operators/distinctuntilchanged-spec.ts index 092f5fde..f4fa4db5 100644 --- a/spec/asynciterable-operators/distinctuntilchanged-spec.ts +++ b/spec/asynciterable-operators/distinctuntilchanged-spec.ts @@ -1,16 +1,16 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { distinctUntilChanged } = Ix.asynciterable; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.distinctUntilChanged]); const { of } = Ix.AsyncIterable; const { sequenceEqual } = Ix.asynciterable; -test('Iterable#distinctUntilChanged no selector', async t => { +test('Iterable#distinctUntilChanged no selector', async (t, [distinctUntilChanged]) => { const res = distinctUntilChanged(of(1, 2, 2, 3, 3, 3, 2, 2, 1)); t.true(await sequenceEqual(res, of(1, 2, 3, 2, 1))); t.end(); }); -test('Iterable#distinctUntilChanged with selector', async t => { +test('Iterable#distinctUntilChanged with selector', async (t, [distinctUntilChanged]) => { const res = distinctUntilChanged(of(1, 1, 2, 3, 4, 5, 5, 6, 7), x => Math.floor(x / 2)); t.true(await sequenceEqual(res, of(1, 2, 4, 6))); t.end(); diff --git a/spec/asynciterable-operators/dowhile-spec.ts b/spec/asynciterable-operators/dowhile-spec.ts index fc704aca..626e6d7c 100644 --- a/spec/asynciterable-operators/dowhile-spec.ts +++ b/spec/asynciterable-operators/dowhile-spec.ts @@ -1,13 +1,13 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.doWhile]); const { defer } = Ix.asynciterable; -const { doWhile } = Ix.asynciterable; const { of } = Ix.AsyncIterable; const { sequenceEqual } = Ix.iterable; const { tap } = Ix.asynciterable; const { toArray } = Ix.asynciterable; -test('Iterable#doWhile some', async t => { +test('Iterable#doWhile some', async (t, [doWhile]) => { let x = 5; const res = await toArray( doWhile( @@ -26,7 +26,7 @@ test('Iterable#doWhile some', async t => { t.end(); }); -test('Iterable#doWhile one', async t => { +test('Iterable#doWhile one', async (t, [doWhile]) => { let x = 0; const res = await toArray( doWhile( diff --git a/spec/asynciterable-operators/elementat-spec.ts b/spec/asynciterable-operators/elementat-spec.ts index 88306c0d..8ef229b8 100644 --- a/spec/asynciterable-operators/elementat-spec.ts +++ b/spec/asynciterable-operators/elementat-spec.ts @@ -1,38 +1,38 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { elementAt } = Ix.asynciterable; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.elementAt]); const { empty } = Ix.asynciterable; const { of } = Ix.AsyncIterable; -test('AsyncIterable#elementAt empty returns undefined', async (t: test.Test) => { +test('AsyncIterable#elementAt empty returns undefined', async (t, [elementAt]) => { const xs = empty(); const res = await elementAt(xs, 0); t.equal(res, undefined); t.end(); }); -test('AsyncIterable#elementAt single value first index', async (t: test.Test) => { +test('AsyncIterable#elementAt single value first index', async (t, [elementAt]) => { const xs = of(42); const res = await elementAt(xs, 0); t.equal(res, 42); t.end(); }); -test('AsyncIterable#elementAt single value invalid index', async (t: test.Test) => { +test('AsyncIterable#elementAt single value invalid index', async (t, [elementAt]) => { const xs = of(42); const res = await elementAt(xs, 1); t.equal(res, undefined); t.end(); }); -test('AsyncIterable#elementAt multiple values valid index', async (t: test.Test) => { +test('AsyncIterable#elementAt multiple values valid index', async (t, [elementAt]) => { const xs = of(1, 42, 3); const res = await elementAt(xs, 1); t.equal(res, 42); t.end(); }); -test('AsyncIterable#elementAt multiple values invalid index', async (t: test.Test) => { +test('AsyncIterable#elementAt multiple values invalid index', async (t, [elementAt]) => { const xs = of(1, 42, 3); const res = await elementAt(xs, 7); t.equal(res, undefined); diff --git a/spec/asynciterable-operators/endwith-spec.ts b/spec/asynciterable-operators/endwith-spec.ts index b1ea1ab4..8cd43812 100644 --- a/spec/asynciterable-operators/endwith-spec.ts +++ b/spec/asynciterable-operators/endwith-spec.ts @@ -1,10 +1,10 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.endWith]); const { range } = Ix.asynciterable; const { sequenceEqual } = Ix.asynciterable; -const { endWith } = Ix.asynciterable; -test('AsyncIterable#endWith adds to end', async t => { +test('AsyncIterable#endWith adds to end', async (t, [endWith]) => { const e = range(0, 5); const r = endWith(e, 5, 6); t.true(await sequenceEqual(r, range(0, 7))); diff --git a/spec/asynciterable-operators/every-spec.ts b/spec/asynciterable-operators/every-spec.ts index 3c999e5a..9a1c50ee 100644 --- a/spec/asynciterable-operators/every-spec.ts +++ b/spec/asynciterable-operators/every-spec.ts @@ -1,10 +1,10 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { every } = Ix.asynciterable; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.every]); const { of } = Ix.AsyncIterable; const { _throw } = Ix.asynciterable; -test('AsyncIterable#every not all match', async (t: test.Test) => { +test('AsyncIterable#every not all match', async (t, [every]) => { const xs = of(1, 2, 3, 4); const ys = await every(xs, async x => x % 2 === 0); @@ -13,7 +13,7 @@ test('AsyncIterable#every not all match', async (t: test.Test) => { t.end(); }); -test('AsyncIterable#every all match', async (t: test.Test) => { +test('AsyncIterable#every all match', async (t, [every]) => { const xs = of(2, 4, 6, 8); const ys = await every(xs, async x => x % 2 === 0); @@ -22,7 +22,7 @@ test('AsyncIterable#every all match', async (t: test.Test) => { t.end(); }); -test('AsyncIterable#every throws', async (t: test.Test) => { +test('AsyncIterable#every throws', async (t, [every]) => { const err = new Error(); const xs = _throw(err); @@ -34,7 +34,7 @@ test('AsyncIterable#every throws', async (t: test.Test) => { t.end(); }); -test('AsyncIterable#every predicate throws', async (t: test.Test) => { +test('AsyncIterable#every predicate throws', async (t, [every]) => { const err = new Error(); const xs = of(1, 2, 3, 4); diff --git a/spec/asynciterable-operators/except-spec.ts b/spec/asynciterable-operators/except-spec.ts index 4d897045..e8f25a5e 100644 --- a/spec/asynciterable-operators/except-spec.ts +++ b/spec/asynciterable-operators/except-spec.ts @@ -1,10 +1,10 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { except } = Ix.asynciterable; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.except]); const { of } = Ix.AsyncIterable; import { hasNext, noNext } from '../asynciterablehelpers'; -test('Iterable#except with default comparer', async t => { +test('Iterable#except with default comparer', async (t, [except]) => { const xs = of(1, 2, 3); const ys = of(3, 5, 1, 4); const res = except(xs, ys); @@ -15,7 +15,7 @@ test('Iterable#except with default comparer', async t => { t.end(); }); -test('Iterable#except with custom comparer', async t => { +test('Iterable#except with custom comparer', async (t, [except]) => { const comparer = (x: number, y: number) => Math.abs(x) === Math.abs(y); const xs = of(1, 2, -3); const ys = of(3, 5, -1, 4); diff --git a/spec/asynciterable-operators/expand-spec.ts b/spec/asynciterable-operators/expand-spec.ts index e93667ed..13eadd4c 100644 --- a/spec/asynciterable-operators/expand-spec.ts +++ b/spec/asynciterable-operators/expand-spec.ts @@ -1,18 +1,18 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { expand } = Ix.asynciterable; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.expand]); const { of } = Ix.AsyncIterable; const { range } = Ix.asynciterable; const { sequenceEqual } = Ix.asynciterable; const { take } = Ix.asynciterable; -test('Iterable#expand with single return behavior', async t => { +test('Iterable#expand with single return behavior', async (t, [expand]) => { const res = take(expand(of(0), async x => of(x + 1)), 10); t.true(await sequenceEqual(res, range(0, 10))); t.end(); }); -test('Iterable#expand with range return behavior', async t => { +test('Iterable#expand with range return behavior', async (t, [expand]) => { const res = expand(of(3), async x => range(0, x)); const exp = of(3, 0, 1, 2, 0, 0, 1, 0); diff --git a/spec/asynciterable-operators/filter-spec.ts b/spec/asynciterable-operators/filter-spec.ts index 30e5d3a9..4c72da40 100644 --- a/spec/asynciterable-operators/filter-spec.ts +++ b/spec/asynciterable-operators/filter-spec.ts @@ -1,12 +1,12 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.filter]); const { empty } = Ix.asynciterable; -const { filter } = Ix.asynciterable; const { of } = Ix.AsyncIterable; const { _throw } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; -test('AsyncIterable#filter', async t => { +test('AsyncIterable#filter', async (t, [filter]) => { const xs = of(8, 5, 7, 4, 6, 9, 2, 1, 0); const ys = filter(xs, async x => x % 2 === 0); @@ -20,7 +20,7 @@ test('AsyncIterable#filter', async t => { t.end(); }); -test('AsyncIterable#filter with index', async t => { +test('AsyncIterable#filter with index', async (t, [filter]) => { const xs = of(8, 5, 7, 4, 6, 9, 2, 1, 0); const ys = filter(xs, async (x, i) => i % 2 === 0); @@ -34,7 +34,7 @@ test('AsyncIterable#filter with index', async t => { t.end(); }); -test('AsyncIterable#filter with typeguard', async t => { +test('AsyncIterable#filter with typeguard', async (t, [filter]) => { const xs = of( new String('8'), 5, @@ -58,7 +58,7 @@ test('AsyncIterable#filter with typeguard', async t => { t.end(); }); -test('AsyncIterable#filter throws part way through', async t => { +test('AsyncIterable#filter throws part way through', async (t, [filter]) => { const xs = of(8, 5, 7, 4, 6, 9, 2, 1, 0); const err = new Error(); const ys = filter(xs, async x => { @@ -80,7 +80,7 @@ test('AsyncIterable#filter throws part way through', async t => { t.end(); }); -test('AsyncIterable#filter with index throws part way through', async t => { +test('AsyncIterable#filter with index throws part way through', async (t, [filter]) => { const xs = of(8, 5, 7, 4, 6, 9, 2, 1, 0); const err = new Error(); const ys = filter(xs, async (x, i) => { @@ -102,7 +102,7 @@ test('AsyncIterable#filter with index throws part way through', async t => { t.end(); }); -test('AsyncIterable#filter with error source', async t => { +test('AsyncIterable#filter with error source', async (t, [filter]) => { const xs = _throw(new Error()); const ys = filter(xs, async x => x % 2 === 0); @@ -115,7 +115,7 @@ test('AsyncIterable#filter with error source', async t => { t.end(); }); -test('AsyncIterable#filter with empty source', async t => { +test('AsyncIterable#filter with empty source', async (t, [filter]) => { const xs = empty(); const ys = filter(xs, async x => x % 2 === 0); diff --git a/spec/asynciterable-operators/finally-spec.ts b/spec/asynciterable-operators/finally-spec.ts index f3056b9a..dfe5e1db 100644 --- a/spec/asynciterable-operators/finally-spec.ts +++ b/spec/asynciterable-operators/finally-spec.ts @@ -1,11 +1,11 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { _finally } = Ix.asynciterable; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable._finally]); const { range } = Ix.asynciterable; const { _throw } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; -test('AsyncIterable#finally defers behavior', async t => { +test('AsyncIterable#finally defers behavior', async (t, [_finally]) => { let done = false; const xs = _finally(range(0, 2), async () => { done = true; }); @@ -26,7 +26,7 @@ test('AsyncIterable#finally defers behavior', async t => { t.end(); }); -test('AsyncIterable#finally calls even with error', async t => { +test('AsyncIterable#finally calls even with error', async (t, [_finally]) => { let done = false; const err = new Error(); diff --git a/spec/asynciterable-operators/first-spec.ts b/spec/asynciterable-operators/first-spec.ts index 511670c9..047c8d74 100644 --- a/spec/asynciterable-operators/first-spec.ts +++ b/spec/asynciterable-operators/first-spec.ts @@ -1,38 +1,38 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.first]); const { empty } = Ix.asynciterable; const { of } = Ix.AsyncIterable; -const { first } = Ix.asynciterable; -test('AsyncIterable#first empty returns undefined', async (t: test.Test) => { +test('AsyncIterable#first empty returns undefined', async (t, [first]) => { const xs = empty(); const ys = await first(xs); t.equal(ys, undefined); t.end(); }); -test('AsyncIterable#first no predicate returns first', async (t: test.Test) => { +test('AsyncIterable#first no predicate returns first', async (t, [first]) => { const xs = of(1, 2, 3); const ys = await first(xs); t.equal(ys, 1); t.end(); }); -test('AsyncIterable#first predicate empty returns undefined', async (t: test.Test) => { +test('AsyncIterable#first predicate empty returns undefined', async (t, [first]) => { const xs = empty(); const ys = await first(xs, async () => true); t.equal(ys, undefined); t.end(); }); -test('AsyncIterable#first predicate hits returns value', async (t: test.Test) => { +test('AsyncIterable#first predicate hits returns value', async (t, [first]) => { const xs = of(1, 2, 3); const ys = await first(xs, async x => x % 2 === 0); t.equal(ys, 2); t.end(); }); -test('AsyncIterable#first predicate misses returns undefined', async (t: test.Test) => { +test('AsyncIterable#first predicate misses returns undefined', async (t, [first]) => { const xs = of(1, 3, 5); const ys = await first(xs, async x => x % 2 === 0); t.equal(ys, undefined); diff --git a/spec/asynciterable-operators/flatmap-spec.ts b/spec/asynciterable-operators/flatmap-spec.ts index 2ce70f27..543b651e 100644 --- a/spec/asynciterable-operators/flatmap-spec.ts +++ b/spec/asynciterable-operators/flatmap-spec.ts @@ -1,12 +1,12 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { flatMap } = Ix.asynciterable; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.flatMap]); const { of } = Ix.AsyncIterable; const { range } = Ix.asynciterable; const { _throw } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; -test('Iterable#flatMap with range', async t => { +test('Iterable#flatMap with range', async (t, [flatMap]) => { const xs = of(1, 2, 3); const ys = flatMap(xs, async x => range(0, x)); @@ -21,7 +21,7 @@ test('Iterable#flatMap with range', async t => { t.end(); }); -test('Iterable#flatMap selector returns throw', async t => { +test('Iterable#flatMap selector returns throw', async (t, [flatMap]) => { const err = new Error(); const xs = of(1, 2, 3); const ys = flatMap(xs, async x => (x < 3 ? range(0, x) : _throw(err))); @@ -38,7 +38,7 @@ test('Iterable#flatMap selector returns throw', async t => { t.end(); }); -test('Iterable#flatMap with error throws', async t => { +test('Iterable#flatMap with error throws', async (t, [flatMap]) => { const err = new Error(); const xs = _throw(err); const ys = flatMap(xs, x => range(0, x)); @@ -52,7 +52,7 @@ test('Iterable#flatMap with error throws', async t => { t.end(); }); -test('Iterable#flatMap selector throws error', async t => { +test('Iterable#flatMap selector throws error', async (t, [flatMap]) => { const err = new Error(); const xs = of(1, 2, 3); const ys = flatMap(xs, async x => { diff --git a/spec/asynciterable-operators/flatten-spec.ts b/spec/asynciterable-operators/flatten-spec.ts index 06f2c211..391d6916 100644 --- a/spec/asynciterable-operators/flatten-spec.ts +++ b/spec/asynciterable-operators/flatten-spec.ts @@ -1,14 +1,15 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { flatten } = Ix.asynciterable; +import * as tape from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.flatten]); const { of } = Ix.AsyncIterable; const { toArray } = Ix.asynciterable; -function compareArrays(t: test.Test, fst: Iterable, snd: Iterable) { +function compareArrays(t: tape.Test, fst: Iterable, snd: Iterable) { t.equal(fst.toString(), snd.toString()); } -test('AsyncIterable#flatten flattens all', async t => { +test('AsyncIterable#flatten flattens all', async (t, [flatten]) => { const xs = of(1, of(2, of(3)), 4); const ys = await toArray(flatten(xs)); @@ -16,7 +17,7 @@ test('AsyncIterable#flatten flattens all', async t => { t.end(); }); -test('AsyncIterable#flatten flattens two layers', async t => { +test('AsyncIterable#flatten flattens two layers', async (t, [flatten]) => { const xs = of(1, of(2, of(3)), 4); const ys = await toArray(flatten(xs, 2)); diff --git a/spec/asynciterable-operators/groupby-spec.ts b/spec/asynciterable-operators/groupby-spec.ts index 91d5dda7..66c5b830 100644 --- a/spec/asynciterable-operators/groupby-spec.ts +++ b/spec/asynciterable-operators/groupby-spec.ts @@ -1,8 +1,8 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.groupBy]); const { empty } = Ix.asynciterable; const { from } = Ix.AsyncIterable; -const { groupBy } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; interface Employee { @@ -10,7 +10,7 @@ interface Employee { age: number; } -test('AsyncIterable#groupBy normal', async t => { +test('AsyncIterable#groupBy normal', async (t, [groupBy]) => { const xs = [ { name: 'Bart', age: 27 }, { name: 'John', age: 62 }, @@ -59,7 +59,7 @@ test('AsyncIterable#groupBy normal', async t => { t.end(); }); -test('AsyncIterable#groupBy normal can get results later', async t => { +test('AsyncIterable#groupBy normal can get results later', async (t, [groupBy]) => { const xs = [ { name: 'Bart', age: 27 }, { name: 'John', age: 62 }, @@ -113,7 +113,7 @@ test('AsyncIterable#groupBy normal can get results later', async t => { t.end(); }); -test('AsyncIterable#groupBy empty', async t => { +test('AsyncIterable#groupBy empty', async (t, [groupBy]) => { const xs = empty(); const ys = groupBy(xs, x => x); @@ -122,7 +122,7 @@ test('AsyncIterable#groupBy empty', async t => { t.end(); }); -test('AsyncIterable#groupBy element selector', async t => { +test('AsyncIterable#groupBy element selector', async (t, [groupBy]) => { const xs = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; const xss = from(xs); const ys = groupBy(xss, async x => x % 3, x => String.fromCharCode(97 + x)); @@ -165,7 +165,7 @@ test('AsyncIterable#groupBy element selector', async t => { t.end(); }); -test('AsyncIterable#groupBy result selector', async t => { +test('AsyncIterable#groupBy result selector', async (t, [groupBy]) => { const xs = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; const xss = from(xs); const ys = groupBy( diff --git a/spec/asynciterable-operators/groupjoin-spec.ts b/spec/asynciterable-operators/groupjoin-spec.ts index abc1659b..c5e0e915 100644 --- a/spec/asynciterable-operators/groupjoin-spec.ts +++ b/spec/asynciterable-operators/groupjoin-spec.ts @@ -1,12 +1,12 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { groupJoin } = Ix.asynciterable; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.groupJoin]); const { of } = Ix.AsyncIterable; const { reduce } = Ix.asynciterable; const { _throw } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; -test('AsyncIterable#groupJoin all groups have values', async t => { +test('AsyncIterable#groupJoin all groups have values', async (t, [groupJoin]) => { const xs = of(0, 1, 2); const ys = of(4, 7, 6, 2, 3, 4, 8, 9); const res = groupJoin( @@ -25,7 +25,7 @@ test('AsyncIterable#groupJoin all groups have values', async t => { t.end(); }); -test('AsyncIterable#groupJoin some groups have values', async t => { +test('AsyncIterable#groupJoin some groups have values', async (t, [groupJoin]) => { const xs = of(0, 1, 2); const ys = of(3, 6, 4); const res = groupJoin( @@ -44,7 +44,7 @@ test('AsyncIterable#groupJoin some groups have values', async t => { t.end(); }); -test('AsyncIterable#groupJoin left throws', async t => { +test('AsyncIterable#groupJoin left throws', async (t, [groupJoin]) => { const err = new Error(); const xs = _throw(err); const ys = of(3, 6, 4); @@ -65,7 +65,7 @@ test('AsyncIterable#groupJoin left throws', async t => { t.end(); }); -test('AsyncIterable#groupJoin right throws', async t => { +test('AsyncIterable#groupJoin right throws', async (t, [groupJoin]) => { const err = new Error(); const xs = of(0, 1, 2); const ys = _throw(err); @@ -86,7 +86,7 @@ test('AsyncIterable#groupJoin right throws', async t => { t.end(); }); -test('AsyncIterable#groupJoin left selector throws', async t => { +test('AsyncIterable#groupJoin left selector throws', async (t, [groupJoin]) => { const err = new Error(); const xs = of(0, 1, 2); const ys = of(3, 6, 4); @@ -109,7 +109,7 @@ test('AsyncIterable#groupJoin left selector throws', async t => { t.end(); }); -test('AsyncIterable#groupJoin right selector throws', async t => { +test('AsyncIterable#groupJoin right selector throws', async (t, [groupJoin]) => { const err = new Error(); const xs = of(0, 1, 2); const ys = of(3, 6, 4); @@ -132,7 +132,7 @@ test('AsyncIterable#groupJoin right selector throws', async t => { t.end(); }); -test('AsyncIterable#groupJoin result selector eventually throws', async t => { +test('AsyncIterable#groupJoin result selector eventually throws', async (t, [groupJoin]) => { const err = new Error(); const xs = of(0, 1, 2); const ys = of(3, 6, 4); diff --git a/spec/asynciterable-operators/ignoreelements.ts b/spec/asynciterable-operators/ignoreelements.ts index bf87eb3c..0704a5c3 100644 --- a/spec/asynciterable-operators/ignoreelements.ts +++ b/spec/asynciterable-operators/ignoreelements.ts @@ -1,11 +1,11 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { ignoreElements } = Ix.asynciterable; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.ignoreElements]); const { range } = Ix.asynciterable; const { take } = Ix.asynciterable; const { tap } = Ix.asynciterable; -test('Iterable#ignoreElements has side effects', async t => { +test('Iterable#ignoreElements has side effects', async (t, [ignoreElements]) => { let n = 0; await take( ignoreElements( diff --git a/spec/asynciterable-operators/includes-spec.ts b/spec/asynciterable-operators/includes-spec.ts index 4219fe6a..651f981a 100644 --- a/spec/asynciterable-operators/includes-spec.ts +++ b/spec/asynciterable-operators/includes-spec.ts @@ -1,30 +1,30 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.includes]); const { of } = Ix.AsyncIterable; -const { includes } = Ix.asynciterable; -test('AsyncIterable#includes includes', async (t: test.Test) => { +test('AsyncIterable#includes includes', async (t, [includes]) => { const xs = of(1, 2, 3, 4, 5); const ys = await includes(xs, 3); t.true(ys); t.end(); }); -test('AsyncIterable#includes does not include', async (t: test.Test) => { +test('AsyncIterable#includes does not include', async (t, [includes]) => { const xs = of(1, 2, 3, 4, 5); const ys = await includes(xs, 6); t.false(ys); t.end(); }); -test('AsyncIterable#includes fromIndex hits', async (t: test.Test) => { +test('AsyncIterable#includes fromIndex hits', async (t, [includes]) => { const xs = of(1, 2, 3, 4, 5); const ys = await includes(xs, 3, 2); t.true(ys); t.end(); }); -test('AsyncIterable#includes fromIndex misses', async (t: test.Test) => { +test('AsyncIterable#includes fromIndex misses', async (t, [includes]) => { const xs = of(1, 2, 3, 4, 5); const ys = await includes(xs, 1, 2); t.false(ys); diff --git a/spec/asynciterable-operators/innerjoin-spec.ts b/spec/asynciterable-operators/innerjoin-spec.ts index 1f561c11..b43f1e34 100644 --- a/spec/asynciterable-operators/innerjoin-spec.ts +++ b/spec/asynciterable-operators/innerjoin-spec.ts @@ -1,11 +1,11 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { innerJoin } = Ix.asynciterable; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.innerJoin]); const { of } = Ix.AsyncIterable; const { _throw } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; -test('AsyncIterable#innerJoin normal', async t => { +test('AsyncIterable#innerJoin normal', async (t, [innerJoin]) => { const xs = of(0, 1, 2); const ys = of(3, 6, 4); const res = innerJoin(xs, ys, async x => x % 3, async y => y % 3, async (x, y) => x + y); @@ -18,7 +18,7 @@ test('AsyncIterable#innerJoin normal', async t => { t.end(); }); -test('AsyncIterable#innerJoin reversed', async t => { +test('AsyncIterable#innerJoin reversed', async (t, [innerJoin]) => { const xs = of(3, 6, 4); const ys = of(0, 1, 2); const res = innerJoin(xs, ys, async x => x % 3, async y => y % 3, async (x, y) => x + y); @@ -31,7 +31,7 @@ test('AsyncIterable#innerJoin reversed', async t => { t.end(); }); -test('AsyncIterable#innerJoin only one group matches', async t => { +test('AsyncIterable#innerJoin only one group matches', async (t, [innerJoin]) => { const xs = of(0, 1, 2); const ys = of(3, 6); const res = innerJoin(xs, ys, async x => x % 3, async y => y % 3, async (x, y) => x + y); @@ -43,7 +43,7 @@ test('AsyncIterable#innerJoin only one group matches', async t => { t.end(); }); -test('AsyncIterable#innerJoin only one group matches reversed', async t => { +test('AsyncIterable#innerJoin only one group matches reversed', async (t, [innerJoin]) => { const xs = of(3, 6); const ys = of(0, 1, 2); const res = innerJoin(xs, ys, async x => x % 3, async y => y % 3, async (x, y) => x + y); @@ -55,7 +55,7 @@ test('AsyncIterable#innerJoin only one group matches reversed', async t => { t.end(); }); -test('AsyncIterable#innerJoin left throws', async t => { +test('AsyncIterable#innerJoin left throws', async (t, [innerJoin]) => { const xs = _throw(new Error()); const ys = of(3, 6, 4); const res = innerJoin(xs, ys, async x => x % 3, async y => y % 3, async (x, y) => x + y); @@ -69,7 +69,7 @@ test('AsyncIterable#innerJoin left throws', async t => { t.end(); }); -test('AsyncIterable#innerJoin right throws', async t => { +test('AsyncIterable#innerJoin right throws', async (t, [innerJoin]) => { const xs = of(0, 1, 2); const ys = _throw(new Error()); const res = innerJoin(xs, ys, async x => x % 3, async y => y % 3, async (x, y) => x + y); @@ -83,7 +83,7 @@ test('AsyncIterable#innerJoin right throws', async t => { t.end(); }); -test('AsyncIterable#innerJoin left selector throws', async t => { +test('AsyncIterable#innerJoin left selector throws', async (t, [innerJoin]) => { const xs = of(0, 1, 2); const ys = of(3, 6, 4); const res = innerJoin( @@ -105,7 +105,7 @@ test('AsyncIterable#innerJoin left selector throws', async t => { t.end(); }); -test('AsyncIterable#innerJoin right selector throws', async t => { +test('AsyncIterable#innerJoin right selector throws', async (t, [innerJoin]) => { const xs = of(0, 1, 2); const ys = of(3, 6, 4); const res = innerJoin( @@ -127,7 +127,7 @@ test('AsyncIterable#innerJoin right selector throws', async t => { t.end(); }); -test('AsyncIterable#innerJoin result selector throws', async t => { +test('AsyncIterable#innerJoin result selector throws', async (t, [innerJoin]) => { const xs = of(0, 1, 2); const ys = of(3, 6, 4); const res = innerJoin( diff --git a/spec/asynciterable-operators/intersect-spec.ts b/spec/asynciterable-operators/intersect-spec.ts index 71105ac0..a6562066 100644 --- a/spec/asynciterable-operators/intersect-spec.ts +++ b/spec/asynciterable-operators/intersect-spec.ts @@ -1,10 +1,10 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.intersect]); const { of } = Ix.AsyncIterable; -const { intersect } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; -test('Iterable#intersect with default comparer', async t => { +test('Iterable#intersect with default comparer', async (t, [intersect]) => { const xs = of(1, 2, 3); const ys = of(3, 5, 1, 4); const res = intersect(xs, ys); @@ -16,7 +16,7 @@ test('Iterable#intersect with default comparer', async t => { t.end(); }); -test('Iterable#intersect with custom comparer', async t => { +test('Iterable#intersect with custom comparer', async (t, [intersect]) => { const comparer = (x: number, y: number) => Math.abs(x) === Math.abs(y); const xs = of(1, 2, -3); const ys = of(3, 5, -1, 4); diff --git a/spec/asynciterable-operators/isempty-spec.ts b/spec/asynciterable-operators/isempty-spec.ts index c293c39e..f0f01075 100644 --- a/spec/asynciterable-operators/isempty-spec.ts +++ b/spec/asynciterable-operators/isempty-spec.ts @@ -1,15 +1,15 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.isEmpty]); const { empty } = Ix.asynciterable; -const { isEmpty } = Ix.asynciterable; const { of } = Ix.AsyncIterable; -test('Iterable#isEmpty empty', async t => { +test('Iterable#isEmpty empty', async (t, [isEmpty]) => { t.true(await isEmpty(empty())); t.end(); }); -test('Iterable#isEmpty not-empty', async t => { +test('Iterable#isEmpty not-empty', async (t, [isEmpty]) => { t.false(await isEmpty(of(1))); t.end(); }); diff --git a/spec/asynciterable-operators/last-spec.ts b/spec/asynciterable-operators/last-spec.ts index e8d9b698..43137759 100644 --- a/spec/asynciterable-operators/last-spec.ts +++ b/spec/asynciterable-operators/last-spec.ts @@ -1,38 +1,38 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.last]); const { empty } = Ix.asynciterable; -const { last } = Ix.asynciterable; const { of } = Ix.AsyncIterable; -test('AsyncIterable#last empty returns undefined', async (t: test.Test) => { +test('AsyncIterable#last empty returns undefined', async (t, [last]) => { const xs = empty(); const ys = await last(xs); t.equal(ys, undefined); t.end(); }); -test('AsyncIterable#last no predicate returns first', async (t: test.Test) => { +test('AsyncIterable#last no predicate returns first', async (t, [last]) => { const xs = of(1, 2, 3); const ys = await last(xs); t.equal(ys, 3); t.end(); }); -test('AsyncIterable#last predicate empty returns undefined', async (t: test.Test) => { +test('AsyncIterable#last predicate empty returns undefined', async (t, [last]) => { const xs = empty(); const ys = await last(xs, async () => true); t.equal(ys, undefined); t.end(); }); -test('AsyncIterable#last predicate hits returns value', async (t: test.Test) => { +test('AsyncIterable#last predicate hits returns value', async (t, [last]) => { const xs = of(1, 2, 3, 4, 5); const ys = await last(xs, async x => x % 2 === 0); t.equal(ys, 4); t.end(); }); -test('AsyncIterable#last predicate misses returns undefined', async (t: test.Test) => { +test('AsyncIterable#last predicate misses returns undefined', async (t, [last]) => { const xs = of(1, 3, 5); const ys = await last(xs, async x => x % 2 === 0); t.equal(ys, undefined); diff --git a/spec/asynciterable-operators/map-spec.ts b/spec/asynciterable-operators/map-spec.ts index eb939c3f..4e5e7099 100644 --- a/spec/asynciterable-operators/map-spec.ts +++ b/spec/asynciterable-operators/map-spec.ts @@ -1,11 +1,11 @@ import * as Ix from '../Ix'; -import * as test from 'tape'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.map]); const { empty } = Ix.asynciterable; -const { map } = Ix.asynciterable; const { of } = Ix.AsyncIterable; const { sequenceEqual } = Ix.asynciterable; -test('AsyncIterable#map single element', async t => { +test('AsyncIterable#map single element', async (t, [map]) => { const source = of({ name: 'Frank', custId: 98088 }); const expected = of('Frank'); @@ -13,7 +13,7 @@ test('AsyncIterable#map single element', async t => { t.end(); }); -test('AsyncIterable#map maps property', t => { +test('AsyncIterable#map maps property', async (t, [map]) => { const source = of( { name: 'Frank', custId: 98088 }, { name: 'Bob', custId: 29099 }, @@ -23,16 +23,16 @@ test('AsyncIterable#map maps property', t => { ); const expected = of('Frank', 'Bob', 'Chris', null, 'Frank'); - t.true(sequenceEqual(expected, map(source, x => x.name))); + t.true(await sequenceEqual(expected, map(source, x => x.name))); t.end(); }); -test('AsyncIterable#map empty', t => { - t.true(sequenceEqual(empty(), map(empty(), (s, i) => s.length + i))); +test('AsyncIterable#map empty', async (t, [map]) => { + t.true(await sequenceEqual(empty(), map(empty(), (s, i) => s.length + i))); t.end(); }); -test('AsyncIterable#map map property using index', async t => { +test('AsyncIterable#map map property using index', async (t, [map]) => { const source = of( { name: 'Frank', custId: 98088 }, { name: 'Bob', custId: 29099 }, @@ -44,7 +44,7 @@ test('AsyncIterable#map map property using index', async t => { t.end(); }); -test('AsyncIterable#map map property using index on last', async t => { +test('AsyncIterable#map map property using index on last', async (t, [map]) => { const source = of( { name: 'Frank', custId: 98088 }, { name: 'Bob', custId: 29099 }, @@ -58,7 +58,7 @@ test('AsyncIterable#map map property using index on last', async t => { t.end(); }); -test('AsyncIterable#map execution is deferred', async t => { +test('AsyncIterable#map execution is deferred', async (t, [map]) => { let fnCalled = false; const source = of(() => { fnCalled = true; diff --git a/spec/asynciterable-operators/max-spec.ts b/spec/asynciterable-operators/max-spec.ts index 9e43787e..7bfdcd83 100644 --- a/spec/asynciterable-operators/max-spec.ts +++ b/spec/asynciterable-operators/max-spec.ts @@ -1,16 +1,16 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.max]); const { empty } = Ix.asynciterable; const { of } = Ix.AsyncIterable; -const { max } = Ix.asynciterable; -test('AsyncItearble#max laws', async (t: test.Test) => { +test('AsyncItearble#max laws', async (t, [max]) => { const xs = of(5, 3, 1, 2, 4); t.equal(await max(xs), await max(xs, async x => x)); t.end(); }); -test('AsyncIterable#max empty throws', async (t: test.Test) => { +test('AsyncIterable#max empty throws', async (t, [max]) => { const xs = empty(); try { await max(xs); @@ -20,14 +20,14 @@ test('AsyncIterable#max empty throws', async (t: test.Test) => { t.end(); }); -test('AsyncIterable#max', async (t: test.Test) => { +test('AsyncIterable#max', async (t, [max]) => { const xs = of(5, 3, 1, 2, 4); const res = await max(xs); t.equal(res, 5); t.end(); }); -test('AsyncIterable#max with selector empty throws', async (t: test.Test) => { +test('AsyncIterable#max with selector empty throws', async (t, [max]) => { const xs = empty(); try { await max(xs, async x => x * 2); @@ -37,7 +37,7 @@ test('AsyncIterable#max with selector empty throws', async (t: test.Test) => { t.end(); }); -test('AsyncIterable#max with selector', async (t: test.Test) => { +test('AsyncIterable#max with selector', async (t, [max]) => { const xs = of(5, 3, 1, 2, 4); const res = await max(xs, async x => x * 2); t.equal(res, 10); diff --git a/spec/asynciterable-operators/maxby-spec.ts b/spec/asynciterable-operators/maxby-spec.ts index c7cb58ab..5d854214 100644 --- a/spec/asynciterable-operators/maxby-spec.ts +++ b/spec/asynciterable-operators/maxby-spec.ts @@ -1,11 +1,11 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.maxBy]); const { empty } = Ix.asynciterable; -const { maxBy } = Ix.asynciterable; const { of } = Ix.AsyncIterable; const { sequenceEqual } = Ix.asynciterable; -test('AsyncIterable#maxBy', async t => { +test('AsyncIterable#maxBy', async (t, [maxBy]) => { const source = of(2, 5, 0, 7, 4, 3, 6, 2, 1); const res = await maxBy(source, async x => x % 3); @@ -13,7 +13,7 @@ test('AsyncIterable#maxBy', async t => { t.end(); }); -test('AsyncIterable#maxBy empty throws', async t => { +test('AsyncIterable#maxBy empty throws', async (t, [maxBy]) => { const source = empty(); try { diff --git a/spec/asynciterable-operators/memoize-spec.ts b/spec/asynciterable-operators/memoize-spec.ts index 6feb06c4..bad504d2 100644 --- a/spec/asynciterable-operators/memoize-spec.ts +++ b/spec/asynciterable-operators/memoize-spec.ts @@ -1,10 +1,10 @@ import * as Ix from '../Ix'; -import * as test from 'tape'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.memoize]); const { concat } = Ix.asynciterable; const { every } = Ix.asynciterable; const { from } = Ix.AsyncIterable; const { map } = Ix.asynciterable; -const { memoize } = Ix.asynciterable; const { range } = Ix.asynciterable; const { sequenceEqual } = Ix.asynciterable; const { take } = Ix.asynciterable; @@ -22,7 +22,7 @@ async function* tick(t: (x: number) => void | Promise) { } } -test('AsyncIterable#memoize memoizes effects', async t => { +test('AsyncIterable#memoize memoizes effects', async (t, [memoize]) => { let n = 0; const rng = memoize( tick(async i => { @@ -62,7 +62,7 @@ test('AsyncIterable#memoize memoizes effects', async t => { t.end(); }); -test('AsyncIterable#memoize single', async t => { +test('AsyncIterable#memoize single', async (t, [memoize]) => { const rng = memoize(range(0, 5)); const it1 = rng[Symbol.asyncIterator](); @@ -77,7 +77,7 @@ test('AsyncIterable#memoize single', async t => { t.end(); }); -test('AsyncIterable#memoize order of operations', async t => { +test('AsyncIterable#memoize order of operations', async (t, [memoize]) => { const rng = memoize(range(0, 5)); const it1 = rng[Symbol.asyncIterator](); @@ -99,7 +99,7 @@ test('AsyncIterable#memoize order of operations', async t => { t.end(); }); -test('AsyncIterable#memoize second early', async t => { +test('AsyncIterable#memoize second early', async (t, [memoize]) => { const rng = memoize(range(0, 5)); const it1 = rng[Symbol.asyncIterator](); @@ -122,7 +122,7 @@ test('AsyncIterable#memoize second early', async t => { t.end(); }); -test('AsyncIterable#memoize max two readers', async t => { +test('AsyncIterable#memoize max two readers', async (t, [memoize]) => { const rng = memoize(range(0, 5), 2); const it1 = rng[Symbol.asyncIterator](); @@ -145,7 +145,7 @@ test('AsyncIterable#memoize max two readers', async t => { t.end(); }); -test('AsyncIterable#memoize concat with error', async t => { +test('AsyncIterable#memoize concat with error', async (t, [memoize]) => { const error = new Error(); const rng = memoize(concat(range(0, 2), _throw(error))); @@ -182,13 +182,13 @@ async function* rand() { } } -test('AsyncIterable#memoize should share effects of random', async t => { +test('AsyncIterable#memoize should share effects of random', async (t, [memoize]) => { const rnd = memoize(take(rand(), 100)); t.true(await every(zip(async ([l, r]) => l === r, rnd, rnd), async x => x)); t.end(); }); -test('AsyncIterable#memoize with selector', async t => { +test('AsyncIterable#memoize with selector', async (t, [memoize]) => { let n = 0; const res = await toArray( memoize( @@ -207,7 +207,7 @@ test('AsyncIterable#memoize with selector', async t => { t.end(); }); -test('AsyncIterable#memoize limited with selector', async t => { +test('AsyncIterable#memoize limited with selector', async (t, [memoize]) => { let n = 0; const res = await toArray( memoize( diff --git a/spec/asynciterable-operators/merge-spec.ts b/spec/asynciterable-operators/merge-spec.ts index d65d83ec..660d89a5 100644 --- a/spec/asynciterable-operators/merge-spec.ts +++ b/spec/asynciterable-operators/merge-spec.ts @@ -1,17 +1,17 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { merge } = Ix.asynciterable; -const { mergeAll } = Ix.asynciterable; +import { testOperator } from '../asynciterablehelpers'; +const testMerge = testOperator([Ix.asynciterable.merge]); +const testMergeAll = testOperator([Ix.asynciterable.mergeAll]); const { of } = Ix.AsyncIterable; const { sequenceEqual } = Ix.asynciterable; -test('AsyncIterable#merge mergeAll behavior', async t => { +testMergeAll('AsyncIterable#merge mergeAll behavior', async (t, [mergeAll]) => { const res = mergeAll(of(of(1, 2, 3), of(4, 5))); t.true(await sequenceEqual(res, of(1, 2, 3, 4, 5))); t.end(); }); -test('AsyncIterable#merge behavior', async t => { +testMerge('AsyncIterable#merge behavior', async (t, [merge]) => { const res = merge(of(1, 2, 3), of(4, 5)); t.true(await sequenceEqual(res, of(1, 2, 3, 4, 5))); t.end(); diff --git a/spec/asynciterable-operators/min-spec.ts b/spec/asynciterable-operators/min-spec.ts index 3d8c6c37..e36a61cd 100644 --- a/spec/asynciterable-operators/min-spec.ts +++ b/spec/asynciterable-operators/min-spec.ts @@ -1,16 +1,16 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.min]); const { empty } = Ix.asynciterable; const { of } = Ix.AsyncIterable; -const { min } = Ix.asynciterable; -test('AsyncItearble#min laws', async (t: test.Test) => { +test('AsyncItearble#min laws', async (t, [min]) => { const xs = of(5, 3, 1, 2, 4); t.equal(await min(xs), await min(xs, x => x)); t.end(); }); -test('AsyncIterable#min empty throws', async (t: test.Test) => { +test('AsyncIterable#min empty throws', async (t, [min]) => { const xs = empty(); try { await min(xs); @@ -20,14 +20,14 @@ test('AsyncIterable#min empty throws', async (t: test.Test) => { t.end(); }); -test('AsyncIterable#min', async (t: test.Test) => { +test('AsyncIterable#min', async (t, [min]) => { const xs = of(5, 3, 1, 2, 4); const res = await min(xs); t.equal(res, 1); t.end(); }); -test('AsyncIterable#min with selector empty throws', async (t: test.Test) => { +test('AsyncIterable#min with selector empty throws', async (t, [min]) => { const xs = empty(); try { await min(xs, async x => x * 2); @@ -37,7 +37,7 @@ test('AsyncIterable#min with selector empty throws', async (t: test.Test) => { t.end(); }); -test('AsyncIterable#min with selector', async (t: test.Test) => { +test('AsyncIterable#min with selector', async (t, [min]) => { const xs = of(5, 3, 1, 2, 4); const res = await min(xs, async x => x * 2); t.equal(res, 2); diff --git a/spec/asynciterable-operators/minby-spec.ts b/spec/asynciterable-operators/minby-spec.ts index a4659f11..e4e58513 100644 --- a/spec/asynciterable-operators/minby-spec.ts +++ b/spec/asynciterable-operators/minby-spec.ts @@ -1,11 +1,11 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.minBy]); const { empty } = Ix.asynciterable; -const { minBy } = Ix.asynciterable; const { of } = Ix.AsyncIterable; const { sequenceEqual } = Ix.asynciterable; -test('AsyncIterable#minBy', async t => { +test('AsyncIterable#minBy', async (t, [minBy]) => { const source = of(2, 5, 0, 7, 4, 3, 6, 2, 1); const res = minBy(source, async x => x % 3); @@ -13,7 +13,7 @@ test('AsyncIterable#minBy', async t => { t.end(); }); -test('AsyncIterable#minBy empty throws', async t => { +test('AsyncIterable#minBy empty throws', async (t, [minBy]) => { const source = empty(); try { diff --git a/spec/asynciterable-operators/onerrorresumenext-spec.ts b/spec/asynciterable-operators/onerrorresumenext-spec.ts index 1f933497..6356e3c8 100644 --- a/spec/asynciterable-operators/onerrorresumenext-spec.ts +++ b/spec/asynciterable-operators/onerrorresumenext-spec.ts @@ -1,12 +1,12 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.onErrorResumeNext]); const { concat } = Ix.asynciterable; const { of } = Ix.AsyncIterable; -const { onErrorResumeNext } = Ix.asynciterable; const { sequenceEqual } = Ix.asynciterable; const { _throw } = Ix.asynciterable; -test('AsyncIterable#onErrorResumeNext continues without error', async t => { +test('AsyncIterable#onErrorResumeNext continues without error', async (t, [onErrorResumeNext]) => { const xs = of(1, 2); const ys = of(3, 4); @@ -15,7 +15,7 @@ test('AsyncIterable#onErrorResumeNext continues without error', async t => { t.end(); }); -test('AsyncIterable#onErrorResumeNext continues after error', async t => { +test('AsyncIterable#onErrorResumeNext continues after error', async (t, [onErrorResumeNext]) => { const xs = concat(of(1, 2), _throw(new Error())); const ys = of(3, 4); diff --git a/spec/asynciterable-operators/orderby-spec.ts b/spec/asynciterable-operators/orderby-spec.ts index b9f6f45b..2fb52551 100644 --- a/spec/asynciterable-operators/orderby-spec.ts +++ b/spec/asynciterable-operators/orderby-spec.ts @@ -1,10 +1,17 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { hasNext, noNext, testOperator } from '../asynciterablehelpers'; const { of } = Ix.AsyncIterable; const { orderBy, orderByDescending, thenBy, thenByDescending } = Ix.asynciterable; -import { hasNext, noNext } from '../asynciterablehelpers'; +const testOrderBy = testOperator([orderBy]); +const testOrderByDescending = testOperator([orderByDescending]); +const testOrderByThenBy = testOperator([orderBy, thenBy] as [typeof orderBy, typeof thenBy]); +//tslint:disable-next-line +const testOrderByDescendingThenByDescending = testOperator([ + orderByDescending, + thenByDescending +] as [typeof orderByDescending, typeof thenByDescending]); -test('AsyncIterable#orderBy normal ordering', async t => { +testOrderBy('AsyncIterable#orderBy normal ordering', async (t, [orderBy]) => { const xs = of(2, 6, 1, 5, 7, 8, 9, 3, 4, 0); const ys = orderBy(xs, x => x); @@ -17,23 +24,26 @@ test('AsyncIterable#orderBy normal ordering', async t => { t.end(); }); -test('AsyncIterable#orderBy normal ordering with thenBy throws', async t => { - const err = new Error(); - const xs = of(2, 6, 1, 5, 7, 8, 9, 3, 4, 0); - const ys = thenBy(orderBy(xs, x => x), () => { - throw err; - }); +testOrderByThenBy( + 'AsyncIterable#orderBy normal ordering with thenBy throws', + async (t, [orderBy, thenBy]) => { + const err = new Error(); + const xs = of(2, 6, 1, 5, 7, 8, 9, 3, 4, 0); + const ys = thenBy(orderBy(xs, x => x), () => { + throw err; + }); - const it = ys[Symbol.asyncIterator](); - try { - await it.next(); - } catch (e) { - t.same(err, e); + const it = ys[Symbol.asyncIterator](); + try { + await it.next(); + } catch (e) { + t.same(err, e); + } + t.end(); } - t.end(); -}); +); -test('AsyncIterable#orderBy selector throws', async t => { +testOrderBy('AsyncIterable#orderBy selector throws', async (t, [orderBy]) => { const err = new Error(); const xs = of(2, 6, 1, 5, 7, 8, 9, 3, 4, 0); const ys = orderBy(xs, () => { @@ -49,31 +59,39 @@ test('AsyncIterable#orderBy selector throws', async t => { t.end(); }); -test('AsyncIterable#orderByDescending normal ordering', async t => { - const xs = of(2, 6, 1, 5, 7, 8, 9, 3, 4, 0); - const ys = orderByDescending(xs, x => x); +//tslint:disable-next-line +testOrderByDescending( + 'AsyncIterable#orderByDescending normal ordering', + async (t, [orderByDescending]) => { + const xs = of(2, 6, 1, 5, 7, 8, 9, 3, 4, 0); + const ys = orderByDescending(xs, x => x); - const it = ys[Symbol.asyncIterator](); - for (let i = 9; i >= 0; i--) { - await hasNext(t, it, i); - } + const it = ys[Symbol.asyncIterator](); + for (let i = 9; i >= 0; i--) { + await hasNext(t, it, i); + } - await noNext(t, it); - t.end(); -}); + await noNext(t, it); + t.end(); + } +); -test('AsyncIterable#orderByDescending normal ordering with thenByDescending throws', async t => { - const err = new Error(); - const xs = of(2, 6, 1, 5, 7, 8, 9, 3, 4, 0); - const ys = thenByDescending(orderByDescending(xs, x => x), () => { - throw err; - }); +//tslint:disable-next-line +testOrderByDescendingThenByDescending( + 'AsyncIterable#orderByDescending normal ordering with thenByDescending throws', + async (t, [orderByDescending, thenByDescending]) => { + const err = new Error(); + const xs = of(2, 6, 1, 5, 7, 8, 9, 3, 4, 0); + const ys = thenByDescending(orderByDescending(xs, x => x), () => { + throw err; + }); - const it = ys[Symbol.asyncIterator](); - try { - await it.next(); - } catch (e) { - t.same(err, e); + const it = ys[Symbol.asyncIterator](); + try { + await it.next(); + } catch (e) { + t.same(err, e); + } + t.end(); } - t.end(); -}); +); diff --git a/spec/asynciterable-operators/pairwise-spec.ts b/spec/asynciterable-operators/pairwise-spec.ts index 7001c649..c162372f 100644 --- a/spec/asynciterable-operators/pairwise-spec.ts +++ b/spec/asynciterable-operators/pairwise-spec.ts @@ -1,11 +1,11 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.pairwise]); const { empty } = Ix.asynciterable; const { of } = Ix.AsyncIterable; -const { pairwise } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; -test('AsyncIterable#pairwise empty return empty', async t => { +test('AsyncIterable#pairwise empty return empty', async (t, [pairwise]) => { const xs = empty(); const ys = pairwise(xs); @@ -14,7 +14,7 @@ test('AsyncIterable#pairwise empty return empty', async t => { t.end(); }); -test('AsyncIterable#pairwise single returns empty', async t => { +test('AsyncIterable#pairwise single returns empty', async (t, [pairwise]) => { const xs = of(5); const ys = pairwise(xs); @@ -23,7 +23,7 @@ test('AsyncIterable#pairwise single returns empty', async t => { t.end(); }); -test('AsyncIterable#pairwise behavior', async t => { +test('AsyncIterable#pairwise behavior', async (t, [pairwise]) => { const xs = of(5, 4, 3, 2, 1); const ys = pairwise(xs); diff --git a/spec/asynciterable-operators/partition-spec.ts b/spec/asynciterable-operators/partition-spec.ts index fcc611e2..75e6264f 100644 --- a/spec/asynciterable-operators/partition-spec.ts +++ b/spec/asynciterable-operators/partition-spec.ts @@ -1,15 +1,15 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.partition]); const { empty } = Ix.asynciterable; const { of } = Ix.AsyncIterable; -const { partition } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; function isEven(x: number) { return x % 2 === 0; } -test('AsyncIterable#partition both empty', async t => { +test('AsyncIterable#partition both empty', async (t, [partition]) => { const xs = empty(); const [fst, snd] = partition(xs, isEven); @@ -21,7 +21,7 @@ test('AsyncIterable#partition both empty', async t => { t.end(); }); -test('AsyncIterable#partition has left', async t => { +test('AsyncIterable#partition has left', async (t, [partition]) => { const xs = of(4); const [fst, snd] = partition(xs, isEven); @@ -34,7 +34,7 @@ test('AsyncIterable#partition has left', async t => { t.end(); }); -test('AsyncIterable#partition has right', async t => { +test('AsyncIterable#partition has right', async (t, [partition]) => { const xs = of(3); const [fst, snd] = partition(xs, isEven); @@ -47,7 +47,7 @@ test('AsyncIterable#partition has right', async t => { t.end(); }); -test('AsyncIterable#partition has both', async t => { +test('AsyncIterable#partition has both', async (t, [partition]) => { const xs = of(1, 2, 3, 4); const [fst, snd] = partition(xs, isEven); diff --git a/spec/asynciterable-operators/pluck-spec.ts b/spec/asynciterable-operators/pluck-spec.ts index bc6d30a8..c115d86f 100644 --- a/spec/asynciterable-operators/pluck-spec.ts +++ b/spec/asynciterable-operators/pluck-spec.ts @@ -1,10 +1,10 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.pluck]); const { of } = Ix.AsyncIterable; -const { pluck } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; -test('Iterable#pluck simple prop', async t => { +test('Iterable#pluck simple prop', async (t, [pluck]) => { const xs = of({ prop: 1 }, { prop: 2 }, { prop: 3 }, { prop: 4 }, { prop: 5 }); const ys = pluck(xs, 'prop'); @@ -18,7 +18,7 @@ test('Iterable#pluck simple prop', async t => { t.end(); }); -test('Iterable#pluck nested prop', async t => { +test('Iterable#pluck nested prop', async (t, [pluck]) => { const xs = of( { a: { b: { c: 1 } } }, { a: { b: { c: 2 } } }, @@ -38,7 +38,7 @@ test('Iterable#pluck nested prop', async t => { t.end(); }); -test('Iterable#pluck edge cases', async t => { +test('Iterable#pluck edge cases', async (t, [pluck]) => { const xs = of( { a: { b: { c: 1 } } }, { a: { b: 2 } }, diff --git a/spec/asynciterable-operators/publish-spec.ts b/spec/asynciterable-operators/publish-spec.ts index 49614a74..ae4c8d8c 100644 --- a/spec/asynciterable-operators/publish-spec.ts +++ b/spec/asynciterable-operators/publish-spec.ts @@ -1,9 +1,9 @@ import * as Ix from '../Ix'; -import * as test from 'tape'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.publish]); const { concat } = Ix.asynciterable; const { from } = Ix.AsyncIterable; const { map } = Ix.asynciterable; -const { publish } = Ix.asynciterable; const { range } = Ix.asynciterable; const { sequenceEqual } = Ix.asynciterable; const { _throw } = Ix.asynciterable; @@ -21,7 +21,7 @@ async function* tick(t: (x: number) => void | Promise) { } } -test('AsyncIterable#publish starts at beginning', async t => { +test('AsyncIterable#publish starts at beginning', async (t, [publish]) => { let n = 0; const rng = publish( tick(async i => { @@ -61,7 +61,7 @@ test('AsyncIterable#publish starts at beginning', async t => { t.end(); }); -test('AsyncIterable#publish single', async t => { +test('AsyncIterable#publish single', async (t, [publish]) => { const rng = publish(range(0, 5)); const it = rng[Symbol.asyncIterator](); @@ -74,7 +74,7 @@ test('AsyncIterable#publish single', async t => { t.end(); }); -test('AsyncIterable#publish two interleaved', async t => { +test('AsyncIterable#publish two interleaved', async (t, [publish]) => { const rng = publish(range(0, 5)); const it1 = rng[Symbol.asyncIterator](); @@ -95,7 +95,7 @@ test('AsyncIterable#publish two interleaved', async t => { t.end(); }); -test('AsyncIterable#publish sequential', async t => { +test('AsyncIterable#publish sequential', async (t, [publish]) => { const rng = publish(range(0, 5)); const it1 = rng[Symbol.asyncIterator](); @@ -117,7 +117,7 @@ test('AsyncIterable#publish sequential', async t => { t.end(); }); -test('AsyncIterable#publish second late', async t => { +test('AsyncIterable#publish second late', async (t, [publish]) => { const rng = publish(range(0, 5)); const it1 = rng[Symbol.asyncIterator](); @@ -136,7 +136,7 @@ test('AsyncIterable#publish second late', async t => { t.end(); }); -test('AsyncIterbale#publish shared exceptions', async t => { +test('AsyncIterbale#publish shared exceptions', async (t, [publish]) => { const error = new Error(); const rng = publish(concat(range(0, 2), _throw(error))); @@ -162,7 +162,7 @@ test('AsyncIterbale#publish shared exceptions', async t => { t.end(); }); -test('AsyncIterable#publish with selector', async t => { +test('AsyncIterable#publish with selector', async (t, [publish]) => { let n = 0; const res = await toArray( publish( diff --git a/spec/asynciterable-operators/reduce-spec.ts b/spec/asynciterable-operators/reduce-spec.ts index 9b1693d4..1d5272c5 100644 --- a/spec/asynciterable-operators/reduce-spec.ts +++ b/spec/asynciterable-operators/reduce-spec.ts @@ -1,17 +1,17 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.reduce]); const { empty } = Ix.asynciterable; const { of } = Ix.AsyncIterable; -const { reduce } = Ix.asynciterable; -test('Iterable#reduce no seed', async t => { +test('Iterable#reduce no seed', async (t, [reduce]) => { const xs = of(0, 1, 2, 3, 4); const ys = await reduce(xs, (x, y, i) => x + y + i); t.equal(ys, 20); t.end(); }); -test('Iterable#reduce no seed empty throws', async t => { +test('Iterable#reduce no seed empty throws', async (t, [reduce]) => { const xs = empty(); try { await reduce(xs, (x, y, i) => x + y + i); @@ -21,14 +21,14 @@ test('Iterable#reduce no seed empty throws', async t => { t.end(); }); -test('Iterable#reduce with seed', async t => { +test('Iterable#reduce with seed', async (t, [reduce]) => { const xs = of(0, 1, 2, 3, 4); const ys = await reduce(xs, (x, y, i) => x - y - i, 20); t.equal(ys, 0); t.end(); }); -test('Iterable#reduce with seed empty', async t => { +test('Iterable#reduce with seed empty', async (t, [reduce]) => { const xs = empty(); const ys = await reduce(xs, (x, y, i) => x - y - i, 20); t.equal(ys, 20); diff --git a/spec/asynciterable-operators/reduceright-spec.ts b/spec/asynciterable-operators/reduceright-spec.ts index a97ae52e..ab0f9163 100644 --- a/spec/asynciterable-operators/reduceright-spec.ts +++ b/spec/asynciterable-operators/reduceright-spec.ts @@ -1,17 +1,17 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.reduceRight]); const { empty } = Ix.asynciterable; const { of } = Ix.AsyncIterable; -const { reduceRight } = Ix.asynciterable; -test('AsyncIterable#reduceRight no seed', async t => { +test('AsyncIterable#reduceRight no seed', async (t, [reduceRight]) => { const xs = of(0, 1, 2, 3, 4); const ys = await reduceRight(xs, (x, y, i) => x + y + i); t.equal(ys, 16); t.end(); }); -test('AsyncIterable#reduceRight no seed empty throws', async t => { +test('AsyncIterable#reduceRight no seed empty throws', async (t, [reduceRight]) => { const xs = empty(); try { await reduceRight(xs, (x, y, i) => x + y + i); @@ -21,14 +21,14 @@ test('AsyncIterable#reduceRight no seed empty throws', async t => { t.end(); }); -test('AsyncIterable#reduceRight with seed', async t => { +test('AsyncIterable#reduceRight with seed', async (t, [reduceRight]) => { const xs = of(0, 1, 2, 3, 4); const ys = await reduceRight(xs, (x, y, i) => x - y - i, 20); t.equal(ys, 0); t.end(); }); -test('AsyncIterable#reduceRight with seed empty', async t => { +test('AsyncIterable#reduceRight with seed empty', async (t, [reduceRight]) => { const xs = empty(); const ys = await reduceRight(xs, (x, y, i) => x - y - i, 20); t.equal(ys, 20); diff --git a/spec/asynciterable-operators/repeat-spec.ts b/spec/asynciterable-operators/repeat-spec.ts index f9d7c1df..5985596c 100644 --- a/spec/asynciterable-operators/repeat-spec.ts +++ b/spec/asynciterable-operators/repeat-spec.ts @@ -1,16 +1,16 @@ import * as Ix from '../Ix'; -import * as test from 'tape'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.repeat]); const { buffer } = Ix.iterable; const { every } = Ix.iterable; const { map } = Ix.iterable; const { of } = Ix.AsyncIterable; -const { repeat } = Ix.asynciterable; const { sum } = Ix.iterable; const { take } = Ix.asynciterable; const { tap } = Ix.asynciterable; const { toArray } = Ix.asynciterable; -test('AsyncIterable#repeat infinite', async t => { +test('AsyncIterable#repeat infinite', async (t, [repeat]) => { let i = 0; const xs = repeat( tap(of(1, 2), { @@ -27,7 +27,7 @@ test('AsyncIterable#repeat infinite', async t => { t.end(); }); -test('AsyncIterable#repeat finite', async t => { +test('AsyncIterable#repeat finite', async (t, [repeat]) => { let i = 0; const xs = repeat( tap(of(1, 2), { diff --git a/spec/asynciterable-operators/retry-spec.ts b/spec/asynciterable-operators/retry-spec.ts index 0113b0be..7ee4bbf1 100644 --- a/spec/asynciterable-operators/retry-spec.ts +++ b/spec/asynciterable-operators/retry-spec.ts @@ -1,13 +1,13 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.retry]); const { concat } = Ix.asynciterable; const { range } = Ix.asynciterable; -const { retry } = Ix.asynciterable; const { sequenceEqual } = Ix.asynciterable; const { _throw } = Ix.asynciterable; import { hasNext } from '../asynciterablehelpers'; -test('AsyncIterable#retry infinite no errors does not retry', async t => { +test('AsyncIterable#retry infinite no errors does not retry', async (t, [retry]) => { const xs = range(0, 10); const res = retry(xs); @@ -15,7 +15,7 @@ test('AsyncIterable#retry infinite no errors does not retry', async t => { t.end(); }); -test('AsyncIterable#retry finite no errors does not retry', async t => { +test('AsyncIterable#retry finite no errors does not retry', async (t, [retry]) => { const xs = range(0, 10); const res = retry(xs, 2); @@ -23,7 +23,7 @@ test('AsyncIterable#retry finite no errors does not retry', async t => { t.end(); }); -test('AsyncIterable#retry finite eventually gives up', async t => { +test('AsyncIterable#retry finite eventually gives up', async (t, [retry]) => { const err = new Error(); const xs = concat(range(0, 2), _throw(err)); diff --git a/spec/asynciterable-operators/reverse-spec.ts b/spec/asynciterable-operators/reverse-spec.ts index 5b91c690..1300f78a 100644 --- a/spec/asynciterable-operators/reverse-spec.ts +++ b/spec/asynciterable-operators/reverse-spec.ts @@ -1,12 +1,12 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.reverse]); const { empty } = Ix.asynciterable; const { of } = Ix.AsyncIterable; -const { reverse } = Ix.asynciterable; const { _throw } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; -test('AsyncIterable#reverse empty', async t => { +test('AsyncIterable#reverse empty', async (t, [reverse]) => { const xs = empty(); const ys = reverse(xs); @@ -15,7 +15,7 @@ test('AsyncIterable#reverse empty', async t => { t.end(); }); -test('AsyncIterable#revrse single element', async t => { +test('AsyncIterable#revrse single element', async (t, [reverse]) => { const xs = of(42); const ys = reverse(xs); @@ -25,7 +25,7 @@ test('AsyncIterable#revrse single element', async t => { t.end(); }); -test('AsyncIterable#reverse multiple elements', async t => { +test('AsyncIterable#reverse multiple elements', async (t, [reverse]) => { const xs = of(1, 2, 3); const ys = reverse(xs); @@ -37,7 +37,7 @@ test('AsyncIterable#reverse multiple elements', async t => { t.end(); }); -test('AsyncIterable#reverse throws', async t => { +test('AsyncIterable#reverse throws', async (t, [reverse]) => { const xs = _throw(new Error()); const ys = reverse(xs); diff --git a/spec/asynciterable-operators/scan-spec.ts b/spec/asynciterable-operators/scan-spec.ts index 8df02e43..9b36b8d0 100644 --- a/spec/asynciterable-operators/scan-spec.ts +++ b/spec/asynciterable-operators/scan-spec.ts @@ -1,10 +1,10 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.scan]); const { range } = Ix.asynciterable; -const { scan } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; -test('AsyncIterable#scan no seed', async t => { +test('AsyncIterable#scan no seed', async (t, [scan]) => { const res = scan(range(0, 5), async (n, x, i) => n + x + i); const it = res[Symbol.asyncIterator](); @@ -16,7 +16,7 @@ test('AsyncIterable#scan no seed', async t => { t.end(); }); -test('AsyncIterable#scan with seed', async t => { +test('AsyncIterable#scan with seed', async (t, [scan]) => { const res = scan(range(0, 5), async (n, x, i) => n - x - i, 20); const it = res[Symbol.asyncIterator](); diff --git a/spec/asynciterable-operators/scanright-spec.ts b/spec/asynciterable-operators/scanright-spec.ts index f2dcc8a6..a27d83fe 100644 --- a/spec/asynciterable-operators/scanright-spec.ts +++ b/spec/asynciterable-operators/scanright-spec.ts @@ -1,10 +1,10 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.scanRight]); const { range } = Ix.asynciterable; -const { scanRight } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; -test('AsyncIterable#scanRight no seed', async t => { +test('AsyncIterable#scanRight no seed', async (t, [scanRight]) => { const res = scanRight(range(0, 5), async (n, x, i) => n + x + i); const it = res[Symbol.asyncIterator](); @@ -16,7 +16,7 @@ test('AsyncIterable#scanRight no seed', async t => { t.end(); }); -test('AsyncIterable#scanRight with seed', async t => { +test('AsyncIterable#scanRight with seed', async (t, [scanRight]) => { const res = scanRight(range(0, 5), async (n, x, i) => n - x - i, 20); const it = res[Symbol.asyncIterator](); diff --git a/spec/asynciterable-operators/sequenceequal-spec.ts b/spec/asynciterable-operators/sequenceequal-spec.ts index 8d51428c..bca8ed09 100644 --- a/spec/asynciterable-operators/sequenceequal-spec.ts +++ b/spec/asynciterable-operators/sequenceequal-spec.ts @@ -1,18 +1,18 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.sequenceEqual]); const { empty } = Ix.asynciterable; const { of } = Ix.AsyncIterable; -const { sequenceEqual } = Ix.asynciterable; const { _throw } = Ix.asynciterable; -test('AsyncIterable#sequenceEqual sequence equals itself', async t => { +test('AsyncIterable#sequenceEqual sequence equals itself', async (t, [sequenceEqual]) => { const xs = of(1, 2, 3); t.true(await sequenceEqual(xs, xs)); t.end(); }); -test('AsyncIterable#sequenceEqual empty sequence equals itself', async t => { +test('AsyncIterable#sequenceEqual empty sequence equals itself', async (t, [sequenceEqual]) => { const xs = empty(); const ys = empty(); @@ -20,7 +20,7 @@ test('AsyncIterable#sequenceEqual empty sequence equals itself', async t => { t.end(); }); -test('AsyncIterable#sequenceEqual two different sequences not equal', async t => { +test('AsyncIterable#sequenceEqual two different sequences not equal', async (t, [sequenceEqual]) => { const xs = of(1, 2, 3); const ys = of(1, 3, 2); @@ -28,7 +28,7 @@ test('AsyncIterable#sequenceEqual two different sequences not equal', async t => t.end(); }); -test('AsyncIterable#sequenceEqual left longer than right not equal', async t => { +test('AsyncIterable#sequenceEqual left longer than right not equal', async (t, [sequenceEqual]) => { const xs = of(1, 2, 3, 4); const ys = of(1, 2, 3); @@ -36,7 +36,7 @@ test('AsyncIterable#sequenceEqual left longer than right not equal', async t => t.end(); }); -test('AsyncIterable#sequenceEqual right longer than left not equal', async t => { +test('AsyncIterable#sequenceEqual right longer than left not equal', async (t, [sequenceEqual]) => { const xs = of(1, 2, 3); const ys = of(1, 2, 3, 4); @@ -44,7 +44,7 @@ test('AsyncIterable#sequenceEqual right longer than left not equal', async t => t.end(); }); -test('AsyncIterable#sequenceEqual left throws', async t => { +test('AsyncIterable#sequenceEqual left throws', async (t, [sequenceEqual]) => { const err = new Error(); const xs = _throw(err); const ys = of(1, 2, 3); @@ -57,7 +57,7 @@ test('AsyncIterable#sequenceEqual left throws', async t => { t.end(); }); -test('AsyncIterable#sequenceEqual right throws', async t => { +test('AsyncIterable#sequenceEqual right throws', async (t, [sequenceEqual]) => { const err = new Error(); const xs = of(1, 2, 3); const ys = _throw(err); @@ -70,7 +70,7 @@ test('AsyncIterable#sequenceEqual right throws', async t => { t.end(); }); -test('AsyncIterable#sequenceEqual with ccustom omparer sequence equals itself', async t => { +test('AsyncIterable#sequenceEqual with ccustom omparer sequence equals itself', async (t, [sequenceEqual]) => { const comparer = (x: number, y: number) => Math.abs(x) === Math.abs(y); const xs = of(1, 2, 3); @@ -78,7 +78,7 @@ test('AsyncIterable#sequenceEqual with ccustom omparer sequence equals itself', t.end(); }); -test('AsyncIterable#sequenceEqual with custom comparer empty sequence equals itself', async t => { +test('AsyncIterable#sequenceEqual with custom comparer empty sequence equals itself', async (t, [sequenceEqual]) => { const comparer = (x: number, y: number) => Math.abs(x) === Math.abs(y); const xs = empty(); const ys = empty(); @@ -87,7 +87,7 @@ test('AsyncIterable#sequenceEqual with custom comparer empty sequence equals its t.end(); }); -test('AsyncIterable#sequenceEqual with custom comparer two different sequences not equal', async t => { +test('AsyncIterable#sequenceEqual with custom comparer two different sequences not equal', async (t, [sequenceEqual]) => { const comparer = (x: number, y: number) => Math.abs(x) === Math.abs(y); const xs = of(1, 2, 3); const ys = of(1, 3, 2); @@ -96,7 +96,7 @@ test('AsyncIterable#sequenceEqual with custom comparer two different sequences n t.end(); }); -test('AsyncIterable#sequenceEqual with custom comparer left longer than right not equal', async t => { +test('AsyncIterable#sequenceEqual with custom comparer left longer than right not equal', async (t, [sequenceEqual]) => { const comparer = (x: number, y: number) => Math.abs(x) === Math.abs(y); const xs = of(1, 2, 3, 4); const ys = of(1, 2, 3); @@ -105,7 +105,7 @@ test('AsyncIterable#sequenceEqual with custom comparer left longer than right no t.end(); }); -test('AsyncIterable#sequenceEqual with custom comparer right longer than left not equal', async t => { +test('AsyncIterable#sequenceEqual with custom comparer right longer than left not equal', async (t, [sequenceEqual]) => { const comparer = (x: number, y: number) => Math.abs(x) === Math.abs(y); const xs = of(1, 2, 3); const ys = of(1, 2, 3, 4); @@ -114,7 +114,7 @@ test('AsyncIterable#sequenceEqual with custom comparer right longer than left no t.end(); }); -test('AsyncIterable#sequenceEqual with custom comparer left throws', async t => { +test('AsyncIterable#sequenceEqual with custom comparer left throws', async (t, [sequenceEqual]) => { const err = new Error(); const comparer = (x: number, y: number) => Math.abs(x) === Math.abs(y); const xs = _throw(err); @@ -128,7 +128,7 @@ test('AsyncIterable#sequenceEqual with custom comparer left throws', async t => t.end(); }); -test('AsyncIterable#sequenceEqual with custom comparer right throws', async t => { +test('AsyncIterable#sequenceEqual with custom comparer right throws', async (t, [sequenceEqual]) => { const err = new Error(); const comparer = (x: number, y: number) => Math.abs(x) === Math.abs(y); const xs = of(1, 2, 3); @@ -142,7 +142,7 @@ test('AsyncIterable#sequenceEqual with custom comparer right throws', async t => t.end(); }); -test('Itearble#sequenceEqual with custom comparer should be equal', async t => { +test('Itearble#sequenceEqual with custom comparer should be equal', async (t, [sequenceEqual]) => { const comparer = (x: number, y: number) => Math.abs(x) === Math.abs(y); const xs = of(1, 2, -3, 4); const ys = of(1, -2, 3, 4); @@ -151,7 +151,7 @@ test('Itearble#sequenceEqual with custom comparer should be equal', async t => { t.end(); }); -test('Itearble#sequenceEqual with custom comparer throws', async t => { +test('Itearble#sequenceEqual with custom comparer throws', async (t, [sequenceEqual]) => { const err = new Error(); const comparer = (x: number, y: number) => { throw err; diff --git a/spec/asynciterable-operators/share-spec.ts b/spec/asynciterable-operators/share-spec.ts index 47f8bd63..26906c27 100644 --- a/spec/asynciterable-operators/share-spec.ts +++ b/spec/asynciterable-operators/share-spec.ts @@ -1,15 +1,15 @@ import * as Ix from '../Ix'; -import * as test from 'tape'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.share]); const { range } = Ix.asynciterable; const { sequenceEqual } = Ix.iterable; -const { share } = Ix.asynciterable; const { take } = Ix.asynciterable; const { tap } = Ix.asynciterable; const { toArray } = Ix.asynciterable; const { zip } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; -test('AsyncIterable#share single', async t => { +test('AsyncIterable#share single', async (t, [share]) => { const rng = share(range(0, 5)); const it = rng[Symbol.asyncIterator](); @@ -22,7 +22,7 @@ test('AsyncIterable#share single', async t => { t.end(); }); -test('AsyncIterable#share shared exhausts in the beginning', async t => { +test('AsyncIterable#share shared exhausts in the beginning', async (t, [share]) => { const rng = share(range(0, 5)); const it1 = rng[Symbol.asyncIterator](); @@ -37,7 +37,7 @@ test('AsyncIterable#share shared exhausts in the beginning', async t => { t.end(); }); -test('AsyncIterable#share shared exhausts any time', async t => { +test('AsyncIterable#share shared exhausts any time', async (t, [share]) => { const rng = share(range(0, 5)); const it1 = rng[Symbol.asyncIterator](); @@ -54,7 +54,7 @@ test('AsyncIterable#share shared exhausts any time', async t => { t.end(); }); -test('AsyncIterable#share with selector', async t => { +test('AsyncIterable#share with selector', async (t, [share]) => { let n = 0; const res = await toArray( share( diff --git a/spec/asynciterable-operators/single-spec.ts b/spec/asynciterable-operators/single-spec.ts index 5fccb535..43b837e6 100644 --- a/spec/asynciterable-operators/single-spec.ts +++ b/spec/asynciterable-operators/single-spec.ts @@ -1,45 +1,45 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.single]); const { empty } = Ix.asynciterable; const { of } = Ix.AsyncIterable; -const { single } = Ix.asynciterable; -test('AsyncIterable#single no predicate empty returns undefined', async (t: test.Test) => { +test('AsyncIterable#single no predicate empty returns undefined', async (t, [single]) => { const xs = empty(); const res = await single(xs); t.equal(res, undefined); t.end(); }); -test('AsyncIterable#single with predicate empty returns undefined', async (t: test.Test) => { +test('AsyncIterable#single with predicate empty returns undefined', async (t, [single]) => { const xs = empty(); const res = await single(xs, async () => true); t.equal(res, undefined); t.end(); }); -test('AsyncIterable#single predicate miss', async (t: test.Test) => { +test('AsyncIterable#single predicate miss', async (t, [single]) => { const xs = of(42); const res = await single(xs, x => x % 2 !== 0); t.equal(res, undefined); t.end(); }); -test('AsyncIterable#single no predicate hit', async (t: test.Test) => { +test('AsyncIterable#single no predicate hit', async (t, [single]) => { const xs = of(42); const res = await single(xs); t.equal(res, 42); t.end(); }); -test('AsyncIterable#single predicate hit', async (t: test.Test) => { +test('AsyncIterable#single predicate hit', async (t, [single]) => { const xs = of(42); const res = await single(xs, x => x % 2 === 0); t.equal(res, 42); t.end(); }); -test('AsyncIterable#single no predicate multiple throws error', async (t: test.Test) => { +test('AsyncIterable#single no predicate multiple throws error', async (t, [single]) => { const xs = of(42, 45, 90); try { await single(xs); @@ -49,7 +49,7 @@ test('AsyncIterable#single no predicate multiple throws error', async (t: test.T t.end(); }); -test('AsyncIterable#single with predicate multiple throws error', async (t: test.Test) => { +test('AsyncIterable#single with predicate multiple throws error', async (t, [single]) => { const xs = of(42, 45, 90); try { await single(xs, async x => x % 2 === 0); diff --git a/spec/asynciterable-operators/skip-spec.ts b/spec/asynciterable-operators/skip-spec.ts index 33608cea..405dc6a5 100644 --- a/spec/asynciterable-operators/skip-spec.ts +++ b/spec/asynciterable-operators/skip-spec.ts @@ -1,11 +1,11 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.skip]); const { of } = Ix.AsyncIterable; -const { skip } = Ix.asynciterable; const { _throw } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; -test('AsyncIterable#skip skips some', async t => { +test('AsyncIterable#skip skips some', async (t, [skip]) => { const xs = of(1, 2, 3, 4); const ys = skip(xs, 2); @@ -16,7 +16,7 @@ test('AsyncIterable#skip skips some', async t => { t.end(); }); -test('AsyncIterable#skip skips more than count', async t => { +test('AsyncIterable#skip skips more than count', async (t, [skip]) => { const xs = of(1, 2, 3, 4); const ys = skip(xs, 10); @@ -25,7 +25,7 @@ test('AsyncIterable#skip skips more than count', async t => { t.end(); }); -test('AsyncIterable#skip none', async t => { +test('AsyncIterable#skip none', async (t, [skip]) => { const xs = of(1, 2, 3, 4); const ys = skip(xs, 0); @@ -38,7 +38,7 @@ test('AsyncIterable#skip none', async t => { t.end(); }); -test('AsyncIterable#skip throws', async t => { +test('AsyncIterable#skip throws', async (t, [skip]) => { const err = new Error(); const xs = _throw(err); const ys = skip(xs, 2); diff --git a/spec/asynciterable-operators/skiplast-spec.ts b/spec/asynciterable-operators/skiplast-spec.ts index 2a33928b..b47ccea4 100644 --- a/spec/asynciterable-operators/skiplast-spec.ts +++ b/spec/asynciterable-operators/skiplast-spec.ts @@ -1,19 +1,19 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.skipLast]); const { empty } = Ix.asynciterable; const { range } = Ix.asynciterable; const { sequenceEqual } = Ix.asynciterable; -const { skipLast } = Ix.asynciterable; const { take } = Ix.asynciterable; -test('AsyncIterable#skipLast empty', async t => { +test('AsyncIterable#skipLast empty', async (t, [skipLast]) => { const e = empty(); const r = skipLast(e, 1); t.true(await sequenceEqual(r, e)); t.end(); }); -test('AsyncIterable#skipLast partial', async t => { +test('AsyncIterable#skipLast partial', async (t, [skipLast]) => { const e = range(0, 5); const r = skipLast(e, 3); t.true(await sequenceEqual(r, take(e, 2))); diff --git a/spec/asynciterable-operators/skipuntil-spec.ts b/spec/asynciterable-operators/skipuntil-spec.ts index 62757a50..e9fac704 100644 --- a/spec/asynciterable-operators/skipuntil-spec.ts +++ b/spec/asynciterable-operators/skipuntil-spec.ts @@ -1,9 +1,9 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { skipUntil } = Ix.asynciterable; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.skipUntil]); import { hasNext, noNext, delayValue } from '../asynciterablehelpers'; -test('AsyncIterable#skipUntil hits', async t => { +test('AsyncIterable#skipUntil hits', async (t, [skipUntil]) => { const xs = async function*() { yield await delayValue(1, 100); yield await delayValue(2, 300); @@ -18,7 +18,7 @@ test('AsyncIterable#skipUntil hits', async t => { t.end(); }); -test('AsyncIterable#skipUntil misses', async t => { +test('AsyncIterable#skipUntil misses', async (t, [skipUntil]) => { const xs = async function*() { yield await delayValue(1, 400); yield await delayValue(2, 500); diff --git a/spec/asynciterable-operators/skipwhile-spec.ts b/spec/asynciterable-operators/skipwhile-spec.ts index a3794edc..34aed10a 100644 --- a/spec/asynciterable-operators/skipwhile-spec.ts +++ b/spec/asynciterable-operators/skipwhile-spec.ts @@ -1,10 +1,10 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.skipWhile]); const { of } = Ix.AsyncIterable; -const { skipWhile } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; -test('AsyncIterable#skipWhile skips some', async t => { +test('AsyncIterable#skipWhile skips some', async (t, [skipWhile]) => { const xs = of(1, 2, 3, 4); const ys = skipWhile(xs, async x => x < 3); @@ -15,7 +15,7 @@ test('AsyncIterable#skipWhile skips some', async t => { t.end(); }); -test('AsyncIterable#skipWhile skips none', async t => { +test('AsyncIterable#skipWhile skips none', async (t, [skipWhile]) => { const xs = of(1, 2, 3, 4); const ys = skipWhile(xs, async () => false); @@ -28,7 +28,7 @@ test('AsyncIterable#skipWhile skips none', async t => { t.end(); }); -test('AsyncIterable#skipWhile skips all', async t => { +test('AsyncIterable#skipWhile skips all', async (t, [skipWhile]) => { const xs = of(1, 2, 3, 4); const ys = skipWhile(xs, async () => true); @@ -37,7 +37,7 @@ test('AsyncIterable#skipWhile skips all', async t => { t.end(); }); -test('AsyncIterable#skipWhile skips some another run', async t => { +test('AsyncIterable#skipWhile skips some another run', async (t, [skipWhile]) => { const xs = of(1, 2, 3, 4, 3, 2, 1); const ys = skipWhile(xs, x => x < 3); @@ -51,7 +51,7 @@ test('AsyncIterable#skipWhile skips some another run', async t => { t.end(); }); -test('AsyncIterable#skipWhile predicate throws', async t => { +test('AsyncIterable#skipWhile predicate throws', async (t, [skipWhile]) => { const err = new Error(); const xs = of(1, 2, 3, 4); const ys = skipWhile(xs, () => { @@ -67,7 +67,7 @@ test('AsyncIterable#skipWhile predicate throws', async t => { t.end(); }); -test('AsyncIterable#skipWhile with index', async t => { +test('AsyncIterable#skipWhile with index', async (t, [skipWhile]) => { const xs = of(1, 2, 3, 4); const ys = skipWhile(xs, async (x, i) => i < 2); diff --git a/spec/asynciterable-operators/slice-spec.ts b/spec/asynciterable-operators/slice-spec.ts index 1bb425ad..b80f78a5 100644 --- a/spec/asynciterable-operators/slice-spec.ts +++ b/spec/asynciterable-operators/slice-spec.ts @@ -1,10 +1,10 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.slice]); const { from } = Ix.AsyncIterable; -const { slice } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; -test('AsyncIterable#slice slices at zero with one item', async t => { +test('AsyncIterable#slice slices at zero with one item', async (t, [slice]) => { const xs = from([1, 2, 3, 4]); const ys = slice(xs, 0, 1); @@ -14,7 +14,7 @@ test('AsyncIterable#slice slices at zero with one item', async t => { t.end(); }); -test('AsyncIterable#slice slices at one with one item', async t => { +test('AsyncIterable#slice slices at one with one item', async (t, [slice]) => { const xs = from([1, 2, 3, 4]); const ys = slice(xs, 1, 1); @@ -24,7 +24,7 @@ test('AsyncIterable#slice slices at one with one item', async t => { t.end(); }); -test('AsyncIterable#slice slices at one with multiple items', async t => { +test('AsyncIterable#slice slices at one with multiple items', async (t, [slice]) => { const xs = from([1, 2, 3, 4]); const ys = slice(xs, 1, 2); @@ -35,7 +35,7 @@ test('AsyncIterable#slice slices at one with multiple items', async t => { t.end(); }); -test('AsyncIterable#slice slices at one with no end', async t => { +test('AsyncIterable#slice slices at one with no end', async (t, [slice]) => { const xs = from([1, 2, 3, 4]); const ys = slice(xs, 1); @@ -47,7 +47,7 @@ test('AsyncIterable#slice slices at one with no end', async t => { t.end(); }); -test('AsyncIterable#slice slices at zero with no end', async t => { +test('AsyncIterable#slice slices at zero with no end', async (t, [slice]) => { const xs = from([1, 2, 3, 4]); const ys = slice(xs, 0); diff --git a/spec/asynciterable-operators/some-spec.ts b/spec/asynciterable-operators/some-spec.ts index a8fed2a7..33acedea 100644 --- a/spec/asynciterable-operators/some-spec.ts +++ b/spec/asynciterable-operators/some-spec.ts @@ -1,24 +1,24 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.some]); const { of } = Ix.AsyncIterable; -const { some } = Ix.asynciterable; const { _throw } = Ix.asynciterable; -test('AsyncIterable#some some true', async (t: test.Test) => { +test('AsyncIterable#some some true', async (t, [some]) => { const xs = of(1, 2, 3, 4); const ys = await some(xs, async x => x % 2 === 0); t.true(ys); t.end(); }); -test('AsyncIterable#some some false', async (t: test.Test) => { +test('AsyncIterable#some some false', async (t, [some]) => { const xs = of(2, 4, 6, 8); const ys = await some(xs, async x => x % 2 !== 0); t.false(ys); t.end(); }); -test('AsyncIterable#some throws', async (t: test.Test) => { +test('AsyncIterable#some throws', async (t, [some]) => { const err = new Error(); const xs = _throw(err); @@ -30,7 +30,7 @@ test('AsyncIterable#some throws', async (t: test.Test) => { t.end(); }); -test('AsyncIterable#some predicate throws', async (t: test.Test) => { +test('AsyncIterable#some predicate throws', async (t, [some]) => { const err = new Error(); const xs = of(1, 2, 3, 4); diff --git a/spec/asynciterable-operators/startwith-spec.ts b/spec/asynciterable-operators/startwith-spec.ts index 5a2c371f..df3d1b4c 100644 --- a/spec/asynciterable-operators/startwith-spec.ts +++ b/spec/asynciterable-operators/startwith-spec.ts @@ -1,20 +1,20 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.startWith]); const { range } = Ix.asynciterable; const { sequenceEqual } = Ix.asynciterable; -const { startWith } = Ix.asynciterable; const { take } = Ix.asynciterable; const { tap } = Ix.asynciterable; const { toArray } = Ix.asynciterable; -test('AsyncIterable#startWith adds to beginning', async t => { +test('AsyncIterable#startWith adds to beginning', async (t, [startWith]) => { const e = range(1, 5); const r = startWith(e, 0); t.true(await sequenceEqual(r, range(0, 6))); t.end(); }); -test('AsyncIterable#startWith adds without causing effects', async t => { +test('AsyncIterable#startWith adds without causing effects', async (t, [startWith]) => { let oops = false; const e = tap(range(1, 5), { next: async () => { oops = true; } }); await toArray(take(startWith(e, 0), 1)); diff --git a/spec/asynciterable-operators/sum-spec.ts b/spec/asynciterable-operators/sum-spec.ts index 02fc8aa4..e4106a2a 100644 --- a/spec/asynciterable-operators/sum-spec.ts +++ b/spec/asynciterable-operators/sum-spec.ts @@ -1,37 +1,37 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.sum]); const { empty } = Ix.asynciterable; const { of } = Ix.AsyncIterable; -const { sum } = Ix.asynciterable; -test('AsyncIterable#sum laws', async t => { +test('AsyncIterable#sum laws', async (t, [sum]) => { const xs = of(1, 2, 3); t.equal(await sum(xs), await sum(xs, async x => x)); t.end(); }); -test('AsyncIterable#sum no selector empty', async t => { +test('AsyncIterable#sum no selector empty', async (t, [sum]) => { const xs = empty(); const res = await sum(xs); t.equal(res, 0); t.end(); }); -test('AsyncIterable#sum no selector', async t => { +test('AsyncIterable#sum no selector', async (t, [sum]) => { const xs = of(1, 2, 3); const res = await sum(xs); t.equal(res, 6); t.end(); }); -test('AsyncIterable#sum with selector empty', async t => { +test('AsyncIterable#sum with selector empty', async (t, [sum]) => { const xs = empty(); const res = await sum(xs, async x => x * 2); t.equal(res, 0); t.end(); }); -test('AsyncIterable#sum with selector', async t => { +test('AsyncIterable#sum with selector', async (t, [sum]) => { const xs = of(1, 2, 3); const res = await sum(xs, async x => x * 2); t.equal(res, 12); diff --git a/spec/asynciterable-operators/take-spec.ts b/spec/asynciterable-operators/take-spec.ts index 32eae5ec..72e06a7e 100644 --- a/spec/asynciterable-operators/take-spec.ts +++ b/spec/asynciterable-operators/take-spec.ts @@ -1,11 +1,11 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.take]); const { of } = Ix.AsyncIterable; -const { take } = Ix.asynciterable; const { _throw } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; -test('AsyncIterable#take zero or less takes nothing', async t => { +test('AsyncIterable#take zero or less takes nothing', async (t, [take]) => { const xs = of(1, 2, 3, 4); const ys = take(xs, -2); @@ -14,7 +14,7 @@ test('AsyncIterable#take zero or less takes nothing', async t => { t.end(); }); -test('AsyncIterable#take less than count', async t => { +test('AsyncIterable#take less than count', async (t, [take]) => { const xs = of(1, 2, 3, 4); const ys = take(xs, 2); @@ -25,7 +25,7 @@ test('AsyncIterable#take less than count', async t => { t.end(); }); -test('AsyncIterable#take more than count', async t => { +test('AsyncIterable#take more than count', async (t, [take]) => { const xs = of(1, 2, 3, 4); const ys = take(xs, 10); @@ -38,7 +38,7 @@ test('AsyncIterable#take more than count', async t => { t.end(); }); -test('AsyncIterable#take throws with error', async t => { +test('AsyncIterable#take throws with error', async (t, [take]) => { const err = new Error(); const xs = _throw(err); const ys = take(xs, 2); diff --git a/spec/asynciterable-operators/takelast-spec.ts b/spec/asynciterable-operators/takelast-spec.ts index 717195e4..b389748a 100644 --- a/spec/asynciterable-operators/takelast-spec.ts +++ b/spec/asynciterable-operators/takelast-spec.ts @@ -1,31 +1,31 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.takeLast]); const { empty } = Ix.asynciterable; const { range } = Ix.asynciterable; const { sequenceEqual } = Ix.asynciterable; const { skip } = Ix.asynciterable; -const { takeLast } = Ix.asynciterable; -test('AsyncIterable#takeLast none', async t => { +test('AsyncIterable#takeLast none', async (t, [takeLast]) => { const res = takeLast(range(1, 5), 0); t.true(await sequenceEqual(res, empty())); t.end(); }); -test('AsyncIterable#takeLast empty', async t => { +test('AsyncIterable#takeLast empty', async (t, [takeLast]) => { const res = takeLast(empty(), 1); t.true(await sequenceEqual(res, empty())); t.end(); }); -test('AsyncIterable#takeLast has all', async t => { +test('AsyncIterable#takeLast has all', async (t, [takeLast]) => { const e = range(0, 5); const r = takeLast(e, 5); t.true(await sequenceEqual(r, e)); t.end(); }); -test('AsyncIterable#takeLast has part', async t => { +test('AsyncIterable#takeLast has part', async (t, [takeLast]) => { const e = range(0, 5); const r = takeLast(e, 3); t.true(await sequenceEqual(r, skip(e, 2))); diff --git a/spec/asynciterable-operators/takeuntil-spec.ts b/spec/asynciterable-operators/takeuntil-spec.ts index ecd0c952..b2190f54 100644 --- a/spec/asynciterable-operators/takeuntil-spec.ts +++ b/spec/asynciterable-operators/takeuntil-spec.ts @@ -1,9 +1,9 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { takeUntil } = Ix.asynciterable; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.takeUntil]); import { hasNext, noNext, delayValue } from '../asynciterablehelpers'; -test('AsyncIterable#takeUntil hits', async t => { +test('AsyncIterable#takeUntil hits', async (t, [takeUntil]) => { const xs = async function*() { yield await delayValue(1, 100); yield await delayValue(2, 300); @@ -18,7 +18,7 @@ test('AsyncIterable#takeUntil hits', async t => { t.end(); }); -test('AsyncIterable#takeUntil misses', async t => { +test('AsyncIterable#takeUntil misses', async (t, [takeUntil]) => { const xs = async function*() { yield await delayValue(1, 100); yield await delayValue(2, 300); diff --git a/spec/asynciterable-operators/takewhile-spec.ts b/spec/asynciterable-operators/takewhile-spec.ts index 9f909f46..c2d5598f 100644 --- a/spec/asynciterable-operators/takewhile-spec.ts +++ b/spec/asynciterable-operators/takewhile-spec.ts @@ -1,10 +1,10 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.takeWhile]); const { of } = Ix.AsyncIterable; -const { takeWhile } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; -test('AsyncIterable#takeWhile some match', async t => { +test('AsyncIterable#takeWhile some match', async (t, [takeWhile]) => { const xs = of(1, 2, 3, 4); const ys = takeWhile(xs, x => x < 3); @@ -15,7 +15,7 @@ test('AsyncIterable#takeWhile some match', async t => { t.end(); }); -test('AsyncIterable#takeWhile no match', async t => { +test('AsyncIterable#takeWhile no match', async (t, [takeWhile]) => { const xs = of(1, 2, 3, 4); const ys = takeWhile(xs, () => false); @@ -24,7 +24,7 @@ test('AsyncIterable#takeWhile no match', async t => { t.end(); }); -test('AsyncItearble#takeWhile all match', async t => { +test('AsyncItearble#takeWhile all match', async (t, [takeWhile]) => { const xs = of(1, 2, 3, 4); const ys = takeWhile(xs, () => true); @@ -37,7 +37,7 @@ test('AsyncItearble#takeWhile all match', async t => { t.end(); }); -test('AsyncIterable#takeWhile uses index', async t => { +test('AsyncIterable#takeWhile uses index', async (t, [takeWhile]) => { const xs = of(1, 2, 3, 4); const ys = takeWhile(xs, (x, i) => i < 2); @@ -48,7 +48,7 @@ test('AsyncIterable#takeWhile uses index', async t => { t.end(); }); -test('AsyncIterable#takeWhile predicate throws', async t => { +test('AsyncIterable#takeWhile predicate throws', async (t, [takeWhile]) => { const err = new Error(); const xs = of(1, 2, 3, 4); const ys = takeWhile(xs, () => { diff --git a/spec/asynciterable-operators/tap-spec.ts b/spec/asynciterable-operators/tap-spec.ts index 0f31055a..f608e6cb 100644 --- a/spec/asynciterable-operators/tap-spec.ts +++ b/spec/asynciterable-operators/tap-spec.ts @@ -1,10 +1,10 @@ import * as Ix from '../Ix'; -import * as test from 'tape'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.tap]); const { range } = Ix.asynciterable; -const { tap } = Ix.asynciterable; const { _throw } = Ix.asynciterable; -test('AsyncItearble#tap next', async t => { +test('AsyncItearble#tap next', async (t, [tap]) => { let n = 0; let source = tap(range(0, 10), { next: async x => { @@ -19,7 +19,7 @@ test('AsyncItearble#tap next', async t => { t.end(); }); -test('AsyncIterable#tap next complete', async t => { +test('AsyncIterable#tap next complete', async (t, [tap]) => { let n = 0; let source = tap(range(0, 10), { next: async x => { @@ -37,7 +37,7 @@ test('AsyncIterable#tap next complete', async t => { t.end(); }); -test('AsyncIterable#tap with error', async t => { +test('AsyncIterable#tap with error', async (t, [tap]) => { let err = new Error(); let ok = false; @@ -72,7 +72,7 @@ class MyObserver { } } -test('AsyncItearble#tap with observer class', async t => { +test('AsyncItearble#tap with observer class', async (t, [tap]) => { const obs = new MyObserver(); const source = tap(range(0, 10), obs); diff --git a/spec/asynciterable-operators/throttle-spec.ts b/spec/asynciterable-operators/throttle-spec.ts index 37e31503..5ee0d3e1 100644 --- a/spec/asynciterable-operators/throttle-spec.ts +++ b/spec/asynciterable-operators/throttle-spec.ts @@ -1,9 +1,9 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { throttle } = Ix.asynciterable; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.throttle]); import { hasNext, noNext, delayValue } from '../asynciterablehelpers'; -test('AsyncIterable#throttle drops none', async t => { +test('AsyncIterable#throttle drops none', async (t, [throttle]) => { const xs = async function*() { yield await delayValue(1, 100); yield await delayValue(2, 100); @@ -19,7 +19,7 @@ test('AsyncIterable#throttle drops none', async t => { t.end(); }); -test('AsyncIterable#throttle drops some', async t => { +test('AsyncIterable#throttle drops some', async (t, [throttle]) => { const xs = async function*() { yield await delayValue(1, 200); yield await delayValue(2, 200); diff --git a/spec/asynciterable-operators/toarray-spec.ts b/spec/asynciterable-operators/toarray-spec.ts index 7ab1bfa8..31d0c284 100644 --- a/spec/asynciterable-operators/toarray-spec.ts +++ b/spec/asynciterable-operators/toarray-spec.ts @@ -1,11 +1,11 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.toArray]); const { empty } = Ix.asynciterable; const { from } = Ix.AsyncIterable; const { sequenceEqual } = Ix.iterable; -const { toArray } = Ix.asynciterable; -test('AsyncIterable#toArray some', async (t: test.Test) => { +test('AsyncIterable#toArray some', async (t, [toArray]) => { const xs = [42, 25, 39]; const ys = from(xs); const res = await toArray(ys); @@ -13,7 +13,7 @@ test('AsyncIterable#toArray some', async (t: test.Test) => { t.end(); }); -test('AsyncIterable#toArray empty', async (t: test.Test) => { +test('AsyncIterable#toArray empty', async (t, [toArray]) => { const xs = empty(); const res = await toArray(xs); t.equal(res.length, 0); diff --git a/spec/asynciterable-operators/tomap-spec.ts b/spec/asynciterable-operators/tomap-spec.ts index 633a152a..9de27f83 100644 --- a/spec/asynciterable-operators/tomap-spec.ts +++ b/spec/asynciterable-operators/tomap-spec.ts @@ -1,9 +1,9 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.toMap]); const { of } = Ix.AsyncIterable; -const { toMap } = Ix.asynciterable; -test('AsyncIterable#toMap stores values', async (t: test.Test) => { +test('AsyncIterable#toMap stores values', async (t, [toMap]) => { const xs = of(1, 4); const res = await toMap(xs, async x => x % 2); t.equal(res.get(0), 4); @@ -11,7 +11,7 @@ test('AsyncIterable#toMap stores values', async (t: test.Test) => { t.end(); }); -test('AsyncIterable#toMap overwrites duplicates', async (t: test.Test) => { +test('AsyncIterable#toMap overwrites duplicates', async (t, [toMap]) => { const xs = of(1, 4, 2); const res = await toMap(xs, async x => x % 2); t.equal(res.get(0), 2); @@ -19,7 +19,7 @@ test('AsyncIterable#toMap overwrites duplicates', async (t: test.Test) => { t.end(); }); -test('AsyncIterable#toMap with element selector', async (t: test.Test) => { +test('AsyncIterable#toMap with element selector', async (t, [toMap]) => { const xs = of(1, 4); const res = await toMap(xs, async x => x % 2, async x => x + 1); t.equal(res.get(0), 5); @@ -27,7 +27,7 @@ test('AsyncIterable#toMap with element selector', async (t: test.Test) => { t.end(); }); -test('AsyncIterable#toMap with element selector overwrites duplicates', async (t: test.Test) => { +test('AsyncIterable#toMap with element selector overwrites duplicates', async (t, [toMap]) => { const xs = of(1, 4, 2); const res = await toMap(xs, async x => x % 2, async x => x + 1); t.equal(res.get(0), 3); diff --git a/spec/asynciterable-operators/toobservable-spec.ts b/spec/asynciterable-operators/toobservable-spec.ts index 8b4e25ad..8b75d1d6 100644 --- a/spec/asynciterable-operators/toobservable-spec.ts +++ b/spec/asynciterable-operators/toobservable-spec.ts @@ -1,11 +1,11 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.toObservable]); const { empty } = Ix.asynciterable; const { of } = Ix.AsyncIterable; const { _throw } = Ix.asynciterable; -const { toObservable } = Ix.asynciterable; -test('AsyncIterable#toObservable empty', async t => { +test('AsyncIterable#toObservable empty', async (t, [toObservable]) => { const xs = empty(); const ys = toObservable(xs); let fail = false; @@ -24,7 +24,7 @@ test('AsyncIterable#toObservable empty', async t => { }); }); -test('AsyncIterable#toObservable non-empty', async t => { +test('AsyncIterable#toObservable non-empty', async (t, [toObservable]) => { const results: number[] = []; const xs = of(1, 2, 3); const ys = toObservable(xs); @@ -45,7 +45,7 @@ test('AsyncIterable#toObservable non-empty', async t => { }); }); -test('AsyncIterable#toObservable error', async t => { +test('AsyncIterable#toObservable error', async (t, [toObservable]) => { const error = new Error(); const xs = _throw(error); const ys = toObservable(xs); diff --git a/spec/asynciterable-operators/toset-spec.ts b/spec/asynciterable-operators/toset-spec.ts index 9726dea2..c90c18c4 100644 --- a/spec/asynciterable-operators/toset-spec.ts +++ b/spec/asynciterable-operators/toset-spec.ts @@ -1,11 +1,11 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.toSet]); const { empty } = Ix.asynciterable; const { from } = Ix.AsyncIterable; const { sequenceEqual } = Ix.iterable; -const { toSet } = Ix.asynciterable; -test('AsyncIterable#toSet non-empty', async (t: test.Test) => { +test('AsyncIterable#toSet non-empty', async (t, [toSet]) => { const xs = [1, 2, 3, 4, 5]; const ys = from(xs); const res = await toSet(ys); @@ -13,14 +13,14 @@ test('AsyncIterable#toSet non-empty', async (t: test.Test) => { t.end(); }); -test('AsyncIterable#toSet empty', async (t: test.Test) => { +test('AsyncIterable#toSet empty', async (t, [toSet]) => { const xs = empty(); const res = await toSet(xs); t.equal(res.size, 0); t.end(); }); -test('AsyncIterable#toSet trims', async (t: test.Test) => { +test('AsyncIterable#toSet trims', async (t, [toSet]) => { const xs = from([1, 2, 3, 3, 2, 1]); const ys = [1, 2, 3]; const res = await toSet(xs); diff --git a/spec/asynciterable-operators/union-spec.ts b/spec/asynciterable-operators/union-spec.ts index 42833978..8564dc9e 100644 --- a/spec/asynciterable-operators/union-spec.ts +++ b/spec/asynciterable-operators/union-spec.ts @@ -1,10 +1,10 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.union]); const { of } = Ix.AsyncIterable; -const { union } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; -test('AsyncIterable#union with default comparer', async t => { +test('AsyncIterable#union with default comparer', async (t, [union]) => { const xs = of(1, 2, 3); const ys = of(3, 5, 1, 4); const res = union(xs, ys); @@ -19,7 +19,7 @@ test('AsyncIterable#union with default comparer', async t => { t.end(); }); -test('AsyncIterable#union with custom comparer', async t => { +test('AsyncIterable#union with custom comparer', async (t, [union]) => { const comparer = (x: number, y: number) => Math.abs(x) === Math.abs(y); const xs = of(1, 2, -3); const ys = of(3, 5, -1, 4); diff --git a/spec/asynciterable-operators/zip-spec.ts b/spec/asynciterable-operators/zip-spec.ts index 0813fb54..33062b84 100644 --- a/spec/asynciterable-operators/zip-spec.ts +++ b/spec/asynciterable-operators/zip-spec.ts @@ -1,11 +1,11 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../asynciterablehelpers'; +const test = testOperator([Ix.asynciterable.zip]); const { of } = Ix.AsyncIterable; const { _throw } = Ix.asynciterable; -const { zip } = Ix.asynciterable; import { hasNext, noNext } from '../asynciterablehelpers'; -test('AsyncIterable#zip equal length', async t => { +test('AsyncIterable#zip equal length', async (t, [zip]) => { const xs = of(1, 2, 3); const ys = of(4, 5, 6); const res = zip(([x, y]) => x * y, xs, ys); @@ -18,7 +18,7 @@ test('AsyncIterable#zip equal length', async t => { t.end(); }); -test('AsyncIterable#zip left longer', async t => { +test('AsyncIterable#zip left longer', async (t, [zip]) => { const xs = of(1, 2, 3, 4); const ys = of(4, 5, 6); const res = zip(([x, y]) => x * y, xs, ys); @@ -31,7 +31,7 @@ test('AsyncIterable#zip left longer', async t => { t.end(); }); -test('AsyncIterable#zip right longer', async t => { +test('AsyncIterable#zip right longer', async (t, [zip]) => { const xs = of(1, 2, 3); const ys = of(4, 5, 6, 7); const res = zip(([x, y]) => x * y, xs, ys); @@ -44,7 +44,7 @@ test('AsyncIterable#zip right longer', async t => { t.end(); }); -test('AsyncIterable#zip multiple sources', async t => { +test('AsyncIterable#zip multiple sources', async (t, [zip]) => { const xs = of(1, 2, 3); const ys = of(4, 5, 6, 7); const zs = of(8, 9, 10); @@ -58,7 +58,7 @@ test('AsyncIterable#zip multiple sources', async t => { t.end(); }); -test('AsyncIterable#zip left throws', async t => { +test('AsyncIterable#zip left throws', async (t, [zip]) => { const err = new Error(); const xs = _throw(err); const ys = of(4, 5, 6); @@ -73,7 +73,7 @@ test('AsyncIterable#zip left throws', async t => { t.end(); }); -test('AsyncIterable#zip right throws', async t => { +test('AsyncIterable#zip right throws', async (t, [zip]) => { const err = new Error(); const xs = of(1, 2, 3); const ys = _throw(err); @@ -88,7 +88,7 @@ test('AsyncIterable#zip right throws', async t => { t.end(); }); -test('AsyncIterable#zip selector throws', async t => { +test('AsyncIterable#zip selector throws', async (t, [zip]) => { const err = new Error(); const xs = of(1, 2, 3); const ys = of(4, 5, 6); diff --git a/spec/asynciterablehelpers.ts b/spec/asynciterablehelpers.ts index 2060bcc9..5e489c2c 100644 --- a/spec/asynciterablehelpers.ts +++ b/spec/asynciterablehelpers.ts @@ -1,10 +1,13 @@ -export async function hasNext(t: any, source: AsyncIterator, expected: T) { +import * as Ix from './Ix'; +import * as test from 'tape-async'; + +export async function hasNext(t: test.Test, source: AsyncIterator, expected: T) { const { done, value } = await source.next(); t.false(done, 'should not be done'); t.deepEqual(value, expected); } -export async function noNext(t: any, source: AsyncIterator) { +export async function noNext(t: test.Test, source: AsyncIterator) { const next = await source.next(); t.true(next.done, 'should be done'); } @@ -18,3 +21,45 @@ export function delayValue(item: T, delay: number): Promise { }, delay); }); } + +const pipe = Ix.AsyncIterable.prototype.pipe; +const operatorNamesMap = Object.keys(Ix.asynciterable).reduce( + (map, name) => map.set((Ix.asynciterable as any)[name], name), + new Map() +); + +export function testOperator(op: Op) { + const ops = (Array.isArray(op) ? op : [op]) as any as Function[]; + const internalNames = ops.map((op) => operatorNamesMap.get(op)!); + const fnNames = internalNames.map((name) => name.replace('_', '')); + const pipeFns = internalNames.map((name) => (Ix.asynciterablePipe as any)[name]); + return function operatorTest(message: string, testFn: (t: test.Test, op: Op) => any | Promise) { + test(`(fp) ${message}`, async t => await (testFn as any)(t, ops)); + test(`(proto) ${message}`, async t => await (testFn as any)(t, fnNames.map(wrapProto))); + if (pipeFns.every((xs) => typeof xs === 'function')) { + test(`(pipe) ${message}`, async t => await (testFn as any)(t, pipeFns.map(wrapPipe))); + } else { + console.log(`AsyncIterable missing a pipe fn in [${internalNames.join(`, `)}], skipping...`); + } + }; +} + +function wrapProto(name: string) { + return function (source: any, ...args: any[]) { + return typeof source !== 'function' ? + cast(source)[name].apply(source, args) : + cast(args[0])[name].apply(args[0], [source, ...args.slice(1)]); + }; +} + +function wrapPipe(fn: any) { + return function (source: any, ...args: any[]) { + return typeof source !== 'function' ? + pipe.call(source, fn(...args)) : + pipe.call(args[0], fn(source, ...args.slice(1))); + }; +} + +function cast(source: any): any { + return source instanceof Ix.AsyncIterable ? source : Ix.AsyncIterable.from(source); +} \ No newline at end of file diff --git a/spec/iterable-operators/average-spec.ts b/spec/iterable-operators/average-spec.ts index 3c9e135e..60357037 100644 --- a/spec/iterable-operators/average-spec.ts +++ b/spec/iterable-operators/average-spec.ts @@ -1,30 +1,30 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { average } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.average]); -test('Iterable#average empty', t => { +test('Iterable#average empty', (t, [average]) => { t.throws(() => average([])); t.end(); }); -test('Iterable#average', t => { +test('Iterable#average', (t, [average]) => { const res = average([1, 2, 3]); t.equal(res, 2); t.end(); }); -test('Iterable#average with selector empty', t => { +test('Iterable#average with selector empty', (t, [average]) => { t.throws(() => average([], x => x * 2)); t.end(); }); -test('Iterable#average with selector', t => { +test('Iterable#average with selector', (t, [average]) => { const res = average([1, 2, 3], x => x * 2); t.equal(res, 4); t.end(); }); -test('Iterable#average laws', t => { +test('Iterable#average laws', (t, [average]) => { const xs = [1, 2, 3]; t.equal(average(xs), average(xs, x => x)); t.end(); diff --git a/spec/iterable-operators/buffer-spec.ts b/spec/iterable-operators/buffer-spec.ts index 5679e322..e5f47735 100644 --- a/spec/iterable-operators/buffer-spec.ts +++ b/spec/iterable-operators/buffer-spec.ts @@ -1,12 +1,12 @@ import * as Ix from '../Ix'; -import * as test from 'tape'; -const { buffer } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.buffer]); const { empty } = Ix.iterable; const { range } = Ix.iterable; const { sequenceEqual } = Ix.iterable; const { toArray } = Ix.iterable; -test('Iterable#buffer no skip non-full buffer', t => { +test('Iterable#buffer no skip non-full buffer', (t, [buffer]) => { const rng = range(0, 10); const res = toArray(buffer(rng, 3)); @@ -19,7 +19,7 @@ test('Iterable#buffer no skip non-full buffer', t => { t.end(); }); -test('Iterable#buffer no skip all full', t => { +test('Iterable#buffer no skip all full', (t, [buffer]) => { const rng = range(0, 10); const res = toArray(buffer(rng, 5)); @@ -30,7 +30,7 @@ test('Iterable#buffer no skip all full', t => { t.end(); }); -test('Iterable#buffer no skip empty buffer', t => { +test('Iterable#buffer no skip empty buffer', (t, [buffer]) => { const rng = empty(); const res = toArray(buffer(rng, 5)); @@ -38,7 +38,7 @@ test('Iterable#buffer no skip empty buffer', t => { t.end(); }); -test('Iterable#buffer skip non-full buffer', t => { +test('Iterable#buffer skip non-full buffer', (t, [buffer]) => { const rng = range(0, 10); const res = toArray(buffer(rng, 3, 2)); @@ -52,7 +52,7 @@ test('Iterable#buffer skip non-full buffer', t => { t.end(); }); -test('Iterable#buffer skip full buffer', t => { +test('Iterable#buffer skip full buffer', (t, [buffer]) => { const rng = range(0, 10); const res = toArray(buffer(rng, 3, 4)); diff --git a/spec/iterable-operators/catch-spec.ts b/spec/iterable-operators/catch-spec.ts index 116fc8af..d71e735c 100644 --- a/spec/iterable-operators/catch-spec.ts +++ b/spec/iterable-operators/catch-spec.ts @@ -1,19 +1,19 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { _catch } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable._catch]); const { concat } = Ix.iterable; const { range } = Ix.iterable; const { sequenceEqual } = Ix.iterable; const { _throw } = Ix.iterable; import { hasNext } from '../iterablehelpers'; -test('Iterable#catch with no errors', t => { +test('Iterable#catch with no errors', (t, [_catch]) => { const res = _catch(range(0, 5), range(5, 5)); t.true(sequenceEqual(res, range(0, 5))); t.end(); }); -test('Iterable#catch with concat error', t => { +test('Iterable#catch with concat error', (t, [_catch]) => { const res = _catch( concat(range(0, 5), _throw(new Error())), range(5, 5) @@ -23,7 +23,7 @@ test('Iterable#catch with concat error', t => { t.end(); }); -test('Iterable#catch still throws', t => { +test('Iterable#catch still throws', (t, [_catch]) => { const e1 = new Error(); const er1 = _throw(e1); diff --git a/spec/iterable-operators/catchwith-spec.ts b/spec/iterable-operators/catchwith-spec.ts index 357d9991..92c796f5 100644 --- a/spec/iterable-operators/catchwith-spec.ts +++ b/spec/iterable-operators/catchwith-spec.ts @@ -1,19 +1,19 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { catchWith } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.catchWith]); const { range } = Ix.iterable; const { sequenceEqual } = Ix.iterable; const { single } = Ix.iterable; const { _throw } = Ix.iterable; -test('Iterable#catchWith error catches', t => { +test('Iterable#catchWith error catches', (t, [catchWith]) => { const err = new Error(); const res = single(catchWith(_throw(err), e => { t.same(err, e); return [42]; })); t.equal(42, res); t.end(); }); -test('Iterable#catchWith no error misses', t => { +test('Iterable#catchWith no error misses', (t, [catchWith]) => { const xs = range(0, 10); const res = catchWith(xs, e => { t.fail(); return [42]; }); t.true(sequenceEqual(res, xs)); diff --git a/spec/iterable-operators/chain-spec.ts b/spec/iterable-operators/chain-spec.ts index 79eb90b0..67ed7c42 100644 --- a/spec/iterable-operators/chain-spec.ts +++ b/spec/iterable-operators/chain-spec.ts @@ -1,10 +1,10 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.chain]); const { empty } = Ix.iterable; -const { chain } = Ix.iterable; import { noNext } from '../iterablehelpers'; -test('Itearble#chain calls function immediately', t => { +test('Itearble#chain calls function immediately', (t, [chain]) => { let called = false; const xs = chain(empty(), x => { called = true; return x; }); t.true(called); diff --git a/spec/iterable-operators/concat-spec.ts b/spec/iterable-operators/concat-spec.ts index f8e9c6dc..43ac9701 100644 --- a/spec/iterable-operators/concat-spec.ts +++ b/spec/iterable-operators/concat-spec.ts @@ -1,19 +1,19 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { concat } = Ix.iterable; -const { concatAll } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const testConcat = testOperator([Ix.iterable.concat]); +const testConcatAll = testOperator([Ix.iterable.concatAll]); const { map } = Ix.iterable; const { range } = Ix.iterable; const { sequenceEqual } = Ix.iterable; const { tap } = Ix.iterable; -test('Iterable#concat concatAll behavior', t => { +testConcatAll('Iterable#concat concatAll behavior', (t, [concatAll]) => { const res = concatAll([[1, 2, 3], [4, 5]]); t.true(sequenceEqual(res, [1, 2, 3, 4, 5])); t.end(); }); -test('Iterable#concat concatAll order of effects', t => { +testConcatAll('Iterable#concat concatAll order of effects', (t, [concatAll]) => { let i = 0; const xss = tap(map(range(0, 3), x => range(0, x + 1)), { next: () => ++i }); const res = map(concatAll(xss), x => i + ' - ' + x); @@ -29,7 +29,7 @@ test('Iterable#concat concatAll order of effects', t => { t.end(); }); -test('Iterable#concat behavior', t => { +testConcat('Iterable#concat behavior', (t, [concat]) => { const res = concat([1, 2, 3], [4, 5]); t.true(sequenceEqual(res, [1, 2, 3, 4, 5])); t.end(); diff --git a/spec/iterable-operators/count-spec.ts b/spec/iterable-operators/count-spec.ts index 44e72d49..aa39e6fb 100644 --- a/spec/iterable-operators/count-spec.ts +++ b/spec/iterable-operators/count-spec.ts @@ -1,23 +1,23 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { count } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.count]); -test('Iterable#count no predicate empty', t => { +test('Iterable#count no predicate empty', (t, [count]) => { t.equal(count([]), 0); t.end(); }); -test('Iterable#count no predicate non-empty', t => { +test('Iterable#count no predicate non-empty', (t, [count]) => { t.equal(count([1, 2, 3]), 3); t.end(); }); -test('Iterable#count predicate empty', t => { +test('Iterable#count predicate empty', (t, [count]) => { t.equal(count([], x => x < 3), 0); t.end(); }); -test('Iterable#count predicate some', t => { +test('Iterable#count predicate some', (t, [count]) => { t.equal(count([1, 2, 3], x => x < 3), 2); t.end(); }); diff --git a/spec/iterable-operators/defaultifempty-spec.ts b/spec/iterable-operators/defaultifempty-spec.ts index e3bf87fa..f7213054 100644 --- a/spec/iterable-operators/defaultifempty-spec.ts +++ b/spec/iterable-operators/defaultifempty-spec.ts @@ -1,11 +1,11 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { defaultIfEmpty } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.defaultIfEmpty]); const { empty } = Ix.iterable; const { _throw } = Ix.iterable; import { hasNext, noNext } from '../iterablehelpers'; -test('Iterable#defaultIfEmpty with empty', t => { +test('Iterable#defaultIfEmpty with empty', (t, [defaultIfEmpty]) => { const xs = empty(); const ys = defaultIfEmpty(xs, 0); @@ -15,7 +15,7 @@ test('Iterable#defaultIfEmpty with empty', t => { t.end(); }); -test('Iterable#defaultIfEmpty with no empty', t => { +test('Iterable#defaultIfEmpty with no empty', (t, [defaultIfEmpty]) => { const xs = [42]; const ys = defaultIfEmpty(xs, 0); @@ -25,7 +25,7 @@ test('Iterable#defaultIfEmpty with no empty', t => { t.end(); }); -test('Iterable#defaultIfEmpty throws', t => { +test('Iterable#defaultIfEmpty throws', (t, [defaultIfEmpty]) => { const xs = _throw(new Error()); const ys = defaultIfEmpty(xs, 0); diff --git a/spec/iterable-operators/distinct-spec.ts b/spec/iterable-operators/distinct-spec.ts index 374be52d..71b19e4b 100644 --- a/spec/iterable-operators/distinct-spec.ts +++ b/spec/iterable-operators/distinct-spec.ts @@ -1,10 +1,10 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { distinct } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.distinct]); const { range } = Ix.iterable; const { sequenceEqual } = Ix.iterable; -test('Iterable#distinct selector', t => { +test('Iterable#distinct selector', (t, [distinct]) => { const res = distinct(range(0, 10), x => x % 5); t.true(sequenceEqual(res, range(0, 5))); t.end(); @@ -14,7 +14,7 @@ function testComparer(x: number, y: number): boolean { return x % 2 === y % 2; } -test('Iterable#distinct with comparer', t => { +test('Iterable#distinct with comparer', (t, [distinct]) => { const res = distinct(range(0, 10), x => x % 5, testComparer); t.true(sequenceEqual(res, [0, 1])); t.end(); diff --git a/spec/iterable-operators/distinctuntilchanged-spec.ts b/spec/iterable-operators/distinctuntilchanged-spec.ts index 32d39952..0e1e11cc 100644 --- a/spec/iterable-operators/distinctuntilchanged-spec.ts +++ b/spec/iterable-operators/distinctuntilchanged-spec.ts @@ -1,15 +1,15 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { distinctUntilChanged } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.distinctUntilChanged]); const { sequenceEqual } = Ix.iterable; -test('Iterable#distinctUntilChanged no selector', t => { +test('Iterable#distinctUntilChanged no selector', (t, [distinctUntilChanged]) => { const res = distinctUntilChanged([1, 2, 2, 3, 3, 3, 2, 2, 1]); t.true(sequenceEqual(res, [1, 2, 3, 2, 1])); t.end(); }); -test('Iterable#distinctUntilChanged with selector', t => { +test('Iterable#distinctUntilChanged with selector', (t, [distinctUntilChanged]) => { const res = distinctUntilChanged([1, 1, 2, 3, 4, 5, 5, 6, 7], x => Math.floor(x / 2)); t.true(sequenceEqual(res, [1, 2, 4, 6])); t.end(); diff --git a/spec/iterable-operators/dowhile-spec.ts b/spec/iterable-operators/dowhile-spec.ts index b75222f4..6d5b2809 100644 --- a/spec/iterable-operators/dowhile-spec.ts +++ b/spec/iterable-operators/dowhile-spec.ts @@ -1,12 +1,12 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.doWhile]); const { defer } = Ix.iterable; -const { doWhile } = Ix.iterable; const { sequenceEqual } = Ix.iterable; const { tap } = Ix.iterable; const { toArray } = Ix.iterable; -test('Iterable#doWhile some', t => { +test('Iterable#doWhile some', (t, [doWhile]) => { let x = 5; const res = toArray( doWhile(defer(() => tap([x], { next: () => x--})), () => x > 0) @@ -16,7 +16,7 @@ test('Iterable#doWhile some', t => { t.end(); }); -test('Iterable#doWhile one', t => { +test('Iterable#doWhile one', (t, [doWhile]) => { let x = 0; const res = toArray( doWhile(defer(() => tap([x], { next: () => x--})), () => x > 0) diff --git a/spec/iterable-operators/elementat-spec.ts b/spec/iterable-operators/elementat-spec.ts index 296eb2c8..614c2075 100644 --- a/spec/iterable-operators/elementat-spec.ts +++ b/spec/iterable-operators/elementat-spec.ts @@ -1,32 +1,32 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { elementAt } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.elementAt]); -test('Iterable#elementAt empty returns undefined', t => { +test('Iterable#elementAt empty returns undefined', (t, [elementAt]) => { const res = elementAt([], 0); t.equal(res, undefined); t.end(); }); -test('Iterable#elementAt single value first index', t => { +test('Iterable#elementAt single value first index', (t, [elementAt]) => { const res = elementAt([42], 0); t.equal(res, 42); t.end(); }); -test('Iterable#elementAt single value invalid index', t => { +test('Iterable#elementAt single value invalid index', (t, [elementAt]) => { const res = elementAt([42], 1); t.equal(res, undefined); t.end(); }); -test('Iterable#elementAt multiple values valid index', t => { +test('Iterable#elementAt multiple values valid index', (t, [elementAt]) => { const res = elementAt([1, 42, 3], 1); t.equal(res, 42); t.end(); }); -test('Iterable#elementAt multiple values invalid index', t => { +test('Iterable#elementAt multiple values invalid index', (t, [elementAt]) => { const res = elementAt([1, 42, 3], 7); t.equal(res, undefined); t.end(); diff --git a/spec/iterable-operators/endwith-spec.ts b/spec/iterable-operators/endwith-spec.ts index 3f934661..9fd5e181 100644 --- a/spec/iterable-operators/endwith-spec.ts +++ b/spec/iterable-operators/endwith-spec.ts @@ -1,10 +1,10 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.endWith]); const { range } = Ix.iterable; const { sequenceEqual } = Ix.iterable; -const { endWith } = Ix.iterable; -test('Iterable#endWith adds to end', t => { +test('Iterable#endWith adds to end', (t, [endWith]) => { const e = range(0, 5); const r = endWith(e, 5, 6); t.true(sequenceEqual(r, range(0, 7))); diff --git a/spec/iterable-operators/every-spec.ts b/spec/iterable-operators/every-spec.ts index f57e8613..89e257be 100644 --- a/spec/iterable-operators/every-spec.ts +++ b/spec/iterable-operators/every-spec.ts @@ -1,14 +1,14 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { every } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.every]); -test('Iterable#every some true', t => { +test('Iterable#every some true', (t, [every]) => { const res = every([1, 2, 3, 4], x => x % 2 === 0); t.false(res); t.end(); }); -test('Iterable#very all true', t => { +test('Iterable#very all true', (t, [every]) => { const res = every([2, 8, 4, 6], x => x % 2 === 0); t.true(res); t.end(); diff --git a/spec/iterable-operators/except-spec.ts b/spec/iterable-operators/except-spec.ts index 8440947d..e671ad27 100644 --- a/spec/iterable-operators/except-spec.ts +++ b/spec/iterable-operators/except-spec.ts @@ -1,9 +1,9 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { except } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.except]); import { hasNext, noNext } from '../iterablehelpers'; -test('Iterable#except with default comparer', t => { +test('Iterable#except with default comparer', (t, [except]) => { const xs = [1, 2, 3]; const ys = [3, 5, 1, 4]; const res = except(xs, ys); @@ -14,7 +14,7 @@ test('Iterable#except with default comparer', t => { t.end(); }); -test('Iterable#except with custom comparer', t => { +test('Iterable#except with custom comparer', (t, [except]) => { const comparer = (x: number, y: number) => Math.abs(x) === Math.abs(y); const xs = [1, 2, -3]; const ys = [3, 5, -1, 4]; diff --git a/spec/iterable-operators/expand-spec.ts b/spec/iterable-operators/expand-spec.ts index bd8b2b94..f56af7ee 100644 --- a/spec/iterable-operators/expand-spec.ts +++ b/spec/iterable-operators/expand-spec.ts @@ -1,17 +1,17 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { expand } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.expand]); const { range } = Ix.iterable; const { sequenceEqual } = Ix.iterable; const { take } = Ix.iterable; -test('Iterable#expand with single return behavior', t => { +test('Iterable#expand with single return behavior', (t, [expand]) => { const res = take(expand([0], x => [x + 1]), 10); t.true(sequenceEqual(res, range(0, 10))); t.end(); }); -test('Iterable#expand with range return behavior', t => { +test('Iterable#expand with range return behavior', (t, [expand]) => { const res = expand([3], x => range(0, x)); const exp = [ 3, diff --git a/spec/iterable-operators/filter-spec.ts b/spec/iterable-operators/filter-spec.ts index 48994a5d..34b74b6e 100644 --- a/spec/iterable-operators/filter-spec.ts +++ b/spec/iterable-operators/filter-spec.ts @@ -1,11 +1,11 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.filter]); const { empty } = Ix.iterable; -const { filter } = Ix.iterable; const { _throw } = Ix.iterable; import { hasNext, noNext } from '../iterablehelpers'; -test('Iterable#filter', t => { +test('Iterable#filter', (t, [filter]) => { const xs = [8, 5, 7, 4, 6, 9, 2, 1, 0]; const ys = filter(xs, x => x % 2 === 0); @@ -19,7 +19,7 @@ test('Iterable#filter', t => { t.end(); }); -test('Iterable#filter with index', t => { +test('Iterable#filter with index', (t, [filter]) => { const xs = [8, 5, 7, 4, 6, 9, 2, 1, 0]; const ys = filter(xs, (x, i) => i % 2 === 0); @@ -33,7 +33,7 @@ test('Iterable#filter with index', t => { t.end(); }); -test('Iterable#filter with typeguard', t => { +test('Iterable#filter with typeguard', (t, [filter]) => { const xs = [ new String('8'), 5, new String('7'), 4, @@ -53,7 +53,7 @@ test('Iterable#filter with typeguard', t => { t.end(); }); -test('Iterable#filter throws part way through', t => { +test('Iterable#filter throws part way through', (t, [filter]) => { const xs = [8, 5, 7, 4, 6, 9, 2, 1, 0]; const err = new Error(); const ys = filter(xs, x => { if (x === 4) { throw err; } return true; }); @@ -66,7 +66,7 @@ test('Iterable#filter throws part way through', t => { t.end(); }); -test('Iterable#filter with index throws part way through', t => { +test('Iterable#filter with index throws part way through', (t, [filter]) => { const xs = [8, 5, 7, 4, 6, 9, 2, 1, 0]; const err = new Error(); const ys = filter(xs, (x, i) => { if (i === 3) { throw err; } return true; }); @@ -79,7 +79,7 @@ test('Iterable#filter with index throws part way through', t => { t.end(); }); -test('Iterable#filter with error source', t => { +test('Iterable#filter with error source', (t, [filter]) => { const xs = _throw(new Error()); const ys = filter(xs, x => x % 2 === 0); @@ -88,7 +88,7 @@ test('Iterable#filter with error source', t => { t.end(); }); -test('Iterable#filter with empty source', t => { +test('Iterable#filter with empty source', (t, [filter]) => { const xs = empty(); const ys = filter(xs, x => x % 2 === 0); diff --git a/spec/iterable-operators/finally-spec.ts b/spec/iterable-operators/finally-spec.ts index 5934fb5b..2afbd791 100644 --- a/spec/iterable-operators/finally-spec.ts +++ b/spec/iterable-operators/finally-spec.ts @@ -1,11 +1,11 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { _finally } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable._finally]); const { range } = Ix.iterable; const { _throw } = Ix.iterable; import { hasNext, noNext } from '../iterablehelpers'; -test('Iterable#finally defers behavior', t => { +test('Iterable#finally defers behavior', (t, [_finally]) => { let done = false; const xs = _finally(range(0, 2), () => done = true); @@ -26,7 +26,7 @@ test('Iterable#finally defers behavior', t => { t.end(); }); -test('Iterable#finally calls even with error', t => { +test('Iterable#finally calls even with error', (t, [_finally]) => { let done = false; const err = new Error(); diff --git a/spec/iterable-operators/first-spec.ts b/spec/iterable-operators/first-spec.ts index b0c4ee43..622cbc98 100644 --- a/spec/iterable-operators/first-spec.ts +++ b/spec/iterable-operators/first-spec.ts @@ -1,28 +1,28 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { first } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.first]); -test('Iterable#first empty returns undefined', t => { +test('Iterable#first empty returns undefined', (t, [first]) => { t.equal(first([]), undefined); t.end(); }); -test('Iterable#first no predicate returns first', t => { +test('Iterable#first no predicate returns first', (t, [first]) => { t.equal(first([1, 2, 3]), 1); t.end(); }); -test('Iterable#first predicate empty returns undefined', t => { +test('Iterable#first predicate empty returns undefined', (t, [first]) => { t.equal(first([], () => true), undefined); t.end(); }); -test('Iterable#first predicate hits returns value', t => { +test('Iterable#first predicate hits returns value', (t, [first]) => { t.equal(first([1, 2, 3], x => x % 2 === 0), 2); t.end(); }); -test('Iterable#first predicate misses returns undefined', t => { +test('Iterable#first predicate misses returns undefined', (t, [first]) => { t.equal(first([1, 3, 5], x => x % 2 === 0), undefined); t.end(); }); diff --git a/spec/iterable-operators/flatmap-spec.ts b/spec/iterable-operators/flatmap-spec.ts index f34fa9ee..f6de1233 100644 --- a/spec/iterable-operators/flatmap-spec.ts +++ b/spec/iterable-operators/flatmap-spec.ts @@ -1,11 +1,11 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { flatMap } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.flatMap]); const { range } = Ix.iterable; const { _throw } = Ix.iterable; import { hasNext, noNext } from '../iterablehelpers'; -test('Iterable#flatMap with range', t => { +test('Iterable#flatMap with range', (t, [flatMap]) => { const xs = [1, 2, 3]; const ys = flatMap(xs, x => range(0, x)); @@ -20,7 +20,7 @@ test('Iterable#flatMap with range', t => { t.end(); }); -test('Iterable#flatMap selector returns throw', t => { +test('Iterable#flatMap selector returns throw', (t, [flatMap]) => { const err = new Error(); const xs = [1, 2, 3]; const ys = flatMap(xs, x => x < 3 ? range(0, x) : _throw(err)); @@ -33,7 +33,7 @@ test('Iterable#flatMap selector returns throw', t => { t.end(); }); -test('Iterable#flatMap with error throws', t => { +test('Iterable#flatMap with error throws', (t, [flatMap]) => { const err = new Error(); const xs = _throw(err); const ys = flatMap(xs, x => range(0, x)); @@ -43,7 +43,7 @@ test('Iterable#flatMap with error throws', t => { t.end(); }); -test('Iterable#flatMap selector throws error', t => { +test('Iterable#flatMap selector throws error', (t, [flatMap]) => { const err = new Error(); const xs = [1, 2, 3]; const ys = flatMap(xs, x => { diff --git a/spec/iterable-operators/flatten-spec.ts b/spec/iterable-operators/flatten-spec.ts index f728bbe3..8a008221 100644 --- a/spec/iterable-operators/flatten-spec.ts +++ b/spec/iterable-operators/flatten-spec.ts @@ -1,13 +1,14 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { flatten } = Ix.iterable; +import * as tape from 'tape-async'; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.flatten]); const { toArray } = Ix.iterable; -function compareArrays(t: test.Test, fst: Iterable, snd: Iterable) { +function compareArrays(t: tape.Test, fst: Iterable, snd: Iterable) { t.equal(fst.toString(), snd.toString()); } -test('Iterable#flatten flattens all', t => { +test('Iterable#flatten flattens all', (t, [flatten]) => { const xs = [1, [2, [3]], 4]; const ys = toArray(flatten(xs)); @@ -15,7 +16,7 @@ test('Iterable#flatten flattens all', t => { t.end(); }); -test('Iterable#flatten flattens two layers', t => { +test('Iterable#flatten flattens two layers', (t, [flatten]) => { const xs = [1, [2, [3]], 4]; const ys = toArray(flatten(xs, 2)); @@ -23,7 +24,7 @@ test('Iterable#flatten flattens two layers', t => { t.end(); }); -test('Iterable#flatten flattens one layer', t => { +test('Iterable#flatten flattens one layer', (t, [flatten]) => { const xs = [1, [2, [3]], 4]; const ys = toArray(flatten(xs, 1)); @@ -31,7 +32,7 @@ test('Iterable#flatten flattens one layer', t => { t.end(); }); -test('Iterable#flatten flattens no layers', t => { +test('Iterable#flatten flattens no layers', (t, [flatten]) => { const xs = [1, [2, [3]], 4]; const ys = toArray(flatten(xs, 1)); diff --git a/spec/iterable-operators/groupby-spec.ts b/spec/iterable-operators/groupby-spec.ts index 75a0af6d..5573f819 100644 --- a/spec/iterable-operators/groupby-spec.ts +++ b/spec/iterable-operators/groupby-spec.ts @@ -1,10 +1,10 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.groupBy]); const { empty } = Ix.iterable; -const { groupBy } = Ix.iterable; import { hasNext, noNext } from '../iterablehelpers'; -test('Iterable#groupBy normal', t => { +test('Iterable#groupBy normal', (t, [groupBy]) => { const xs = [ { name: 'Bart', age: 27 }, { name: 'John', age: 62 }, @@ -52,7 +52,7 @@ test('Iterable#groupBy normal', t => { t.end(); }); -test('Iterable#groupBy normal can get results later', t => { +test('Iterable#groupBy normal can get results later', (t, [groupBy]) => { const xs = [ { name: 'Bart', age: 27 }, { name: 'John', age: 62 }, @@ -105,7 +105,7 @@ test('Iterable#groupBy normal can get results later', t => { t.end(); }); -test('Iterable#groupBy empty', t => { +test('Iterable#groupBy empty', (t, [groupBy]) => { const xs = empty(); const ys = groupBy(xs, x => x); @@ -114,7 +114,7 @@ test('Iterable#groupBy empty', t => { t.end(); }); -test('Iterable#groupBy element selector', t => { +test('Iterable#groupBy element selector', (t, [groupBy]) => { const xs = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; const ys = groupBy(xs, x => x % 3, x => String.fromCharCode(97 + x)); @@ -156,7 +156,7 @@ test('Iterable#groupBy element selector', t => { t.end(); }); -test('Iterable#groupBy result selector', t => { +test('Iterable#groupBy result selector', (t, [groupBy]) => { const xs = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; const ys = groupBy(xs, x => x % 3, x => String.fromCharCode(97 + x), (k, v) => ({ k, v })); diff --git a/spec/iterable-operators/groupjoin-spec.ts b/spec/iterable-operators/groupjoin-spec.ts index d4ff5005..aa7699e8 100644 --- a/spec/iterable-operators/groupjoin-spec.ts +++ b/spec/iterable-operators/groupjoin-spec.ts @@ -1,11 +1,11 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { groupJoin } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.groupJoin]); const { reduce } = Ix.iterable; const { _throw } = Ix.iterable; import { hasNext, noNext } from '../iterablehelpers'; -test('Iterable#groupJoin all groups have values', t => { +test('Iterable#groupJoin all groups have values', (t, [groupJoin]) => { const xs = [0, 1, 2]; const ys = [4, 7, 6, 2, 3, 4, 8, 9]; const res = groupJoin( @@ -23,7 +23,7 @@ test('Iterable#groupJoin all groups have values', t => { t.end(); }); -test('Iterable#groupJoin some groups have values', t => { +test('Iterable#groupJoin some groups have values', (t, [groupJoin]) => { const xs = [0, 1, 2]; const ys = [3, 6, 4]; const res = groupJoin( @@ -41,7 +41,7 @@ test('Iterable#groupJoin some groups have values', t => { t.end(); }); -test('Iterable#groupJoin left throws', t => { +test('Iterable#groupJoin left throws', (t, [groupJoin]) => { const xs = _throw(new Error()); const ys = [3, 6, 4]; const res = groupJoin( @@ -56,7 +56,7 @@ test('Iterable#groupJoin left throws', t => { t.end(); }); -test('Iterable#groupJoin right throws', t => { +test('Iterable#groupJoin right throws', (t, [groupJoin]) => { const xs = [0, 1, 2]; const ys = _throw(new Error()); const res = groupJoin( @@ -71,7 +71,7 @@ test('Iterable#groupJoin right throws', t => { t.end(); }); -test('Iterable#groupJoin left selector throws', t => { +test('Iterable#groupJoin left selector throws', (t, [groupJoin]) => { const xs = [0, 1, 2]; const ys = [3, 6, 4]; const res = groupJoin( @@ -86,7 +86,7 @@ test('Iterable#groupJoin left selector throws', t => { t.end(); }); -test('Iterable#groupJoin right selector throws', t => { +test('Iterable#groupJoin right selector throws', (t, [groupJoin]) => { const xs = [0, 1, 2]; const ys = [3, 6, 4]; const res = groupJoin( @@ -101,7 +101,7 @@ test('Iterable#groupJoin right selector throws', t => { t.end(); }); -test('Iterable#groupJoin result selector eventually throws', t => { +test('Iterable#groupJoin result selector eventually throws', (t, [groupJoin]) => { const xs = [0, 1, 2]; const ys = [3, 6, 4]; const res = groupJoin( diff --git a/spec/iterable-operators/ignoreelements-spec.ts b/spec/iterable-operators/ignoreelements-spec.ts index 6b617719..6c9e7718 100644 --- a/spec/iterable-operators/ignoreelements-spec.ts +++ b/spec/iterable-operators/ignoreelements-spec.ts @@ -1,11 +1,11 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { ignoreElements } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.ignoreElements]); const { range } = Ix.iterable; const { take } = Ix.iterable; const { tap } = Ix.iterable; -test('Iterable#ignoreElements has side effects', t => { +test('Iterable#ignoreElements has side effects', (t, [ignoreElements]) => { let n = 0; take(ignoreElements(tap(range(0, 10), { next: () => n++ })), 5).forEach(() => { /* tslint:disable-next-line:no-empty */ diff --git a/spec/iterable-operators/includes-spec.ts b/spec/iterable-operators/includes-spec.ts index d2735046..3a768f59 100644 --- a/spec/iterable-operators/includes-spec.ts +++ b/spec/iterable-operators/includes-spec.ts @@ -1,29 +1,29 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { includes } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.includes]); -test('Iterable#includes includes', t => { +test('Iterable#includes includes', (t, [includes]) => { const xs = [1, 2, 3, 4, 5]; const ys = includes(xs, 3); t.true(ys); t.end(); }); -test('Iterable#includes does not include', t => { +test('Iterable#includes does not include', (t, [includes]) => { const xs = [1, 2, 3, 4, 5]; const ys = includes(xs, 6); t.false(ys); t.end(); }); -test('Iterable#includes fromIndex hits', t => { +test('Iterable#includes fromIndex hits', (t, [includes]) => { const xs = [1, 2, 3, 4, 5]; const ys = includes(xs, 3, 2); t.true(ys); t.end(); }); -test('Iterable#includes fromIndex misses', t => { +test('Iterable#includes fromIndex misses', (t, [includes]) => { const xs = [1, 2, 3, 4, 5]; const ys = includes(xs, 1, 2); t.false(ys); diff --git a/spec/iterable-operators/innerjoin-spec.ts b/spec/iterable-operators/innerjoin-spec.ts index ab7bb963..c281337b 100644 --- a/spec/iterable-operators/innerjoin-spec.ts +++ b/spec/iterable-operators/innerjoin-spec.ts @@ -1,10 +1,10 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { innerJoin } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.innerJoin]); const { _throw } = Ix.iterable; import { hasNext, noNext } from '../iterablehelpers'; -test('Iterable#innerJoin normal', t => { +test('Iterable#innerJoin normal', (t, [innerJoin]) => { const xs = [0, 1, 2]; const ys = [3, 6, 4]; const res = innerJoin( @@ -22,7 +22,7 @@ test('Iterable#innerJoin normal', t => { t.end(); }); -test('Iterable#innerJoin reversed', t => { +test('Iterable#innerJoin reversed', (t, [innerJoin]) => { const xs = [3, 6, 4]; const ys = [0, 1, 2]; const res = innerJoin( @@ -40,7 +40,7 @@ test('Iterable#innerJoin reversed', t => { t.end(); }); -test('Iterable#innerJoin only one group matches', t => { +test('Iterable#innerJoin only one group matches', (t, [innerJoin]) => { const xs = [0, 1, 2]; const ys = [3, 6]; const res = innerJoin( @@ -57,7 +57,7 @@ test('Iterable#innerJoin only one group matches', t => { t.end(); }); -test('Iterable#innerJoin only one group matches reversed', t => { +test('Iterable#innerJoin only one group matches reversed', (t, [innerJoin]) => { const xs = [3, 6]; const ys = [0, 1, 2]; const res = innerJoin( @@ -74,7 +74,7 @@ test('Iterable#innerJoin only one group matches reversed', t => { t.end(); }); -test('Iterable#innerJoin left throws', t => { +test('Iterable#innerJoin left throws', (t, [innerJoin]) => { const xs = _throw(new Error()); const ys = [3, 6, 4]; const res = innerJoin( @@ -89,7 +89,7 @@ test('Iterable#innerJoin left throws', t => { t.end(); }); -test('Iterable#innerJoin right throws', t => { +test('Iterable#innerJoin right throws', (t, [innerJoin]) => { const xs = [0, 1, 2]; const ys = _throw(new Error()); const res = innerJoin( @@ -104,7 +104,7 @@ test('Iterable#innerJoin right throws', t => { t.end(); }); -test('Iterable#innerJoin left selector throws', t => { +test('Iterable#innerJoin left selector throws', (t, [innerJoin]) => { const xs = [0, 1, 2]; const ys = [3, 6, 4]; const res = innerJoin( @@ -119,7 +119,7 @@ test('Iterable#innerJoin left selector throws', t => { t.end(); }); -test('Iterable#join right selector throws', t => { +test('Iterable#join right selector throws', (t, [innerJoin]) => { const xs = [0, 1, 2]; const ys = [3, 6, 4]; const res = innerJoin( @@ -134,7 +134,7 @@ test('Iterable#join right selector throws', t => { t.end(); }); -test('Iterable#innerJoin result selector throws', t => { +test('Iterable#innerJoin result selector throws', (t, [innerJoin]) => { const xs = [0, 1, 2]; const ys = [3, 6, 4]; const res = innerJoin( diff --git a/spec/iterable-operators/intersect-spec.ts b/spec/iterable-operators/intersect-spec.ts index 8f218e3e..0c7a5183 100644 --- a/spec/iterable-operators/intersect-spec.ts +++ b/spec/iterable-operators/intersect-spec.ts @@ -1,9 +1,9 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { intersect } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.intersect]); import { hasNext, noNext } from '../iterablehelpers'; -test('Iterable#union with default comparer', t => { +test('Iterable#union with default comparer', (t, [intersect]) => { const xs = [1, 2, 3]; const ys = [3, 5, 1, 4]; const res = intersect(xs, ys); @@ -15,7 +15,7 @@ test('Iterable#union with default comparer', t => { t.end(); }); -test('Iterable#union with custom comparer', t => { +test('Iterable#union with custom comparer', (t, [intersect]) => { const comparer = (x: number, y: number) => Math.abs(x) === Math.abs(y); const xs = [1, 2, -3]; const ys = [3, 5, -1, 4]; diff --git a/spec/iterable-operators/isempty-spec.ts b/spec/iterable-operators/isempty-spec.ts index 80b51a0f..b7f167ac 100644 --- a/spec/iterable-operators/isempty-spec.ts +++ b/spec/iterable-operators/isempty-spec.ts @@ -1,14 +1,14 @@ import * as Ix from '../Ix'; -import * as test from 'tape'; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.isEmpty]); const { empty } = Ix.iterable; -const { isEmpty } = Ix.iterable; -test('Iterable#isEmpty empty', t => { +test('Iterable#isEmpty empty', (t, [isEmpty]) => { t.true(isEmpty(empty())); t.end(); }); -test('Iterable#isEmpty not-empty', t => { +test('Iterable#isEmpty not-empty', (t, [isEmpty]) => { t.false(isEmpty([1])); t.end(); }); diff --git a/spec/iterable-operators/last-spec.ts b/spec/iterable-operators/last-spec.ts index f61c925f..71607139 100644 --- a/spec/iterable-operators/last-spec.ts +++ b/spec/iterable-operators/last-spec.ts @@ -1,28 +1,28 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { last } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.last]); -test('Iterable#last empty returns undefined', t => { +test('Iterable#last empty returns undefined', (t, [last]) => { t.equal(last([]), undefined); t.end(); }); -test('Iterable#last no predicate returns first', t => { +test('Iterable#last no predicate returns first', (t, [last]) => { t.equal(last([1, 2, 3]), 3); t.end(); }); -test('Iterable#last predicate empty returns undefined', t => { +test('Iterable#last predicate empty returns undefined', (t, [last]) => { t.equal(last([], () => true), undefined); t.end(); }); -test('Iterable#last predicate hits returns value', t => { +test('Iterable#last predicate hits returns value', (t, [last]) => { t.equal(last([1, 2, 3, 4, 5], x => x % 2 === 0), 4); t.end(); }); -test('Iterable#last predicate misses returns undefined', t => { +test('Iterable#last predicate misses returns undefined', (t, [last]) => { t.equal(last([1, 3, 5], x => x % 2 === 0), undefined); t.end(); }); diff --git a/spec/iterable-operators/map-spec.ts b/spec/iterable-operators/map-spec.ts index d7cd1a36..39b9c529 100644 --- a/spec/iterable-operators/map-spec.ts +++ b/spec/iterable-operators/map-spec.ts @@ -1,10 +1,10 @@ import * as Ix from '../Ix'; -import * as test from 'tape'; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.map]); const { empty } = Ix.iterable; -const { map } = Ix.iterable; const { sequenceEqual } = Ix.iterable; -test('Iterable#map single element', t => { +test('Iterable#map single element', (t, [map]) => { const source = [{ name: 'Frank', custId: 98088 }]; const expected = ['Frank']; @@ -12,7 +12,7 @@ test('Iterable#map single element', t => { t.end(); }); -test('Iterable#map maps property', t => { +test('Iterable#map maps property', (t, [map]) => { const source = [ { name: 'Frank', custId: 98088 }, { name: 'Bob', custId: 29099 }, @@ -26,12 +26,12 @@ test('Iterable#map maps property', t => { t.end(); }); -test('Iterable#map empty', t => { +test('Iterable#map empty', (t, [map]) => { t.true(sequenceEqual(empty(), map(empty(), (s, i) => s.length + i))); t.end(); }); -test('Iterable#map map property using index', t => { +test('Iterable#map map property using index', (t, [map]) => { const source = [ { name: 'Frank', custId: 98088 }, { name: 'Bob', custId: 29099 }, @@ -43,7 +43,7 @@ test('Iterable#map map property using index', t => { t.end(); }); -test('Iterable#map map property using index on last', t => { +test('Iterable#map map property using index on last', (t, [map]) => { const source = [ { name: 'Frank', custId: 98088 }, { name: 'Bob', custId: 29099 }, @@ -57,7 +57,7 @@ test('Iterable#map map property using index on last', t => { t.end(); }); -test('Iterable#map execution is deferred', t => { +test('Iterable#map execution is deferred', (t, [map]) => { let fnCalled = false; const source = [() => { fnCalled = true; return 1; }]; @@ -67,7 +67,7 @@ test('Iterable#map execution is deferred', t => { t.end(); }); -test('Iterable#map source returns expected values', t => { +test('Iterable#map source returns expected values', (t, [map]) => { const source = [1, 2, 3, 4, 5]; const fn = (i: number) => i + 1; diff --git a/spec/iterable-operators/max-spec.ts b/spec/iterable-operators/max-spec.ts index f2ed3e02..40d39e79 100644 --- a/spec/iterable-operators/max-spec.ts +++ b/spec/iterable-operators/max-spec.ts @@ -1,30 +1,30 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { max } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.max]); -test('Itearble#max laws', t => { +test('Itearble#max laws', (t, [max]) => { const xs = [5, 3, 1, 2, 4]; t.equal(max(xs), max(xs, x => x)); t.end(); }); -test('Iterable#max empty throws', t => { +test('Iterable#max empty throws', (t, [max]) => { t.throws(() => max([])); t.end(); }); -test('Iterable#max', t => { +test('Iterable#max', (t, [max]) => { const xs = [5, 3, 1, 2, 4]; t.equal(max(xs), 5); t.end(); }); -test('Iterable#max with selector empty throws', t => { +test('Iterable#max with selector empty throws', (t, [max]) => { t.throws(() => max([], x => x * 2)); t.end(); }); -test('Iterable#max with selector', t => { +test('Iterable#max with selector', (t, [max]) => { const xs = [5, 3, 1, 2, 4]; t.equal(max(xs, x => x * 2), 10); t.end(); diff --git a/spec/iterable-operators/maxby-spec.ts b/spec/iterable-operators/maxby-spec.ts index f249538c..f94cddb8 100644 --- a/spec/iterable-operators/maxby-spec.ts +++ b/spec/iterable-operators/maxby-spec.ts @@ -1,9 +1,9 @@ import * as Ix from '../Ix'; -import * as test from 'tape'; -const { maxBy } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.maxBy]); const { sequenceEqual } = Ix.iterable; -test('Iterable#maxBy', t => { +test('Iterable#maxBy', (t, [maxBy]) => { const source = [2, 5, 0, 7, 4, 3, 6, 2, 1]; const res = maxBy(source, x => x % 3); @@ -11,7 +11,7 @@ test('Iterable#maxBy', t => { t.end(); }); -test('Iterable#maxBy empty throws', t => { +test('Iterable#maxBy empty throws', (t, [maxBy]) => { const source: number[] = []; try { diff --git a/spec/iterable-operators/memoize-spec.ts b/spec/iterable-operators/memoize-spec.ts index 7900b1a5..d89ac6a6 100644 --- a/spec/iterable-operators/memoize-spec.ts +++ b/spec/iterable-operators/memoize-spec.ts @@ -1,9 +1,9 @@ import * as Ix from '../Ix'; -import * as test from 'tape'; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.memoize]); const { concat } = Ix.iterable; const { every } = Ix.iterable; const { map } = Ix.iterable; -const { memoize } = Ix.iterable; const { range } = Ix.iterable; const { sequenceEqual } = Ix.iterable; const { take } = Ix.iterable; @@ -21,7 +21,7 @@ function* tick(t: (x: number) => void) { } } -test('Iterable#memoize memoizes effects', t => { +test('Iterable#memoize memoizes effects', (t, [memoize]) => { let n = 0; const rng = memoize(tick(i => n += i)); @@ -57,7 +57,7 @@ test('Iterable#memoize memoizes effects', t => { t.end(); }); -test('Iterable#memoize single', t => { +test('Iterable#memoize single', (t, [memoize]) => { const rng = memoize(range(0, 5)); const it1 = rng[Symbol.iterator](); @@ -72,7 +72,7 @@ test('Iterable#memoize single', t => { t.end(); }); -test('Iterable#memoize order of operations', t => { +test('Iterable#memoize order of operations', (t, [memoize]) => { const rng = memoize(range(0, 5)); const it1 = rng[Symbol.iterator](); @@ -94,7 +94,7 @@ test('Iterable#memoize order of operations', t => { t.end(); }); -test('Iterable#memoize second early', t => { +test('Iterable#memoize second early', (t, [memoize]) => { const rng = memoize(range(0, 5)); const it1 = rng[Symbol.iterator](); @@ -117,7 +117,7 @@ test('Iterable#memoize second early', t => { t.end(); }); -test('Iterable#memoize max two readers', t => { +test('Iterable#memoize max two readers', (t, [memoize]) => { const rng = memoize(range(0, 5), 2); const it1 = rng[Symbol.iterator](); @@ -136,7 +136,7 @@ test('Iterable#memoize max two readers', t => { t.end(); }); -test('Iterable#memoize concat with error', t => { +test('Iterable#memoize concat with error', (t, [memoize]) => { const error = new Error(); const rng = memoize(concat(range(0, 2), _throw(error))); @@ -164,13 +164,13 @@ function* rand() { } } -test('Iterable#memoize should share effects of random', t => { +test('Iterable#memoize should share effects of random', (t, [memoize]) => { const rnd = memoize(take(rand(), 100)); t.true(every(zip(([l, r]) => l === r, rnd, rnd), x => x)); t.end(); }); -test('Iterable#memoize with selector', t => { +test('Iterable#memoize with selector', (t, [memoize]) => { let n = 0; const res = toArray( memoize( @@ -185,7 +185,7 @@ test('Iterable#memoize with selector', t => { t.end(); }); -test('Iterable#memoize limited with selector', t => { +test('Iterable#memoize limited with selector', (t, [memoize]) => { let n = 0; const res = toArray( memoize( diff --git a/spec/iterable-operators/min-spec.ts b/spec/iterable-operators/min-spec.ts index 1f04e4b9..8c3eb378 100644 --- a/spec/iterable-operators/min-spec.ts +++ b/spec/iterable-operators/min-spec.ts @@ -1,30 +1,30 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { min } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.min]); -test('Itearble#min laws', t => { +test('Itearble#min laws', (t, [min]) => { const xs = [5, 3, 1, 2, 4]; t.equal(min(xs), min(xs, x => x)); t.end(); }); -test('Iterable#min empty throws', t => { +test('Iterable#min empty throws', (t, [min]) => { t.throws(() => min([])); t.end(); }); -test('Iterable#min', t => { +test('Iterable#min', (t, [min]) => { const xs = [5, 3, 1, 2, 4]; t.equal(min(xs), 1); t.end(); }); -test('Iterable#min with selector empty throws', t => { +test('Iterable#min with selector empty throws', (t, [min]) => { t.throws(() => min([], x => x * 2)); t.end(); }); -test('Iterable#min with selector', t => { +test('Iterable#min with selector', (t, [min]) => { const xs = [5, 3, 1, 2, 4]; t.equal(min(xs, x => x * 2), 2); t.end(); diff --git a/spec/iterable-operators/minby-spec.ts b/spec/iterable-operators/minby-spec.ts index 1d97f966..40931d7c 100644 --- a/spec/iterable-operators/minby-spec.ts +++ b/spec/iterable-operators/minby-spec.ts @@ -1,9 +1,9 @@ import * as Ix from '../Ix'; -import * as test from 'tape'; -const { minBy } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.minBy]); const { sequenceEqual } = Ix.iterable; -test('Iterable#minBy', t => { +test('Iterable#minBy', (t, [minBy]) => { const source = [2, 5, 0, 7, 4, 3, 6, 2, 1]; const res = minBy(source, x => x % 3); @@ -11,7 +11,7 @@ test('Iterable#minBy', t => { t.end(); }); -test('Iterable#minBy empty throws', t => { +test('Iterable#minBy empty throws', (t, [minBy]) => { const source: number[] = []; try { diff --git a/spec/iterable-operators/onerrorresumenext-spec.ts b/spec/iterable-operators/onerrorresumenext-spec.ts index d53a1d72..a94c3de6 100644 --- a/spec/iterable-operators/onerrorresumenext-spec.ts +++ b/spec/iterable-operators/onerrorresumenext-spec.ts @@ -1,11 +1,11 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.onErrorResumeNext]); const { concat } = Ix.iterable; -const { onErrorResumeNext } = Ix.iterable; const { sequenceEqual } = Ix.iterable; const { _throw } = Ix.iterable; -test('Iterable#onErrorResumeNext continues without error', t => { +test('Iterable#onErrorResumeNext continues without error', (t, [onErrorResumeNext]) => { const xs = [1, 2]; const ys = [3, 4]; @@ -14,7 +14,7 @@ test('Iterable#onErrorResumeNext continues without error', t => { t.end(); }); -test('Iterable#onErrorResumeNext continues after error', t => { +test('Iterable#onErrorResumeNext continues after error', (t, [onErrorResumeNext]) => { const xs = concat([1, 2], _throw(new Error())); const ys = [3, 4]; diff --git a/spec/iterable-operators/orderby-spec.ts b/spec/iterable-operators/orderby-spec.ts index 20549bd8..7ee75af2 100644 --- a/spec/iterable-operators/orderby-spec.ts +++ b/spec/iterable-operators/orderby-spec.ts @@ -1,9 +1,16 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { hasNext, noNext, testOperator } from '../iterablehelpers'; const { orderBy, orderByDescending, thenBy, thenByDescending } = Ix.iterable; -import { hasNext, noNext } from '../iterablehelpers'; +const testOrderBy = testOperator([orderBy]); +const testOrderByDescending = testOperator([orderByDescending]); +const testOrderByThenBy = testOperator([orderBy, thenBy] as [typeof orderBy, typeof thenBy]); +//tslint:disable-next-line +const testOrderByDescendingThenByDescending = testOperator([ + orderByDescending, + thenByDescending +] as [typeof orderByDescending, typeof thenByDescending]); -test('Iterable#orderBy normal ordering', t => { +testOrderBy('Iterable#orderBy normal ordering', (t, [orderBy]) => { const xs = [2, 6, 1, 5, 7, 8, 9, 3, 4, 0]; const ys = orderBy(xs, x => x); @@ -16,25 +23,30 @@ test('Iterable#orderBy normal ordering', t => { t.end(); }); -test('Iterable#orderBy normal ordering with thenBy throws', t => { +testOrderByThenBy('Iterable#orderBy normal ordering with thenBy throws', (t, [orderBy, thenBy]) => { const xs = [2, 6, 1, 5, 7, 8, 9, 3, 4, 0]; - const ys = thenBy(orderBy(xs, x => x), () => { throw new Error(); }); + const ys = thenBy(orderBy(xs, x => x), () => { + throw new Error(); + }); const it = ys[Symbol.iterator](); t.throws(() => it.next()); t.end(); }); -test('Iterable#orderBy selector throws', t => { +testOrderBy('Iterable#orderBy selector throws', (t, [orderBy]) => { const xs = [2, 6, 1, 5, 7, 8, 9, 3, 4, 0]; - const ys = orderBy(xs, () => { throw new Error(); }); + const ys = orderBy(xs, () => { + throw new Error(); + }); const it = ys[Symbol.iterator](); t.throws(() => it.next()); t.end(); }); -test('Iterable#orderByDescending normal ordering', t => { +//tslint:disable-next-line +testOrderByDescending('Iterable#orderByDescending normal ordering', (t, [orderByDescending]) => { const xs = [2, 6, 1, 5, 7, 8, 9, 3, 4, 0]; const ys = orderByDescending(xs, x => x); @@ -47,11 +59,17 @@ test('Iterable#orderByDescending normal ordering', t => { t.end(); }); -test('Iterable#orderByDescending normal ordering with thenByDescending throws', t => { - const xs = [2, 6, 1, 5, 7, 8, 9, 3, 4, 0]; - const ys = thenByDescending(orderByDescending(xs, x => x), () => { throw new Error(); }); +//tslint:disable-next-line +testOrderByDescendingThenByDescending( + 'Iterable#orderByDescending normal ordering with thenByDescending throws', + (t, [orderByDescending, thenByDescending]) => { + const xs = [2, 6, 1, 5, 7, 8, 9, 3, 4, 0]; + const ys = thenByDescending(orderByDescending(xs, x => x), () => { + throw new Error(); + }); - const it = ys[Symbol.iterator](); - t.throws(() => it.next()); - t.end(); -}); + const it = ys[Symbol.iterator](); + t.throws(() => it.next()); + t.end(); + } +); diff --git a/spec/iterable-operators/pairwise-spec.ts b/spec/iterable-operators/pairwise-spec.ts index 4ce32d9f..ae4a70bf 100644 --- a/spec/iterable-operators/pairwise-spec.ts +++ b/spec/iterable-operators/pairwise-spec.ts @@ -1,11 +1,11 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.pairwise]); const { empty } = Ix.iterable; const { of } = Ix.Iterable; -const { pairwise } = Ix.iterable; import { hasNext, noNext } from '../iterablehelpers'; -test('Iterable#pairwise empty return empty', t => { +test('Iterable#pairwise empty return empty', (t, [pairwise]) => { const xs = empty(); const ys = pairwise(xs); @@ -14,7 +14,7 @@ test('Iterable#pairwise empty return empty', t => { t.end(); }); -test('Iterable#pairwise single returns empty', t => { +test('Iterable#pairwise single returns empty', (t, [pairwise]) => { const xs = of(5); const ys = pairwise(xs); @@ -23,7 +23,7 @@ test('Iterable#pairwise single returns empty', t => { t.end(); }); -test('Iterable#pairwise behavior', t => { +test('Iterable#pairwise behavior', (t, [pairwise]) => { const xs = of(5, 4, 3, 2, 1); const ys = pairwise(xs); diff --git a/spec/iterable-operators/partition-spec.ts b/spec/iterable-operators/partition-spec.ts index 5b382c7f..4b45d7df 100644 --- a/spec/iterable-operators/partition-spec.ts +++ b/spec/iterable-operators/partition-spec.ts @@ -1,15 +1,15 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.partition]); const { empty } = Ix.iterable; const { of } = Ix.Iterable; -const { partition } = Ix.iterable; import { hasNext, noNext } from '../iterablehelpers'; function isEven(x: number) { return x % 2 === 0; } -test('Iterable#partition both empty', t => { +test('Iterable#partition both empty', (t, [partition]) => { const xs = empty(); const [fst, snd] = partition(xs, isEven); @@ -21,7 +21,7 @@ test('Iterable#partition both empty', t => { t.end(); }); -test('Iterable#partition has left', t => { +test('Iterable#partition has left', (t, [partition]) => { const xs = of(4); const [fst, snd] = partition(xs, isEven); @@ -34,7 +34,7 @@ test('Iterable#partition has left', t => { t.end(); }); -test('Iterable#partition has right', t => { +test('Iterable#partition has right', (t, [partition]) => { const xs = of(3); const [fst, snd] = partition(xs, isEven); @@ -47,7 +47,7 @@ test('Iterable#partition has right', t => { t.end(); }); -test('Iterable#partition has both', t => { +test('Iterable#partition has both', (t, [partition]) => { const xs = of(1, 2, 3, 4); const [fst, snd] = partition(xs, isEven); diff --git a/spec/iterable-operators/pluck-spec.ts b/spec/iterable-operators/pluck-spec.ts index 804288e8..f6d45e0b 100644 --- a/spec/iterable-operators/pluck-spec.ts +++ b/spec/iterable-operators/pluck-spec.ts @@ -1,10 +1,10 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.pluck]); const { of } = Ix.Iterable; -const { pluck } = Ix.iterable; import { hasNext, noNext } from '../iterablehelpers'; -test('Iterable#pluck simple prop', t => { +test('Iterable#pluck simple prop', (t, [pluck]) => { const xs = of({ prop: 1 }, { prop: 2 }, { prop: 3 }, { prop: 4 }, { prop: 5 }); const ys = pluck(xs, 'prop'); @@ -18,7 +18,7 @@ test('Iterable#pluck simple prop', t => { t.end(); }); -test('Iterable#pluck nested prop', t => { +test('Iterable#pluck nested prop', (t, [pluck]) => { const xs = of( { a: { b: { c: 1 } } }, { a: { b: { c: 2 } } }, @@ -38,7 +38,7 @@ test('Iterable#pluck nested prop', t => { t.end(); }); -test('Iterable#pluck edge cases', t => { +test('Iterable#pluck edge cases', (t, [pluck]) => { const xs = of( { a: { b: { c: 1 } } }, { a: { b: 2 } }, diff --git a/spec/iterable-operators/publish-spec.ts b/spec/iterable-operators/publish-spec.ts index 7845f368..f1409d9e 100644 --- a/spec/iterable-operators/publish-spec.ts +++ b/spec/iterable-operators/publish-spec.ts @@ -1,8 +1,8 @@ import * as Ix from '../Ix'; -import * as test from 'tape'; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.publish]); const { concat } = Ix.iterable; const { map } = Ix.iterable; -const { publish } = Ix.iterable; const { range } = Ix.iterable; const { sequenceEqual } = Ix.iterable; const { _throw } = Ix.iterable; @@ -20,7 +20,7 @@ function* tick(t: (x: number) => void) { } } -test('Iterable#publish starts at beginning', t => { +test('Iterable#publish starts at beginning', (t, [publish]) => { let n = 0; const rng = publish(tick(i => n += i)); @@ -56,7 +56,7 @@ test('Iterable#publish starts at beginning', t => { t.end(); }); -test('Iterable#publish single', t => { +test('Iterable#publish single', (t, [publish]) => { const rng = publish(range(0, 5)); const it = rng[Symbol.iterator](); @@ -69,7 +69,7 @@ test('Iterable#publish single', t => { t.end(); }); -test('Iterable#publish two interleaved', t => { +test('Iterable#publish two interleaved', (t, [publish]) => { const rng = publish(range(0, 5)); const it1 = rng[Symbol.iterator](); @@ -90,7 +90,7 @@ test('Iterable#publish two interleaved', t => { t.end(); }); -test('Iterable#publish sequential', t => { +test('Iterable#publish sequential', (t, [publish]) => { const rng = publish(range(0, 5)); const it1 = rng[Symbol.iterator](); @@ -112,7 +112,7 @@ test('Iterable#publish sequential', t => { t.end(); }); -test('Iterable#publish second late', t => { +test('Iterable#publish second late', (t, [publish]) => { const rng = publish(range(0, 5)); const it1 = rng[Symbol.iterator](); @@ -131,7 +131,7 @@ test('Iterable#publish second late', t => { t.end(); }); -test('Iterbale#publish shared exceptions', t => { +test('Iterbale#publish shared exceptions', (t, [publish]) => { const error = new Error(); const rng = publish(concat(range(0, 2), _throw(error))); @@ -149,7 +149,7 @@ test('Iterbale#publish shared exceptions', t => { t.end(); }); -test('Iterable#publish with selector', t => { +test('Iterable#publish with selector', (t, [publish]) => { let n = 0; const res = toArray( publish( diff --git a/spec/iterable-operators/reduce-spec.ts b/spec/iterable-operators/reduce-spec.ts index 3a01b27b..dd2ae514 100644 --- a/spec/iterable-operators/reduce-spec.ts +++ b/spec/iterable-operators/reduce-spec.ts @@ -1,30 +1,30 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.reduce]); const { empty } = Ix.iterable; const { of } = Ix.Iterable; -const { reduce } = Ix.iterable; -test('Iterable#reduce no seed', t => { +test('Iterable#reduce no seed', (t, [reduce]) => { const xs = of(0, 1, 2, 3, 4); const ys = reduce(xs, (x, y, i) => x + y + i); t.equal(ys, 20); t.end(); }); -test('Iterable#reduce no seed empty throws', t => { +test('Iterable#reduce no seed empty throws', (t, [reduce]) => { const xs = empty(); t.throws(() => reduce(xs, (x, y, i) => x + y + i)); t.end(); }); -test('Iterable#reduce with seed', t => { +test('Iterable#reduce with seed', (t, [reduce]) => { const xs = of(0, 1, 2, 3, 4); const ys = reduce(xs, (x, y, i) => x - y - i, 20); t.equal(ys, 0); t.end(); }); -test('Iterable#reduce with seed empty', t => { +test('Iterable#reduce with seed empty', (t, [reduce]) => { const xs = empty(); const ys = reduce(xs, (x, y, i) => x - y - i, 20); t.equal(ys, 20); diff --git a/spec/iterable-operators/reduceright-spec.ts b/spec/iterable-operators/reduceright-spec.ts index 029ca0bc..121ae59f 100644 --- a/spec/iterable-operators/reduceright-spec.ts +++ b/spec/iterable-operators/reduceright-spec.ts @@ -1,30 +1,30 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.reduceRight]); const { empty } = Ix.iterable; const { of } = Ix.Iterable; -const { reduceRight } = Ix.iterable; -test('Iterable#reduceRight no seed', t => { +test('Iterable#reduceRight no seed', (t, [reduceRight]) => { const xs = of(0, 1, 2, 3, 4); const ys = reduceRight(xs, (x, y, i) => x + y + i); t.equal(ys, 16); t.end(); }); -test('Iterable#reduceRight no seed empty throws', t => { +test('Iterable#reduceRight no seed empty throws', (t, [reduceRight]) => { const xs = empty(); t.throws(() => reduceRight(xs, (x, y, i) => x + y + i)); t.end(); }); -test('Iterable#reduceRight with seed', t => { +test('Iterable#reduceRight with seed', (t, [reduceRight]) => { const xs = of(0, 1, 2, 3, 4); const ys = reduceRight(xs, (x, y, i) => x - y - i, 20); t.equal(ys, 0); t.end(); }); -test('Iterable#reduceRight with seed empty', t => { +test('Iterable#reduceRight with seed empty', (t, [reduceRight]) => { const xs = empty(); const ys = reduceRight(xs, (x, y, i) => x - y - i, 20); t.equal(ys, 20); diff --git a/spec/iterable-operators/repeat-spec.ts b/spec/iterable-operators/repeat-spec.ts index 296e01a3..423c1e8f 100644 --- a/spec/iterable-operators/repeat-spec.ts +++ b/spec/iterable-operators/repeat-spec.ts @@ -1,15 +1,15 @@ import * as Ix from '../Ix'; -import * as test from 'tape'; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.repeat]); const { buffer } = Ix.iterable; const { every } = Ix.iterable; const { map } = Ix.iterable; -const { repeat } = Ix.iterable; const { sum } = Ix.iterable; const { take } = Ix.iterable; const { tap } = Ix.iterable; const { toArray } = Ix.iterable; -test('Iterable#repeat infinite', t => { +test('Iterable#repeat infinite', (t, [repeat]) => { let i = 0; const xs = repeat(tap([1,2], { next: () => ++i })); @@ -20,7 +20,7 @@ test('Iterable#repeat infinite', t => { t.end(); }); -test('Iterable#repeat finite', t => { +test('Iterable#repeat finite', (t, [repeat]) => { let i = 0; const xs = repeat(tap([1,2], { next: () => ++i }), 5); diff --git a/spec/iterable-operators/retry-spec.ts b/spec/iterable-operators/retry-spec.ts index a8e3a27c..343c42f5 100644 --- a/spec/iterable-operators/retry-spec.ts +++ b/spec/iterable-operators/retry-spec.ts @@ -1,13 +1,13 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.retry]); const { concat } = Ix.iterable; const { range } = Ix.iterable; -const { retry } = Ix.iterable; const { sequenceEqual } = Ix.iterable; const { _throw } = Ix.iterable; import { hasNext } from '../iterablehelpers'; -test('Iterable#retry infinite no errors does not retry', t => { +test('Iterable#retry infinite no errors does not retry', (t, [retry]) => { const xs = range(0, 10); const res = retry(xs); @@ -15,7 +15,7 @@ test('Iterable#retry infinite no errors does not retry', t => { t.end(); }); -test('Iterable#retry finite no errors does not retry', t => { +test('Iterable#retry finite no errors does not retry', (t, [retry]) => { const xs = range(0, 10); const res = retry(xs, 2); @@ -23,7 +23,7 @@ test('Iterable#retry finite no errors does not retry', t => { t.end(); }); -test('Iterable#retry finite eventually gives up', t => { +test('Iterable#retry finite eventually gives up', (t, [retry]) => { const err = new Error(); const xs = concat(range(0, 2), _throw(err)); diff --git a/spec/iterable-operators/reverse-spec.ts b/spec/iterable-operators/reverse-spec.ts index 1a61513e..3a02c203 100644 --- a/spec/iterable-operators/reverse-spec.ts +++ b/spec/iterable-operators/reverse-spec.ts @@ -1,11 +1,11 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.reverse]); const { empty } = Ix.iterable; -const { reverse } = Ix.iterable; const { _throw } = Ix.iterable; import { hasNext, noNext } from '../iterablehelpers'; -test('Iterable#reverse empty', t => { +test('Iterable#reverse empty', (t, [reverse]) => { const xs = empty(); const ys = reverse(xs); @@ -14,7 +14,7 @@ test('Iterable#reverse empty', t => { t.end(); }); -test('Iterable#revrse single element', t => { +test('Iterable#revrse single element', (t, [reverse]) => { const xs = [42]; const ys = reverse(xs); @@ -24,7 +24,7 @@ test('Iterable#revrse single element', t => { t.end(); }); -test('Iterable#reverse multiple elements', t => { +test('Iterable#reverse multiple elements', (t, [reverse]) => { const xs = [1, 2, 3]; const ys = reverse(xs); @@ -36,7 +36,7 @@ test('Iterable#reverse multiple elements', t => { t.end(); }); -test('Iterable#reverse throws', t => { +test('Iterable#reverse throws', (t, [reverse]) => { const xs = _throw(new Error()); const ys = reverse(xs); diff --git a/spec/iterable-operators/scan-spec.ts b/spec/iterable-operators/scan-spec.ts index 8d69d82b..25e6073c 100644 --- a/spec/iterable-operators/scan-spec.ts +++ b/spec/iterable-operators/scan-spec.ts @@ -1,10 +1,10 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.scan]); const { range } = Ix.iterable; -const { scan } = Ix.iterable; import { hasNext, noNext } from '../iterablehelpers'; -test('Iterable#scan no seed', t => { +test('Iterable#scan no seed', (t, [scan]) => { const res = scan(range(0, 5), (n, x, i) => n + x + i); const it = res[Symbol.iterator](); @@ -16,7 +16,7 @@ test('Iterable#scan no seed', t => { t.end(); }); -test('Iterable#scan with seed', t => { +test('Iterable#scan with seed', (t, [scan]) => { const res = scan(range(0, 5), (n, x, i) => n - x - i, 20); const it = res[Symbol.iterator](); diff --git a/spec/iterable-operators/scanright-spec.ts b/spec/iterable-operators/scanright-spec.ts index bc327121..7a63ea52 100644 --- a/spec/iterable-operators/scanright-spec.ts +++ b/spec/iterable-operators/scanright-spec.ts @@ -1,10 +1,10 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.scanRight]); const { range } = Ix.iterable; -const { scanRight } = Ix.iterable; import { hasNext, noNext } from '../iterablehelpers'; -test('Iterable#scanRight no seed', t => { +test('Iterable#scanRight no seed', (t, [scanRight]) => { const res = scanRight(range(0, 5), (n, x, i) => n + x + i); const it = res[Symbol.iterator](); @@ -16,7 +16,7 @@ test('Iterable#scanRight no seed', t => { t.end(); }); -test('Iterable#scanRight with seed', t => { +test('Iterable#scanRight with seed', (t, [scanRight]) => { const res = scanRight(range(0, 5), (n, x, i) => n - x - i, 20); const it = res[Symbol.iterator](); diff --git a/spec/iterable-operators/sequenceequal-spec.ts b/spec/iterable-operators/sequenceequal-spec.ts index 029baf9a..98f60830 100644 --- a/spec/iterable-operators/sequenceequal-spec.ts +++ b/spec/iterable-operators/sequenceequal-spec.ts @@ -1,17 +1,17 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.sequenceEqual]); const { empty } = Ix.iterable; -const { sequenceEqual } = Ix.iterable; const { _throw } = Ix.iterable; -test('Iterable#sequenceEqual sequence equals itself', t => { +test('Iterable#sequenceEqual sequence equals itself', (t, [sequenceEqual]) => { const xs = [1, 2, 3]; t.true(sequenceEqual(xs, xs)); t.end(); }); -test('Iterable#sequenceEqual empty sequence equals itself', t => { +test('Iterable#sequenceEqual empty sequence equals itself', (t, [sequenceEqual]) => { const xs = empty(); const ys = empty(); @@ -19,7 +19,7 @@ test('Iterable#sequenceEqual empty sequence equals itself', t => { t.end(); }); -test('Iterable#sequenceEqual two different sequences not equal', t => { +test('Iterable#sequenceEqual two different sequences not equal', (t, [sequenceEqual]) => { const xs = [1, 2, 3]; const ys = [1, 3, 2]; @@ -27,7 +27,7 @@ test('Iterable#sequenceEqual two different sequences not equal', t => { t.end(); }); -test('Iterable#sequenceEqual left longer than right not equal', t => { +test('Iterable#sequenceEqual left longer than right not equal', (t, [sequenceEqual]) => { const xs = [1, 2, 3, 4]; const ys = [1, 2, 3]; @@ -35,7 +35,7 @@ test('Iterable#sequenceEqual left longer than right not equal', t => { t.end(); }); -test('Iterable#sequenceEqual right longer than left not equal', t => { +test('Iterable#sequenceEqual right longer than left not equal', (t, [sequenceEqual]) => { const xs = [1, 2, 3]; const ys = [1, 2, 3, 4]; @@ -43,7 +43,7 @@ test('Iterable#sequenceEqual right longer than left not equal', t => { t.end(); }); -test('Iterable#sequenceEqual left throws', t => { +test('Iterable#sequenceEqual left throws', (t, [sequenceEqual]) => { const xs = _throw(new Error()); const ys = [1, 2, 3]; @@ -51,7 +51,7 @@ test('Iterable#sequenceEqual left throws', t => { t.end(); }); -test('Iterable#sequenceEqual right throws', t => { +test('Iterable#sequenceEqual right throws', (t, [sequenceEqual]) => { const xs = [1, 2, 3]; const ys = _throw(new Error()); @@ -59,7 +59,7 @@ test('Iterable#sequenceEqual right throws', t => { t.end(); }); -test('Iterable#sequenceEqual with ccustom omparer sequence equals itself', t => { +test('Iterable#sequenceEqual with ccustom omparer sequence equals itself', (t, [sequenceEqual]) => { const comparer = (x: number, y: number) => Math.abs(x) === Math.abs(y); const xs = [1, 2, 3]; @@ -67,7 +67,7 @@ test('Iterable#sequenceEqual with ccustom omparer sequence equals itself', t => t.end(); }); -test('Iterable#sequenceEqual with custom comparer empty sequence equals itself', t => { +test('Iterable#sequenceEqual with custom comparer empty sequence equals itself', (t, [sequenceEqual]) => { const comparer = (x: number, y: number) => Math.abs(x) === Math.abs(y); const xs = empty(); const ys = empty(); @@ -76,7 +76,7 @@ test('Iterable#sequenceEqual with custom comparer empty sequence equals itself', t.end(); }); -test('Iterable#sequenceEqual with custom comparer two different sequences not equal', t => { +test('Iterable#sequenceEqual with custom comparer two different sequences not equal', (t, [sequenceEqual]) => { const comparer = (x: number, y: number) => Math.abs(x) === Math.abs(y); const xs = [1, 2, 3]; const ys = [1, 3, 2]; @@ -85,7 +85,7 @@ test('Iterable#sequenceEqual with custom comparer two different sequences not eq t.end(); }); -test('Iterable#sequenceEqual with custom comparer left longer than right not equal', t => { +test('Iterable#sequenceEqual with custom comparer left longer than right not equal', (t, [sequenceEqual]) => { const comparer = (x: number, y: number) => Math.abs(x) === Math.abs(y); const xs = [1, 2, 3, 4]; const ys = [1, 2, 3]; @@ -94,7 +94,7 @@ test('Iterable#sequenceEqual with custom comparer left longer than right not equ t.end(); }); -test('Iterable#sequenceEqual with custom comparer right longer than left not equal', t => { +test('Iterable#sequenceEqual with custom comparer right longer than left not equal', (t, [sequenceEqual]) => { const comparer = (x: number, y: number) => Math.abs(x) === Math.abs(y); const xs = [1, 2, 3]; const ys = [1, 2, 3, 4]; @@ -103,7 +103,7 @@ test('Iterable#sequenceEqual with custom comparer right longer than left not equ t.end(); }); -test('Iterable#sequenceEqual with custom comparer left throws', t => { +test('Iterable#sequenceEqual with custom comparer left throws', (t, [sequenceEqual]) => { const comparer = (x: number, y: number) => Math.abs(x) === Math.abs(y); const xs = _throw(new Error()); const ys = [1, 2, 3]; @@ -112,7 +112,7 @@ test('Iterable#sequenceEqual with custom comparer left throws', t => { t.end(); }); -test('Iterable#sequenceEqual with custom comparer right throws', t => { +test('Iterable#sequenceEqual with custom comparer right throws', (t, [sequenceEqual]) => { const comparer = (x: number, y: number) => Math.abs(x) === Math.abs(y); const xs = [1, 2, 3]; const ys = _throw(new Error()); @@ -121,7 +121,7 @@ test('Iterable#sequenceEqual with custom comparer right throws', t => { t.end(); }); -test('Itearble#sequenceEqual with custom comparer should be equal', t => { +test('Itearble#sequenceEqual with custom comparer should be equal', (t, [sequenceEqual]) => { const comparer = (x: number, y: number) => Math.abs(x) === Math.abs(y); const xs = [1, 2, -3, 4]; const ys = [1, -2, 3, 4]; @@ -130,7 +130,7 @@ test('Itearble#sequenceEqual with custom comparer should be equal', t => { t.end(); }); -test('Itearble#sequenceEqual with custom comparer throws', t => { +test('Itearble#sequenceEqual with custom comparer throws', (t, [sequenceEqual]) => { const comparer = (x: number, y: number) => { throw new Error(); }; const xs = [1, 2, -3, 4]; const ys = [1, -2, 3, 4]; diff --git a/spec/iterable-operators/share-spec.ts b/spec/iterable-operators/share-spec.ts index 0dca40fa..a8e10ce5 100644 --- a/spec/iterable-operators/share-spec.ts +++ b/spec/iterable-operators/share-spec.ts @@ -1,15 +1,15 @@ import * as Ix from '../Ix'; -import * as test from 'tape'; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.share]); const { range } = Ix.iterable; const { sequenceEqual } = Ix.iterable; -const { share } = Ix.iterable; const { take } = Ix.iterable; const { tap } = Ix.iterable; const { toArray } = Ix.iterable; const { zip } = Ix.iterable; import { hasNext, noNext } from '../iterablehelpers'; -test('Iterable#share single', t => { +test('Iterable#share single', (t, [share]) => { const rng = share(range(0, 5)); const it = rng[Symbol.iterator](); @@ -22,7 +22,7 @@ test('Iterable#share single', t => { t.end(); }); -test('Iterable#share shared exhausts in the beginning', t => { +test('Iterable#share shared exhausts in the beginning', (t, [share]) => { const rng = share(range(0, 5)); const it1 = rng[Symbol.iterator](); @@ -37,7 +37,7 @@ test('Iterable#share shared exhausts in the beginning', t => { t.end(); }); -test('Iterable#share shared exhausts any time', t => { +test('Iterable#share shared exhausts any time', (t, [share]) => { const rng = share(range(0, 5)); const it1 = rng[Symbol.iterator](); @@ -54,7 +54,7 @@ test('Iterable#share shared exhausts any time', t => { t.end(); }); -test('Iterable#share with selector', t => { +test('Iterable#share with selector', (t, [share]) => { let n = 0; const res = toArray( share( diff --git a/spec/iterable-operators/single-spec.ts b/spec/iterable-operators/single-spec.ts index 5edda156..1c6354be 100644 --- a/spec/iterable-operators/single-spec.ts +++ b/spec/iterable-operators/single-spec.ts @@ -1,43 +1,43 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { single } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.single]); -test('Iterable#single no predicate empty returns undefined', t => { +test('Iterable#single no predicate empty returns undefined', (t, [single]) => { const res = single([]); t.equal(res, undefined); t.end(); }); -test('Iterable#single with predicate empty returns undefined', t => { +test('Iterable#single with predicate empty returns undefined', (t, [single]) => { const res = single([], () => true); t.equal(res, undefined); t.end(); }); -test('Iterable#single predicate miss', t => { +test('Iterable#single predicate miss', (t, [single]) => { const res = single([42], x => x % 2 !== 0); t.equal(res, undefined); t.end(); }); -test('Iterable#single no predicate hit', t => { +test('Iterable#single no predicate hit', (t, [single]) => { const res = single([42]); t.equal(res, 42); t.end(); }); -test('Iterable#single predicate hit', t => { +test('Iterable#single predicate hit', (t, [single]) => { const res = single([42], x => x % 2 === 0); t.equal(res, 42); t.end(); }); -test('Iterable#single no predicate multiple throws error', t => { +test('Iterable#single no predicate multiple throws error', (t, [single]) => { t.throws(() => single([42, 45, 90])); t.end(); }); -test('Iterable#single with predicate multiple throws error', t => { +test('Iterable#single with predicate multiple throws error', (t, [single]) => { t.throws(() => single([42, 45, 90], x => x % 2 === 0)); t.end(); }); diff --git a/spec/iterable-operators/skip-spec.ts b/spec/iterable-operators/skip-spec.ts index ed661504..e0d0c8f9 100644 --- a/spec/iterable-operators/skip-spec.ts +++ b/spec/iterable-operators/skip-spec.ts @@ -1,10 +1,10 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { skip } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.skip]); const { _throw } = Ix.iterable; import { hasNext, noNext } from '../iterablehelpers'; -test('Iterable#skip skips some', t => { +test('Iterable#skip skips some', (t, [skip]) => { const xs = [1, 2, 3, 4]; const ys = skip(xs, 2); @@ -15,7 +15,7 @@ test('Iterable#skip skips some', t => { t.end(); }); -test('Iterable#skip skips more than count', t => { +test('Iterable#skip skips more than count', (t, [skip]) => { const xs = [1, 2, 3, 4]; const ys = skip(xs, 10); @@ -24,7 +24,7 @@ test('Iterable#skip skips more than count', t => { t.end(); }); -test('Iterable#skip none', t => { +test('Iterable#skip none', (t, [skip]) => { const xs = [1, 2, 3, 4]; const ys = skip(xs, 0); @@ -37,7 +37,7 @@ test('Iterable#skip none', t => { t.end(); }); -test('Iterable#skip throws', t => { +test('Iterable#skip throws', (t, [skip]) => { const xs = _throw(new Error()); const ys = skip(xs, 2); diff --git a/spec/iterable-operators/skiplast-spec.ts b/spec/iterable-operators/skiplast-spec.ts index 498f726d..06a71567 100644 --- a/spec/iterable-operators/skiplast-spec.ts +++ b/spec/iterable-operators/skiplast-spec.ts @@ -1,19 +1,19 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.skipLast]); const { empty } = Ix.iterable; const { range } = Ix.iterable; const { sequenceEqual } = Ix.iterable; -const { skipLast } = Ix.iterable; const { take } = Ix.iterable; -test('Iterable#skipLast empty', t => { +test('Iterable#skipLast empty', (t, [skipLast]) => { const e = empty(); const r = skipLast(e, 1); t.true(sequenceEqual(r, e)); t.end(); }); -test('Iterable#skipLast partial', t => { +test('Iterable#skipLast partial', (t, [skipLast]) => { const e = range(0, 5); const r = skipLast(e, 3); t.true(sequenceEqual(r, take(e, 2))); diff --git a/spec/iterable-operators/skipwhile-spec.ts b/spec/iterable-operators/skipwhile-spec.ts index 1cd7d3f0..97bec3d3 100644 --- a/spec/iterable-operators/skipwhile-spec.ts +++ b/spec/iterable-operators/skipwhile-spec.ts @@ -1,9 +1,9 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { skipWhile } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.skipWhile]); import { hasNext, noNext } from '../iterablehelpers'; -test('Iterable#skipWhile skips some', t => { +test('Iterable#skipWhile skips some', (t, [skipWhile]) => { const xs = [1, 2, 3, 4]; const ys = skipWhile(xs, x => x < 3); @@ -14,7 +14,7 @@ test('Iterable#skipWhile skips some', t => { t.end(); }); -test('Iterable#skipWhile skips none', t => { +test('Iterable#skipWhile skips none', (t, [skipWhile]) => { const xs = [1, 2, 3, 4]; const ys = skipWhile(xs, () => false); @@ -27,7 +27,7 @@ test('Iterable#skipWhile skips none', t => { t.end(); }); -test('Iterable#skipWhile skips all', t => { +test('Iterable#skipWhile skips all', (t, [skipWhile]) => { const xs = [1, 2, 3, 4]; const ys = skipWhile(xs, () => true); @@ -36,7 +36,7 @@ test('Iterable#skipWhile skips all', t => { t.end(); }); -test('Iterable#skipWhile skips some another run', t => { +test('Iterable#skipWhile skips some another run', (t, [skipWhile]) => { const xs = [1, 2, 3, 4, 3, 2, 1]; const ys = skipWhile(xs, x => x < 3); @@ -50,7 +50,7 @@ test('Iterable#skipWhile skips some another run', t => { t.end(); }); -test('Iterable#skipWhile predicate throws', t => { +test('Iterable#skipWhile predicate throws', (t, [skipWhile]) => { const xs = [1, 2, 3, 4]; const ys = skipWhile(xs, () => { throw new Error(); }); @@ -59,7 +59,7 @@ test('Iterable#skipWhile predicate throws', t => { t.end(); }); -test('Iterable#skipWhile with index', t => { +test('Iterable#skipWhile with index', (t, [skipWhile]) => { const xs = [1, 2, 3, 4]; const ys = skipWhile(xs, (x, i) => i < 2); diff --git a/spec/iterable-operators/slice-spec.ts b/spec/iterable-operators/slice-spec.ts index 3c3a87a3..6756dcc8 100644 --- a/spec/iterable-operators/slice-spec.ts +++ b/spec/iterable-operators/slice-spec.ts @@ -1,10 +1,10 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.slice]); const { from } = Ix.Iterable; -const { slice } = Ix.iterable; import { hasNext, noNext } from '../iterablehelpers'; -test('Iterable#slice slices at zero with one item', t => { +test('Iterable#slice slices at zero with one item', (t, [slice]) => { const xs = from([1, 2, 3, 4]); const ys = slice(xs, 0, 1); @@ -14,7 +14,7 @@ test('Iterable#slice slices at zero with one item', t => { t.end(); }); -test('Iterable#slice slices at one with one item', t => { +test('Iterable#slice slices at one with one item', (t, [slice]) => { const xs = from([1, 2, 3, 4]); const ys = slice(xs, 1, 1); @@ -24,7 +24,7 @@ test('Iterable#slice slices at one with one item', t => { t.end(); }); -test('Iterable#slice slices at one with multiple items', t => { +test('Iterable#slice slices at one with multiple items', (t, [slice]) => { const xs = from([1, 2, 3, 4]); const ys = slice(xs, 1, 2); @@ -35,7 +35,7 @@ test('Iterable#slice slices at one with multiple items', t => { t.end(); }); -test('Iterable#slice slices at one with no end', t => { +test('Iterable#slice slices at one with no end', (t, [slice]) => { const xs = from([1, 2, 3, 4]); const ys = slice(xs, 1); @@ -47,7 +47,7 @@ test('Iterable#slice slices at one with no end', t => { t.end(); }); -test('Iterable#slice slices at zero with no end', t => { +test('Iterable#slice slices at zero with no end', (t, [slice]) => { const xs = from([1, 2, 3, 4]); const ys = slice(xs, 0); diff --git a/spec/iterable-operators/some-spec.ts b/spec/iterable-operators/some-spec.ts index 940d2a02..93908fb6 100644 --- a/spec/iterable-operators/some-spec.ts +++ b/spec/iterable-operators/some-spec.ts @@ -1,14 +1,14 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { some } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.some]); -test('Iterable#some some true', t => { +test('Iterable#some some true', (t, [some]) => { const res = some([1, 2, 3, 4], x => x % 2 === 0); t.true(res); t.end(); }); -test('Iterable#some none true', t => { +test('Iterable#some none true', (t, [some]) => { const res = some([2, 8, 4, 6], x => x % 2 !== 0); t.false(res); t.end(); diff --git a/spec/iterable-operators/startwith-spec.ts b/spec/iterable-operators/startwith-spec.ts index 8f665982..acdcc695 100644 --- a/spec/iterable-operators/startwith-spec.ts +++ b/spec/iterable-operators/startwith-spec.ts @@ -1,20 +1,20 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.startWith]); const { range } = Ix.iterable; const { sequenceEqual } = Ix.iterable; -const { startWith } = Ix.iterable; const { take } = Ix.iterable; const { tap } = Ix.iterable; const { toArray } = Ix.iterable; -test('Iterable#startWith adds to beginning', t => { +test('Iterable#startWith adds to beginning', (t, [startWith]) => { const e = range(1, 5); const r = startWith(e, 0); t.true(sequenceEqual(r, range(0, 6))); t.end(); }); -test('Iterable#startWith adds without causing effects', t => { +test('Iterable#startWith adds without causing effects', (t, [startWith]) => { let oops = false; const e = tap(range(1, 5), { next: () => oops = true }); toArray(take(startWith(e, 0), 1)); diff --git a/spec/iterable-operators/sum-spec.ts b/spec/iterable-operators/sum-spec.ts index 8f95ab90..919d1803 100644 --- a/spec/iterable-operators/sum-spec.ts +++ b/spec/iterable-operators/sum-spec.ts @@ -1,32 +1,32 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { sum } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.sum]); -test('Iterable#sum laws', t => { +test('Iterable#sum laws', (t, [sum]) => { const xs = [1, 2, 3]; t.equal(sum(xs), sum(xs, x => x)); t.end(); }); -test('Iterable#sum no selector empty', t => { +test('Iterable#sum no selector empty', (t, [sum]) => { const xs: number[] = []; t.equal(sum(xs), 0); t.end(); }); -test('#Iterable#sum no selector', t => { +test('#Iterable#sum no selector', (t, [sum]) => { const xs: number[] = [1, 2, 3]; t.equal(sum(xs), 6); t.end(); }); -test('Iterable#sum with selector empty', t => { +test('Iterable#sum with selector empty', (t, [sum]) => { const xs: number[] = []; t.equal(sum(xs, x => x * 2), 0); t.end(); }); -test('#Iterable#sum with selector', t => { +test('#Iterable#sum with selector', (t, [sum]) => { const xs: number[] = [1, 2, 3]; t.equal(sum(xs, x => x * 2), 12); t.end(); diff --git a/spec/iterable-operators/take-spec.ts b/spec/iterable-operators/take-spec.ts index 5a822173..48303506 100644 --- a/spec/iterable-operators/take-spec.ts +++ b/spec/iterable-operators/take-spec.ts @@ -1,10 +1,10 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { take } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.take]); const { _throw } = Ix.iterable; import { hasNext, noNext } from '../iterablehelpers'; -test('Iterable#take zero or less takes nothing', t => { +test('Iterable#take zero or less takes nothing', (t, [take]) => { const xs = [1, 2, 3, 4]; const ys = take(xs, -2); @@ -13,7 +13,7 @@ test('Iterable#take zero or less takes nothing', t => { t.end(); }); -test('Iterable#take less than count', t => { +test('Iterable#take less than count', (t, [take]) => { const xs = [1, 2, 3, 4]; const ys = take(xs, 2); @@ -24,7 +24,7 @@ test('Iterable#take less than count', t => { t.end(); }); -test('Iterable#take more than count', t => { +test('Iterable#take more than count', (t, [take]) => { const xs = [1, 2, 3, 4]; const ys = take(xs, 10); @@ -37,7 +37,7 @@ test('Iterable#take more than count', t => { t.end(); }); -test('Iterable#take throws with error', t => { +test('Iterable#take throws with error', (t, [take]) => { const xs = _throw(new Error()); const ys = take(xs, 2); diff --git a/spec/iterable-operators/takelast-spec.ts b/spec/iterable-operators/takelast-spec.ts index 00358605..c8d19801 100644 --- a/spec/iterable-operators/takelast-spec.ts +++ b/spec/iterable-operators/takelast-spec.ts @@ -1,30 +1,30 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.takeLast]); const { range } = Ix.iterable; const { sequenceEqual } = Ix.iterable; const { skip } = Ix.iterable; -const { takeLast } = Ix.iterable; -test('Iterable#takeLast none', t => { +test('Iterable#takeLast none', (t, [takeLast]) => { const res = takeLast(range(1, 5), 0); t.true(sequenceEqual(res, [])); t.end(); }); -test('Iterable#takeLast empty', t => { +test('Iterable#takeLast empty', (t, [takeLast]) => { const res = takeLast([], 1); t.true(sequenceEqual(res, [])); t.end(); }); -test('Iterable#takeLast has all', t => { +test('Iterable#takeLast has all', (t, [takeLast]) => { const e = range(0, 5); const r = takeLast(e, 5); t.true(sequenceEqual(r, e)); t.end(); }); -test('Iterable#takeLast has part', t => { +test('Iterable#takeLast has part', (t, [takeLast]) => { const e = range(0, 5); const r = takeLast(e, 3); t.true(sequenceEqual(r, skip(e, 2))); diff --git a/spec/iterable-operators/takewhile-spec.ts b/spec/iterable-operators/takewhile-spec.ts index 5993f9d5..f4f306b4 100644 --- a/spec/iterable-operators/takewhile-spec.ts +++ b/spec/iterable-operators/takewhile-spec.ts @@ -1,9 +1,9 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { takeWhile } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.takeWhile]); import { hasNext, noNext } from '../iterablehelpers'; -test('Iterable#takeWhile some match', t => { +test('Iterable#takeWhile some match', (t, [takeWhile]) => { const xs = [1, 2, 3, 4]; const ys = takeWhile(xs, x => x < 3); @@ -14,7 +14,7 @@ test('Iterable#takeWhile some match', t => { t.end(); }); -test('Iterable#takeWhile no match', t => { +test('Iterable#takeWhile no match', (t, [takeWhile]) => { const xs = [1, 2, 3, 4]; const ys = takeWhile(xs, () => false); @@ -23,7 +23,7 @@ test('Iterable#takeWhile no match', t => { t.end(); }); -test('Itearble#takeWhile all match', t => { +test('Itearble#takeWhile all match', (t, [takeWhile]) => { const xs = [1, 2, 3, 4]; const ys = takeWhile(xs, () => true); @@ -36,7 +36,7 @@ test('Itearble#takeWhile all match', t => { t.end(); }); -test('Iterable#takeWhile uses index', t => { +test('Iterable#takeWhile uses index', (t, [takeWhile]) => { const xs = [1, 2, 3, 4]; const ys = takeWhile(xs, (x, i) => i < 2); @@ -47,7 +47,7 @@ test('Iterable#takeWhile uses index', t => { t.end(); }); -test('Iterable#takeWhile predicate throws', t => { +test('Iterable#takeWhile predicate throws', (t, [takeWhile]) => { const xs = [1, 2, 3, 4]; const ys = takeWhile(xs, () => { throw new Error(); }); diff --git a/spec/iterable-operators/tap-spec.ts b/spec/iterable-operators/tap-spec.ts index ae01cd3c..35dd4c99 100644 --- a/spec/iterable-operators/tap-spec.ts +++ b/spec/iterable-operators/tap-spec.ts @@ -1,10 +1,10 @@ import * as Ix from '../Ix'; -import * as test from 'tape'; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.tap]); const { range } = Ix.iterable; -const { tap } = Ix.iterable; const { _throw } = Ix.iterable; -test('Itearble#tap next', t => { +test('Itearble#tap next', (t, [tap]) => { let n = 0; let source = tap(range(0, 10), { next: function (x) { @@ -19,7 +19,7 @@ test('Itearble#tap next', t => { t.end(); }); -test('Iterable#tap next complete', t => { +test('Iterable#tap next complete', (t, [tap]) => { let n = 0; let source = tap(range(0, 10), { next: function (x) { @@ -37,7 +37,7 @@ test('Iterable#tap next complete', t => { t.end(); }); -test('Iterable#tap with error', t => { +test('Iterable#tap with error', (t, [tap]) => { let err = new Error(); let ok = false; @@ -70,7 +70,7 @@ class MyObserver { } } -test('Itearble#tap with observer class', t => { +test('Itearble#tap with observer class', (t, [tap]) => { const obs = new MyObserver(); const source = tap(range(0, 10), obs); diff --git a/spec/iterable-operators/toarray-spec.ts b/spec/iterable-operators/toarray-spec.ts index fd1b65b6..f32427bb 100644 --- a/spec/iterable-operators/toarray-spec.ts +++ b/spec/iterable-operators/toarray-spec.ts @@ -1,16 +1,16 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.toArray]); const { sequenceEqual } = Ix.iterable; -const { toArray } = Ix.iterable; -test('Iterable#toArray some', t => { +test('Iterable#toArray some', (t, [toArray]) => { const xs = [42, 25, 39]; const res = toArray(xs); t.true(sequenceEqual(res, xs)); t.end(); }); -test('Iterable#toArray empty', t => { +test('Iterable#toArray empty', (t, [toArray]) => { const res = toArray([]); t.equal(res.length, 0); t.end(); diff --git a/spec/iterable-operators/tomap-spec.ts b/spec/iterable-operators/tomap-spec.ts index 866257fc..a082b6a1 100644 --- a/spec/iterable-operators/tomap-spec.ts +++ b/spec/iterable-operators/tomap-spec.ts @@ -1,29 +1,29 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { toMap } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.toMap]); -test('Iterable#toMap stores values', t => { +test('Iterable#toMap stores values', (t, [toMap]) => { const res = toMap([1, 4], x => x % 2); t.equal(res.get(0), 4); t.equal(res.get(1), 1); t.end(); }); -test('Iterable#toMap overwrites duplicates', t => { +test('Iterable#toMap overwrites duplicates', (t, [toMap]) => { const res = toMap([1, 4, 2], x => x % 2); t.equal(res.get(0), 2); t.equal(res.get(1), 1); t.end(); }); -test('Iterable#toMap with element selector', t => { +test('Iterable#toMap with element selector', (t, [toMap]) => { const res = toMap([1, 4], x => x % 2, x => x + 1); t.equal(res.get(0), 5); t.equal(res.get(1), 2); t.end(); }); -test('Iterable#toMap with element selector overwrites duplicates', t => { +test('Iterable#toMap with element selector overwrites duplicates', (t, [toMap]) => { const res = toMap([1, 4, 2], x => x % 2, x => x + 1); t.equal(res.get(0), 3); t.equal(res.get(1), 2); diff --git a/spec/iterable-operators/toset-spec.ts b/spec/iterable-operators/toset-spec.ts index 30fc3f82..57209658 100644 --- a/spec/iterable-operators/toset-spec.ts +++ b/spec/iterable-operators/toset-spec.ts @@ -1,22 +1,22 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.toSet]); const { sequenceEqual } = Ix.iterable; -const { toSet } = Ix.iterable; -test('Iterable#toSet non-empty', t => { +test('Iterable#toSet non-empty', (t, [toSet]) => { const xs = [1, 2, 3, 4, 5]; const res = toSet(xs); t.true(sequenceEqual(res, xs)); t.end(); }); -test('Iterable#toSet empty', t => { +test('Iterable#toSet empty', (t, [toSet]) => { const res = toSet([]); t.equal(res.size, 0); t.end(); }); -test('Iterable#toSet trims', t => { +test('Iterable#toSet trims', (t, [toSet]) => { const xs = [1, 2, 3, 3, 2, 1]; const ys = [1, 2, 3]; const res = toSet(xs); diff --git a/spec/iterable-operators/union-spec.ts b/spec/iterable-operators/union-spec.ts index 6ef56044..2bdd309d 100644 --- a/spec/iterable-operators/union-spec.ts +++ b/spec/iterable-operators/union-spec.ts @@ -1,9 +1,9 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { union } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.union]); import { hasNext, noNext } from '../iterablehelpers'; -test('Iterable#union with default comparer', t => { +test('Iterable#union with default comparer', (t, [union]) => { const xs = [1, 2, 3]; const ys = [3, 5, 1, 4]; const res = union(xs, ys); @@ -18,7 +18,7 @@ test('Iterable#union with default comparer', t => { t.end(); }); -test('Iterable#union with custom comparer', t => { +test('Iterable#union with custom comparer', (t, [union]) => { const comparer = (x: number, y: number) => Math.abs(x) === Math.abs(y); const xs = [1, 2, -3]; const ys = [3, 5, -1, 4]; diff --git a/spec/iterable-operators/zip-spec.ts b/spec/iterable-operators/zip-spec.ts index b8aa4441..e0b65f6d 100644 --- a/spec/iterable-operators/zip-spec.ts +++ b/spec/iterable-operators/zip-spec.ts @@ -1,10 +1,10 @@ import * as Ix from '../Ix'; -import * as test from 'tape-async'; -const { zip } = Ix.iterable; +import { testOperator } from '../iterablehelpers'; +const test = testOperator([Ix.iterable.zip]); const { _throw } = Ix.iterable; import { hasNext, noNext } from '../iterablehelpers'; -test('Iterable#zip equal length', t => { +test('Iterable#zip equal length', (t, [zip]) => { const xs = [1, 2, 3]; const ys = [4, 5, 6]; const res = zip(([x, y]) => x * y, xs, ys); @@ -17,7 +17,7 @@ test('Iterable#zip equal length', t => { t.end(); }); -test('Iterable#zip left longer', t => { +test('Iterable#zip left longer', (t, [zip]) => { const xs = [1, 2, 3, 4]; const ys = [4, 5, 6]; const res = zip(([x, y]) => x * y, xs, ys); @@ -30,7 +30,7 @@ test('Iterable#zip left longer', t => { t.end(); }); -test('Iterable#zip right longer', t => { +test('Iterable#zip right longer', (t, [zip]) => { const xs = [1, 2, 3]; const ys = [4, 5, 6, 7]; const res = zip(([x, y]) => x * y, xs, ys); @@ -43,7 +43,7 @@ test('Iterable#zip right longer', t => { t.end(); }); -test('Iterable#zip multiple sources', t => { +test('Iterable#zip multiple sources', (t, [zip]) => { const xs = [1, 2, 3]; const ys = [4, 5, 6, 7]; const zs = [8, 9, 10]; @@ -57,7 +57,7 @@ test('Iterable#zip multiple sources', t => { t.end(); }); -test('Iterable#zip left throws', t => { +test('Iterable#zip left throws', (t, [zip]) => { const xs = _throw(new Error()); const ys = [4, 5, 6]; const res = zip(([x, y]) => x * y, xs, ys); @@ -67,7 +67,7 @@ test('Iterable#zip left throws', t => { t.end(); }); -test('Iterable#zip right throws', t => { +test('Iterable#zip right throws', (t, [zip]) => { const xs = [1, 2, 3]; const ys = _throw(new Error()); const res = zip(([x, y]) => x * y, xs, ys); @@ -77,7 +77,7 @@ test('Iterable#zip right throws', t => { t.end(); }); -test('Iterable#zip selector throws', t => { +test('Iterable#zip selector throws', (t, [zip]) => { const xs = [1, 2, 3]; const ys = [4, 5, 6]; const res = zip(([x, y]) => { if (x > 0) { throw new Error(); } return x * y; }, xs, ys); diff --git a/spec/iterablehelpers.ts b/spec/iterablehelpers.ts index 5715a5f8..9c29f05d 100644 --- a/spec/iterablehelpers.ts +++ b/spec/iterablehelpers.ts @@ -1,10 +1,55 @@ -export function hasNext(t: any, source: Iterator, expected: T) { +import * as Ix from './Ix'; +import * as test from 'tape-async'; + +export function hasNext(t: test.Test, source: Iterator, expected: T) { const { done, value } = source.next(); t.false(done, 'should not be done'); t.deepEqual(value, expected); } -export function noNext(t: any, source: Iterator) { +export function noNext(t: test.Test, source: Iterator) { const next = source.next(); t.true(next.done, 'should be done'); } + +const pipe = Ix.Iterable.prototype.pipe; +const operatorNamesMap = Object.keys(Ix.iterable).reduce( + (map, name) => map.set((Ix.iterable as any)[name], name), + new Map() +); + +export function testOperator(op: Op) { + const ops = (Array.isArray(op) ? op : [op]) as any as Function[]; + const internalNames = ops.map((op) => operatorNamesMap.get(op)!); + const fnNames = internalNames.map((name) => name.replace('_', '')); + const pipeFns = internalNames.map((name) => (Ix.iterablePipe as any)[name]); + return function operatorTest(message: string, testFn: (t: test.Test, op: Op) => any | Promise) { + test(`(fp) ${message}`, t => (testFn as any)(t, ops)); + test(`(proto) ${message}`, t => (testFn as any)(t, fnNames.map(wrapProto))); + if (pipeFns.every((xs) => typeof xs === 'function')) { + test(`(pipe) ${message}`, t => (testFn as any)(t, pipeFns.map(wrapPipe))); + } else { + console.log(`Iterable missing a pipe fn in [${internalNames.join(`, `)}], skipping...`); + } + }; +} + +function wrapProto(name: any) { + return function (source: any, ...args: any[]) { + return typeof source !== 'function' ? + cast(source)[name].apply(source, args) : + cast(args[0])[name].apply(args[0], [source, ...args.slice(1)]); + }; +} + +function wrapPipe(fn: any) { + return function (source: any, ...args: any[]) { + return typeof source !== 'function' ? + pipe.call(source, fn(...args)) : + pipe.call(args[0], fn(source, ...args.slice(1))); + }; +} + +function cast(source: any): any { + return source instanceof Ix.Iterable ? source : Ix.Iterable.from(source); +} \ No newline at end of file diff --git a/src/Ix.internal.ts b/src/Ix.internal.ts index ccafd763..18d39e10 100644 --- a/src/Ix.internal.ts +++ b/src/Ix.internal.ts @@ -1,6 +1,9 @@ -import iterableX from './iterable/__modules'; -import asynciterableX from './asynciterable/__modules'; +import * as iterableX from './iterable/__modules'; +import * as iterableXPipe from './iterable/pipe/__modules'; +import * as asynciterableX from './asynciterable/__modules'; +import * as asynciterableXPipe from './asynciterable/pipe/__modules'; export { iterableX as iterable, asynciterableX as asynciterable }; +export { iterableXPipe as iterablePipe, asynciterableXPipe as asynciterablePipe }; /* These declarations are needed for the closure/umd targets */ export declare namespace Symbol { @@ -12,7 +15,9 @@ try { if (typeof Ix === 'object') { // string indexers tell closure compiler not to rename these properties Ix['iterable'] = iterableX; + Ix['iterablePipe'] = iterableXPipe; Ix['asynciterable'] = asynciterableX; + Ix['asynciterablePipe'] = asynciterableXPipe; } } catch (e) { /* not the UMD bundle */ diff --git a/src/Ix.ts b/src/Ix.ts index 73d459f6..f5021d9c 100644 --- a/src/Ix.ts +++ b/src/Ix.ts @@ -2,9 +2,11 @@ import { IterableX } from './iterable'; import { AsyncSink } from './asyncsink'; import { AsyncIterableX } from './asynciterable'; import { GroupedIterable } from './iterable/groupby'; -import { OrderedIterableX } from './iterable/orderby'; import { GroupedAsyncIterable } from './asynciterable/groupby'; -import { OrderedAsyncIterableX } from './asynciterable/orderby'; +export { OrderedIterableX as OrderedIterable } from './iterable/orderby'; +export { OrderedIterableBaseX as OrderedIterableBase } from './iterable/orderby'; +export { OrderedAsyncIterableX as OrderedAsyncIterable } from './asynciterable/orderby'; +export { OrderedAsyncIterableBaseX as OrderedAsyncIterableBase } from './asynciterable/orderby'; export { AsyncSink, IterableX as Iterable, AsyncIterableX as AsyncIterable }; @@ -16,9 +18,7 @@ export default { }; export type GroupedIterable = GroupedIterable; -export type OrderedIterable = OrderedIterableX; export type GroupedAsyncIterable = GroupedAsyncIterable; -export type OrderedAsyncIterable = OrderedAsyncIterableX; /* These declarations are needed for the closure/umd targets */ export declare namespace Symbol { diff --git a/src/add/asynciterable-operators/reduce.ts b/src/add/asynciterable-operators/reduce.ts index 20fda792..bcff6176 100644 --- a/src/add/asynciterable-operators/reduce.ts +++ b/src/add/asynciterable-operators/reduce.ts @@ -13,12 +13,12 @@ export async function reduceProto( /** * @ignore */ -export async function reduceProto( +export function reduceProto( this: AsyncIterableX, accumulator: (acc: T | R, value: T, index: number) => R | Promise, ...args: (T | R)[] ): Promise { - return args.length === 3 ? reduce(this, accumulator, args[0]) : reduce(this, accumulator); + return args.length === 1 ? reduce(this, accumulator, args[0]) : reduce(this, accumulator); } AsyncIterableX.prototype.reduce = reduceProto; diff --git a/src/add/asynciterable-operators/reduceright.ts b/src/add/asynciterable-operators/reduceright.ts index 9a461b52..8e592cce 100644 --- a/src/add/asynciterable-operators/reduceright.ts +++ b/src/add/asynciterable-operators/reduceright.ts @@ -13,12 +13,12 @@ export async function reduceRightProto( /** * @ignore */ -export async function reduceRightProto( +export function reduceRightProto( this: AsyncIterableX, accumulator: (acc: T | R, value: T, index: number) => R | Promise, ...args: (T | R)[] ): Promise { - return args.length === 3 + return args.length === 1 ? reduceRight(this, accumulator, args[0]) : reduceRight(this, accumulator); } diff --git a/src/add/asynciterable-operators/scan.ts b/src/add/asynciterable-operators/scan.ts index dfca890e..77f16493 100644 --- a/src/add/asynciterable-operators/scan.ts +++ b/src/add/asynciterable-operators/scan.ts @@ -13,12 +13,12 @@ export function scanProto( /** * @ignore */ -export async function* scanProto( +export function scanProto( this: AsyncIterableX, accumulator: (acc: T | R, value: T, index: number) => R | Promise, ...args: (T | R)[] ): AsyncIterable { - return args.length === 3 ? scan(this, accumulator, args[0]) : scan(this, accumulator); + return args.length === 1 ? scan(this, accumulator, args[0]) : scan(this, accumulator); } AsyncIterableX.prototype.scan = scanProto; diff --git a/src/add/asynciterable-operators/scanright.ts b/src/add/asynciterable-operators/scanright.ts index e62fee6c..a8e01736 100644 --- a/src/add/asynciterable-operators/scanright.ts +++ b/src/add/asynciterable-operators/scanright.ts @@ -13,12 +13,12 @@ export function scanRightProto( /** * @ignore */ -export async function* scanRightProto( +export function scanRightProto( this: AsyncIterableX, accumulator: (acc: T | R, value: T, index: number) => R | Promise, ...args: (T | R)[] ): AsyncIterable { - return args.length === 3 ? scanRight(this, accumulator, args[0]) : scanRight(this, accumulator); + return args.length === 1 ? scanRight(this, accumulator, args[0]) : scanRight(this, accumulator); } AsyncIterableX.prototype.scanRight = scanRightProto; diff --git a/src/add/iterable-operators/reduceright.ts b/src/add/iterable-operators/reduceright.ts index 6ab239f4..3eaba59d 100644 --- a/src/add/iterable-operators/reduceright.ts +++ b/src/add/iterable-operators/reduceright.ts @@ -24,7 +24,7 @@ export function reduceRightProto( fn: (acc: R, x: T, index: number) => R, seed?: T | R ): T | R { - return arguments.length === 3 ? reduceRight(this, fn, seed) : reduceRight(this, fn); + return arguments.length === 2 ? reduceRight(this, fn, seed) : reduceRight(this, fn); } IterableX.prototype.reduceRight = reduceRightProto; diff --git a/src/add/iterable-operators/scan.ts b/src/add/iterable-operators/scan.ts index b716ae44..1bf426b6 100644 --- a/src/add/iterable-operators/scan.ts +++ b/src/add/iterable-operators/scan.ts @@ -18,7 +18,7 @@ export function scanProto( accumulator: (acc: T | R, value: T, index: number) => R, ...args: (T | R)[] ): IterableX { - return scan(this, accumulator, ...args); + return args.length === 1 ? scan(this, accumulator, args[0]) : scan(this, accumulator); } IterableX.prototype.scan = scanProto; diff --git a/src/add/iterable-operators/scanright.ts b/src/add/iterable-operators/scanright.ts index b7b68643..5af6d843 100644 --- a/src/add/iterable-operators/scanright.ts +++ b/src/add/iterable-operators/scanright.ts @@ -18,7 +18,7 @@ export function scanRightProto( accumulator: (acc: T | R, value: T, index: number) => R, ...args: (T | R)[] ): IterableX { - return args.length === 3 ? scanRight(this, accumulator, args[0]) : scanRight(this, accumulator); + return args.length === 1 ? scanRight(this, accumulator, args[0]) : scanRight(this, accumulator); } IterableX.prototype.scanRight = scanRightProto; diff --git a/src/asynciterable.ts b/src/asynciterable.ts index 494f66de..c29d8500 100644 --- a/src/asynciterable.ts +++ b/src/asynciterable.ts @@ -22,66 +22,6 @@ export abstract class AsyncIterableX implements AsyncIterable { } } - pipe(): AsyncIterableX; - pipe(op1: OperatorAsyncFunction): AsyncIterableX; - pipe(op1: OperatorAsyncFunction, op2: OperatorAsyncFunction): AsyncIterableX; - pipe( - op1: OperatorAsyncFunction, - op2: OperatorAsyncFunction, - op3: OperatorAsyncFunction - ): AsyncIterableX; - pipe( - op1: OperatorAsyncFunction, - op2: OperatorAsyncFunction, - op3: OperatorAsyncFunction, - op4: OperatorAsyncFunction - ): AsyncIterableX; - pipe( - op1: OperatorAsyncFunction, - op2: OperatorAsyncFunction, - op3: OperatorAsyncFunction, - op4: OperatorAsyncFunction, - op5: OperatorAsyncFunction - ): AsyncIterableX; - pipe( - op1: OperatorAsyncFunction, - op2: OperatorAsyncFunction, - op3: OperatorAsyncFunction, - op4: OperatorAsyncFunction, - op5: OperatorAsyncFunction, - op6: OperatorAsyncFunction - ): AsyncIterableX; - pipe( - op1: OperatorAsyncFunction, - op2: OperatorAsyncFunction, - op3: OperatorAsyncFunction, - op4: OperatorAsyncFunction, - op5: OperatorAsyncFunction, - op6: OperatorAsyncFunction, - op7: OperatorAsyncFunction - ): AsyncIterableX; - pipe( - op1: OperatorAsyncFunction, - op2: OperatorAsyncFunction, - op3: OperatorAsyncFunction, - op4: OperatorAsyncFunction, - op5: OperatorAsyncFunction, - op6: OperatorAsyncFunction, - op7: OperatorAsyncFunction, - op8: OperatorAsyncFunction - ): AsyncIterableX; - pipe( - op1: OperatorAsyncFunction, - op2: OperatorAsyncFunction, - op3: OperatorAsyncFunction, - op4: OperatorAsyncFunction, - op5: OperatorAsyncFunction, - op6: OperatorAsyncFunction, - op7: OperatorAsyncFunction, - op8: OperatorAsyncFunction, - op9: OperatorAsyncFunction - ): AsyncIterableX; - pipe(...operations: OperatorAsyncFunction[]): AsyncIterableX { if (operations.length === 0) { return this as any; @@ -289,3 +229,71 @@ class OfAsyncIterable extends AsyncIterableX { } } } + +declare module './asynciterable' { + interface AsyncIterableX { + pipe(): AsyncIterableX; + pipe(op1: OperatorAsyncFunction): AsyncIterableX; + pipe( + op1: OperatorAsyncFunction, + op2: OperatorAsyncFunction + ): AsyncIterableX; + pipe( + op1: OperatorAsyncFunction, + op2: OperatorAsyncFunction, + op3: OperatorAsyncFunction + ): AsyncIterableX; + pipe( + op1: OperatorAsyncFunction, + op2: OperatorAsyncFunction, + op3: OperatorAsyncFunction, + op4: OperatorAsyncFunction + ): AsyncIterableX; + pipe( + op1: OperatorAsyncFunction, + op2: OperatorAsyncFunction, + op3: OperatorAsyncFunction, + op4: OperatorAsyncFunction, + op5: OperatorAsyncFunction + ): AsyncIterableX; + pipe( + op1: OperatorAsyncFunction, + op2: OperatorAsyncFunction, + op3: OperatorAsyncFunction, + op4: OperatorAsyncFunction, + op5: OperatorAsyncFunction, + op6: OperatorAsyncFunction + ): AsyncIterableX; + pipe( + op1: OperatorAsyncFunction, + op2: OperatorAsyncFunction, + op3: OperatorAsyncFunction, + op4: OperatorAsyncFunction, + op5: OperatorAsyncFunction, + op6: OperatorAsyncFunction, + op7: OperatorAsyncFunction + ): AsyncIterableX; + pipe( + op1: OperatorAsyncFunction, + op2: OperatorAsyncFunction, + op3: OperatorAsyncFunction, + op4: OperatorAsyncFunction, + op5: OperatorAsyncFunction, + op6: OperatorAsyncFunction, + op7: OperatorAsyncFunction, + op8: OperatorAsyncFunction + ): AsyncIterableX; + pipe( + op1: OperatorAsyncFunction, + op2: OperatorAsyncFunction, + op3: OperatorAsyncFunction, + op4: OperatorAsyncFunction, + op5: OperatorAsyncFunction, + op6: OperatorAsyncFunction, + op7: OperatorAsyncFunction, + op8: OperatorAsyncFunction, + op9: OperatorAsyncFunction + ): AsyncIterableX; + pipe(...operations: OperatorAsyncFunction[]): AsyncIterableX; + } +} diff --git a/src/asynciterable/__modules.ts b/src/asynciterable/__modules.ts index fe596ccf..bcd2127a 100644 --- a/src/asynciterable/__modules.ts +++ b/src/asynciterable/__modules.ts @@ -1,353 +1,106 @@ -import { Observable } from '../observer'; -import { NextAsyncObserver } from '../observer'; -import { ErrorAsyncObserver } from '../observer'; -import { CompletionAsyncObserver } from '../observer'; -import { AsyncIterableX } from '../asynciterable'; -import { GroupedAsyncIterable } from './groupby'; -import { OrderedAsyncIterableX } from './orderby'; -import { OrderedAsyncIterableBaseX } from './orderby'; -import { TimeInterval } from './timeinterval'; -import { Timestamp } from './timestamp'; - -import { asyncify } from './asyncify'; -import { asyncifyErrback } from './asyncifyerrback'; -import { average } from './average'; -import { buffer } from './buffer'; -import { _case } from './case'; -import { _catch } from './catch'; -import { _catchStatic } from './catch'; -import { catchWith } from './catchwith'; -import { chain } from './chain'; -import { concat } from './concat'; -import { concatAll } from './concatall'; -import { concatStatic } from './concat'; -import { count } from './count'; -import { create } from './create'; -import { debounce } from './debounce'; -import { defaultIfEmpty } from './defaultifempty'; -import { defer } from './defer'; -import { distinct } from './distinct'; -import { distinctUntilChanged } from './distinctuntilchanged'; -import { doWhile } from './dowhile'; -import { elementAt } from './elementat'; -import { empty } from './empty'; -import { endWith } from './endwith'; -import { every } from './every'; -import { except } from './except'; -import { expand } from './expand'; -import { filter } from './filter'; -import { _finally } from './finally'; -import { find } from './find'; -import { findIndex } from './findindex'; -import { first } from './first'; -import { flatMap } from './flatmap'; -import { flatten } from './flatten'; -import { _for } from './for'; -import { fromEvent } from './fromevent'; -import { fromEventPattern } from './fromeventpattern'; -import { generate } from './generate'; -import { generateTime } from './generatetime'; -import { groupBy } from './groupby'; -import { groupJoin } from './groupjoin'; -import { _if } from './if'; -import { ignoreElements } from './ignoreelements'; -import { includes } from './includes'; -import { innerJoin } from './innerjoin'; -import { intersect } from './intersect'; -import { isEmpty } from './isempty'; -import { last } from './last'; -import { map } from './map'; -import { max } from './max'; -import { maxBy } from './maxby'; -import { memoize } from './memoize'; -import { merge } from './merge'; -import { mergeAll } from './mergeall'; -import { min } from './min'; -import { minBy } from './minby'; -import { ofEntries } from './ofentries'; -import { ofKeys } from './ofkeys'; -import { ofValues } from './ofvalues'; -import { onErrorResumeNext } from './onerrorresumenext'; -import { onErrorResumeNextStatic } from './onerrorresumenext'; -import { orderBy } from './orderby'; -import { orderByDescending } from './orderby'; -import { thenBy } from './orderby'; -import { thenByDescending } from './orderby'; -import { pairwise } from './pairwise'; -import { partition } from './partition'; -import { pluck } from './pluck'; -import { publish } from './publish'; -import { race } from './race'; -import { range } from './range'; -import { reduce } from './reduce'; -import { reduceRight } from './reduceright'; -import { repeat } from './repeat'; -import { repeatStatic } from './repeat'; -import { retry } from './retry'; -import { reverse } from './reverse'; -import { scan } from './scan'; -import { scanRight } from './scanright'; -import { sequenceEqual } from './sequenceequal'; -import { share } from './share'; -import { single } from './single'; -import { skip } from './skip'; -import { skipLast } from './skiplast'; -import { skipUntil } from './skipuntil'; -import { skipWhile } from './skipwhile'; -import { slice } from './slice'; -import { some } from './some'; -import { startWith } from './startwith'; -import { sum } from './sum'; -import { take } from './take'; -import { takeLast } from './takelast'; -import { takeUntil } from './takeuntil'; -import { takeWhile } from './takewhile'; -import { tap } from './tap'; -import { throttle } from './throttle'; -import { timeInterval } from './timeinterval'; -import { timeout } from './timeout'; -import { timestamp } from './timestamp'; -import { _throw } from './throw'; -import { toArray } from './toarray'; -import { toMap } from './tomap'; -import { toObservable } from './toobservable'; -import { toSet } from './toset'; -import { union } from './union'; -import { _while } from './while'; -import { zip } from './zip'; - -import { buffer as bufferPipe } from './pipe/buffer'; -import { _catch as catchPipe } from './pipe/catch'; -import { catchWith as catchWithPipe } from './pipe/catchwith'; -import { concat as concatPipe } from './pipe/concat'; -import { concatAll as concatAllPipe } from './pipe/concatall'; -import { debounce as debouncePipe } from './pipe/debounce'; -import { defaultIfEmpty as defaultIfEmptyPipe } from './pipe/defaultifempty'; -import { delay as delayPipe } from './pipe/delay'; -import { delayEach as delayEachPipe } from './pipe/delayeach'; -import { distinct as distinctPipe } from './pipe/distinct'; -import { distinctUntilChanged as distinctUntilChangedPipe } from './pipe/distinctuntilchanged'; -import { doWhile as doWhilePipe } from './pipe/dowhile'; -import { endWith as endWithPipe } from './pipe/endwith'; -import { except as exceptPipe } from './pipe/except'; -import { expand as expandPipe } from './pipe/expand'; -import { filter as filterPipe } from './pipe/filter'; -import { _finally as finallyPipe } from './pipe/finally'; -import { flatMap as flatMapPipe } from './pipe/flatmap'; -import { flatten as flattenPipe } from './pipe/flatten'; -import { groupBy as groupByPipe } from './pipe/groupby'; -import { groupJoin as groupJoinPipe } from './pipe/groupjoin'; -import { ignoreElements as ignoreElementsPipe } from './pipe/ignoreelements'; -import { innerJoin as innerJoinPipe } from './pipe/innerjoin'; -import { intersect as intersectPipe } from './pipe/intersect'; -import { map as mapPipe } from './pipe/map'; -import { maxBy as maxByPipe } from './pipe/maxby'; -import { memoize as memoizePipe } from './pipe/memoize'; -import { merge as mergePipe } from './pipe/merge'; -import { mergeAll as mergeAllPipe } from './pipe/mergeall'; -import { minBy as minByPipe } from './pipe/minby'; -import { onErrorResumeNext as onErrorResumeNextPipe } from './pipe/onerrorresumenext'; -import { pairwise as pairwisePipe } from './pipe/pairwise'; -import { pluck as pluckPipe } from './pipe/pluck'; -import { publish as publishPipe } from './pipe/publish'; -import { repeat as repeatPipe } from './pipe/repeat'; -import { retry as retryPipe } from './pipe/retry'; -import { reverse as reversePipe } from './pipe/reverse'; -import { scan as scanPipe } from './pipe/scan'; -import { scanRight as scanRightPipe } from './pipe/scanright'; -import { share as sharePipe } from './pipe/share'; -import { skip as skipPipe } from './pipe/skip'; -import { skipLast as skipLastPipe } from './pipe/skiplast'; -import { skipUntil as skipUntilPipe } from './pipe/skipuntil'; -import { skipWhile as skipWhilePipe } from './pipe/skipwhile'; -import { slice as slicePipe } from './pipe/slice'; -import { startWith as startWithPipe } from './pipe/startwith'; -import { take as takePipe } from './pipe/take'; -import { takeLast as takeLastPipe } from './pipe/takelast'; -import { takeUntil as takeUntilPipe } from './pipe/takeuntil'; -import { takeWhile as takeWhilePipe } from './pipe/takewhile'; -import { tap as tapPipe } from './pipe/tap'; -import { throttle as throttlePipe } from './pipe/throttle'; -import { timeInterval as timeIntervalPipe } from './pipe/timeinterval'; -import { timeout as timeoutPipe } from './pipe/timeout'; -import { timestamp as timestampPipe } from './pipe/timestamp'; -import { union as unionPipe } from './pipe/union'; -import { zip as zipPipe } from './pipe/zip'; - -export type AsyncIterableX = AsyncIterableX; -export type Observable = Observable; -export type NextAsyncObserver = NextAsyncObserver; -export type ErrorAsyncObserver = ErrorAsyncObserver; -export type CompletionAsyncObserver = CompletionAsyncObserver; -export type GroupedAsyncIterable = GroupedAsyncIterable; -export type OrderedAsyncIterableX = OrderedAsyncIterableX; -export type OrderedAsyncIterableBaseX = OrderedAsyncIterableBaseX; -export type TimeInterval = TimeInterval; -export type Timestamp = Timestamp; - -export default { - asyncify, - asyncifyErrback, - average, - buffer, - _case, - _catch, - _catchStatic, - catchWith, - chain, - concat, - concatAll, - concatStatic, - count, - create, - debounce, - defaultIfEmpty, - defer, - distinct, - distinctUntilChanged, - doWhile, - elementAt, - empty, - endWith, - every, - except, - expand, - filter, - _finally, - find, - findIndex, - first, - flatMap, - flatten, - _for, - fromEvent, - fromEventPattern, - generate, - generateTime, - groupBy, - groupJoin, - _if, - ignoreElements, - includes, - innerJoin, - intersect, - isEmpty, - last, - map, - max, - maxBy, - memoize, - merge, - mergeAll, - min, - minBy, - ofEntries, - ofKeys, - ofValues, - onErrorResumeNext, - onErrorResumeNextStatic, - orderBy, - orderByDescending, - thenBy, - thenByDescending, - pairwise, - partition, - pluck, - publish, - race, - range, - reduce, - reduceRight, - repeat, - repeatStatic, - retry, - reverse, - scan, - scanRight, - sequenceEqual, - share, - single, - skip, - skipLast, - skipUntil, - skipWhile, - slice, - some, - startWith, - sum, - take, - takeLast, - takeUntil, - takeWhile, - tap, - throttle, - timeInterval, - timestamp, - timeout, - _throw, - toArray, - toMap, - toObservable, - toSet, - union, - _while, - zip, - - bufferPipe, - catchPipe, - catchWithPipe, - concatPipe, - concatAllPipe, - debouncePipe, - defaultIfEmptyPipe, - delayPipe, - delayEachPipe, - distinctPipe, - distinctUntilChangedPipe, - doWhilePipe, - endWithPipe, - exceptPipe, - expandPipe, - filterPipe, - finallyPipe, - flatMapPipe, - flattenPipe, - groupByPipe, - groupJoinPipe, - ignoreElementsPipe, - innerJoinPipe, - intersectPipe, - mapPipe, - maxByPipe, - memoizePipe, - mergePipe, - mergeAllPipe, - minByPipe, - onErrorResumeNextPipe, - pairwisePipe, - pluckPipe, - publishPipe, - repeatPipe, - retryPipe, - reversePipe, - scanPipe, - scanRightPipe, - sharePipe, - skipPipe, - skipLastPipe, - skipUntilPipe, - skipWhilePipe, - slicePipe, - startWithPipe, - takePipe, - takeLastPipe, - takeUntilPipe, - takeWhilePipe, - tapPipe, - throttlePipe, - timeIntervalPipe, - timestampPipe, - timeoutPipe, - unionPipe, - zipPipe -}; +export { asyncify } from './asyncify'; +export { asyncifyErrback } from './asyncifyerrback'; +export { average } from './average'; +export { buffer } from './buffer'; +export { _case } from './case'; +export { _catch } from './catch'; +export { _catchStatic } from './catch'; +export { catchWith } from './catchwith'; +export { chain } from './chain'; +export { concat } from './concat'; +export { concatAll } from './concatall'; +export { concatStatic } from './concat'; +export { count } from './count'; +export { create } from './create'; +export { debounce } from './debounce'; +export { defaultIfEmpty } from './defaultifempty'; +export { defer } from './defer'; +export { distinct } from './distinct'; +export { distinctUntilChanged } from './distinctuntilchanged'; +export { doWhile } from './dowhile'; +export { elementAt } from './elementat'; +export { empty } from './empty'; +export { endWith } from './endwith'; +export { every } from './every'; +export { except } from './except'; +export { expand } from './expand'; +export { filter } from './filter'; +export { _finally } from './finally'; +export { find } from './find'; +export { findIndex } from './findindex'; +export { first } from './first'; +export { flatMap } from './flatmap'; +export { flatten } from './flatten'; +export { _for } from './for'; +export { fromEvent } from './fromevent'; +export { fromEventPattern } from './fromeventpattern'; +export { generate } from './generate'; +export { generateTime } from './generatetime'; +export { groupBy } from './groupby'; +export { groupJoin } from './groupjoin'; +export { _if } from './if'; +export { ignoreElements } from './ignoreelements'; +export { includes } from './includes'; +export { innerJoin } from './innerjoin'; +export { intersect } from './intersect'; +export { isEmpty } from './isempty'; +export { last } from './last'; +export { map } from './map'; +export { max } from './max'; +export { maxBy } from './maxby'; +export { memoize } from './memoize'; +export { merge } from './merge'; +export { mergeAll } from './mergeall'; +export { min } from './min'; +export { minBy } from './minby'; +export { ofEntries } from './ofentries'; +export { ofKeys } from './ofkeys'; +export { ofValues } from './ofvalues'; +export { onErrorResumeNext } from './onerrorresumenext'; +export { onErrorResumeNextStatic } from './onerrorresumenext'; +export { orderBy } from './orderby'; +export { orderByDescending } from './orderby'; +export { thenBy } from './orderby'; +export { thenByDescending } from './orderby'; +export { pairwise } from './pairwise'; +export { partition } from './partition'; +export { pluck } from './pluck'; +export { publish } from './publish'; +export { race } from './race'; +export { range } from './range'; +export { reduce } from './reduce'; +export { reduceRight } from './reduceright'; +export { repeat } from './repeat'; +export { repeatStatic } from './repeat'; +export { retry } from './retry'; +export { reverse } from './reverse'; +export { scan } from './scan'; +export { scanRight } from './scanright'; +export { sequenceEqual } from './sequenceequal'; +export { share } from './share'; +export { single } from './single'; +export { skip } from './skip'; +export { skipLast } from './skiplast'; +export { skipUntil } from './skipuntil'; +export { skipWhile } from './skipwhile'; +export { slice } from './slice'; +export { some } from './some'; +export { startWith } from './startwith'; +export { sum } from './sum'; +export { take } from './take'; +export { takeLast } from './takelast'; +export { takeUntil } from './takeuntil'; +export { takeWhile } from './takewhile'; +export { tap } from './tap'; +export { throttle } from './throttle'; +export { timeInterval } from './timeinterval'; +export { timeout } from './timeout'; +export { timestamp } from './timestamp'; +export { _throw } from './throw'; +export { toArray } from './toarray'; +export { toMap } from './tomap'; +export { toObservable } from './toobservable'; +export { toSet } from './toset'; +export { union } from './union'; +export { _while } from './while'; +export { zip } from './zip'; diff --git a/src/asynciterable/pipe/__modules.ts b/src/asynciterable/pipe/__modules.ts new file mode 100644 index 00000000..0a60e093 --- /dev/null +++ b/src/asynciterable/pipe/__modules.ts @@ -0,0 +1,57 @@ +export { buffer } from './buffer'; +export { _catch } from './catch'; +export { catchWith } from './catchwith'; +export { concat } from './concat'; +export { concatAll } from './concatall'; +export { debounce } from './debounce'; +export { defaultIfEmpty } from './defaultifempty'; +export { delay } from './delay'; +export { delayEach } from './delayeach'; +export { distinct } from './distinct'; +export { distinctUntilChanged } from './distinctuntilchanged'; +export { doWhile } from './dowhile'; +export { endWith } from './endwith'; +export { except } from './except'; +export { expand } from './expand'; +export { filter } from './filter'; +export { _finally } from './finally'; +export { flatMap } from './flatmap'; +export { flatten } from './flatten'; +export { groupBy } from './groupby'; +export { groupJoin } from './groupjoin'; +export { ignoreElements } from './ignoreelements'; +export { innerJoin } from './innerjoin'; +export { intersect } from './intersect'; +export { map } from './map'; +export { maxBy } from './maxby'; +export { memoize } from './memoize'; +export { merge } from './merge'; +export { mergeAll } from './mergeall'; +export { minBy } from './minby'; +export { onErrorResumeNext } from './onerrorresumenext'; +export { pairwise } from './pairwise'; +export { pluck } from './pluck'; +export { publish } from './publish'; +export { repeat } from './repeat'; +export { retry } from './retry'; +export { reverse } from './reverse'; +export { scan } from './scan'; +export { scanRight } from './scanright'; +export { share } from './share'; +export { skip } from './skip'; +export { skipLast } from './skiplast'; +export { skipUntil } from './skipuntil'; +export { skipWhile } from './skipwhile'; +export { slice } from './slice'; +export { startWith } from './startwith'; +export { take } from './take'; +export { takeLast } from './takelast'; +export { takeUntil } from './takeuntil'; +export { takeWhile } from './takewhile'; +export { tap } from './tap'; +export { throttle } from './throttle'; +export { timeInterval } from './timeinterval'; +export { timeout } from './timeout'; +export { timestamp } from './timestamp'; +export { union } from './union'; +export { zip } from './zip'; diff --git a/src/iterable.ts b/src/iterable.ts index 34ccc19d..e4c23fec 100644 --- a/src/iterable.ts +++ b/src/iterable.ts @@ -18,67 +18,6 @@ export abstract class IterableX implements Iterable { } } - pipe(): IterableX; - pipe(op1: OperatorFunction): IterableX; - pipe(op1: OperatorFunction, op2: OperatorFunction): IterableX; - pipe( - op1: OperatorFunction, - op2: OperatorFunction, - op3: OperatorFunction - ): IterableX; - pipe( - op1: OperatorFunction, - op2: OperatorFunction, - op3: OperatorFunction, - op4: OperatorFunction - ): IterableX; - pipe( - op1: OperatorFunction, - op2: OperatorFunction, - op3: OperatorFunction, - op4: OperatorFunction, - op5: OperatorFunction - ): IterableX; - pipe( - op1: OperatorFunction, - op2: OperatorFunction, - op3: OperatorFunction, - op4: OperatorFunction, - op5: OperatorFunction, - op6: OperatorFunction - ): IterableX; - pipe( - op1: OperatorFunction, - op2: OperatorFunction, - op3: OperatorFunction, - op4: OperatorFunction, - op5: OperatorFunction, - op6: OperatorFunction, - op7: OperatorFunction - ): IterableX; - pipe( - op1: OperatorFunction, - op2: OperatorFunction, - op3: OperatorFunction, - op4: OperatorFunction, - op5: OperatorFunction, - op6: OperatorFunction, - op7: OperatorFunction, - op8: OperatorFunction - ): IterableX; - pipe( - op1: OperatorFunction, - op2: OperatorFunction, - op3: OperatorFunction, - op4: OperatorFunction, - op5: OperatorFunction, - op6: OperatorFunction, - op7: OperatorFunction, - op8: OperatorFunction, - op9: OperatorFunction - ): IterableX; - /* tslint:enable:max-line-length */ - pipe(...operations: OperatorFunction[]): IterableX { if (operations.length === 0) { return this as any; @@ -156,3 +95,68 @@ class OfIterable extends IterableX { yield* this._args; } } + +declare module './iterable' { + interface IterableX { + pipe(): IterableX; + pipe(op1: OperatorFunction): IterableX; + pipe(op1: OperatorFunction, op2: OperatorFunction): IterableX; + pipe( + op1: OperatorFunction, + op2: OperatorFunction, + op3: OperatorFunction + ): IterableX; + pipe( + op1: OperatorFunction, + op2: OperatorFunction, + op3: OperatorFunction, + op4: OperatorFunction + ): IterableX; + pipe( + op1: OperatorFunction, + op2: OperatorFunction, + op3: OperatorFunction, + op4: OperatorFunction, + op5: OperatorFunction + ): IterableX; + pipe( + op1: OperatorFunction, + op2: OperatorFunction, + op3: OperatorFunction, + op4: OperatorFunction, + op5: OperatorFunction, + op6: OperatorFunction + ): IterableX; + pipe( + op1: OperatorFunction, + op2: OperatorFunction, + op3: OperatorFunction, + op4: OperatorFunction, + op5: OperatorFunction, + op6: OperatorFunction, + op7: OperatorFunction + ): IterableX; + pipe( + op1: OperatorFunction, + op2: OperatorFunction, + op3: OperatorFunction, + op4: OperatorFunction, + op5: OperatorFunction, + op6: OperatorFunction, + op7: OperatorFunction, + op8: OperatorFunction + ): IterableX; + pipe( + op1: OperatorFunction, + op2: OperatorFunction, + op3: OperatorFunction, + op4: OperatorFunction, + op5: OperatorFunction, + op6: OperatorFunction, + op7: OperatorFunction, + op8: OperatorFunction, + op9: OperatorFunction + ): IterableX; + pipe(...operations: OperatorFunction[]): IterableX; + } +} diff --git a/src/iterable/__modules.ts b/src/iterable/__modules.ts index d9c87377..d29b9b04 100644 --- a/src/iterable/__modules.ts +++ b/src/iterable/__modules.ts @@ -1,295 +1,90 @@ -import { Observable } from '../observer'; -import { NextObserver } from '../observer'; -import { ErrorObserver } from '../observer'; -import { CompletionObserver } from '../observer'; -import { IterableX } from '../iterable'; -import { GroupedIterable } from './groupby'; -import { OrderedIterableX } from './orderby'; -import { OrderedIterableBaseX } from './orderby'; - -import { average } from './average'; -import { buffer } from './buffer'; -import { _case } from './case'; -import { _catch } from './catch'; -import { _catchStatic } from './catch'; -import { catchWith } from './catchwith'; -import { chain } from './chain'; -import { concat } from './concat'; -import { concatAll } from './concatall'; -import { concatStatic } from './concat'; -import { count } from './count'; -import { create } from './create'; -import { defaultIfEmpty } from './defaultifempty'; -import { defer } from './defer'; -import { distinct } from './distinct'; -import { distinctUntilChanged } from './distinctuntilchanged'; -import { doWhile } from './dowhile'; -import { elementAt } from './elementat'; -import { empty } from './empty'; -import { endWith } from './endwith'; -import { every } from './every'; -import { except } from './except'; -import { expand } from './expand'; -import { filter } from './filter'; -import { _finally } from './finally'; -import { find } from './find'; -import { findIndex } from './findindex'; -import { first } from './first'; -import { flatMap } from './flatmap'; -import { flatten } from './flatten'; -import { _for } from './for'; -import { generate } from './generate'; -import { groupBy } from './groupby'; -import { groupJoin } from './groupjoin'; -import { _if } from './if'; -import { ignoreElements } from './ignoreelements'; -import { includes } from './includes'; -import { innerJoin } from './innerjoin'; -import { intersect } from './intersect'; -import { isEmpty } from './isempty'; -import { last } from './last'; -import { map } from './map'; -import { max } from './max'; -import { maxBy } from './maxby'; -import { memoize } from './memoize'; -import { min } from './min'; -import { minBy } from './minby'; -import { ofEntries } from './ofentries'; -import { ofKeys } from './ofkeys'; -import { ofValues } from './ofvalues'; -import { onErrorResumeNext } from './onerrorresumenext'; -import { orderBy } from './orderby'; -import { orderByDescending } from './orderby'; -import { thenBy } from './orderby'; -import { thenByDescending } from './orderby'; -import { pairwise } from './pairwise'; -import { partition } from './partition'; -import { pipe } from './pipe'; -import { pluck } from './pluck'; -import { publish } from './publish'; -import { range } from './range'; -import { reduce } from './reduce'; -import { reduceRight } from './reduceright'; -import { repeat } from './repeat'; -import { repeatStatic } from './repeat'; -import { retry } from './retry'; -import { reverse } from './reverse'; -import { scan } from './scan'; -import { scanRight } from './scanright'; -import { sequenceEqual } from './sequenceequal'; -import { share } from './share'; -import { single } from './single'; -import { skip } from './skip'; -import { skipLast } from './skiplast'; -import { skipWhile } from './skipwhile'; -import { slice } from './slice'; -import { some } from './some'; -import { startWith } from './startwith'; -import { sum } from './sum'; -import { take } from './take'; -import { takeLast } from './takelast'; -import { takeWhile } from './takewhile'; -import { tap } from './tap'; -import { _throw } from './throw'; -import { toArray } from './toarray'; -import { toMap } from './tomap'; -import { toSet } from './toset'; -import { union } from './union'; -import { _while } from './while'; -import { zip } from './zip'; - -import { buffer as bufferPipe } from './pipe/buffer'; -import { _catch as catchPipe } from './pipe/catch'; -import { catchWith as catchWithPipe } from './pipe/catchwith'; -import { concat as concatPipe } from './pipe/concat'; -import { concatAll as concatAllPipe } from './pipe/concatall'; -import { defaultIfEmpty as defaultIfEmptyPipe } from './pipe/defaultifempty'; -import { distinct as distinctPipe } from './pipe/distinct'; -import { distinctUntilChanged as distinctUntilChangedPipe } from './pipe/distinctuntilchanged'; -import { doWhile as doWhilePipe } from './pipe/dowhile'; -import { endWith as endWithPipe } from './pipe/endwith'; -import { except as exceptPipe } from './pipe/except'; -import { expand as expandPipe } from './pipe/expand'; -import { filter as filterPipe } from './pipe/filter'; -import { _finally as finallyPipe } from './pipe/finally'; -import { flatMap as flatMapPipe } from './pipe/flatmap'; -import { flatten as flattenPipe } from './pipe/flatten'; -import { groupBy as groupByPipe } from './pipe/groupby'; -import { groupJoin as groupJoinPipe } from './pipe/groupjoin'; -import { ignoreElements as ignoreElementsPipe } from './pipe/ignoreelements'; -import { innerJoin as innerJoinPipe } from './pipe/innerjoin'; -import { intersect as intersectPipe } from './pipe/intersect'; -import { map as mapPipe } from './pipe/map'; -import { maxBy as maxByPipe } from './pipe/maxby'; -import { memoize as memoizePipe } from './pipe/memoize'; -import { minBy as minByPipe } from './pipe/minby'; -import { onErrorResumeNext as onErrorResumeNextPipe } from './pipe/onerrorresumenext'; -import { pairwise as pairwisePipe } from './pipe/pairwise'; -import { pluck as pluckPipe } from './pipe/pluck'; -import { publish as publishPipe } from './pipe/publish'; -import { repeat as repeatPipe } from './pipe/repeat'; -import { retry as retryPipe } from './pipe/retry'; -import { reverse as reversePipe } from './pipe/reverse'; -import { scan as scanPipe } from './pipe/scan'; -import { scanRight as scanRightPipe } from './pipe/scanright'; -import { share as sharePipe } from './pipe/share'; -import { skip as skipPipe } from './pipe/skip'; -import { skipLast as skipLastPipe } from './pipe/skiplast'; -import { skipWhile as skipWhilePipe } from './pipe/skipwhile'; -import { slice as slicePipe } from './pipe/slice'; -import { startWith as startWithPipe } from './pipe/startwith'; -import { take as takePipe } from './pipe/take'; -import { takeLast as takeLastPipe } from './pipe/takelast'; -import { takeWhile as takeWhilePipe } from './pipe/takewhile'; -import { tap as tapPipe } from './pipe/tap'; -import { union as unionPipe } from './pipe/union'; -import { zip as zipPipe } from './pipe/zip'; - -export type IterableX = IterableX; -export type Observable = Observable; -export type NextObserver = NextObserver; -export type ErrorObserver = ErrorObserver; -export type CompletionObserver = CompletionObserver; -export type GroupedIterable = GroupedIterable; -export type OrderedIterableX = OrderedIterableX; -export type OrderedIterableBaseX = OrderedIterableBaseX; - -export default { - average, - buffer, - _case, - _catch, - _catchStatic, - catchWith, - chain, - concat, - concatAll, - concatStatic, - count, - create, - defaultIfEmpty, - defer, - distinct, - distinctUntilChanged, - doWhile, - elementAt, - empty, - endWith, - every, - except, - expand, - filter, - _finally, - find, - findIndex, - first, - flatMap, - flatten, - _for, - generate, - groupBy, - groupJoin, - _if, - ignoreElements, - includes, - innerJoin, - intersect, - isEmpty, - last, - map, - max, - maxBy, - memoize, - min, - minBy, - ofEntries, - ofKeys, - ofValues, - onErrorResumeNext, - orderBy, - orderByDescending, - thenBy, - thenByDescending, - pairwise, - partition, - pipe, - pluck, - publish, - range, - reduce, - reduceRight, - repeat, - repeatStatic, - retry, - reverse, - scan, - scanRight, - sequenceEqual, - share, - single, - skip, - skipLast, - skipWhile, - slice, - some, - startWith, - sum, - take, - takeLast, - takeWhile, - tap, - _throw, - toArray, - toMap, - toSet, - union, - _while, - zip, - - bufferPipe, - catchPipe, - catchWithPipe, - concatPipe, - concatAllPipe, - defaultIfEmptyPipe, - distinctPipe, - distinctUntilChangedPipe, - doWhilePipe, - endWithPipe, - exceptPipe, - expandPipe, - filterPipe, - finallyPipe, - flatMapPipe, - flattenPipe, - groupByPipe, - groupJoinPipe, - ignoreElementsPipe, - innerJoinPipe, - intersectPipe, - mapPipe, - maxByPipe, - memoizePipe, - minByPipe, - onErrorResumeNextPipe, - pairwisePipe, - pluckPipe, - publishPipe, - repeatPipe, - retryPipe, - reversePipe, - scanPipe, - scanRightPipe, - sharePipe, - skipPipe, - skipLastPipe, - skipWhilePipe, - slicePipe, - startWithPipe, - takePipe, - takeLastPipe, - takeWhilePipe, - tapPipe, - unionPipe, - zipPipe -}; +export { average } from './average'; +export { buffer } from './buffer'; +export { _case } from './case'; +export { _catch } from './catch'; +export { _catchStatic } from './catch'; +export { catchWith } from './catchwith'; +export { chain } from './chain'; +export { concat } from './concat'; +export { concatAll } from './concatall'; +export { concatStatic } from './concat'; +export { count } from './count'; +export { create } from './create'; +export { defaultIfEmpty } from './defaultifempty'; +export { defer } from './defer'; +export { distinct } from './distinct'; +export { distinctUntilChanged } from './distinctuntilchanged'; +export { doWhile } from './dowhile'; +export { elementAt } from './elementat'; +export { empty } from './empty'; +export { endWith } from './endwith'; +export { every } from './every'; +export { except } from './except'; +export { expand } from './expand'; +export { filter } from './filter'; +export { _finally } from './finally'; +export { find } from './find'; +export { findIndex } from './findindex'; +export { first } from './first'; +export { flatMap } from './flatmap'; +export { flatten } from './flatten'; +export { _for } from './for'; +export { generate } from './generate'; +export { groupBy } from './groupby'; +export { groupJoin } from './groupjoin'; +export { _if } from './if'; +export { ignoreElements } from './ignoreelements'; +export { includes } from './includes'; +export { innerJoin } from './innerjoin'; +export { intersect } from './intersect'; +export { isEmpty } from './isempty'; +export { last } from './last'; +export { map } from './map'; +export { max } from './max'; +export { maxBy } from './maxby'; +export { memoize } from './memoize'; +export { min } from './min'; +export { minBy } from './minby'; +export { ofEntries } from './ofentries'; +export { ofKeys } from './ofkeys'; +export { ofValues } from './ofvalues'; +export { onErrorResumeNext } from './onerrorresumenext'; +export { orderBy } from './orderby'; +export { orderByDescending } from './orderby'; +export { thenBy } from './orderby'; +export { thenByDescending } from './orderby'; +export { pairwise } from './pairwise'; +export { partition } from './partition'; +export { pipe } from './pipe'; +export { pluck } from './pluck'; +export { publish } from './publish'; +export { range } from './range'; +export { reduce } from './reduce'; +export { reduceRight } from './reduceright'; +export { repeat } from './repeat'; +export { repeatStatic } from './repeat'; +export { retry } from './retry'; +export { reverse } from './reverse'; +export { scan } from './scan'; +export { scanRight } from './scanright'; +export { sequenceEqual } from './sequenceequal'; +export { share } from './share'; +export { single } from './single'; +export { skip } from './skip'; +export { skipLast } from './skiplast'; +export { skipWhile } from './skipwhile'; +export { slice } from './slice'; +export { some } from './some'; +export { startWith } from './startwith'; +export { sum } from './sum'; +export { take } from './take'; +export { takeLast } from './takelast'; +export { takeWhile } from './takewhile'; +export { tap } from './tap'; +export { _throw } from './throw'; +export { toArray } from './toarray'; +export { toMap } from './tomap'; +export { toSet } from './toset'; +export { union } from './union'; +export { _while } from './while'; +export { zip } from './zip'; diff --git a/src/iterable/pipe/__modules.ts b/src/iterable/pipe/__modules.ts new file mode 100644 index 00000000..9462bc18 --- /dev/null +++ b/src/iterable/pipe/__modules.ts @@ -0,0 +1,46 @@ +export { buffer } from './buffer'; +export { _catch } from './catch'; +export { catchWith } from './catchwith'; +export { concat } from './concat'; +export { concatAll } from './concatall'; +export { defaultIfEmpty } from './defaultifempty'; +export { distinct } from './distinct'; +export { distinctUntilChanged } from './distinctuntilchanged'; +export { doWhile } from './dowhile'; +export { endWith } from './endwith'; +export { except } from './except'; +export { expand } from './expand'; +export { filter } from './filter'; +export { _finally } from './finally'; +export { flatMap } from './flatmap'; +export { flatten } from './flatten'; +export { groupBy } from './groupby'; +export { groupJoin } from './groupjoin'; +export { ignoreElements } from './ignoreelements'; +export { innerJoin } from './innerjoin'; +export { intersect } from './intersect'; +export { map } from './map'; +export { maxBy } from './maxby'; +export { memoize } from './memoize'; +export { minBy } from './minby'; +export { onErrorResumeNext } from './onerrorresumenext'; +export { pairwise } from './pairwise'; +export { pluck } from './pluck'; +export { publish } from './publish'; +export { repeat } from './repeat'; +export { retry } from './retry'; +export { reverse } from './reverse'; +export { scan } from './scan'; +export { scanRight } from './scanright'; +export { share } from './share'; +export { skip } from './skip'; +export { skipLast } from './skiplast'; +export { skipWhile } from './skipwhile'; +export { slice } from './slice'; +export { startWith } from './startwith'; +export { take } from './take'; +export { takeLast } from './takelast'; +export { takeWhile } from './takewhile'; +export { tap } from './tap'; +export { union } from './union'; +export { zip } from './zip'; From 8e62fe49ac23a96037dedc3d6c44cacb6fccbe79 Mon Sep 17 00:00:00 2001 From: Paul Taylor Date: Sun, 29 Oct 2017 13:48:51 -0700 Subject: [PATCH 106/106] test(helpers): disable missing pipe fn logging --- spec/asynciterablehelpers.ts | 37 +++++++++++++++++++----------------- spec/iterablehelpers.ts | 37 +++++++++++++++++++----------------- 2 files changed, 40 insertions(+), 34 deletions(-) diff --git a/spec/asynciterablehelpers.ts b/spec/asynciterablehelpers.ts index 5e489c2c..d88b63c2 100644 --- a/spec/asynciterablehelpers.ts +++ b/spec/asynciterablehelpers.ts @@ -29,37 +29,40 @@ const operatorNamesMap = Object.keys(Ix.asynciterable).reduce( ); export function testOperator(op: Op) { - const ops = (Array.isArray(op) ? op : [op]) as any as Function[]; - const internalNames = ops.map((op) => operatorNamesMap.get(op)!); - const fnNames = internalNames.map((name) => name.replace('_', '')); - const pipeFns = internalNames.map((name) => (Ix.asynciterablePipe as any)[name]); - return function operatorTest(message: string, testFn: (t: test.Test, op: Op) => any | Promise) { + const ops = ((Array.isArray(op) ? op : [op]) as any) as Function[]; + const internalNames = ops.map(op => operatorNamesMap.get(op)!); + const fnNames = internalNames.map(name => name.replace('_', '')); + const pipeFns = internalNames.map(name => (Ix.asynciterablePipe as any)[name]); + return function operatorTest( + message: string, + testFn: (t: test.Test, op: Op) => any | Promise + ) { test(`(fp) ${message}`, async t => await (testFn as any)(t, ops)); test(`(proto) ${message}`, async t => await (testFn as any)(t, fnNames.map(wrapProto))); - if (pipeFns.every((xs) => typeof xs === 'function')) { + if (pipeFns.every(xs => typeof xs === 'function')) { test(`(pipe) ${message}`, async t => await (testFn as any)(t, pipeFns.map(wrapPipe))); - } else { - console.log(`AsyncIterable missing a pipe fn in [${internalNames.join(`, `)}], skipping...`); + // } else { + // console.log(`AsyncIterable missing a pipe fn in [${internalNames.join(`, `)}], skipping...`); } }; } function wrapProto(name: string) { - return function (source: any, ...args: any[]) { - return typeof source !== 'function' ? - cast(source)[name].apply(source, args) : - cast(args[0])[name].apply(args[0], [source, ...args.slice(1)]); + return function(source: any, ...args: any[]) { + return typeof source !== 'function' + ? cast(source)[name].apply(source, args) + : cast(args[0])[name].apply(args[0], [source, ...args.slice(1)]); }; } function wrapPipe(fn: any) { - return function (source: any, ...args: any[]) { - return typeof source !== 'function' ? - pipe.call(source, fn(...args)) : - pipe.call(args[0], fn(source, ...args.slice(1))); + return function(source: any, ...args: any[]) { + return typeof source !== 'function' + ? pipe.call(source, fn(...args)) + : pipe.call(args[0], fn(source, ...args.slice(1))); }; } function cast(source: any): any { return source instanceof Ix.AsyncIterable ? source : Ix.AsyncIterable.from(source); -} \ No newline at end of file +} diff --git a/spec/iterablehelpers.ts b/spec/iterablehelpers.ts index 9c29f05d..a391320b 100644 --- a/spec/iterablehelpers.ts +++ b/spec/iterablehelpers.ts @@ -19,37 +19,40 @@ const operatorNamesMap = Object.keys(Ix.iterable).reduce( ); export function testOperator(op: Op) { - const ops = (Array.isArray(op) ? op : [op]) as any as Function[]; - const internalNames = ops.map((op) => operatorNamesMap.get(op)!); - const fnNames = internalNames.map((name) => name.replace('_', '')); - const pipeFns = internalNames.map((name) => (Ix.iterablePipe as any)[name]); - return function operatorTest(message: string, testFn: (t: test.Test, op: Op) => any | Promise) { + const ops = ((Array.isArray(op) ? op : [op]) as any) as Function[]; + const internalNames = ops.map(op => operatorNamesMap.get(op)!); + const fnNames = internalNames.map(name => name.replace('_', '')); + const pipeFns = internalNames.map(name => (Ix.iterablePipe as any)[name]); + return function operatorTest( + message: string, + testFn: (t: test.Test, op: Op) => any | Promise + ) { test(`(fp) ${message}`, t => (testFn as any)(t, ops)); test(`(proto) ${message}`, t => (testFn as any)(t, fnNames.map(wrapProto))); - if (pipeFns.every((xs) => typeof xs === 'function')) { + if (pipeFns.every(xs => typeof xs === 'function')) { test(`(pipe) ${message}`, t => (testFn as any)(t, pipeFns.map(wrapPipe))); - } else { - console.log(`Iterable missing a pipe fn in [${internalNames.join(`, `)}], skipping...`); + // } else { + // console.log(`Iterable missing a pipe fn in [${internalNames.join(`, `)}], skipping...`); } }; } function wrapProto(name: any) { - return function (source: any, ...args: any[]) { - return typeof source !== 'function' ? - cast(source)[name].apply(source, args) : - cast(args[0])[name].apply(args[0], [source, ...args.slice(1)]); + return function(source: any, ...args: any[]) { + return typeof source !== 'function' + ? cast(source)[name].apply(source, args) + : cast(args[0])[name].apply(args[0], [source, ...args.slice(1)]); }; } function wrapPipe(fn: any) { - return function (source: any, ...args: any[]) { - return typeof source !== 'function' ? - pipe.call(source, fn(...args)) : - pipe.call(args[0], fn(source, ...args.slice(1))); + return function(source: any, ...args: any[]) { + return typeof source !== 'function' + ? pipe.call(source, fn(...args)) + : pipe.call(args[0], fn(source, ...args.slice(1))); }; } function cast(source: any): any { return source instanceof Ix.Iterable ? source : Ix.Iterable.from(source); -} \ No newline at end of file +}