FuncType - v0.60.3
    Preparing search index...

    Interface Foldable<A>

    Foldable type class represents data structures that can be folded to a summary value.

    This interface provides the universal fold operations (foldLeft, foldRight) that work consistently across all data structures. The fold method is intentionally excluded because it has different semantics for sum types vs collections:

    • Sum types (Option, Either, Try): fold(onEmpty, onValue) — pattern match
    • Collections (List, Set, Map): fold(initial, fn) — left-reduce accumulator

    Each type category defines its own fold with the appropriate signature.

    interface Foldable<out A> {
        foldLeft<B>(z: B): (op: (b: B, a: A) => B) => B;
        foldRight<B>(z: B): (op: (a: A, b: B) => B) => B;
    }

    Type Parameters

    • out A

      The type of elements in the data structure

    Hierarchy (View Summary)

    Index

    Methods

    • Left-associative fold using the provided zero value and operation

      Type Parameters

      • B

      Parameters

      • z: B

        Zero/identity value

      Returns (op: (b: B, a: A) => B) => B

      A function that takes an operation to apply

    • Right-associative fold using the provided zero value and operation

      Type Parameters

      • B

      Parameters

      • z: B

        Zero/identity value

      Returns (op: (a: A, b: B) => B) => B

      A function that takes an operation to apply