/** * @since 2.0.0 */ import { Applicative, Applicative1, Applicative2, Applicative2C, Applicative3 } from './Applicative.js'; import { HKT, Kind, Kind2, Kind3, Kind4, URIS, URIS2, URIS3, URIS4 } from './HKT.js'; import { Monad, Monad1, Monad2, Monad2C, Monad3, Monad3C } from './Monad.js'; import { Monoid } from './Monoid.js'; /** * @category model * @since 2.0.0 */ export interface Foldable { readonly URI: F; readonly reduce: (fa: HKT, b: B, f: (b: B, a: A) => B) => B; readonly foldMap: (M: Monoid) => (fa: HKT, f: (a: A) => M) => M; readonly reduceRight: (fa: HKT, b: B, f: (a: A, b: B) => B) => B; } /** * @category model * @since 2.0.0 */ export interface Foldable1 { readonly URI: F; readonly reduce: (fa: Kind, b: B, f: (b: B, a: A) => B) => B; readonly foldMap: (M: Monoid) => (fa: Kind, f: (a: A) => M) => M; readonly reduceRight: (fa: Kind, b: B, f: (a: A, b: B) => B) => B; } /** * @category model * @since 2.0.0 */ export interface Foldable2 { readonly URI: F; readonly reduce: (fa: Kind2, b: B, f: (b: B, a: A) => B) => B; readonly foldMap: (M: Monoid) => (fa: Kind2, f: (a: A) => M) => M; readonly reduceRight: (fa: Kind2, b: B, f: (a: A, b: B) => B) => B; } /** * @category model * @since 2.0.0 */ export interface Foldable2C { readonly URI: F; readonly _E: E; readonly reduce: (fa: Kind2, b: B, f: (b: B, a: A) => B) => B; readonly foldMap: (M: Monoid) => (fa: Kind2, f: (a: A) => M) => M; readonly reduceRight: (fa: Kind2, b: B, f: (a: A, b: B) => B) => B; } /** * @category model * @since 2.0.0 */ export interface Foldable3 { readonly URI: F; readonly reduce: (fa: Kind3, b: B, f: (b: B, a: A) => B) => B; readonly foldMap: (M: Monoid) => (fa: Kind3, f: (a: A) => M) => M; readonly reduceRight: (fa: Kind3, b: B, f: (a: A, b: B) => B) => B; } /** * @category model * @since 2.2.0 */ export interface Foldable3C { readonly URI: F; readonly _E: E; readonly reduce: (fa: Kind3, b: B, f: (b: B, a: A) => B) => B; readonly foldMap: (M: Monoid) => (fa: Kind3, f: (a: A) => M) => M; readonly reduceRight: (fa: Kind3, b: B, f: (a: A, b: B) => B) => B; } /** * @category model * @since 2.0.0 */ export interface Foldable4 { readonly URI: F; readonly reduce: (fa: Kind4, b: B, f: (b: B, a: A) => B) => B; readonly foldMap: (M: Monoid) => (fa: Kind4, f: (a: A) => M) => M; readonly reduceRight: (fa: Kind4, b: B, f: (a: A, b: B) => B) => B; } /** * `reduce` composition. * * @since 2.10.0 */ export declare function reduce(F: Foldable1, G: Foldable1): (b: B, f: (b: B, a: A) => B) => (fga: Kind>) => B; export declare function reduce(F: Foldable, G: Foldable): (b: B, f: (b: B, a: A) => B) => (fga: HKT>) => B; /** * `foldMap` composition. * * @since 2.10.0 */ export declare function foldMap(F: Foldable1, G: Foldable1): (M: Monoid) => (f: (a: A) => M) => (fga: Kind>) => M; export declare function foldMap(F: Foldable, G: Foldable): (M: Monoid) => (f: (a: A) => M) => (fga: HKT>) => M; /** * `reduceRight` composition. * * @since 2.10.0 */ export declare function reduceRight(F: Foldable1, G: Foldable1): (b: B, f: (a: A, b: B) => B) => (fga: Kind>) => B; export declare function reduceRight(F: Foldable, G: Foldable): (b: B, f: (a: A, b: B) => B) => (fga: HKT>) => B; /** * Similar to 'reduce', but the result is encapsulated in a monad. * * Note: this function is not generally stack-safe, e.g., for monads which build up thunks a la `IO`. * * @example * import { reduceM } from 'fp-ts/Foldable' * import { Monad, some } from 'fp-ts/Option' * import { make, Foldable } from 'fp-ts/Tree' * import { pipe } from 'fp-ts/function' * * const t = make(1, [make(2, []), make(3, []), make(4, [])]) * assert.deepStrictEqual(pipe(t, reduceM(Monad, Foldable)(0, (b, a) => (a > 2 ? some(b + a) : some(b)))), some(7)) * * @since 2.8.0 */ export declare function reduceM(M: Monad3, F: Foldable1): (b: B, f: (b: B, a: A) => Kind3) => (fa: Kind) => Kind3; export declare function reduceM(M: Monad3C, F: Foldable1): (b: B, f: (b: B, a: A) => Kind3) => (fa: Kind) => Kind3; export declare function reduceM(M: Monad2, F: Foldable1): (b: B, f: (b: B, a: A) => Kind2) => (fa: Kind) => Kind2; export declare function reduceM(M: Monad2C, F: Foldable1): (b: B, f: (b: B, a: A) => Kind2) => (fa: Kind) => Kind2; export declare function reduceM(M: Monad1, F: Foldable1): (b: B, f: (b: B, a: A) => Kind) => (fa: Kind) => Kind; export declare function reduceM(M: Monad, F: Foldable): (b: B, f: (b: B, a: A) => HKT) => (fa: HKT) => HKT; /** * Fold a data structure, accumulating values in some `Monoid`, combining adjacent elements using the specified separator * * @example * import { intercalate } from 'fp-ts/Foldable' * import * as S from 'fp-ts/string' * import { make, Foldable } from 'fp-ts/Tree' * * const t = make('a', [make('b', []), make('c', []), make('d', [])]) * assert.strictEqual(intercalate(S.Monoid, Foldable)('|', t), 'a|b|c|d') * * @since 2.0.0 */ export declare function intercalate(M: Monoid, F: Foldable3): (middle: M, fm: Kind3) => M; export declare function intercalate(M: Monoid, F: Foldable2): (middle: M, fm: Kind2) => M; export declare function intercalate(M: Monoid, F: Foldable2C): (middle: M, fm: Kind2) => M; export declare function intercalate(M: Monoid, F: Foldable1): (middle: M, fm: Kind) => M; export declare function intercalate(M: Monoid, F: Foldable): (middle: M, fm: HKT) => M; /** * Transforms a `Foldable` into a `toReadonlyArray`. * * @example * import { toReadonlyArray } from 'fp-ts/Foldable' * import { Foldable, make } from 'fp-ts/Tree' * * const t = make(1, [make(2, []), make(3, []), make(4, [])]) * assert.deepStrictEqual(toReadonlyArray(Foldable)(t), [1, 2, 3, 4]) * * @since 2.10.0 */ export declare function toReadonlyArray(F: Foldable4): (fa: Kind4) => ReadonlyArray; export declare function toReadonlyArray(F: Foldable3): (fa: Kind3) => ReadonlyArray; export declare function toReadonlyArray(F: Foldable3C): (fa: Kind3) => ReadonlyArray; export declare function toReadonlyArray(F: Foldable2): (fa: Kind2) => ReadonlyArray; export declare function toReadonlyArray(F: Foldable2C): (fa: Kind2) => ReadonlyArray; export declare function toReadonlyArray(F: Foldable1): (fa: Kind) => ReadonlyArray; export declare function toReadonlyArray(F: Foldable): (fa: HKT) => ReadonlyArray; /** * Traverse a data structure, performing some effects encoded by an `Applicative` functor at each value, ignoring the * final result. * * @example * import { Foldable } from 'fp-ts/Array' * import { traverse_ } from 'fp-ts/Foldable' * import { Applicative } from 'fp-ts/IO' * * let log = '' * const append = (s: string) => () => (log += s) * traverse_(Applicative, Foldable)(['a', 'b', 'c'], append)() * assert.strictEqual(log, 'abc') * * @since 2.0.0 */ export declare function traverse_(M: Applicative3, F: Foldable1): (fa: Kind, f: (a: A) => Kind3) => Kind3; export declare function traverse_(M: Applicative2, F: Foldable1): (fa: Kind, f: (a: A) => Kind2) => Kind2; export declare function traverse_(M: Applicative2C, F: Foldable1): (fa: Kind, f: (a: A) => Kind2) => Kind2; export declare function traverse_(M: Applicative1, F: Foldable1): (fa: Kind, f: (a: A) => Kind) => Kind; export declare function traverse_(M: Applicative, F: Foldable): (fa: HKT, f: (a: A) => HKT) => HKT; /** * Use [`reduceM`](#reducem) instead * * @category zone of death * @since 2.0.0 * @deprecated */ export declare function foldM(M: Monad3, F: Foldable1): (fa: Kind, b: B, f: (b: B, a: A) => Kind3) => Kind3; /** @deprecated */ export declare function foldM(M: Monad3C, F: Foldable1): (fa: Kind, b: B, f: (b: B, a: A) => Kind3) => Kind3; /** @deprecated */ export declare function foldM(M: Monad2, F: Foldable1): (fa: Kind, b: B, f: (b: B, a: A) => Kind2) => Kind2; /** @deprecated */ export declare function foldM(M: Monad2C, F: Foldable1): (fa: Kind, b: B, f: (b: B, a: A) => Kind2) => Kind2; /** @deprecated */ export declare function foldM(M: Monad1, F: Foldable1): (fa: Kind, b: B, f: (b: B, a: A) => Kind) => Kind; /** @deprecated */ export declare function foldM(M: Monad, F: Foldable): (fa: HKT, b: B, f: (b: B, a: A) => HKT) => HKT; /** * Use [`toReadonlyArray`](#toreadonlyarray) instead * * @category zone of death * @since 2.8.0 * @deprecated */ export declare const toArray: typeof toReadonlyArray; /** * @category zone of death * @since 2.0.0 * @deprecated */ export interface FoldableComposition { readonly reduce: (fga: HKT>, b: B, f: (b: B, a: A) => B) => B; readonly foldMap: (M: Monoid) => (fa: HKT>, f: (a: A) => M) => M; readonly reduceRight: (fa: HKT>, b: B, f: (a: A, b: B) => B) => B; } /** * @category zone of death * @since 2.0.0 * @deprecated */ export interface FoldableComposition11 { readonly reduce: (fga: Kind>, b: B, f: (b: B, a: A) => B) => B; readonly foldMap: (M: Monoid) => (fa: Kind>, f: (a: A) => M) => M; readonly reduceRight: (fa: Kind>, b: B, f: (a: A, b: B) => B) => B; } /** * @category zone of death * @since 2.0.0 * @deprecated */ export interface FoldableComposition12 { readonly reduce: (fga: Kind>, b: B, f: (b: B, a: A) => B) => B; readonly foldMap: (M: Monoid) => (fa: Kind>, f: (a: A) => M) => M; readonly reduceRight: (fa: Kind>, b: B, f: (a: A, b: B) => B) => B; } /** * @category zone of death * @since 2.0.0 * @deprecated */ export interface FoldableComposition12C { readonly reduce: (fga: Kind>, b: B, f: (b: B, a: A) => B) => B; readonly foldMap: (M: Monoid) => (fa: Kind>, f: (a: A) => M) => M; readonly reduceRight: (fa: Kind>, b: B, f: (a: A, b: B) => B) => B; } /** * @category zone of death * @since 2.0.0 * @deprecated */ export interface FoldableComposition21 { readonly reduce: (fga: Kind2>, b: B, f: (b: B, a: A) => B) => B; readonly foldMap: (M: Monoid) => (fa: Kind2>, f: (a: A) => M) => M; readonly reduceRight: (fa: Kind2>, b: B, f: (a: A, b: B) => B) => B; } /** * @category zone of death * @since 2.0.0 * @deprecated */ export interface FoldableComposition2C1 { readonly reduce: (fga: Kind2>, b: B, f: (b: B, a: A) => B) => B; readonly foldMap: (M: Monoid) => (fa: Kind2>, f: (a: A) => M) => M; readonly reduceRight: (fa: Kind2>, b: B, f: (a: A, b: B) => B) => B; } /** * @category zone of death * @since 2.0.0 * @deprecated */ export interface FoldableComposition22 { readonly reduce: (fga: Kind2>, b: B, f: (b: B, a: A) => B) => B; readonly foldMap: (M: Monoid) => (fa: Kind2>, f: (a: A) => M) => M; readonly reduceRight: (fa: Kind2>, b: B, f: (a: A, b: B) => B) => B; } /** * @category zone of death * @since 2.0.0 * @deprecated */ export interface FoldableComposition22C { readonly reduce: (fga: Kind2>, b: B, f: (b: B, a: A) => B) => B; readonly foldMap: (M: Monoid) => (fa: Kind2>, f: (a: A) => M) => M; readonly reduceRight: (fa: Kind2>, b: B, f: (a: A, b: B) => B) => B; } /** * Use * * - [reduce](#reduce) * - [foldMap](#foldmap) * - [reduceRight](#reduceright) * * instead. * * @category zone of death * @since 2.0.0 * @deprecated */ export declare function getFoldableComposition(F: Foldable2, G: Foldable2C): FoldableComposition22C; /** @deprecated */ export declare function getFoldableComposition(F: Foldable2, G: Foldable2): FoldableComposition22; /** @deprecated */ export declare function getFoldableComposition(F: Foldable2C, G: Foldable1): FoldableComposition2C1; /** @deprecated */ export declare function getFoldableComposition(F: Foldable2, G: Foldable1): FoldableComposition21; /** @deprecated */ export declare function getFoldableComposition(F: Foldable1, G: Foldable2C): FoldableComposition12C; /** @deprecated */ export declare function getFoldableComposition(F: Foldable1, G: Foldable2): FoldableComposition12; /** @deprecated */ export declare function getFoldableComposition(F: Foldable1, G: Foldable1): FoldableComposition11; /** @deprecated */ export declare function getFoldableComposition(F: Foldable, G: Foldable): FoldableComposition;