UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

32 lines (31 loc) 902 B
/** * 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 * @category Util * @param pairs The predicate-function pairs. * @returns Returns the new composite function. * @example * * ```js * 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' * ``` */ export declare function cond<R = any>(pairs: Array<Array<[(...args: any[]) => boolean, (...args: any[]) => R]>>): R; export default cond;