Skip to content

Commit

Permalink
chore(add): clean up adds
Browse files Browse the repository at this point in the history
  • Loading branch information
mpodwysocki authored and trxcllnt committed Sep 1, 2020
1 parent c179ca9 commit 8371ee4
Show file tree
Hide file tree
Showing 33 changed files with 783 additions and 301 deletions.
7 changes: 4 additions & 3 deletions src/add/asynciterable-operators/count.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { AsyncIterableX } from '../../asynciterable/asynciterablex';
import { count } from '../../asynciterable/count';
import { OptionalFindOptions } from '../../asynciterable/findoptions';

/**
* @ignore
*/
export function countProto<T>(
this: AsyncIterableX<T>,
selector?: (value: T) => boolean | Promise<boolean>
this: AsyncIterable<T>,
options?: OptionalFindOptions<T>
): Promise<number> {
return count<T>(this, selector);
return count<T>(this, options);
}

AsyncIterableX.prototype.count = countProto;
Expand Down
6 changes: 1 addition & 5 deletions src/add/asynciterable-operators/every.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { AsyncIterableX } from '../../asynciterable/asynciterablex';
import { every } from '../../asynciterable/every';
import { FindSubclassedOptions, FindOptions } from '../../asynciterable/findoptions';
import { FindOptions } from '../../asynciterable/findoptions';

/**
* @ignore
*/
export function everyProto<T, S extends T>(
this: AsyncIterable<T>,
options: FindSubclassedOptions<T, S>
): Promise<boolean>;
export function everyProto<T>(this: AsyncIterable<T>, options: FindOptions<T>): Promise<boolean> {
return every(this, options as any);
}
Expand Down
15 changes: 1 addition & 14 deletions src/add/asynciterable-operators/find.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
import { AsyncIterableX } from '../../asynciterable/asynciterablex';
import { find } from '../../asynciterable/find';
import { FindSubclassedOptions, FindOptions } from '../../asynciterable/findoptions';
import { FindOptions } from '../../asynciterable/findoptions';

