Options
All
  • Public
  • Public/Protected
  • All
Menu

Module cond

Index

References

Functions Util

References

Renames and re-exports cond

Util Functions

  • cond<R>(pairs: [(...args: any[]) => boolean, (...args: any[]) => R][][]): R
  • Creates a function that iterates over pairs and invokes the corresponding function of the first predicate to return truthy. The predicate-function pairs are invoked with the this binding and arguments of the created function.

    since

    5.12.0

    example
    const func = cond([
    [matches({ 'a': 1 }), () => 'matches A'],
    [conforms({ 'b': isNumber }), () => 'matches B'],
    [() => true, () => 'no match']
    ])

    func({ 'a': 1, 'b': 2 })
    // => 'matches A'

    func({ 'a': 0, 'b': 1 })
    // => 'matches B'

    func({ 'a': '1', 'b': '2' })
    // => 'no match'

    Type parameters

    • R = any

    Parameters

    • pairs: [(...args: any[]) => boolean, (...args: any[]) => R][][]

      The predicate-function pairs.

    Returns R

    Returns the new composite function.