Skip to content

Commit

Permalink
chore(add): fix add operators
Browse files Browse the repository at this point in the history
  • Loading branch information
mpodwysocki authored and trxcllnt committed Sep 1, 2020
1 parent 313a1b4 commit bb38187
Show file tree
Hide file tree
Showing 80 changed files with 381 additions and 563 deletions.
21 changes: 9 additions & 12 deletions src/add/asynciterable-operators/average.ts
@@ -1,23 +1,20 @@
import { AsyncIterableX } from '../../asynciterable/asynciterablex';
import { identityAsync } from '../../util/identity';
import { average } from '../../asynciterable/average';
import { MathOptions } from '../../asynciterable/mathoptions';

export function averageProto(
this: AsyncIterableX<number>,
selector?: (x: number) => number | Promise<number>
this: AsyncIterable<number>,
options?: MathOptions<number>
): Promise<number>;
export function averageProto<T>(
this: AsyncIterableX<T>,
selector?: (x: T) => number | Promise<number>
export function averageProto<TSource>(
this: AsyncIterable<TSource>,
options?: MathOptions<TSource>
): Promise<number>;
/**
* @ignore
*/
export function averageProto(
this: AsyncIterableX<any>,
selector: (x: any) => number | Promise<number> = identityAsync
this: AsyncIterable<any>,
options?: MathOptions<any>
): Promise<number> {
return average(this, selector);
return average(this, options);
}

AsyncIterableX.prototype.average = averageProto;
Expand Down
4 changes: 2 additions & 2 deletions src/add/asynciterable-operators/batch.ts
@@ -1,11 +1,11 @@
import { AsyncIterableX } from '../../asynciterable/asynciterablex';
import { batch } from '../../asynciterable/operators/batch';
import { BatchAsyncIterable } from '../../asynciterable/operators/batch';

/**
* @ignore
*/
export function batchProto<T>(this: AsyncIterableX<T>): AsyncIterableX<T[]> {
return batch<T>()(this);
return new BatchAsyncIterable<T>(this);
}

AsyncIterableX.prototype.batch = batchProto;
Expand Down
4 changes: 2 additions & 2 deletions src/add/asynciterable-operators/concatall.ts
@@ -1,11 +1,11 @@
import { AsyncIterableX } from '../../asynciterable/asynciterablex';
import { concatAll } from '../../asynciterable/operators/concatall';
import { ConcatAllAsyncIterable } from '../../asynciterable/operators/concatall';

/**
* @ignore
*/
export function concatAllProto<T>(this: AsyncIterableX<AsyncIterable<T>>): AsyncIterableX<T> {
return concatAll<T>()(this);
return new ConcatAllAsyncIterable<T>(this);
}

AsyncIterableX.prototype.concatAll = concatAllProto;
Expand Down
17 changes: 17 additions & 0 deletions src/add/asynciterable-operators/delay.ts
@@ -0,0 +1,17 @@
import { AsyncIterableX } from '../../asynciterable/asynciterablex';
import { DelayAsyncIterable } from '../../asynciterable/operators/delay';

export function delayProto<TSource>(
this: AsyncIterableX<TSource>,
dueTime: number
): AsyncIterableX<TSource> {
return new DelayAsyncIterable<TSource>(this, dueTime);
}

AsyncIterableX.prototype.delay = delayProto;

declare module '../../asynciterable/asynciterablex' {
interface AsyncIterableX<T> {
delay: typeof delayProto;
}
}
17 changes: 17 additions & 0 deletions src/add/asynciterable-operators/delayeach.ts
@@ -0,0 +1,17 @@
import { AsyncIterableX } from '../../asynciterable/asynciterablex';
import { DelayEachAsyncIterable } from '../../asynciterable/operators/delayeach';

export function delayEachProto<TSource>(
this: AsyncIterableX<TSource>,
dueTime: number
): AsyncIterableX<TSource> {
return new DelayEachAsyncIterable<TSource>(this, dueTime);
}

AsyncIterableX.prototype.delayEach = delayEachProto;

declare module '../../asynciterable/asynciterablex' {
interface AsyncIterableX<T> {
delayEach: typeof delayEachProto;
}
}
6 changes: 3 additions & 3 deletions src/add/asynciterable-operators/distinct.ts
@@ -1,15 +1,15 @@
import { AsyncIterableX } from '../../asynciterable/asynciterablex';
import { distinct } from '../../asynciterable/operators/distinct';
import { DistinctOptions } from '../../asynciterable/operators/distinctoptions';

/**
* @ignore
*/
export function distinctProto<TSource, TKey>(
this: AsyncIterableX<TSource>,
keySelector?: (value: TSource) => TKey | Promise<TKey>,
comparer?: (x: TKey, y: TKey) => boolean | Promise<boolean>
options?: DistinctOptions<TSource, TKey>
): AsyncIterableX<TSource> {
return distinct(keySelector, comparer)(this);
return distinct(options)(this);
}

AsyncIterableX.prototype.distinct = distinctProto;
Expand Down
12 changes: 6 additions & 6 deletions src/add/asynciterable-operators/distinctuntilchanged.ts
@@ -1,15 +1,15 @@
import { AsyncIterableX } from '../../asynciterable/asynciterablex';
import { distinctUntilChanged } from '../../asynciterable/operators/distinctuntilchanged';
import { DistinctOptions } from '../../asynciterable/operators/distinctoptions';

/**
* @ignore
*/
export function distinctUntilChangedProto<T, TKey>(
this: AsyncIterableX<T>,
keySelector?: (value: T) => TKey | Promise<TKey>,
comparer?: (x: TKey, y: TKey) => boolean | Promise<boolean>
): AsyncIterableX<T> {
return distinctUntilChanged(keySelector, comparer)(this);
export function distinctUntilChangedProto<TSource, TKey>(
this: AsyncIterableX<TSource>,
options?: DistinctOptions<TSource, TKey>
): AsyncIterableX<TSource> {
return distinctUntilChanged(options)(this);
}

AsyncIterableX.prototype.distinctUntilChanged = distinctUntilChangedProto;
Expand Down
4 changes: 2 additions & 2 deletions src/add/asynciterable-operators/endwith.ts
@@ -1,11 +1,11 @@
import { AsyncIterableX } from '../../asynciterable/asynciterablex';
import { endWith } from '../../asynciterable/operators/endwith';
import { EndWithAsyncIterable } from '../../asynciterable/operators/endwith';

/**
* @ignore
*/
export function endWithProto<T>(this: AsyncIterableX<T>, ...args: T[]) {
return endWith<T>(...args)(this);
return new EndWithAsyncIterable<T>(this, args);
}

AsyncIterableX.prototype.endWith = endWithProto;
Expand Down
16 changes: 5 additions & 11 deletions src/add/asynciterable-operators/every.ts
@@ -1,22 +1,16 @@
import { AsyncIterableX } from '../../asynciterable/asynciterablex';
import { every } from '../../asynciterable/every';
import { FindSubclassedOptions, FindOptions } from '../../asynciterable/findoptions';

/**
* @ignore
*/
export function everyProto<T, S extends T>(
this: AsyncIterableX<T>,
predicate: (value: T, index: number) => value is S
this: AsyncIterable<T>,
options: FindSubclassedOptions<T, S>
): Promise<boolean>;
export function everyProto<T>(
this: AsyncIterableX<T>,
predicate: (value: T, index: number) => boolean | Promise<boolean>
): Promise<boolean>;
export function everyProto<T>(
this: AsyncIterableX<T>,
predicate: (value: T, index: number) => boolean | Promise<boolean>
): Promise<boolean> {
return every<T>(this, predicate);
export function everyProto<T>(this: AsyncIterable<T>, options: FindOptions<T>): Promise<boolean> {
return every(this, options as any);
}

AsyncIterableX.prototype.every = everyProto;
Expand Down
6 changes: 3 additions & 3 deletions src/add/asynciterable-operators/expand.ts
@@ -1,14 +1,14 @@
import { AsyncIterableX } from '../../asynciterable/asynciterablex';
import { expand } from '../../asynciterable/operators/expand';
import { ExpandAsyncIterable } from '../../asynciterable/operators/expand';

/**
* @ignore
*/
export function expandProto<T>(
this: AsyncIterableX<T>,
selector: (value: T) => AsyncIterable<T> | Promise<AsyncIterable<T>>
selector: (value: T, signal?: AbortSignal) => AsyncIterable<T> | Promise<AsyncIterable<T>>
) {
return expand<T>(selector)(this);
return new ExpandAsyncIterable<T>(this, selector);
}

AsyncIterableX.prototype.expand = expandProto;
Expand Down
11 changes: 5 additions & 6 deletions src/add/asynciterable-operators/filter.ts
@@ -1,26 +1,25 @@
import { AsyncIterableX } from '../../asynciterable/asynciterablex';
import { filter } from '../../asynciterable/operators/filter';
import { FilterAsyncIterable } from '../../asynciterable/operators/filter';

/**
* @ignore
*/

export function filterProto<T, S extends T>(
this: AsyncIterableX<T>,
predicate: (value: T, index: number) => value is S,
predicate: (value: T, index: number, signal?: AbortSignal) => value is S,
thisArg?: any
): AsyncIterableX<S>;
export function filterProto<T>(
this: AsyncIterableX<T>,
predicate: (value: T, index: number) => boolean | Promise<boolean>,
predicate: (value: T, index: number, signal?: AbortSignal) => boolean | Promise<boolean>,
thisArg?: any
): AsyncIterableX<T>;
export function filterProto<T>(
this: AsyncIterableX<T>,
predicate: (value: T, index: number) => boolean | Promise<boolean>,
predicate: (value: T, index: number, signal?: AbortSignal) => boolean | Promise<boolean>,
thisArg?: any
): AsyncIterableX<T> {
return filter<T>(predicate, thisArg)(this);
return new FilterAsyncIterable<T>(this, predicate, thisArg);
}

AsyncIterableX.prototype.filter = filterProto;
Expand Down
30 changes: 16 additions & 14 deletions src/add/asynciterable-operators/find.ts
@@ -1,26 +1,28 @@
import { AsyncIterableX } from '../../asynciterable/asynciterablex';
import { find } from '../../asynciterable/find';
import { FindSubclassedOptions, FindOptions } from '../../asynciterable/findoptions';

/**
* @ignore
*/

export function findProto<T, S extends T>(
this: AsyncIterableX<T>,
predicate: (value: T, index: number) => value is S,
thisArg?: any
this: AsyncIterable<T>,
options: FindSubclassedOptions<T, S>
): Promise<S | undefined>;
export function findProto<T>(
this: AsyncIterableX<T>,
predicate: (value: T, index: number) => boolean | Promise<boolean>,
thisArg?: any
): Promise<T | undefined>;
export function findProto<T>(
this: AsyncIterableX<T>,
predicate: (value: T, index: number) => boolean | Promise<boolean>,
thisArg?: any
/**
* Returns the value of the first element in the provided async-iterable that satisfies the provided testing function.
*
* @export
* @template T The type of the elements in the source sequence.
* @param {AsyncIterable<T>} source An async-iterable sequence whose elements to apply the predicate to.
* @param {FindOptions<T>} options The options for a predicate for filtering, thisArg for binding and AbortSignal for cancellation.
* @returns {(Promise<S | undefined>)} A promise with the value of the first element that matches the predicate.
*/
export async function findProto<T>(
this: AsyncIterable<T>,
options: FindOptions<T>
): Promise<T | undefined> {
return find(this, predicate, thisArg);
return find(this, options as any);
}

AsyncIterableX.prototype.find = findProto;
Expand Down
8 changes: 4 additions & 4 deletions src/add/asynciterable-operators/findindex.ts
@@ -1,15 +1,15 @@
import { AsyncIterableX } from '../../asynciterable/asynciterablex';
import { findIndex } from '../../asynciterable/findindex';
import { FindOptions } from '../../asynciterable/findoptions';

/**
* @ignore
*/
export function findIndexProto<T>(
this: AsyncIterableX<T>,
predicate: (value: T, index: number) => boolean | Promise<boolean>,
thisArg?: any
this: AsyncIterable<T>,
options: FindOptions<T>
): Promise<number> {
return findIndex(this, predicate, thisArg);
return findIndex(this, options);
}

AsyncIterableX.prototype.findIndex = findIndexProto;
Expand Down
21 changes: 10 additions & 11 deletions src/add/asynciterable-operators/first.ts
@@ -1,23 +1,22 @@
import { AsyncIterableX } from '../../asynciterable/asynciterablex';
import { first } from '../../asynciterable/first';
import {
OptionalFindSubclassedOptions,
OptionalFindOptions,
} from '../../asynciterable/findoptions';

/**
* @ignore
*/

export function firstProto<T, S extends T>(
this: AsyncIterableX<T>,
predicate: (value: T, index: number) => value is S
this: AsyncIterable<T>,
options?: OptionalFindSubclassedOptions<T, S>
): Promise<S | undefined>;
export function firstProto<T>(
this: AsyncIterableX<T>,
predicate?: (value: T, index: number) => boolean | Promise<boolean>
): Promise<T | undefined>;
export function firstProto<T>(
this: AsyncIterableX<T>,
predicate?: (value: T, index: number) => boolean | Promise<boolean>
export async function firstProto<T>(
this: AsyncIterable<T>,
options?: OptionalFindOptions<T>
): Promise<T | undefined> {
return first(this, predicate);
return first(this, options as any);
}

AsyncIterableX.prototype.first = firstProto;
Expand Down
6 changes: 5 additions & 1 deletion src/add/asynciterable-operators/flatmap.ts
Expand Up @@ -6,7 +6,11 @@ import { flatMap } from '../../asynciterable/operators/flatmap';
*/
export function flatMapProto<T, R>(
this: AsyncIterableX<T>,
selector: (value: T) => AsyncIterable<R> | Promise<AsyncIterable<R>>,
selector: (
value: T,
index: number,
signal?: AbortSignal
) => AsyncIterable<R> | Promise<AsyncIterable<R>>,
thisArg?: any
): AsyncIterableX<R> {
return flatMap<T, R>(selector, thisArg)(this);
Expand Down
1 change: 0 additions & 1 deletion src/add/asynciterable-operators/forkjoin.ts
Expand Up @@ -4,7 +4,6 @@ import { forkJoin } from '../../asynciterable/forkjoin';
/**
* @ignore
*/

export function forkJoinProto<T, T2>(
this: AsyncIterableX<T>,
source2: AsyncIterable<T2>
Expand Down

0 comments on commit bb38187

Please sign in to comment.