import { Mapper, Predicate, TypedPredicate } from "./callbacks"; declare type ToMap = T extends readonly [infer K, infer V] ? Map : never; export interface IWrap extends Iterable { } export declare class IWrap { private readonly source; constructor(source: Iterable); /*************************************************************************/ /****************************** Convertors *******************************/ /** * Creates an Array from this iterable. * @returns The created Array. */ toArray(): T[]; /** * Creates a Map from this iterable if its elements are key value tuples. * Raises an error otherwise. * @returns The created Map. */ toMap(): ToMap; /** * Creates a Map using `keySelector` to extract the key from the elements. * @param keySelector Extract the key from the element. * @returns The created Map. */ toMap(keySelector: (o: T) => K): Map; /** * Creates a Map using `keySelector` to extract the key from the elements and * `valueSelector` to extract the value. * @param keySelector Extract the key from the element. * @param valueSelector Extract the value from the element. * @returns The created Map. */ toMap(keySelector: (o: T) => K, valueSelector: (o: T) => V): Map; /** * Creates a Set from this iterable. * @returns The created Set. */ toSet(): Set; /*************************************************************************/ /*************************** Consumer Methods ****************************/ /** * Determines whether all the members of an iterable satisfy the specified test. * @param predicate A function that accepts up to two arguments. The every method calls the predicate function for each element in the iterable until the predicate returns a value which is coercible to the Boolean value false, or until the end of the iterable. * @see {@link IterUtil.every} */ every(predicate: Predicate): boolean; /** * Returns the value of the first element in the iterable where predicate is true, and undefined otherwise. * @param predicate find calls predicate once for each element of the iterable until it finds one where predicate returns true. If such an element is found, find immediately returns that element value. Otherwise, find returns undefined. * @see {@link IterUtil.find} */ find(predicate: TypedPredicate): U | undefined; /** * Returns the index of the first element in the iterable where predicate is true, and -1 otherwise. * @param predicate find calls predicate once for each element of the iterable until it finds one where predicate returns true. If such an element is found, findIndex immediately returns that element index. Otherwise, findIndex returns -1. * @see {@link IterUtil.findIndex} */ findIndex(predicate: Predicate): number; /** * Returns the index of the first occurrence of a value in an iterable, or -1 if it is not present. * @param searchElement The value to locate. * @see {@link IterUtil.indexOf} */ indexOf(searchElement: T): number; /** * Adds all the elements of an iterable into a string, separated by the specified separator string. * @param seperator A string used to separate one element of the iterable from the next in the resulting string. If omitted, the iterable elements are separated with a comma. * @see {@link IterUtil.join} */ join(seperator?: string): string; /** * Calls the specified accumulator function for all the elements in an iterable. The return value of the accumulator function is the accumulated result, and is provided as an argument in the next call to the accumulator function. * @param accumulator A function that accepts up to three arguments. The reduce method calls the accumulator function one time for each element in the iterable. * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the accumulator function provides this value as an argument instead of an iterable value. * @see {@link IterUtil.reduce} */ reduce(accumulator: (previousValue: T, currentValue: T, currentIndex: number) => T): T; reduce(accumulator: (previousValue: T, currentValue: T, currentIndex: number) => T, initialValue: T): T; reduce(accumulator: (previousValue: U, currentValue: T, currentIndex: number) => U, initialValue: U): U; /** * Determines whether the specified callback function returns true for any element of an iterable. * @param predicate A function that accepts up to two arguments. The some method calls the predicate function for each element in the iterable until the predicate returns a value which is coercible to the Boolean value true, or until the end of the iterable. * @see {@link IterUtil.some} */ some(predicate: Predicate): boolean; /*************************************************************************/ /***************************** Lazy Methods ******************************/ /** * Adds the iterables at the end. * @param iterables * @returns * @see {@link Generators.concat} */ concat[]>(...iterables: I): IWrap, ...I][number]>>; /** * Ignores elements that doesn't satisfy the predicate. * @param predicate * @returns * @see {@link IterUtil.filter} */ filter(predicate: TypedPredicate): IWrap; /** * Apply `mapper` on every elements. * @param mapper Called for each element. * @returns * @see {@link IterUtil.map} */ map(mapper: Mapper): IWrap; /** * Takes only `count` elements. * @param count The number of elements to take. * @returns */ take(count: number): IWrap; /** * Takes elements while `predicate` return `true`. * @param predicate * @returns */ while(predicate: TypedPredicate): IWrap; /** * Zips this iterable with the provided iterables. * @param iterables * @returns * @see {@link Generators.zip} */ zip[]>(...iterables: I): IWrap<[T, ...{ [K in keyof I]: I[K] extends Iterable ? U : never; }]>; /*************************************************************************/ /************************** Static Constructors **************************/ /** * Creates a {@link IWrap} based on {@link Generators.concat}. * @param iterables * @returns */ static concat[]>(...iterables: I): IWrap>; /** * Creates a {@link IWrap} based on {@link Generators.cycle}. * @param iterable * @returns */ static cycle(iterable: Iterable): IWrap; /** * Creates a {@link IWrap} that wrap the iterable. * @param iterable * @returns */ static from(iterable: Iterable): IWrap; /** * Creates a {@link IWrap} based on {@link Generators.infinity}. * @param start * @param step * @returns */ static infinity(start?: number, step?: number): IWrap; /** * Creates a {@link IWrap} based on {@link Generators.range}. * @param start * @param end * @param step * @returns */ static range(start: number, end: number, step?: number): IWrap; /** * Creates a {@link IWrap} based on {@link Generators.repeat}. * @param value * @param count * @returns */ static repeat(value: T, count: number): IWrap; /** * Creates a {@link IWrap} based on {@link Generators.zip}. * @param iterables * @returns */ static zip[]>(...iterables: I): IWrap<{ [K in keyof I]: I[K] extends Iterable ? U : never; }>; } export {};