• Returns a new function for Partial Application of the original function.

    Given a function with N parameters, returns a new function that supports partial application. The new function accepts anywhere from 1 to N parameters. When that function is called with M parameters, where M is less than N, it returns a new function that accepts the remaining parameters. It continues to accept more parameters until all N parameters have been supplied.

    This contrived example uses a partially applied function as an predicate, which returns true if an object is found in both arrays.

    Parameters

    • fn: any

    Returns any

    // returns true if an object is in both of the two arrays
    function inBoth(array1, array2, object) {
    return array1.indexOf(object) !== -1 &&
    array2.indexOf(object) !== 1;
    }
    let obj1, obj2, obj3, obj4, obj5, obj6, obj7
    let foos = [obj1, obj3]
    let bars = [obj3, obj4, obj5]

    // A curried "copy" of inBoth
    let curriedInBoth = curry(inBoth);
    // Partially apply both the array1 and array2
    let inFoosAndBars = curriedInBoth(foos, bars);

    // Supply the final argument; since all arguments are
    // supplied, the original inBoth function is then called.
    let obj1InBoth = inFoosAndBars(obj1); // false

    // Use the inFoosAndBars as a predicate.
    // Filter, on each iteration, supplies the final argument
    let allObjs = [ obj1, obj2, obj3, obj4, obj5, obj6, obj7 ];
    let foundInBoth = allObjs.filter(inFoosAndBars); // [ obj3 ]