/*! * @author electricessence / https://github.com/electricessence/ * Original: http://linqjs.codeplex.com/ * Licensing: MIT https://github.com/electricessence/TypeScript.NET/blob/master/LICENSE.md */ import { EnumeratorBase } from "../System/Collections/Enumeration/EnumeratorBase"; import { DisposableBase } from "../System/Disposable/DisposableBase"; import { IEnumerator } from "../System/Collections/Enumeration/IEnumerator"; import { IEnumerable } from "../System/Collections/Enumeration/IEnumerable"; import { Action, ActionWithIndex, Closure, Comparison, EqualityComparison, HashSelector, PredicateWithIndex, Selector, SelectorWithIndex } from "../System/FunctionTypes"; import { IDictionary, IMap } from "../System/Collections/Dictionaries/IDictionary"; import { Comparable } from "../System/IComparable"; import { Order } from "../System/Collections/Sorting/Order"; import { EnumerableAction } from "./EnumerableAction"; import { Primitive } from "../System/Primitive"; import { ForEachEnumerable } from "../System/Collections/Enumeration/ForEachEnumerable"; import { InfiniteValueFactory } from "../System/Collections/Enumeration/InfiniteEnumerator"; export declare class InfiniteLinqEnumerable extends DisposableBase { protected _enumeratorFactory: () => IEnumerator; constructor(_enumeratorFactory: () => IEnumerator, finalizer?: Closure | null); protected _isEndless: boolean | undefined; readonly isEndless: boolean | undefined; getEnumerator(): IEnumerator; protected _onDispose(): void; asEnumerable(): this; /** * Similar to forEach, but executes an action for each time a value is enumerated. * If the action explicitly returns false or 0 (EnumerationAction.Break), the enumeration will complete. * If it returns a 2 (EnumerationAction.Skip) it will move on to the next item. * This also automatically handles disposing the enumerator. * @param action * @param initializer * @param isEndless Special case where isEndless can be null in order to negate inheritance. * @param onComplete Executes just before the enumerator releases when there is no more entries. * @returns {any} */ doAction(action: ActionWithIndex | PredicateWithIndex | SelectorWithIndex | SelectorWithIndex, initializer: Closure | null, isEndless: true, onComplete?: Action): InfiniteLinqEnumerable; doAction(action: ActionWithIndex | PredicateWithIndex | SelectorWithIndex | SelectorWithIndex, initializer?: Closure | null, isEndless?: boolean | null | undefined, onComplete?: Action): LinqEnumerable; force(): void; skip(count: number): this; take(count: number): FiniteEnumerable; elementAt(index: number): T; elementAtOrDefault(index: number): T | undefined; elementAtOrDefault(index: number, defaultValue: T): T; first(): T; firstOrDefault(): T | undefined; firstOrDefault(defaultValue: T): T; single(): T; singleOrDefault(): T | undefined; singleOrDefault(defaultValue: T): T; any(): boolean; isEmpty(): boolean; traverseDepthFirst(childrenSelector: (element: T) => ForEachEnumerable | null | undefined): LinqEnumerable; traverseDepthFirst(childrenSelector: (element: T | TNode) => ForEachEnumerable | null | undefined): LinqEnumerable; traverseDepthFirst(childrenSelector: (element: T) => ForEachEnumerable | null | undefined, resultSelector: SelectorWithIndex): LinqEnumerable; traverseDepthFirst(childrenSelector: (element: T | TNode) => ForEachEnumerable | null | undefined, resultSelector: SelectorWithIndex): LinqEnumerable; flatten(): InfiniteLinqEnumerable; flatten(): InfiniteLinqEnumerable; pairwise(selector: (previous: T, current: T, index: number) => TSelect): InfiniteLinqEnumerable; scan(func: (previous: T, current: T, index: number) => T, seed?: T): this; select(selector: SelectorWithIndex): InfiniteLinqEnumerable; map(selector: SelectorWithIndex): InfiniteLinqEnumerable; protected _selectMany(collectionSelector: SelectorWithIndex | null | undefined>, resultSelector?: (collection: T, element: TElement) => TResult): LinqEnumerable; selectMany(collectionSelector: SelectorWithIndex | null | undefined>): InfiniteLinqEnumerable; selectMany(collectionSelector: SelectorWithIndex | null | undefined>, resultSelector: (collection: T, element: TElement) => TResult): InfiniteLinqEnumerable; protected _filterSelected(selector?: SelectorWithIndex, filter?: PredicateWithIndex): LinqEnumerable; protected _filterSelected(selector: SelectorWithIndex, filter?: PredicateWithIndex): LinqEnumerable; /** * Returns selected values that are not null or undefined. */ choose(): InfiniteLinqEnumerable; choose(selector?: Selector): InfiniteLinqEnumerable; where(predicate: PredicateWithIndex): this; filter(predicate: PredicateWithIndex): this; nonNull(): this; ofType(type: { new (...params: any[]): TType; }): InfiniteLinqEnumerable; except(second: ForEachEnumerable, compareSelector?: HashSelector): this; distinct(compareSelector?: HashSelector): this; distinctUntilChanged(compareSelector?: HashSelector): this; /** * Returns a single default value if empty. * @param defaultValue * @returns {Enumerable} */ defaultIfEmpty(defaultValue?: T): this; zip(second: ForEachEnumerable, resultSelector: (first: T, second: TSecond, index: number) => TResult): LinqEnumerable; zipMultiple(second: ArrayLike>, resultSelector: (first: T, second: TSecond, index: number) => TResult): LinqEnumerable; join(inner: ForEachEnumerable, outerKeySelector: Selector, innerKeySelector: Selector, resultSelector: (outer: T, inner: TInner) => TResult, compareSelector?: HashSelector): LinqEnumerable; groupJoin(inner: ForEachEnumerable, outerKeySelector: Selector, innerKeySelector: Selector, resultSelector: (outer: T, inner: TInner[] | null) => TResult, compareSelector?: HashSelector): LinqEnumerable; merge(enumerables: ArrayLike>): this; concat(...enumerables: Array>): this; union(second: ForEachEnumerable, compareSelector?: HashSelector): this; insertAt(index: number, other: ForEachEnumerable): this; alternateMultiple(sequence: ForEachEnumerable): this; alternateSingle(value: T): this; alternate(...sequence: T[]): this; catchError(handler: (e: any) => void): this; finallyAction(action: Closure): this; buffer(size: number): InfiniteLinqEnumerable; share(): this; memoize(): InfiniteLinqEnumerable; } /** * Enumerable is a wrapper class that allows more primitive enumerables to exhibit LINQ behavior. * * In C# Enumerable is not an instance but has extensions for IEnumerable. * In this case, we use Enumerable as the underlying class that is being chained. */ export declare class LinqEnumerable extends InfiniteLinqEnumerable { constructor(enumeratorFactory: () => IEnumerator, finalizer?: Closure | null, isEndless?: boolean); asEnumerable(): this; skipWhile(predicate: PredicateWithIndex): LinqEnumerable; takeWhile(predicate: PredicateWithIndex): this; takeUntil(predicate: PredicateWithIndex, includeUntilValue?: boolean): this; traverseBreadthFirst(childrenSelector: (element: T) => ForEachEnumerable | null | undefined): LinqEnumerable; traverseBreadthFirst(childrenSelector: (element: T | TNode) => ForEachEnumerable | null | undefined): LinqEnumerable; traverseBreadthFirst(childrenSelector: (element: T) => ForEachEnumerable | null | undefined, resultSelector: SelectorWithIndex): LinqEnumerable; traverseBreadthFirst(childrenSelector: (element: T | TNode) => ForEachEnumerable | null | undefined, resultSelector: SelectorWithIndex): LinqEnumerable; forEach(action: ActionWithIndex, max?: number): number; forEach(action: PredicateWithIndex, max?: number): number; toArray(predicate?: PredicateWithIndex): T[]; copyTo(target: T[], index?: number, count?: number): T[]; toLookup(keySelector: SelectorWithIndex, elementSelector?: SelectorWithIndex, compareSelector?: HashSelector): Lookup; toMap(keySelector: SelectorWithIndex, elementSelector: SelectorWithIndex): IMap; toDictionary(keySelector: SelectorWithIndex, elementSelector: SelectorWithIndex, compareSelector?: HashSelector): IDictionary; toJoinedString(separator?: string, selector?: Selector): string; takeExceptLast(count?: number): this; skipToLast(count: number): this; select(selector: SelectorWithIndex): LinqEnumerable; map(selector: SelectorWithIndex): LinqEnumerable; selectMany(collectionSelector: SelectorWithIndex | null | undefined>): LinqEnumerable; selectMany(collectionSelector: SelectorWithIndex | null | undefined>, resultSelector: (collection: T, element: TElement) => TResult): LinqEnumerable; choose(): LinqEnumerable; choose(selector: SelectorWithIndex): LinqEnumerable; reverse(): this; shuffle(): this; count(predicate?: PredicateWithIndex): number; all(predicate: PredicateWithIndex): boolean; every(predicate: PredicateWithIndex): boolean; any(predicate?: PredicateWithIndex): boolean; some(predicate?: PredicateWithIndex): boolean; contains(value: T, compareSelector?: Selector): boolean; indexOf(value: T, compareSelector?: SelectorWithIndex): number; lastIndexOf(value: T, compareSelector?: SelectorWithIndex): number; intersect(second: ForEachEnumerable, compareSelector?: HashSelector): this; sequenceEqual(second: ForEachEnumerable, equalityComparer?: EqualityComparison): boolean; ofType(type: { new (...params: any[]): TType; }): LinqEnumerable; orderBy(keySelector?: Selector): IOrderedEnumerable; orderUsing(comparison: Comparison): IOrderedEnumerable; orderUsingReversed(comparison: Comparison): IOrderedEnumerable; orderByDescending(keySelector?: Selector): IOrderedEnumerable; buffer(size: number): LinqEnumerable; groupBy(keySelector: SelectorWithIndex): LinqEnumerable>; groupBy(keySelector: SelectorWithIndex, elementSelector: SelectorWithIndex, compareSelector?: HashSelector): LinqEnumerable>; groupBy(keySelector: SelectorWithIndex, elementSelector: SelectorWithIndex, compareSelector?: HashSelector): LinqEnumerable>; partitionBy(keySelector: Selector): LinqEnumerable>; partitionBy(keySelector: Selector, elementSelector?: Selector, resultSelector?: (key: TKey, element: TElement[]) => Grouping, compareSelector?: Selector): LinqEnumerable>; flatten(): LinqEnumerable; flatten(): LinqEnumerable; pairwise(selector: (previous: T, current: T, index: number) => TSelect): LinqEnumerable; aggregate(reduction: (previous: T, current: T, index?: number) => T): T | undefined; aggregate(reduction: (previous: U, current: T, index?: number) => U, initialValue: U): U; reduce(reduction: (previous: T, current: T, index?: number) => T): T | undefined; reduce(reduction: (previous: U, current: T, index?: number) => U, initialValue: U): U; average(selector?: SelectorWithIndex): number; max(): T | undefined; min(): T | undefined; maxBy(keySelector?: Selector): T | undefined; minBy(keySelector?: Selector): T | undefined; sum(selector?: SelectorWithIndex): number; product(selector?: SelectorWithIndex): number; /** * Takes the first number and divides it by all following. * @param selector * @returns {number} */ quotient(selector?: SelectorWithIndex): number; last(): T; lastOrDefault(): T | undefined; lastOrDefault(defaultValue: T): T; memoize(): LinqEnumerable; throwWhenEmpty(): NotEmptyEnumerable; } export interface NotEmptyEnumerable extends LinqEnumerable { aggregate(reduction: (previous: T, current: T, index?: number) => T): T; reduce(reduction: (previous: T, current: T, index?: number) => T): T; max(): T; min(): T; maxBy(keySelector?: Selector): T; minBy(keySelector?: Selector): T; } export declare class FiniteEnumerable extends LinqEnumerable { constructor(enumeratorFactory: () => IEnumerator, finalizer?: Closure); } export interface IOrderedEnumerable extends FiniteEnumerable { thenBy(keySelector: (value: T) => any): IOrderedEnumerable; thenByDescending(keySelector: (value: T) => any): IOrderedEnumerable; thenUsing(comparison: Comparison): IOrderedEnumerable; thenUsingReversed(comparison: Comparison): IOrderedEnumerable; } export declare class ArrayEnumerable extends FiniteEnumerable { private _source; constructor(source: ArrayLike); protected _onDispose(): void; readonly source: ArrayLike; toArray(): T[]; asEnumerable(): this; forEach(action: ActionWithIndex, max?: number): number; forEach(action: PredicateWithIndex, max?: number): number; any(predicate?: PredicateWithIndex): boolean; count(predicate?: PredicateWithIndex): number; elementAtOrDefault(index: number): T | undefined; elementAtOrDefault(index: number, defaultValue: T): T; last(): T; lastOrDefault(): T | undefined; lastOrDefault(defaultValue: T): T; skip(count: number): this; takeExceptLast(count?: number): this; skipToLast(count: number): this; reverse(): this; memoize(): this; sequenceEqual(second: ForEachEnumerable, equalityComparer?: EqualityComparison): boolean; toJoinedString(separator?: string, selector?: Selector): string; } export declare class Grouping extends ArrayEnumerable { private _groupKey; constructor(_groupKey: TKey, elements: TElement[]); readonly key: TKey; } export declare class Lookup { private _dictionary; constructor(_dictionary: IDictionary); readonly count: number; get(key: TKey): TElement[] | null; contains(key: TKey): boolean; getEnumerator(): IEnumerator>; } export declare class OrderedEnumerable extends FiniteEnumerable { private source; keySelector: Selector | null; order: Order; parent?: OrderedEnumerable | null | undefined; comparer: Comparison; constructor(source: IEnumerable, keySelector: Selector | null, order: Order, parent?: OrderedEnumerable | null | undefined, comparer?: Comparison); private createOrderedEnumerable; thenBy(keySelector: (value: T) => TOrderBy): IOrderedEnumerable; thenUsing(comparison: Comparison): IOrderedEnumerable; thenByDescending(keySelector: (value: T) => TOrderBy): IOrderedEnumerable; thenUsingReversed(comparison: Comparison): IOrderedEnumerable; getEnumerator(): EnumeratorBase; protected _onDispose(): void; } export declare function Enumerable(source: InfiniteValueFactory): InfiniteLinqEnumerable; export declare function Enumerable(source: ForEachEnumerable, ...additional: Array>): LinqEnumerable; export declare module Enumerable { /** * Universal method for converting a primitive enumerables into a LINQ enabled ones. * * Is not limited to TypeScript usages. */ function from(source: InfiniteValueFactory): InfiniteLinqEnumerable; function from(source: ForEachEnumerable, ...additional: Array>): LinqEnumerable; function fromAny(source: InfiniteValueFactory): InfiniteLinqEnumerable; function fromAny(source: ForEachEnumerable): LinqEnumerable; function fromAny(source: any): LinqEnumerable | undefined; function fromAny(source: ForEachEnumerable, defaultEnumerable: LinqEnumerable): LinqEnumerable; function fromThese(sources: ForEachEnumerable[]): LinqEnumerable; function fromOrEmpty(source: ForEachEnumerable): LinqEnumerable; /** * Static helper for converting enumerables to an array. * @param source * @returns {any} */ function toArray(source: ForEachEnumerable): T[]; function _choice(values: T[]): InfiniteLinqEnumerable; function choice(values: ArrayLike): InfiniteLinqEnumerable; function chooseFrom(arg: T, ...args: T[]): InfiniteLinqEnumerable; function cycle(values: ArrayLike): InfiniteLinqEnumerable; function cycleThrough(arg: T, ...args: T[]): InfiniteLinqEnumerable; function empty(): FiniteEnumerable; function repeat(element: T): InfiniteLinqEnumerable; function repeat(element: T, count: number): FiniteEnumerable; /** * DEPRECATED This method began to not make sense in so many ways. * @deprecated since version 4.2 * @param initializer * @param finalizer */ function repeatWithFinalize(initializer: () => T, finalizer: Closure): InfiniteLinqEnumerable; function repeatWithFinalize(initializer: () => T, finalizer?: Action): InfiniteLinqEnumerable; /** * Creates an enumerable of one element. * @param element * @returns {FiniteEnumerable} */ function make(element: T): FiniteEnumerable; function range(start: number, count: number, step?: number): FiniteEnumerable; function rangeDown(start: number, count: number, step?: number): FiniteEnumerable; function toInfinity(start?: number, step?: number): InfiniteLinqEnumerable; function toNegativeInfinity(start?: number, step?: number): InfiniteLinqEnumerable; function rangeTo(start: number, to: number, step?: number): FiniteEnumerable; function matches(input: string, pattern: any, flags?: string): FiniteEnumerable; function generate(factory: () => T): InfiniteLinqEnumerable; function generate(factory: () => T, count: number): FiniteEnumerable; function generate(factory: (index: number) => T): InfiniteLinqEnumerable; function generate(factory: (index: number) => T, count: number): FiniteEnumerable; module random { function floats(maxExclusive?: number): InfiniteLinqEnumerable; function integers(boundary: number, inclusive?: boolean): InfiniteLinqEnumerable; } function unfold(seed: T, valueFactory: SelectorWithIndex, skipSeed?: Boolean): InfiniteLinqEnumerable; function forEach(e: ForEachEnumerable, action: ActionWithIndex, max?: number): number; function forEach(e: ForEachEnumerable, action: PredicateWithIndex, max?: number): number; function map(enumerable: ForEachEnumerable, selector: SelectorWithIndex): TResult[]; function max(values: FiniteEnumerable): number; function min(values: FiniteEnumerable): number; /** * Takes any set of collections of the same type and weaves them together. * @param enumerables * @returns {Enumerable} */ function weave(enumerables: ForEachEnumerable>): LinqEnumerable; } export default Enumerable;