/** * This file contains the Iterable algebraic data type. Iterable is a lazy, * synchronous, and native structure defined by ecmascript. Generally, one * interacts with the Iterator structure directly, but the Iterable type, being * more generic, is a better target for functional. Any data structure that * implements Iterable (ie. Array, Map, Set, etc) can use the iterable methods * contained here if neeeded. * * Something to keep in mind here is that Iterables can have nasty edge cases * that don't exist for non-lazy data structures. Specifically, an iterable can * generate a theoretically infinite number of values, making the draining of an * iterable potentially impossible (trying it will cause the runtime to hang). * Additionally, many iterables are constructed using generators, which cannot * be easily cloned. This makes the process of chaining iterables a resource * intensive operation. As always, use these combinators with care. * * @module Iterable * @since 2.0.0 */ import "./_dnt.polyfills.js"; import type { Kind, Out } from "./kind.js"; import type { Applicable } from "./applicable.js"; import type { Combinable } from "./combinable.js"; import type { Either } from "./either.js"; import type { Filterable } from "./filterable.js"; import type { Flatmappable } from "./flatmappable.js"; import type { Foldable } from "./foldable.js"; import type { Initializable } from "./initializable.js"; import type { Mappable } from "./mappable.js"; import type { Option } from "./option.js"; import type { Pair } from "./pair.js"; import type { Predicate } from "./predicate.js"; import type { Refinement } from "./refinement.js"; import type { Showable } from "./showable.js"; import type { Wrappable } from "./wrappable.js"; /** * @since 2.0.0 */ export interface KindIterable extends Kind { readonly kind: Iterable>; } /** * @since 2.0.0 */ export declare function iterable(fa: () => Iterator): Iterable; /** * @since 2.0.0 */ export declare function clone(ta: Iterable): Iterable; /** * @since 2.0.0 */ export declare function range(count?: number, start?: number, step?: number): Iterable; /** * @since 2.0.0 */ export declare function wrap(...a: A[]): Iterable; /** * @since 2.0.0 */ export declare function apply(ua: Iterable): (ufai: Iterable<(a: A) => I>) => Iterable; /** * @since 2.0.0 */ export declare function map(fai: (a: A) => I): (ta: Iterable) => Iterable; /** * @since 2.0.0 */ export declare function flatmap(fati: (a: A) => Iterable): (ta: Iterable) => Iterable; /** * @since 2.0.0 */ export declare function forEach(fa: (a: A) => void): (ta: Iterable) => void; /** * @since 2.0.0 */ export declare function fold(foldr: (accumulator: O, value: A) => O, initial: O): (ua: Iterable) => O; /** * @since 2.0.0 */ export declare function scan(foldr: (accumulator: O, value: A, index: number) => O, initial: O): (ta: Iterable) => Iterable; /** * @since 2.0.0 */ export declare function filter(refinement: Refinement): (ua: Iterable) => Iterable; export declare function filter(predicate: Predicate): (ua: Iterable) => Iterable; /** * @since 2.0.0 */ export declare function filterMap(predicate: (a: A) => Option): (ua: Iterable) => Iterable; /** * @since 2.0.0 */ export declare function partition(refinement: (a: A) => a is B): (ua: Iterable) => Pair, Iterable>; export declare function partition(predicate: (a: A) => boolean): (ua: Iterable) => Pair, Iterable>; /** * @since 2.0.0 */ export declare function partitionMap(predicate: (a: A) => Either): (ua: Iterable) => Pair, Iterable>; /** * Collect all values of an iterable into an array. WARNING: If the iterable is * infinite then this will cause the program to hang indefinitely. * * @since 2.0.0 */ export declare function collect(ta: Iterable): ReadonlyArray; /** * @since 2.0.0 */ export declare function take(n: number): (ta: Iterable) => Iterable; /** * @since 2.0.0 */ export declare function takeUntil(predicate: Predicate): (ta: Iterable) => Iterable; /** * @since 2.0.0 */ export declare function takeWhile(predicate: Predicate): (ta: Iterable) => Iterable; /** * @since 2.0.0 */ export declare function repeat(n: number): (ta: Iterable) => Iterable; /** * @since 2.0.0 */ export declare function init(): Iterable; /** * @since 2.0.0 */ export declare function combine(second: Iterable): (first: Iterable) => Iterable; /** * @since 2.0.0 */ export declare function getCombinable(): Combinable>; /** * @since 2.0.0 */ export declare function getInitializable(): Initializable>; /** * @since 2.0.0 */ export declare function getShowable(S: Showable): Showable>; /** * @since 2.0.0 */ export declare const ApplicableIterable: Applicable; /** * @since 2.0.0 */ export declare const FlatmappableIterable: Flatmappable; /** * @since 2.0.0 */ export declare const FilterableIterable: Filterable; /** * @since 2.0.0 */ export declare const FoldableIterable: Foldable; /** * @since 2.0.0 */ export declare const MappableIterable: Mappable; /** * @since 2.0.0 */ export declare const WrappableIterable: Wrappable; /** * @since 2.0.0 */ export declare const tap: (fn: (value: A) => void) => (ua: Iterable) => Iterable; /** * @since 2.0.0 */ export declare const bind: (name: Exclude, faui: (a: A) => Iterable) => (ua: Iterable) => Iterable<{ readonly [K_1 in N | keyof A]: K_1 extends keyof A ? A[K_1] : I; }>; /** * @since 2.0.0 */ export declare const bindTo: (name: N) => (ua: Iterable) => Iterable<{ readonly [K in N]: A; }>;