Home Reference Source

ts_temp/function/flip.js

import curryN from './curryN';
/**
 * Returns a new function much like the supplied one, except that the first two
 * arguments' order is reversed.
 *
 * @param {Function} fn The function to invoke with its first two parameters reversed.
 * @return {*} The result of invoking `fn` with its first two parameters' order reversed.
 * @example
 *
 *      const neg = (a, b) => a - b
 *
 *      flip(neg)(3, 5); //=> 2
 */
export default ((fn) => curryN(2, function (a, b) {
    const args = Array.prototype.slice.call(arguments);
    args[0] = b;
    args[1] = a;
    return fn.apply(this, args);
}));