1 | import _curry1 from "./internal/_curry1.js";
|
---|
2 | import curryN from "./curryN.js";
|
---|
3 | /**
|
---|
4 | * Returns a new function much like the supplied one, except that the first two
|
---|
5 | * arguments' order is reversed.
|
---|
6 | *
|
---|
7 | * @func
|
---|
8 | * @memberOf R
|
---|
9 | * @since v0.1.0
|
---|
10 | * @category Function
|
---|
11 | * @sig ((a, b, c, ...) -> z) -> (b -> a -> c -> ... -> z)
|
---|
12 | * @param {Function} fn The function to invoke with its first two parameters reversed.
|
---|
13 | * @return {*} The result of invoking `fn` with its first two parameters' order reversed.
|
---|
14 | * @example
|
---|
15 | *
|
---|
16 | * const mergeThree = (a, b, c) => [].concat(a, b, c);
|
---|
17 | *
|
---|
18 | * mergeThree(1, 2, 3); //=> [1, 2, 3]
|
---|
19 | *
|
---|
20 | * R.flip(mergeThree)(1, 2, 3); //=> [2, 1, 3]
|
---|
21 | * @symb R.flip(f)(a, b, c) = f(b, a, c)
|
---|
22 | */
|
---|
23 |
|
---|
24 | var flip =
|
---|
25 | /*#__PURE__*/
|
---|
26 | _curry1(function flip(fn) {
|
---|
27 | return curryN(fn.length, function (a, b) {
|
---|
28 | var args = Array.prototype.slice.call(arguments, 0);
|
---|
29 | args[0] = b;
|
---|
30 | args[1] = a;
|
---|
31 | return fn.apply(this, args);
|
---|
32 | });
|
---|
33 | });
|
---|
34 |
|
---|
35 | export default flip; |
---|