main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
992 bytes
|
Line | |
---|
1 | import { curryN, reverse } from 'ramda';
|
---|
2 |
|
---|
3 | /**
|
---|
4 | * Returns a curried equivalent of the provided function, with the specified arity.
|
---|
5 | * This function is like curryN, except that the provided arguments order is reversed.
|
---|
6 | *
|
---|
7 | * @func curryRightN
|
---|
8 | * @memberOf RA
|
---|
9 | * @since {@link https://char0n.github.io/ramda-adjunct/1.12.0|v1.12.0}
|
---|
10 | * @category Function
|
---|
11 | * @sig Number -> (* -> a) -> (* -> a)
|
---|
12 | * @param {number} length The arity for the returned function
|
---|
13 | * @param {Function} fn The function to curry
|
---|
14 | * @return {Function} A new, curried function
|
---|
15 | * @see {@link http://ramdajs.com/docs/#curryN|R.curryN}, {@link RA.curryRight|curryRight}
|
---|
16 | * @example
|
---|
17 | *
|
---|
18 | * const concatStrings = (a, b, c) => a + b + c;
|
---|
19 | * const concatStringsCurried = RA.curryRightN(3, concatStrings);
|
---|
20 | *
|
---|
21 | * concatStringCurried('a')('b')('c'); // => 'cba'
|
---|
22 | */
|
---|
23 | const curryRightN = curryN(2, (arity, fn) =>
|
---|
24 | curryN(arity, function wrapper(...args) {
|
---|
25 | return fn.apply(this, reverse(args));
|
---|
26 | })
|
---|
27 | );
|
---|
28 |
|
---|
29 | export default curryRightN;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.