import { Either } from './Either'; import { Lazy } from './function'; import { Alternative1 } from './Functors/Alternative'; import { ChainRec1 } from './Functors/ChainRec'; import { Monad1 } from './Functors/Monad'; import { Maybe } from './Maybe'; import { Predicate } from './Predicate'; export declare const IterKind: unique symbol; export declare type IterKind = typeof IterKind; declare module './Functors/HKT' { interface Kinded { readonly [IterKind]: Iterable; } } /** * Returns whether an iterator is empty. * * @example * * ```ts * assert.deepStrictEqual(isEmpty([]), true) * assert.deepStrictEqual(isEmpty(new Map()), true) * assert.deepStrictEqual(isEmpty(new Set()), true) * assert.deepStrictEqual(isEmpty({ [Symbol.iterator]: function*() {} }), true) * ``` */ export declare const isEmpty: (ma: Iterable) => boolean; /** * Returns if the iterator is instanceof `Array`, otherwise returns a new array created by `Array.from`. * * @example * * ```ts * assert.deepStrictEqual(toArray([1, 2, 3]), [1, 2, 3]) * assert.deepStrictEqual(toArray(new Set([1, 2, 3])), [1, 2, 3]) * ``` */ export declare const toArray: (ma: Iterable) => A[]; /** * Returns an iterator with the elements at last. */ export declare function push(a: Iterable, ...as: A[]): Iterable; /** * Returns an iterator with the elements at start. */ export declare function unshift(a: Iterable, ...items: T[]): Iterable; /** * Creates an iterator with an array. */ export declare function of(...as: A[]): Iterable; /** * Returns whether the index is out of bounds. * * @example * * ```ts * assert.deepStrictEqual(pipe([1, 2, 3], isOutOfBounds(1)), false) * assert.deepStrictEqual(pipe([1, 2, 3], isOutOfBounds(-1)), true) * assert.deepStrictEqual(pipe([1, 2, 3], isOutOfBounds(3)), true) * ``` */ export declare const isOutOfBounds: (index: number) => (as: Iterable) => boolean; /** * Returns the value at the index of a iterator and wrapped in a Some if the index is not out of bounds. Otherwise returns a none. * * @example * * ```ts * assert.deepStrictEqual(pipe([1, 2, 3], nth(1)), some(2)) * assert.deepStrictEqual(pipe([1, 2, 3], nth(-1)), some(3)) * assert.deepStrictEqual(pipe([1, 2, 3], nth(3)), none) * ``` */ export declare const nth: (index: number) => (as: Iterable) => Maybe; /** * Returns an empty list. * @returns */ export declare const empty: () => Iterable; /** * Alias of `empty`. */ export declare const zero: () => Iterable; /** * Calls a callback function on each element of the iterator, and returns an iterator contains the results. */ export declare const map: (f: (a: A) => B) => (ma: Iterable) => Iterable; /** * Creates an iterator from a given range with step. * * @example * * ```ts * assert.deepStrictEqual(flow(range, collect)(1, 3), [1, 2]) * assert.deepStrictEqual(flow(range, collect)(1, 6, 2), [1, 3, 5]) * assert.deepStrictEqual(flow(range, collect)(3, 1), [3, 2]) * ``` */ export declare function range(from: number, end: number, step?: number): Iterable; /** * Creates an iterator from a range starting from `0` to end with step. * * @example * * ```ts * assert.deepStrictEqual(flow(to, collect)(3), [1, 2]) * assert.deepStrictEqual(flow(to, collect)(6, 2), [0, 2, 4]) * ``` */ export declare const to: (end: number, step?: number) => Iterable; /** * Creates an iterator of length `n` initialized with `f(i)`. * * @example * * ```ts * assert.deepStrictEqual(flow(makeBy, collect)(3, n => n * 2), [0, 2, 4]) * ``` */ export declare function makeBy(n: number, f: (i: number) => A): Iterable; /** * Creates an iterator from a value repeated the specified number of times. * * @example * * ```ts * assert.deepStrictEqual(flow(replicate, collect)('a', 2), ['a', 'a']) * ``` */ export declare const replicate: (ma: A, n: number) => Iterable; /** * Creates an array from an iterator. * * @example * * ```ts * assert.deepStrictEqual(collect([1, 2, 3]), [1, 2, 3])) * assert.deepStrictEqual(collect(function* () { * for(let i = 1; i <=3; i++) yield i * }), [1, 2, 3])) * ``` */ export declare const collect: (ma: Iterable) => A[]; /** * Adds all the elements of an iterator into a string, separated by the specified separator string. * * @example * * ```ts * assert.deepStrictEqual(pipe(['a', 'b', 'c'], join('-')), 'a-b-c') * ``` */ export declare const join: (seperator?: string) => (ma: Iterable) => string; /** * Returns the length or size of an iterator. * * @example * * ```ts * assert.deepStrictEqual(count([1, 2, 3]), 3) * assert.deepStrictEqual(count(function* () { * yield 1 * yield 2 * yield 3 * }), 3) * ``` */ export declare const count: (ma: Iterable) => number; /** * Returns an iterator that elements meet the condition specified in a predicate function. * * @example * * ```ts * assert.deepStrictEqual( * pipe( * [1, 2, 3, 4], * filter(a => a % 2 === 0) * ), * [2, 4] * ) * ``` */ export declare const filter: (predicate: Predicate) => (ma: Iterable) => Iterable; /** * Concats two iterators that have different types. * * @example * * ```ts * assert.deepStrictEqual(pipe([1], alt(() => ['2', '3']), collect), [1, '2', '3']) * ``` */ export declare const alt: (that: Lazy>) => (ma: Iterable) => Iterable; /** * Chains the result of the applying function to the iterator with the other. * * @example * * ```ts * const f = (s: string) => (n: number) => s + n * assert.deepStrictEqual(pipe(['a', 'b'], map(f), ap([1, 2]), collect), ['a1', 'a2', 'b1', 'b2']) * ``` */ export declare const ap: (ma: Iterable) => (f: Iterable<(a: A) => B>) => Iterable; /** * Calls the specified callback function for all the elements in an iterator. * The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. * * @example * * ```ts * assert.deepStrictEqual( * pipe([2, 3, 4], reduce((acc: number, cur: number) => acc + cur, 1)), 10 * ) * ``` */ export declare function reduce(f: (b: A, a: A, i: number, as: Iterable) => A): (as: Iterable) => A; export declare function reduce(f: (b: A, a: A, i: number, as: Iterable) => A, b: A): (as: Iterable) => A; export declare function reduce(f: (b: B, a: A, i: number, as: Iterable) => B, b: B): (as: Iterable) => B; /** * Returns `Some` the first element of an iterator if it exists, otherwise returns `None`. * * @example * * assert.deepStrictEqual(head([1, 2, 3]), some(1)) * assert.deepStrictEqual(head([]), none) */ export declare const head: (ma: Iterable) => import("./Maybe").None | import("./Maybe").Some; /** * Try to return the first element of an iterator. * * @example * * ```ts * assert.deepStrictEqual(tryHead([1, 2, 3]), 1) * assert.deepStrictEqual(tryHead([]), undefined) * ``` */ export declare const tryHead: (ma: Iterable) => A | undefined; /** * Returns `Some` the last element of an iterator if it exists, otherwise returns `None`. * * @example * * assert.deepStrictEqual(tail([1, 2, 3]), some(3)) * assert.deepStrictEqual(tail([]), none) */ export declare const tail: (ma: Iterable) => Maybe; /** * Try to return the last element of an iterator. * * @example * * assert.deepStrictEqual(tryTail([1, 2, 3]), 3) * assert.deepStrictEqual(tryTail([]), undefined) */ export declare const tryTail: (ma: Iterable) => A | undefined; /** * Combines two or more iterators. * * @example * * assert.deepStrictEqual(pipe([1], concat([2, 3], [4, 5]), collect), [1, 2, 3, 4, 5]) */ export declare const concat: (...items: Iterable[]) => (ma: Iterable) => Iterable; /** * Takes two iterator and returns an iterator of the function results. If one iterator is short, excess items of the longer iterator are discarded. * * @example * * ```ts * assert.deepStrictEqual(flow(zipWith, collect)([1, 2], [1, 2], (a, b) => a + b), [2, 4]) * assert.deepStrictEqual(flow(zipWith, collect)(function* () { yield 1 }, [1, 2], (a, b) => a + b), [2]) * ``` */ export declare function zipWith(a: Iterable, b: Iterable, f: (a: A, b: B) => C): Iterable; /** * Takes two iterator and returns an iterator of corresponding pairs. If one iterator is short, excess items of the longer iterator are discarded. * * @example * * ```ts * assert.deepStrictEqual(flow(zip, collect)([1, 2], [1, 2]), [[1, 1], [2, 2]]) * assert.deepStrictEqual(flow(zip, collect)(function* () { yield 1 }, [1, 2]), [[1, 1]]) * ``` */ export declare function zip(a: Iterable, b: Iterable): Iterable<[A, B]>; /** * Similar as reverse of `zip`. Takes an iterator of pairs but returns two corresponding arrarys. * * @example * * ```ts * assert.deepStrictEqual(unzip([[1, 2], [3, 4]]), [[1, 3], [2, 4]]) * ``` */ export declare const unzip: (as: Iterable<[A, B]>) => [A[], B[]]; /** * Takes an iterator of iterators of `A` and flattens them into an iterator of `A`. * * @example * * ```ts * assert.deepStrictEqual(flatten([["a"], ["b", "c"], ["d", "e", "f"]]), ["a", "b", "c", "d", "e", "f"]) * ``` */ export declare function flatten(as: Iterable>): Iterable; /** * Splits an iterator into a group of iterators by the size of per group. * * @example * * ```ts * assert.deepStrictEqual(group([1, 2, 3, 4, 5, 6, 7], 3), [ * [1, 2, 3], * [4, 5, 6], * [7], * ]) * ``` */ export declare const group: (ma: Iterable, size: number) => Iterable>; /** * Returns an iterator that concatenates the function result into a single interator (like [`flatten`](#flatten)). * * @example * * ```ts * const f = (n: number) => flow(replicate, collect)(`${n}`, n) * * assert.deepStrictEqual(pipe([1,2,3], map(f), collect), [['1'],['2','2'],['3','3','3']]) * assert.deepStrictEqual(pipe([1,2,3], chain(f), collect), ['1','2','2','3','3','3']) * ``` */ export declare const chain: (f: (a: A, i: number) => Iterable) => (as: Iterable) => Iterable; /** * Depth-first chainRec. * * Chains until the next iterable is empty. * * @example * * ```ts * const f = (n: number) => n < 5 ? [right(n), left(n + 1)] : [right(n)] * assert.deepStrictEqual(pipe(1, chainRec(f), collect), [1, 2, 3, 4, 5]) * * const f2 = (n: number) => n < 5 ? [left(n + 1), right(n)] : [right(n)] * assert.deepStrictEqual(pipe(1, chainRec(f2), collect), [5, 4, 3, 2, 1]) * ``` */ export declare const chainRec: (f: (a: A) => Iterable>) => (a: A) => Iterable; /** * Creates an `Iter` from an iterator. * * @example * * ```ts * assert.deepStrictEqual(iter([1]), new Iter(() => [1])) * ``` */ export declare const iter: (ma: Iterable | (() => Iterable)) => Iter; /** * Iter */ export declare class Iter implements Iterable { private readonly _iter; constructor(_iter: () => Iterable); [Symbol.iterator](): Iterator; get arr(): A[]; static zero: () => Iter; static of: (...args: A_1[]) => Iter; static to: (end: number, step?: number | undefined) => Iter; static range: (from: number, end: number, step?: number | undefined) => Iter; static makeBy: (n: number, f: (i: number) => A_1) => Iter; static replicate: (ma: A_1, n: number) => Iter; head: () => import("./Maybe").None | import("./Maybe").Some; tryHead: () => A | undefined; tail: () => Maybe; tryTail: () => A | undefined; map: (f: (a: A) => B) => Iter; toArray: () => A[]; isEmpty: () => boolean; push: (...as: A[]) => Iter; unshift: (...as: A[]) => Iter; filter: (predicate: Predicate) => Iter; reduce: (f: (b: B, a: A) => B, b: B) => B; collect: () => A[]; join: (seperator?: string) => string; count: () => number; zipWith: (b: Iterable, f: (a: A, b: B) => C) => Iter; zip: (b: Iterable) => Iter<[A, B]>; unzip: () => Iter<[(A extends [infer X, any] | readonly [infer X, any] | (infer X)[] ? X : unknown)[], (A extends [any, infer Y] | readonly [any, infer Y] | (infer Y)[] ? Y : unknown)[]]>; flatten: () => A extends Iterable ? Iter : never; group: (size: number) => Iter>; chain: (f: (a: A, i: number) => Iterable) => Iter; concat: (...items: Iterable[]) => Iter>; ap: (ma: A extends (a: B) => any ? Iterable : never) => Iter any ? ReturnType : never>; alt: (that: Lazy>) => Iter; } /** * Alternative Functor */ export declare const Alternative: Alternative1; /** * Monad Functor */ export declare const Monad: Monad1; /** * ChainRec Functor */ export declare const ChainRec: ChainRec1;