sync local repositories
add booleanish predicates enable custom inspection default to sequence of any when sequence type is unknown
This commit is contained in:
@@ -6,7 +6,7 @@ import { getRandomElementAsync } from "../random/index.js";
|
||||
import { AsyncRandomOptions } from "../random/types.js";
|
||||
import { selectionSorter } from "../sorting.js";
|
||||
import { Sequence } from "../sync/types.js";
|
||||
import { MaybeAsyncConverter, MaybeAsyncPredicate, MaybeAsyncEquater, MaybeAsyncBiConverter, MaybeAsyncAccumulator, MaybeAsyncComparer, MaybeAsyncAction, MaybePromiseLike, MaybeAsyncGenerator, MaybeAsyncSequence } from "../types.js";
|
||||
import { MaybeAsyncAnyPredicate, MaybeAsyncConverter, MaybeAsyncEquater, MaybeAsyncBiConverter, MaybeAsyncAccumulator, MaybeAsyncComparer, MaybeAsyncAction, MaybePromiseLike, MaybeAsyncGenerator, MaybeAsyncSequence } from "../types.js";
|
||||
import { strictEquals, identity, operatorCompare, defaultArrayComparer, combineAsyncComparers, asAsyncIterable } from "../utils.js";
|
||||
import { array, empty, wrap } from "./index.js";
|
||||
import { AsyncSequence, GroupedAsyncSequence, OrderedAsyncSequence } from "./types.js";
|
||||
@@ -25,15 +25,15 @@ export abstract class BaseAsyncSequence<TElement> extends AsyncSequenceMarker im
|
||||
}
|
||||
|
||||
select<TResult>(converter: MaybeAsyncConverter<TElement, TResult>): AsyncSequence<TResult> {
|
||||
return new MapperAsyncSequence<TElement, TResult>(this, converter);
|
||||
return new SelectAsyncSequence<TElement, TResult>(this, converter);
|
||||
}
|
||||
|
||||
selectMany<TResult>(converter: MaybeAsyncConverter<TElement, MaybeAsyncSequence<TResult>>): AsyncSequence<TResult> {
|
||||
return new FlatMapperAsyncSequence<TElement, TResult>(this, converter);
|
||||
return new SelectManyAsyncSequence<TElement, TResult>(this, converter);
|
||||
}
|
||||
|
||||
where(predicate: MaybeAsyncPredicate<TElement>): AsyncSequence<TElement> {
|
||||
return new FilterAsyncSequence<TElement>(this, predicate);
|
||||
where(predicate: MaybeAsyncAnyPredicate<TElement>): AsyncSequence<TElement> {
|
||||
return new WhereAsyncSequence<TElement>(this, predicate);
|
||||
}
|
||||
|
||||
groupBy<TKey>(keySelector: MaybeAsyncConverter<TElement, TKey>, elementSelector?: undefined, keyComparer?: MaybeAsyncEquater<TKey> | undefined): AsyncSequence<GroupedAsyncSequence<TKey, TElement>>;
|
||||
@@ -133,7 +133,7 @@ export abstract class BaseAsyncSequence<TElement> extends AsyncSequenceMarker im
|
||||
return new ConcatAsyncSequence(arr);
|
||||
}
|
||||
|
||||
async count(predicate?: MaybeAsyncPredicate<TElement>) {
|
||||
async count(predicate?: MaybeAsyncAnyPredicate<TElement>) {
|
||||
let count = 0;
|
||||
|
||||
if (predicate) {
|
||||
@@ -167,7 +167,7 @@ export abstract class BaseAsyncSequence<TElement> extends AsyncSequenceMarker im
|
||||
return n >= 0 ? n : Infinity;
|
||||
}
|
||||
|
||||
async #tryGetFirst(predicate?: MaybeAsyncPredicate<TElement>) {
|
||||
async #tryGetFirst(predicate?: MaybeAsyncAnyPredicate<TElement>) {
|
||||
if (predicate) {
|
||||
for await (const element of this) {
|
||||
if (await predicate(element)) {
|
||||
@@ -193,7 +193,7 @@ export abstract class BaseAsyncSequence<TElement> extends AsyncSequenceMarker im
|
||||
} as const;
|
||||
}
|
||||
|
||||
async first(predicate?: MaybeAsyncPredicate<TElement>) {
|
||||
async first(predicate?: MaybeAsyncAnyPredicate<TElement>) {
|
||||
const result = await this.#tryGetFirst(predicate);
|
||||
|
||||
if (result.found) {
|
||||
@@ -203,13 +203,13 @@ export abstract class BaseAsyncSequence<TElement> extends AsyncSequenceMarker im
|
||||
throw new Error("No element was found.");
|
||||
}
|
||||
|
||||
async firstOrDefault(predicate?: MaybeAsyncPredicate<TElement>, def?: TElement) {
|
||||
async firstOrDefault(predicate?: MaybeAsyncAnyPredicate<TElement>, def?: TElement) {
|
||||
const result = await this.#tryGetFirst(predicate);
|
||||
|
||||
return result.found ? result.element : def;
|
||||
}
|
||||
|
||||
async #tryGetLast(predicate?: MaybeAsyncPredicate<TElement>) {
|
||||
async #tryGetLast(predicate?: MaybeAsyncAnyPredicate<TElement>) {
|
||||
let found = false;
|
||||
let result: TElement | undefined = undefined;
|
||||
|
||||
@@ -233,7 +233,7 @@ export abstract class BaseAsyncSequence<TElement> extends AsyncSequenceMarker im
|
||||
};
|
||||
}
|
||||
|
||||
async last(predicate?: MaybeAsyncPredicate<TElement>) {
|
||||
async last(predicate?: MaybeAsyncAnyPredicate<TElement>) {
|
||||
const result = await this.#tryGetLast(predicate);
|
||||
|
||||
if (result.found) {
|
||||
@@ -243,13 +243,13 @@ export abstract class BaseAsyncSequence<TElement> extends AsyncSequenceMarker im
|
||||
throw new Error("No element was found.");
|
||||
}
|
||||
|
||||
async lastOrDefault(predicate?: MaybeAsyncPredicate<TElement>, def?: TElement) {
|
||||
async lastOrDefault(predicate?: MaybeAsyncAnyPredicate<TElement>, def?: TElement) {
|
||||
const result = await this.#tryGetLast(predicate);
|
||||
|
||||
return result.found ? result.element : def;
|
||||
}
|
||||
|
||||
async #tryGetSingle(predicate?: MaybeAsyncPredicate<TElement>) {
|
||||
async #tryGetSingle(predicate?: MaybeAsyncAnyPredicate<TElement>) {
|
||||
if (predicate) {
|
||||
let result: { found: true; element: TElement; } | undefined = undefined;
|
||||
|
||||
@@ -297,7 +297,7 @@ export abstract class BaseAsyncSequence<TElement> extends AsyncSequenceMarker im
|
||||
} as const;
|
||||
}
|
||||
|
||||
async single(predicate?: MaybeAsyncPredicate<TElement>) {
|
||||
async single(predicate?: MaybeAsyncAnyPredicate<TElement>) {
|
||||
const result = await this.#tryGetSingle(predicate);
|
||||
|
||||
if (result.found == true) {
|
||||
@@ -318,7 +318,7 @@ export abstract class BaseAsyncSequence<TElement> extends AsyncSequenceMarker im
|
||||
throw new Error(reason);
|
||||
}
|
||||
|
||||
async singleOrDefault(predicate?: MaybeAsyncPredicate<TElement>, def?: TElement) {
|
||||
async singleOrDefault(predicate?: MaybeAsyncAnyPredicate<TElement>, def?: TElement) {
|
||||
const result = await this.#tryGetSingle(predicate);
|
||||
|
||||
return result.found ? result.element : def;
|
||||
@@ -391,7 +391,7 @@ export abstract class BaseAsyncSequence<TElement> extends AsyncSequenceMarker im
|
||||
return acc as unknown as TResult;
|
||||
}
|
||||
|
||||
async #find<TResult>(sorter: MaybeAsyncPredicate<number>, selector?: MaybeAsyncConverter<TElement, TResult>, comparer?: MaybeAsyncComparer<TResult>) {
|
||||
async #find<TResult>(sorter: MaybeAsyncAnyPredicate<number>, selector?: MaybeAsyncConverter<TElement, TResult>, comparer?: MaybeAsyncComparer<TResult>) {
|
||||
const iterator = this.iterator();
|
||||
|
||||
let next = await iterator.next();
|
||||
@@ -462,11 +462,11 @@ export abstract class BaseAsyncSequence<TElement> extends AsyncSequenceMarker im
|
||||
return new OrderByAsyncSequence<TElement, TBy>(this, true, selector, comparer);
|
||||
}
|
||||
|
||||
partition(equater?: MaybeAsyncEquater<TElement>): AsyncSequence<TElement[]> {
|
||||
partition(equater?: MaybeAsyncEquater<TElement>): AsyncSequence<AsyncSequence<TElement>> {
|
||||
return new PartitionAsyncSequence<TElement>(this, equater);
|
||||
}
|
||||
|
||||
partitionBy<TBy>(selector: MaybeAsyncConverter<TElement, TBy>, equater?: MaybeAsyncEquater<TBy>): AsyncSequence<TElement[]> {
|
||||
partitionBy<TBy>(selector: MaybeAsyncConverter<TElement, TBy>, equater?: MaybeAsyncEquater<TBy>): AsyncSequence<AsyncSequence<TElement>> {
|
||||
return new PartitionByAsyncSequence<TElement, TBy>(this, selector, equater);
|
||||
}
|
||||
|
||||
@@ -502,7 +502,7 @@ export abstract class BaseAsyncSequence<TElement> extends AsyncSequenceMarker im
|
||||
return new IntersectByAsyncSequence<TElement, TBy>(this, wrap(sequence), selector);
|
||||
}
|
||||
|
||||
async all(predicate: MaybeAsyncPredicate<TElement>) {
|
||||
async all(predicate: MaybeAsyncAnyPredicate<TElement>) {
|
||||
const n = await this.nonEnumeratedCount();
|
||||
|
||||
if (n === 0) {
|
||||
@@ -518,7 +518,7 @@ export abstract class BaseAsyncSequence<TElement> extends AsyncSequenceMarker im
|
||||
return true;
|
||||
}
|
||||
|
||||
async any(predicate?: MaybeAsyncPredicate<TElement>) {
|
||||
async any(predicate?: MaybeAsyncAnyPredicate<TElement>) {
|
||||
const n = await this.nonEnumeratedCount();
|
||||
|
||||
if (n === 0) {
|
||||
@@ -538,7 +538,7 @@ export abstract class BaseAsyncSequence<TElement> extends AsyncSequenceMarker im
|
||||
return n < 0 ? !(await this.iterator().next()).done : n > 0;
|
||||
}
|
||||
|
||||
async none(predicate?: MaybeAsyncPredicate<TElement>) {
|
||||
async none(predicate?: MaybeAsyncAnyPredicate<TElement>) {
|
||||
const n = await this.nonEnumeratedCount();
|
||||
|
||||
if (n === 0) {
|
||||
@@ -574,7 +574,7 @@ export abstract class BaseAsyncSequence<TElement> extends AsyncSequenceMarker im
|
||||
return n === 0 ? this : new SkipLastAsyncSequence<TElement>(this, n);
|
||||
}
|
||||
|
||||
skipWhile(predicate: MaybeAsyncPredicate<TElement>): AsyncSequence<TElement> {
|
||||
skipWhile(predicate: MaybeAsyncAnyPredicate<TElement>): AsyncSequence<TElement> {
|
||||
return new SkipWhileAsyncSequence<TElement>(this, predicate);
|
||||
}
|
||||
|
||||
@@ -594,7 +594,7 @@ export abstract class BaseAsyncSequence<TElement> extends AsyncSequenceMarker im
|
||||
return n === 0 ? empty<TElement>() : new TakeLastAsyncSequence<TElement>(this, n);
|
||||
}
|
||||
|
||||
takeWhile(predicate: MaybeAsyncPredicate<TElement>): AsyncSequence<TElement> {
|
||||
takeWhile(predicate: MaybeAsyncAnyPredicate<TElement>): AsyncSequence<TElement> {
|
||||
return new TakeWhileAsyncSequence<TElement>(this, predicate);
|
||||
}
|
||||
|
||||
@@ -612,7 +612,7 @@ export abstract class BaseAsyncSequence<TElement> extends AsyncSequenceMarker im
|
||||
return new ZippedAsyncSequence<TElement, TOther>(this, wrap(sequence));
|
||||
}
|
||||
|
||||
indexex(): AsyncSequence<[number, TElement]> {
|
||||
indexed(): AsyncSequence<[number, TElement]> {
|
||||
return new IndexedAsyncSequence<TElement>(this);
|
||||
}
|
||||
|
||||
@@ -620,12 +620,15 @@ export abstract class BaseAsyncSequence<TElement> extends AsyncSequenceMarker im
|
||||
return new ReversedAsyncSequence<TElement>(this);
|
||||
}
|
||||
|
||||
chunked(size: number): AsyncSequence<AsyncSequence<TElement>> {
|
||||
chunked(size: number, asArray?: false): AsyncSequence<AsyncSequence<TElement>>;
|
||||
chunked(size: number, asArray: true): AsyncSequence<TElement[]>;
|
||||
chunked(size: number, asArray?: boolean): AsyncSequence<AsyncSequence<TElement>> | AsyncSequence<TElement[]> {
|
||||
if (size <= 0) {
|
||||
throw new Error("Chunk size must be positive.");
|
||||
}
|
||||
|
||||
return new ChunkedAsyncSequence<TElement>(this, size);
|
||||
const sequence = new ChunkedAsyncSequence<TElement>(this, size);
|
||||
return asArray ? sequence : sequence.select(array);
|
||||
}
|
||||
|
||||
async random(options?: AsyncRandomOptions<TElement> | undefined): Promise<TElement | undefined> {
|
||||
@@ -636,6 +639,10 @@ export abstract class BaseAsyncSequence<TElement> extends AsyncSequenceMarker im
|
||||
return new CacheAsyncSequence<TElement>(this);
|
||||
}
|
||||
|
||||
async asArray(): Promise<TElement[]> {
|
||||
return await this.toArray();
|
||||
}
|
||||
|
||||
async toArray() {
|
||||
const array: TElement[] = [];
|
||||
|
||||
@@ -646,8 +653,12 @@ export abstract class BaseAsyncSequence<TElement> extends AsyncSequenceMarker im
|
||||
return array;
|
||||
}
|
||||
|
||||
async toMap<TKey, TValue>(keySelector: MaybeAsyncConverter<TElement, TKey>, valueSelector: MaybeAsyncConverter<TElement, TValue>) {
|
||||
const map = new Map<TKey, TValue>();
|
||||
toMap<TKey>(keySelector: MaybeAsyncConverter<TElement, TKey>): Promise<Map<TKey, TElement>>;
|
||||
toMap<TKey, TValue>(keySelector: MaybeAsyncConverter<TElement, TKey>, valueSelector: MaybeAsyncConverter<TElement, TValue>): Promise<Map<TKey, TValue>>;
|
||||
async toMap<TKey>(keySelector: MaybeAsyncConverter<TElement, TKey>, valueSelector?: MaybeAsyncConverter<TElement, any>): Promise<Map<TKey, any>> {
|
||||
valueSelector ??= identity;
|
||||
|
||||
const map = new Map<TKey, any>();
|
||||
|
||||
for await (const element of this) {
|
||||
const key = await keySelector(element);
|
||||
@@ -669,8 +680,12 @@ export abstract class BaseAsyncSequence<TElement> extends AsyncSequenceMarker im
|
||||
return set;
|
||||
}
|
||||
|
||||
async toObject<TValue>(keySelector: MaybeAsyncConverter<TElement, PropertyKey>, valueSelector: MaybeAsyncConverter<TElement, TValue>) {
|
||||
const obj: Record<PropertyKey, TValue> = {};
|
||||
toObject<TKey extends PropertyKey>(keySelector: MaybeAsyncConverter<TElement, TKey>): Promise<Record<TKey, TElement>>;
|
||||
toObject<TKey extends PropertyKey, TValue>(keySelector: MaybeAsyncConverter<TElement, TKey>, valueSelector: MaybeAsyncConverter<TElement, TValue>): Promise<Record<TKey, TValue>>;
|
||||
async toObject<TKey extends PropertyKey>(keySelector: MaybeAsyncConverter<TElement, TKey>, valueSelector?: MaybeAsyncConverter<TElement, any>): Promise<Record<TKey, any>> {
|
||||
valueSelector ??= identity;
|
||||
|
||||
const obj: Record<PropertyKey, any> = {};
|
||||
|
||||
for await (const element of this) {
|
||||
const key = await keySelector(element);
|
||||
@@ -722,7 +737,7 @@ export class DelegatedAsyncSequence<TElement> extends AsyncSequenceMarker implem
|
||||
return this.#sequence.apply(pipeline);
|
||||
}
|
||||
|
||||
count(predicate?: MaybeAsyncPredicate<TElement> | undefined): Promise<number> {
|
||||
count(predicate?: MaybeAsyncAnyPredicate<TElement> | undefined): Promise<number> {
|
||||
return this.#sequence.count(predicate);
|
||||
}
|
||||
|
||||
@@ -746,7 +761,7 @@ export class DelegatedAsyncSequence<TElement> extends AsyncSequenceMarker implem
|
||||
return this.#sequence.selectMany(selector);
|
||||
}
|
||||
|
||||
where(predicate: MaybeAsyncPredicate<TElement>): AsyncSequence<TElement> {
|
||||
where(predicate: MaybeAsyncAnyPredicate<TElement>): AsyncSequence<TElement> {
|
||||
return this.#sequence.where(predicate);
|
||||
}
|
||||
|
||||
@@ -792,27 +807,27 @@ export class DelegatedAsyncSequence<TElement> extends AsyncSequenceMarker implem
|
||||
return this.#sequence.concat(...sequences);
|
||||
}
|
||||
|
||||
first(predicate?: MaybeAsyncPredicate<TElement> | undefined): Promise<TElement> {
|
||||
first(predicate?: MaybeAsyncAnyPredicate<TElement> | undefined): Promise<TElement> {
|
||||
return this.#sequence.first(predicate);
|
||||
}
|
||||
|
||||
firstOrDefault(predicate?: MaybeAsyncPredicate<TElement> | undefined, def?: TElement | undefined): Promise<TElement | undefined> {
|
||||
firstOrDefault(predicate?: MaybeAsyncAnyPredicate<TElement> | undefined, def?: TElement | undefined): Promise<TElement | undefined> {
|
||||
return this.#sequence.firstOrDefault(predicate, def);
|
||||
}
|
||||
|
||||
last(predicate?: MaybeAsyncPredicate<TElement> | undefined): Promise<TElement> {
|
||||
last(predicate?: MaybeAsyncAnyPredicate<TElement> | undefined): Promise<TElement> {
|
||||
return this.#sequence.last(predicate);
|
||||
}
|
||||
|
||||
lastOrDefault(predicate?: MaybeAsyncPredicate<TElement> | undefined, def?: TElement | undefined): Promise<TElement | undefined> {
|
||||
lastOrDefault(predicate?: MaybeAsyncAnyPredicate<TElement> | undefined, def?: TElement | undefined): Promise<TElement | undefined> {
|
||||
return this.#sequence.lastOrDefault(predicate, def);
|
||||
}
|
||||
|
||||
single(predicate?: MaybeAsyncPredicate<TElement> | undefined): Promise<TElement> {
|
||||
single(predicate?: MaybeAsyncAnyPredicate<TElement> | undefined): Promise<TElement> {
|
||||
return this.#sequence.single(predicate);
|
||||
}
|
||||
|
||||
singleOrDefault(predicate?: MaybeAsyncPredicate<TElement> | undefined, def?: TElement | undefined): Promise<TElement | undefined> {
|
||||
singleOrDefault(predicate?: MaybeAsyncAnyPredicate<TElement> | undefined, def?: TElement | undefined): Promise<TElement | undefined> {
|
||||
return this.#sequence.singleOrDefault(predicate, def);
|
||||
}
|
||||
|
||||
@@ -863,11 +878,11 @@ export class DelegatedAsyncSequence<TElement> extends AsyncSequenceMarker implem
|
||||
return this.#sequence.orderByDescending(selector, comparer);
|
||||
}
|
||||
|
||||
partition(equater?: MaybeAsyncEquater<TElement> | undefined): AsyncSequence<TElement[]> {
|
||||
partition(equater?: MaybeAsyncEquater<TElement> | undefined): AsyncSequence<AsyncSequence<TElement>> {
|
||||
return this.#sequence.partition(equater);
|
||||
}
|
||||
|
||||
partitionBy<TBy>(selector: MaybeAsyncConverter<TElement, TBy>, equater?: MaybeAsyncEquater<TBy> | undefined): AsyncSequence<TElement[]> {
|
||||
partitionBy<TBy>(selector: MaybeAsyncConverter<TElement, TBy>, equater?: MaybeAsyncEquater<TBy> | undefined): AsyncSequence<AsyncSequence<TElement>> {
|
||||
return this.#sequence.partitionBy(selector, equater);
|
||||
}
|
||||
|
||||
@@ -903,17 +918,17 @@ export class DelegatedAsyncSequence<TElement> extends AsyncSequenceMarker implem
|
||||
return this.#sequence.intersectBy(wrap(sequence), selector, equater);
|
||||
}
|
||||
|
||||
all(predicate: MaybeAsyncPredicate<TElement>): Promise<boolean> {
|
||||
all(predicate: MaybeAsyncAnyPredicate<TElement>): Promise<boolean> {
|
||||
return this.#sequence.all(predicate);
|
||||
}
|
||||
|
||||
any(predicate: MaybeAsyncPredicate<TElement>): Promise<boolean>;
|
||||
any(predicate: MaybeAsyncAnyPredicate<TElement>): Promise<boolean>;
|
||||
any(): Promise<boolean>;
|
||||
any(predicate?: any) {
|
||||
return this.#sequence.any(predicate);
|
||||
}
|
||||
|
||||
none(predicate: MaybeAsyncPredicate<TElement>): Promise<boolean>;
|
||||
none(predicate: MaybeAsyncAnyPredicate<TElement>): Promise<boolean>;
|
||||
none(): Promise<boolean>;
|
||||
none(predicate?: any) {
|
||||
return this.#sequence.none(predicate);
|
||||
@@ -927,7 +942,7 @@ export class DelegatedAsyncSequence<TElement> extends AsyncSequenceMarker implem
|
||||
return this.#sequence.skipLast(n);
|
||||
}
|
||||
|
||||
skipWhile(condition: MaybeAsyncPredicate<TElement>): AsyncSequence<TElement> {
|
||||
skipWhile(condition: MaybeAsyncAnyPredicate<TElement>): AsyncSequence<TElement> {
|
||||
return this.#sequence.skipWhile(condition);
|
||||
}
|
||||
|
||||
@@ -939,7 +954,7 @@ export class DelegatedAsyncSequence<TElement> extends AsyncSequenceMarker implem
|
||||
return this.#sequence.takeLast(n);
|
||||
}
|
||||
|
||||
takeWhile(condition: MaybeAsyncPredicate<TElement>): AsyncSequence<TElement> {
|
||||
takeWhile(condition: MaybeAsyncAnyPredicate<TElement>): AsyncSequence<TElement> {
|
||||
return this.#sequence.takeWhile(condition);
|
||||
}
|
||||
|
||||
@@ -955,16 +970,18 @@ export class DelegatedAsyncSequence<TElement> extends AsyncSequenceMarker implem
|
||||
return this.#sequence.zip(wrap(sequence));
|
||||
}
|
||||
|
||||
indexex(): AsyncSequence<[number, TElement]> {
|
||||
return this.#sequence.indexex();
|
||||
indexed(): AsyncSequence<[number, TElement]> {
|
||||
return this.#sequence.indexed();
|
||||
}
|
||||
|
||||
reversed(): AsyncSequence<TElement> {
|
||||
return this.#sequence.reversed();
|
||||
}
|
||||
|
||||
chunked(size: number): AsyncSequence<AsyncSequence<TElement>> {
|
||||
return this.#sequence.chunked(size);
|
||||
chunked(size: number, asArray?: false): AsyncSequence<AsyncSequence<TElement>>;
|
||||
chunked(size: number, asArray: true): AsyncSequence<TElement[]>;
|
||||
chunked(size: number, asArray?: any): AsyncSequence<AsyncSequence<TElement>> | AsyncSequence<TElement[]> {
|
||||
return this.#sequence.chunked(size, asArray);
|
||||
}
|
||||
|
||||
random(options?: AsyncRandomOptions<TElement> | undefined): Promise<TElement | undefined> {
|
||||
@@ -975,11 +992,17 @@ export class DelegatedAsyncSequence<TElement> extends AsyncSequenceMarker implem
|
||||
return this.#sequence.cached();
|
||||
}
|
||||
|
||||
asArray(): Promise<TElement[]> {
|
||||
return this.#sequence.asArray();
|
||||
}
|
||||
|
||||
toArray(): Promise<TElement[]> {
|
||||
return this.#sequence.toArray();
|
||||
}
|
||||
|
||||
toMap<TKey, TValue>(keySelector: MaybeAsyncConverter<TElement, TKey>, valueSelector: MaybeAsyncConverter<TElement, TValue>): Promise<Map<TKey, TValue>> {
|
||||
toMap<TKey>(keySelector: MaybeAsyncConverter<TElement, TKey>): Promise<Map<TKey, TElement>>;
|
||||
toMap<TKey, TValue>(keySelector: MaybeAsyncConverter<TElement, TKey>, valueSelector: MaybeAsyncConverter<TElement, TValue>): Promise<Map<TKey, TValue>>;
|
||||
toMap(keySelector: any, valueSelector?: any) {
|
||||
return this.#sequence.toMap(keySelector, valueSelector);
|
||||
}
|
||||
|
||||
@@ -987,7 +1010,9 @@ export class DelegatedAsyncSequence<TElement> extends AsyncSequenceMarker implem
|
||||
return this.#sequence.toSet();
|
||||
}
|
||||
|
||||
toObject<TKey extends PropertyKey, TValue>(keySelector: MaybeAsyncConverter<TElement, TKey>, valueSelector: MaybeAsyncConverter<TElement, TValue>): Promise<Record<TKey, TValue>> {
|
||||
toObject<TKey extends PropertyKey>(keySelector: MaybeAsyncConverter<TElement, TKey>): Promise<Record<TKey, TElement>>;
|
||||
toObject<TKey extends PropertyKey, TValue>(keySelector: MaybeAsyncConverter<TElement, TKey>, valueSelector: MaybeAsyncConverter<TElement, TValue>): Promise<Record<TKey, TValue>>;
|
||||
toObject(keySelector: any, valueSelector?: any) {
|
||||
return this.#sequence.toObject(keySelector, valueSelector);
|
||||
}
|
||||
|
||||
@@ -1352,11 +1377,11 @@ class DistinctByAsyncSequence<T, U> extends BaseAsyncSequence<T> {
|
||||
}
|
||||
}
|
||||
|
||||
class FilterAsyncSequence<T> extends BaseAsyncSequence<T> {
|
||||
class WhereAsyncSequence<T> extends BaseAsyncSequence<T> {
|
||||
readonly #sequence: AsyncSequence<T>;
|
||||
readonly #predicate: MaybeAsyncPredicate<T>;
|
||||
readonly #predicate: MaybeAsyncAnyPredicate<T>;
|
||||
|
||||
constructor(sequence: AsyncSequence<T>, predicate: MaybeAsyncPredicate<T>) {
|
||||
constructor(sequence: AsyncSequence<T>, predicate: MaybeAsyncAnyPredicate<T>) {
|
||||
super();
|
||||
|
||||
this.#sequence = sequence;
|
||||
@@ -1372,7 +1397,7 @@ class FilterAsyncSequence<T> extends BaseAsyncSequence<T> {
|
||||
}
|
||||
}
|
||||
|
||||
class FlatMapperAsyncSequence<T, U> extends BaseAsyncSequence<U> {
|
||||
class SelectManyAsyncSequence<T, U> extends BaseAsyncSequence<U> {
|
||||
readonly #sequence: AsyncSequence<T>;
|
||||
readonly #converter: MaybeAsyncConverter<T, MaybeAsyncSequence<U>>;
|
||||
|
||||
@@ -1408,7 +1433,7 @@ class IndexedAsyncSequence<T> extends BaseAsyncSequence<[number, T]> {
|
||||
}
|
||||
}
|
||||
|
||||
class MapperAsyncSequence<T, U> extends BaseAsyncSequence<U> {
|
||||
class SelectAsyncSequence<T, U> extends BaseAsyncSequence<U> {
|
||||
readonly #sequence: AsyncSequence<T>;
|
||||
readonly #converter: MaybeAsyncConverter<T, U>;
|
||||
|
||||
@@ -1432,9 +1457,9 @@ class MapperAsyncSequence<T, U> extends BaseAsyncSequence<U> {
|
||||
|
||||
class SkipWhileAsyncSequence<T> extends BaseAsyncSequence<T> {
|
||||
readonly #sequence: AsyncSequence<T>;
|
||||
readonly #predicate: MaybeAsyncPredicate<T>;
|
||||
readonly #predicate: MaybeAsyncAnyPredicate<T>;
|
||||
|
||||
constructor(sequence: AsyncSequence<T>, predicate: MaybeAsyncPredicate<T>) {
|
||||
constructor(sequence: AsyncSequence<T>, predicate: MaybeAsyncAnyPredicate<T>) {
|
||||
super();
|
||||
|
||||
this.#sequence = sequence;
|
||||
@@ -1538,9 +1563,9 @@ class SkipAsyncSequence<T> extends BaseAsyncSequence<T> {
|
||||
|
||||
class TakeWhileAsyncSequence<T> extends BaseAsyncSequence<T> {
|
||||
readonly #sequence: AsyncSequence<T>;
|
||||
readonly #predicate: MaybeAsyncPredicate<T>;
|
||||
readonly #predicate: MaybeAsyncAnyPredicate<T>;
|
||||
|
||||
constructor(sequence: AsyncSequence<T>, predicate: MaybeAsyncPredicate<T>) {
|
||||
constructor(sequence: AsyncSequence<T>, predicate: MaybeAsyncAnyPredicate<T>) {
|
||||
super();
|
||||
|
||||
this.#sequence = sequence;
|
||||
@@ -1998,7 +2023,7 @@ class GroupByAsyncSequence<TElement, TKey, TResult> extends BaseAsyncSequence<Gr
|
||||
}
|
||||
}
|
||||
|
||||
class ChunkedAsyncSequence<T> extends BaseAsyncSequence<AsyncSequence<T>> {
|
||||
class ChunkedAsyncSequence<T> extends BaseAsyncSequence<T[]> {
|
||||
readonly #sequence: AsyncSequence<T>;
|
||||
readonly #size: number;
|
||||
|
||||
@@ -2021,13 +2046,13 @@ class ChunkedAsyncSequence<T> extends BaseAsyncSequence<AsyncSequence<T>> {
|
||||
chunk.push(obj);
|
||||
|
||||
if (chunk.length === this.#size) {
|
||||
yield array(chunk);
|
||||
yield chunk;
|
||||
chunk = [];
|
||||
}
|
||||
}
|
||||
|
||||
if (chunk.length > 0) {
|
||||
yield array(chunk);
|
||||
yield chunk;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2158,7 +2183,7 @@ class CacheAsyncSequence<T> extends BaseAsyncSequence<T> {
|
||||
}
|
||||
}
|
||||
|
||||
class PartitionAsyncSequence<T> extends BaseAsyncSequence<T[]> {
|
||||
class PartitionAsyncSequence<T> extends BaseAsyncSequence<AsyncSequence<T>> {
|
||||
readonly #sequence: AsyncSequence<T>;
|
||||
readonly #equater: MaybeAsyncEquater<T>;
|
||||
|
||||
@@ -2182,11 +2207,13 @@ class PartitionAsyncSequence<T> extends BaseAsyncSequence<T[]> {
|
||||
}
|
||||
}
|
||||
|
||||
yield* partitions.values();
|
||||
for (const partition of partitions.values()) {
|
||||
yield array(partition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PartitionByAsyncSequence<TElement, TBy> extends BaseAsyncSequence<TElement[]> {
|
||||
class PartitionByAsyncSequence<TElement, TBy> extends BaseAsyncSequence<AsyncSequence<TElement>> {
|
||||
readonly #sequence: AsyncSequence<TElement>;
|
||||
readonly #selector: MaybeAsyncConverter<TElement, TBy>;
|
||||
readonly #equater: MaybeAsyncEquater<TBy>;
|
||||
@@ -2213,6 +2240,8 @@ class PartitionByAsyncSequence<TElement, TBy> extends BaseAsyncSequence<TElement
|
||||
}
|
||||
}
|
||||
|
||||
yield* partitions.values();
|
||||
for (const partition of partitions.values()) {
|
||||
yield array(partition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user