Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "xform/match-first"

Index

Functions

Functions

matchFirst

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

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

    Yields none or only the first value which passed the predicate check and then causes early termination. If src input is given, returns first match found (or undefined). Also see {@link (matchLast:1)}.

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

    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