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.
pairs
this
The predicate-function pairs.
Returns the new composite function.
5.12.0
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' Copy
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'
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 thethis
binding and arguments of the created function.