Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface Foldable<T>

Type parameters

  • T

Hierarchy

Index

Methods

fold

  • fold(zero: T, fn: function): T
  • Reduces the collection to a single value using the associative binary function you give. Since the function is associative, order of application doesn't matter.

    Example:

    HashSet.of(1,2,3).fold(0, (a,b) => a + b);
    => 6
    

    Parameters

    • zero: T
    • fn: function
        • (v1: T, v2: T): T
        • Parameters

          • v1: T
          • v2: T

          Returns T

    Returns T

foldLeft

  • foldLeft<U>(zero: U, fn: function): U
  • Reduces the collection to a single value. Left-associative.

    Example:

    Vector.of("a", "b", "c").foldLeft("!", (xs,x) => x+xs);
    => "cba!"
    

    Type parameters

    • U

    Parameters

    • zero: U

      The initial value

    • fn: function

      A function taking the previous value and the current collection item, and returning an updated value.

        • (soFar: U, cur: T): U
        • Parameters

          • soFar: U
          • cur: T

          Returns U

    Returns U

foldRight

  • foldRight<U>(zero: U, fn: function): U
  • Reduces the collection to a single value. Right-associative.

    Example:

    Vector.of("a", "b", "c").foldRight("!", (x,xs) => xs+x)
    => "!cba"
    

    Type parameters

    • U

    Parameters

    • zero: U

      The initial value

    • fn: function

      A function taking the current collection item and the previous value , and returning an updated value.

        • (cur: T, soFar: U): U
        • Parameters

          • cur: T
          • soFar: U

          Returns U

    Returns U

reduce

  • reduce(combine: function): Option<T>
  • Reduces the collection to a single value by repeatedly calling the combine function. No starting value. The order in which the elements are passed to the combining function is undetermined.

    Parameters

    • combine: function
        • (v1: T, v2: T): T
        • Parameters

          • v1: T
          • v2: T

          Returns T

    Returns Option<T>

Generated using TypeDoc