import { IEnumerator } from '../enumerator'; import { Action, Comparer, EqualityComparer, GroupByResultSelector, JoinResultSelector, Predicate, ResultSelector, ResultSelectorWithIndex } from '../types'; import { IGrouping } from './lookup'; /** * Represents a generic collection like an array, list or map * that can be enumerated. */ export declare abstract class IEnumerable implements Iterable { /** * Returns the sequence as an enumerable. */ asEnumerable(): IEnumerable; /** * Returns the sequence as an array. */ toArray(): TSource[]; /** * Converts an IEnumerable of promises to a single * promise that can be awaited. */ toAwaitable(): Promise>>; /** * Returns the sequence as a map, using the * keySelector function to generate the key * for each entry. */ toMap(keySelector: ResultSelector): Map; /** * Returns the sequence as a map, using the * keySelector function to generate the key * for each entry; and the valueSelector function * to generate the value for each entry. */ toMap(keySelector: ResultSelector, valueSelector: ResultSelector): Map; /** * Returns the sequence as a set. */ toSet(): Set; /** * Returns a new enumerable, wrapping the * sequence of this enumerable. This is useful, * when you need to call an ambiguous method on * the enumerable. `Array.prototype.forEach` will * always be called on an array, even if it's type * is `IEnumerable`. */ toEnumerable(): IEnumerable; /** * Returns a specified number of contiguous elements * from the start of a sequence. */ take(count: number): IEnumerable; /** * Returns elements of a sequence * while a specified predicate resolves to true. */ takeWhile(predicate: (value: TSource, index: number) => boolean): IEnumerable; /** * Returns the last `count` elements of a sequence. */ takeLast(count: number): IEnumerable; /** * Splits the elements of a sequence into chunks of size at most size. */ chunk(size: number): IEnumerable; /** * Splits the elements of a sequence into chunks of specified size. * If the sequence is shorter than the size, the last chunk will be * null. */ chunkOrDefault(size: number): IEnumerable; /** * Splits the elements of a sequence into chunks of specified size. * If the sequence is shorter than the size, the last chunk will be * a default value. */ chunkOrDefault(size: number, defaultValue: TSource[]): IEnumerable; /** * Concatenates two sequences. * This represents the concat LINQ method * and is named this way as to not interfere with * the JS Array.concat method. */ chain(second: IEnumerable): IEnumerable; /** * Appends an element to the end of the sequence. */ append(element: TSource): IEnumerable; /** * Prepends an element to the beginning of the sequence. */ prepend(element: TSource): IEnumerable; /** * Returns the count of elements in the sequence. */ count(): number; /** * Returns distinct elements of a sequence, * using Object.is equality. */ distinct(): IEnumerable; /** * Returns distinct elements of a sequence, * using a specified equality comparer. */ distinct(equalityComparer: EqualityComparer): IEnumerable; /** * Returns distinct elements from a sequence by using * a specified key selector function whose values * are compared using `Object.is` equality. */ distinctBy(keySelector: ResultSelector): IEnumerable; /** * Returns distinct elements from a sequence according to * a specified key selector function and using a specified * comparer to compare selected values. */ distinctBy(keySelector: ResultSelector, equalityComparer: EqualityComparer): IEnumerable; /** * Returns a single element of a sequence. * * @throws {@link MethodInvocationException } If the sequence is empty * or contains more than one element. */ single(predicate?: Predicate): TSource; /** * Returns the only element of a sequence or null * if the sequence is empty, or contains more than one element. */ singleOrDefault(): TSource | null; /** * Returns the only element of a sequence that satisfies a condition * or null if no such element exists. */ singleOrDefault(predicate: Predicate): TSource | null; /** * Returns the only element of a sequence or a default value * if the sequence is empty, or contains more than one element. */ singleOrDefault(defaultValue?: TSource): TSource; /** * Returns the only element of a sequence that satisfies a * condition or a default value if no such element exists */ singleOrDefault(predicate: Predicate, defaultValue: TSource): TSource; /** * Bypasses a specified number of elements in a sequence * and then returns the remaining elements. */ skip(count: number): IEnumerable; /** * Returns a sequence that contains the elements * from source with the last `count` elements of the source * collection omitted. */ skipLast(count: number): IEnumerable; /** * Bypasses elements in a sequence as long as a specified condition is true * and then returns the remaining elements. */ skipWhile(predicate: (element: TSource, index: number) => boolean): IEnumerable; /** * Determines whether two sequences are equal * according to `Object.is` equality. */ sequenceEqual(second: IEnumerable): boolean; /** * Determines whether two sequences are equal * according to an equality comparer. */ sequenceEqual(second: IEnumerable, equalityComparer: EqualityComparer): boolean; /** * Returns a sequence containing all elements that are * an instance of a specified type. */ ofType(type: TType): IEnumerable; /** * Returns a sequence that contains all elements that * satisfy the condition. */ where(predicate: Predicate): IEnumerable; /** * Projects each element of a sequence into a new form. */ select(selector: ResultSelectorWithIndex): IEnumerable; /** * Projects each element of a sequence to an IEnumerable * and flattens the resulting sequences into one sequence. */ selectMany(collectionSelector: ResultSelector>): IEnumerable; /** * Projects each element of a sequence to an IEnumerable * and flattens the resulting sequences into one sequence, * and invokes a result selector function on each element. */ selectMany(collectionSelector: ResultSelector>, resultSelector: ResultSelector): IEnumerable; /** * Performs a specified action on each element of a sequence. */ forElement(action: Action): void; /** * Returns the first element of a sequence. * * @throws {@link MethodInvocationException } If the sequence is empty */ first(): TSource; /** * Returns the first element of a sequence * that satisfies a condition. * * @throws {@link MethodInvocationException } If the sequence * contains no such element. */ first(predicate: Predicate): TSource; /** * Returns the first element of a sequence, or null if * the sequence contains no elements. */ firstOrDefault(): TSource | null; /** * Returns the first element of the sequence that satisfies * a condition or null if no such element exists. */ firstOrDefault(predicate: Predicate): TSource | null; /** * Returns the first element of the sequence or a * default value if the sequence contains no elements. */ firstOrDefault(defaultValue?: TSource): TSource; /** * Returns the first element of the sequence that satisfies * a condition or a default value if no such element exists. */ firstOrDefault(predicate: Predicate, defaultValue: TSource): TSource; /** * Returns the last element of a sequence. * * @throws {@link MethodInvocationException } If the sequence is empty */ last(): TSource; /** * Returns the last element of a sequence * that satisfies a condition. * * @throws {@link MethodInvocationException } If the sequence * contains no such element. */ last(predicate: Predicate): TSource; /** * Returns the last element of a sequence * or null if the sequence contains no elements. */ lastOrDefault(): TSource | null; /** * Returns the last element of a sequence that satisfies a condition * or null if no such element exists. */ lastOrDefault(predicate: Predicate): TSource | null; /** * Returns the last element of a sequence or * a default value if the sequence contains no elements. */ lastOrDefault(defaultValue?: TSource): TSource; /** * Returns the last element of a sequence that satisfies a condition * or a default value if no such element exists. */ lastOrDefault(predicate: Predicate, defaultValue: TSource): TSource; /** * Determines wether the sequence has any elements. */ any(): boolean; /** * Determines wether the sequence has any elements * that satisfy the predicate. */ any(predicate: Predicate): boolean; /** * Determines whether all elements of a sequence satisfy a condition. */ all(predicate: Predicate): boolean; /** * Determines whether a sequence contains a specified element. */ contains(value: TSource): boolean; /** * Returns the element at a specified index in a sequence. * * @throws {@link MethodInvocationException } If the index is out of range */ elementAt(index: number): TSource; /** * Reverses the order of the elements in a sequence. * * @remarks * This method enumerates all elements in the sequence * when the sequence is enumerated. */ reverse(): IEnumerable; /** * Returns the element at a specified index in a sequence or null * if the index is out of range. */ elementAtOrDefault(index: number): TSource | null; /** * Returns the element at a specified index in a sequence or a default value * if the index is out of range. */ elementAtOrDefault(index: number, defaultValue: TSource): TSource; /** * Returns a sequence containing the difference of two sequences. * Uses `Object.is` equality to compare elements. * * @remarks * This method returns those elements in first that don't appear * in second. It doesn't return those elements in second that * don't appear in first. */ except(second: IEnumerable): IEnumerable; /** * Returns a sequence containing the difference of two sequences. * Uses the specified equality comparer to compare elements. * * @remarks * This method returns those elements in first that don't appear * in second. It doesn't return those elements in second that * don't appear in first. */ except(second: IEnumerable, comparer: EqualityComparer): IEnumerable; /** * Returns a sequence containing the difference of two sequences * according to a selector function. Uses `Object.is` equality * to compare elements. * * @remarks * This method returns those elements in first that don't appear * in second. It doesn't return those elements in second that * don't appear in first. */ exceptBy(second: IEnumerable, keySelector: ResultSelector): IEnumerable; /** * Returns a sequence containing the difference of two sequences * according to a selector function. Uses the specified equality * comparer to compare elements. * * @remarks * This method returns those elements in first that don't appear * in second. It doesn't return those elements in second that * don't appear in first. */ exceptBy(second: IEnumerable, keySelector: ResultSelector, comparer: EqualityComparer): IEnumerable; /** * Produces the set intersection of two sequences by using * `Object.is` equality to compare values. */ intersect(second: IEnumerable): IEnumerable; /** * Produces the set intersection of two sequences by using * a specified equality comparer to compare values. */ intersect(second: IEnumerable, equalityComparer: EqualityComparer): IEnumerable; /** * Produces the set intersection of two sequences according * to a specified key selector function using * `Object.is` equality to compare values. */ intersectBy(second: IEnumerable, keySelector: ResultSelector): IEnumerable; /** * Produces the set intersection of two sequences according * to a specified key selector function using * a specified equality comparer to compare values. */ intersectBy(second: IEnumerable, keySelector: ResultSelector, equalityComparer: EqualityComparer): IEnumerable; /** * Applies an accumulator function over a sequence. */ aggregate(accumulator: (acc: TSource, element: TSource) => TSource): TSource; /** * Applies an accumulator function over a sequence. * The specified seed value is used as the initial accumulator value. */ aggregate(accumulator: (acc: TAccumulate, element: TSource) => TAccumulate, seed: TAccumulate): TAccumulate; /** * Applies an accumulator function over a sequence. * The specified seed value is used as the initial accumulator value, * and the specified function is used to select the result value. */ aggregate(accumulator: (acc: TAccumulate, element: TSource) => TAccumulate, seed: TAccumulate, resultSelector: ResultSelector): TResult; /** * Returns the maximum value in the sequence. * Uses the `>` operator to compare elements. */ max(): TSource; /** * Returns the maximum value in the sequence. * Uses a specified comparer to compare elements. */ max(compare: Comparer): TSource; /** * Returns the maximum value in the sequence according to * a specified key selector function. */ maxBy(keySelector: ResultSelector): TKey; /** * Returns the maximum value in the sequence according to * a specified key selector function and a specified * key comparer. */ maxBy(keySelector: ResultSelector, comparer: Comparer): TKey; /** * Returns the minimum value in the sequence. * Uses the `<` operator to compare elements. */ min(): TSource; /** * Returns the maximum value in the sequence. * Uses a specified comparer to compare elements. */ min(compare: Comparer): TSource; /** * Returns the minimum value in the sequence according to * a specified key selector function. */ minBy(keySelector: ResultSelector): TKey; /** * Returns the minimum value in the sequence according to * a specified key selector function and a specified * key comparer. */ minBy(keySelector: ResultSelector, comparer: Comparer): TKey; /** * Sums up the sequence using the `+` operator. */ sum(source: IEnumerable): TSource; /** * Sums up the result of the selector using the `+` operator. */ sum(source: IEnumerable, selector: ResultSelector): TResult; /** * Produces a sequence of unique elements of both sequences. * Uses `Object.is` equality to compare elements. */ union(second: IEnumerable): IEnumerable; /** * Produces a sequence of unique elements of both sequences. * Uses a specified equality comparer to compare elements. */ union(second: IEnumerable, equalityComparer: EqualityComparer): IEnumerable; /** * Produces a sequence of unique elements of both sequences * according to a specified key selector. * Uses `Object.is` equality to compare elements. */ unionBy(second: IEnumerable, keySelector: ResultSelector): IEnumerable; /** * Produces a sequence of unique elements of both sequences * according to a specified key selector. * Uses a specified equality comparer to compare elements. */ unionBy(second: IEnumerable, keySelector: ResultSelector, equalityComparer: EqualityComparer): IEnumerable; /** * Correlates the elements of two sequences based on matching keys. * Uses `Object.is` equality to compare keys. */ innerJoin( /** * The sequence to join to the first sequence. */ inner: IEnumerable, /** * A function to extract the join key from each * element of the first sequence. */ outerKeySelector: ResultSelector, /** * A function to extract the join key from each * element of the second sequence. */ innerKeySelector: ResultSelector, /** * A function to create a result element from two matching elements. */ resultSelector: JoinResultSelector): IEnumerable; /** * Correlates the elements of two sequences based on matching keys. * Uses a specified equality comparer to compare keys. */ innerJoin( /** * The sequence to join to the first sequence. */ inner: IEnumerable, /** * A function to extract the join key from each * element of the first sequence. */ outerKeySelector: ResultSelector, /** * A function to extract the join key from each * element of the second sequence. */ innerKeySelector: ResultSelector, /** * A function to create a result element from two matching elements. */ resultSelector: JoinResultSelector, /** * An equality comparer to compare keys. */ equalityComparer: EqualityComparer): IEnumerable; /** * Correlates the elements of two sequences based on matching keys * and groups the results. Uses `Object.is` equality to compare keys. */ groupJoin(outer: IEnumerable, inner: IEnumerable, outerKeySelector: ResultSelector, innerKeySelector: ResultSelector, resultSelector: JoinResultSelector, TResult>): IEnumerable; /** * Correlates the elements of two sequences based on matching keys * and groups the results. Uses a specified equality comparer to compare keys. */ groupJoin(outer: IEnumerable, inner: IEnumerable, outerKeySelector: ResultSelector, innerKeySelector: ResultSelector, resultSelector: JoinResultSelector, TResult>, equalityComparer: EqualityComparer): IEnumerable; /** * Groups the elements of a sequence according to a specified key selector function. */ groupBy(source: IEnumerable, keySelector: ResultSelector): IEnumerable>; /** * Groups the elements of a sequence according to a specified key selector * function and creates a result value from each group and its key. */ groupBy(source: IEnumerable, keySelector: ResultSelector, resultSelector: GroupByResultSelector): IEnumerable; /** * Groups the elements of a sequence according to a specified key selector * function and creates a result value from each group and its key. * The elements of each group are projected by using a specified function. */ groupBy(source: IEnumerable, keySelector: ResultSelector, elementSelector: ResultSelector, resultSelector: GroupByResultSelector): IEnumerable; /** * Groups the elements of a sequence according to a specified key selector * function and creates a result value from each group and its key. Key values * are compared by using a specified comparer, and the elements of each group are * projected by using a specified function. */ groupBy(source: IEnumerable, keySelector: ResultSelector, elementSelector: ResultSelector, resultSelector: GroupByResultSelector, equalityComparer: EqualityComparer): IEnumerable; /** * Joins all elements of a sequence to a single string. * Uses "" as the default separator. */ joinBy(character?: string): string; /** * Applies a specified function to the corresponding * elements of two sequences, producing a sequence of the results. * [1,2,3].zip([4,5,6], (a,b) => [a, b]) => [[1,4],[2,5],[3,6]] */ zip(second: IEnumerable, resultSelector: (first: TSource, second: TSecond) => TResult): IEnumerable; /** * Returns the IEnumerator of the source. */ abstract getEnumerator(): IEnumerator; [Symbol.iterator](): Iterator; }