Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "xform/match-last"

Index

Functions

Functions

matchLast

  • matchLast<T>(pred: Predicate<T>): Transducer<T, T>
  • matchLast<T>(pred: Predicate<T>, src: Iterable<T>): T | undefined
  • Transducer composition / syntax sugar for:

    example
    comp(filter(pred), takeLast(1))

    Yields none or only the last value which passed the predicate check. If src input is given, returns last match found (or undefined).

    example
    matchLast((x) => x >= 5, [3, 1, 6, 5, 4, 2])
    // 5
    
    transduce(
      comp(
        matchLast((x) => x >= 5),
        map((x) => x * 10)
      ),
      last(),
      [3, 1, 4, 2, 6, 5]
    )
    // 50

    Type parameters

    • T

    Parameters

    • pred: Predicate<T>

      predicate function

    Returns Transducer<T, T>

  • Type parameters

    • T

    Parameters

    • pred: Predicate<T>
    • src: Iterable<T>

    Returns T | undefined

Generated using TypeDoc