/**
* @ignore
*/
export function findProto<T, S extends T>(
this: AsyncIterable<T>,
options: FindSubclassedOptions<T, S>
): Promise<S | undefined>;
/**
* 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>
Expand Down
9 changes: 1 addition & 8 deletions src/add/asynciterable-operators/first.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import { AsyncIterableX } from '../../asynciterable/asynciterablex';
import { first } from '../../asynciterable/first';
import {
OptionalFindSubclassedOptions,
OptionalFindOptions,
} from '../../asynciterable/findoptions';
import { OptionalFindOptions } from '../../asynciterable/findoptions';

/**
* @ignore
*/
export function firstProto<T, S extends T>(
this: AsyncIterable<T>,
options?: OptionalFindSubclassedOptions<T, S>
): Promise<S | undefined>;
export async function firstProto<T>(
this: AsyncIterable<T>,
options?: OptionalFindOptions<T>
Expand Down
9 changes: 1 addition & 8 deletions src/add/asynciterable-operators/last.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import { AsyncIterableX } from '../../asynciterable/asynciterablex';
import { last } from '../../asynciterable/last';
import {
OptionalFindSubclassedOptions,
OptionalFindOptions,
} from '../../asynciterable/findoptions';
import { OptionalFindOptions } from '../../asynciterable/findoptions';

/**
* @ignore
*/
export function lastProto<T, S extends T>(
this: AsyncIterable<T>,
options?: OptionalFindSubclassedOptions<T, S>
): Promise<S | undefined>;
export async function lastProto<T>(
this: AsyncIterable<T>,
options?: OptionalFindOptions<T>
Expand Down
9 changes: 1 addition & 8 deletions src/add/asynciterable-operators/single.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import { AsyncIterableX } from '../../asynciterable/asynciterablex';
import { single } from '../../asynciterable/single';
import {
OptionalFindSubclassedOptions,
OptionalFindOptions,
} from '../../asynciterable/findoptions';
import { OptionalFindOptions } from '../../asynciterable/findoptions';

/**
* @ignore
*/
export function singleProto<T, S extends T>(
this: AsyncIterable<T>,
options?: OptionalFindSubclassedOptions<T, S>
): Promise<S | undefined>;
export function singleProto<T>(
this: AsyncIterable<T>,
options?: OptionalFindOptions<T>
Expand Down
6 changes: 1 addition & 5 deletions src/add/asynciterable-operators/some.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { AsyncIterableX } from '../../asynciterable/asynciterablex';
import { some } from '../../asynciterable/some';
import { FindSubclassedOptions, FindOptions } from '../../asynciterable/findoptions';
import { FindOptions } from '../../asynciterable/findoptions';

/**
* @ignore
*/
export function someProto<T, S extends T>(
this: AsyncIterable<T>,
options: FindSubclassedOptions<T, S>
): Promise<boolean>;
export function someProto<T>(this: AsyncIterable<T>, options: FindOptions<T>): Promise<boolean> {
return some(this, options as any);
}
Expand Down
10 changes: 3 additions & 7 deletions src/add/asynciterable/merge.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { AsyncIterableX } from '../../asynciterable/asynciterablex';
import { mergeStatic as mergeStatic_ } from '../../asynciterable/merge';
import { merge as mergeStatic } from '../../asynciterable/merge';

/** @nocollapse */
AsyncIterableX.merge = mergeStatic_;

export declare namespace asynciterable {
let mergeStatic: typeof mergeStatic_;
}
AsyncIterableX.merge = mergeStatic;

declare module '../../asynciterable/asynciterablex' {
// eslint-disable-next-line no-shadow
namespace AsyncIterableX {
export let merge: typeof mergeStatic_;
export let merge: typeof mergeStatic;
}
}
6 changes: 1 addition & 5 deletions src/add/iterable-operators/every.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { IterableX } from '../../iterable/iterablex';
import { every } from '../../iterable/every';
import { FindSubclassedOptions, FindOptions } from '../../iterable/findoptions';
import { FindOptions } from '../../iterable/findoptions';

/**
* @ignore
*/
export function everyProto<T, S extends T>(
this: IterableX<T>,
options: FindSubclassedOptions<T, S>
): boolean;
export function everyProto<T>(this: IterableX<T>, options: FindOptions<T>): boolean {
return every(this, options as any);
}
Expand Down
6 changes: 1 addition & 5 deletions src/add/iterable-operators/find.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { IterableX } from '../../iterable/iterablex';
import { find } from '../../iterable/find';
import { FindOptions, FindSubclassedOptions } from 'ix/iterable/findoptions';
import { FindOptions } from 'ix/iterable/findoptions';

/**
* @ignore
*/
export function findProto<T, S extends T>(
this: IterableX<T>,
options: FindSubclassedOptions<T, S>
): Promise<S | undefined>;
export function findProto<T>(this: IterableX<T>, options: FindOptions<T>): T | undefined {
return find(this, options as any);
}
Expand Down
6 changes: 1 addition & 5 deletions src/add/iterable-operators/first.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { IterableX } from '../../iterable/iterablex';
import { first } from '../../iterable/first';
import { OptionalFindOptions, OptionalFindSubclassedOptions } from '../../iterable/findoptions';
import { OptionalFindOptions } from '../../iterable/findoptions';

/**
* @ignore
*/
export function firstProto<T, S extends T>(
this: IterableX<T>,
options?: OptionalFindSubclassedOptions<T, S>
): S | undefined;
export function firstProto<T>(this: IterableX<T>, options?: OptionalFindOptions<T>): T | undefined {
return first(this, options as any);
}
Expand Down
6 changes: 1 addition & 5 deletions src/add/iterable-operators/last.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { IterableX } from '../../iterable/iterablex';
import { last } from '../../iterable/last';
import { OptionalFindOptions, OptionalFindSubclassedOptions } from '../../iterable/findoptions';
import { OptionalFindOptions } from '../../iterable/findoptions';

/**
* @ignore
*/
export function lastProto<T, S extends T>(
this: IterableX<T>,
options?: OptionalFindSubclassedOptions<T, S>
): S | undefined;
export function lastProto<T>(this: IterableX<T>, options?: OptionalFindOptions<T>): T | undefined {
return last(this, options as any);
}
Expand Down
6 changes: 1 addition & 5 deletions src/add/iterable-operators/single.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { IterableX } from '../../iterable/iterablex';
import { single } from '../../iterable/single';
import { OptionalFindOptions, OptionalFindSubclassedOptions } from '../../iterable/findoptions';
import { OptionalFindOptions } from '../../iterable/findoptions';

/**
* @ignore
*/
export function singleProto<T, S extends T>(
this: IterableX<T>,
options?: OptionalFindSubclassedOptions<T, S>
): S | undefined;
export function singleProto<T>(
this: IterableX<T>,
options?: OptionalFindOptions<T>
Expand Down
6 changes: 1 addition & 5 deletions src/add/iterable-operators/some.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { IterableX } from '../../iterable/iterablex';
import { some } from '../../iterable/some';
import { FindSubclassedOptions, FindOptions } from '../../iterable/findoptions';
import { FindOptions } from '../../iterable/findoptions';

/**
* @ignore
*/
export function someProto<T, S extends T>(
this: IterableX<T>,
options: FindSubclassedOptions<T, S>
): boolean;
export function someProto<T>(this: IterableX<T>, options: FindOptions<T>): boolean {
return some(this, options as any);
}
Expand Down
2 changes: 1 addition & 1 deletion src/add/iterable/onerrorresumenext.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IterableX } from '../../iterable/iterablex';
import { onErrorResumeNextStatic } from '../../iterable/onerrorresumenext';
import { onErrorResumeNext as onErrorResumeNextStatic } from '../../iterable/onerrorresumenext';

/** @nocollapse */
IterableX.onErrorResumeNext = onErrorResumeNextStatic;
Expand Down
1 change: 0 additions & 1 deletion src/asynciterable/concat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export function _concatAll<TSource>(
return new ConcatAsyncIterable<TSource>(source);
}

export function concat<T>(v1: AsyncIterable<T>): AsyncIterableX<T>;
/**
* Concatenates the second async-iterable sequence to the first async-iterable sequence upon successful termination of the first.
*
Expand Down
16 changes: 1 addition & 15 deletions src/asynciterable/find.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
import { wrapWithAbort } from './operators/withabort';
import { throwIfAborted } from '../aborterror';
import { FindOptions, FindSubclassedOptions } from './findoptions';
import { FindOptions } from './findoptions';

/**
* 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.
* @template S The return type from the predicate which is falsy or truthy.
* @param {AsyncIterable<T>} source An async-iterable sequence whose elements to apply the predicate to.
* @param {FindSubclassedOptions<T, S>} 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 find<T, S extends T>(
source: AsyncIterable<T>,
options: FindSubclassedOptions<T, S>
): Promise<S | undefined>;
/**
* Returns the value of the first element in the provided async-iterable that satisfies the provided testing function.
*
Expand Down
4 changes: 2 additions & 2 deletions src/asynciterable/iif.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { empty } from './empty';
* @template TSource The type of the elements in the result sequence.
* @param {((signal?: AbortSignal) => boolean | Promise<boolean>)} condition Condition evaluated to decide which sequence to return.
* @param {AsyncIterable<TSource>} thenSource Sequence returned in case evaluates true.
* @param {AsyncIterable<TSource>} [elseSource=empty<TSource>()] Sequence returned in case condition evaluates false.
* @param {AsyncIterable<TSource>} [elseSource=empty()] Sequence returned in case condition evaluates false.
* @returns {AsyncIterableX<TSource>} thenSource if condition evaluates true; elseSource otherwise.
*/
export function iif<TSource>(
condition: (signal?: AbortSignal) => boolean | Promise<boolean>,
thenSource: AsyncIterable<TSource>,
elseSource: AsyncIterable<TSource> = empty<TSource>()
elseSource: AsyncIterable<TSource> = empty()
): AsyncIterableX<TSource> {
return defer<TSource>(async (signal) => ((await condition(signal)) ? thenSource : elseSource));
}
Loading

0 comments on commit 8371ee4

Please sign in to comment.