• 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.

    Type Parameters

    • T

    • R

    Parameters

    • pairs: CondPair<T, R>[]

      The predicate-function pairs.

    Returns ((Target) => R)

    Returns the new composite function.

      • (Target): 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.

        Parameters

        • Target: T

        Returns R

        Returns the new composite function.

        Since

        4.0.0

        Category

        Util

        Example

        var func = _.cond([
        [_.matches({ 'a': 1 }), _.constant('matches A')],
        [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
        [_.stubTrue, _.constant('no match')]
        ]);

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

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

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

    Since

    4.0.0

    Example

    var func = _.cond([
    [_.matches({ 'a': 1 }), _.constant('matches A')],
    [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
    [_.stubTrue, _.constant('no match')]
    ]);

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

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

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

Generated using TypeDoc