[ rss / options / help ]
post ]
[ b / iq / g / zoo ] [ e / news / lab ] [ v / nom / pol / eco / emo / 101 / shed ]
[ art / A / beat / boo / com / fat / job / lit / map / mph / poof / £$€¥ / spo / uhu / uni / x / y ] [ * | sfw | o ]
logo
technology

Return ]

Posting mode: Reply
Reply ]
Subject   (reply to 25730)
Message
File  []
close
15391116_1815837221997328_5152972153592525687_n.jpg
257302573025730
>> No. 25730 Anonymous
9th December 2016
Friday 2:03 am
25730 spacer
Is there a better way of writing a generic curry function maker in js than this?

function curry(fn, presets) { return function() { return fn.apply(null, presets.slice(0).concat([].slice.call(arguments, 0))); }; }

Expand all images.
>> No. 25731 Anonymous
9th December 2016
Friday 2:05 am
25731 spacer
Here it is in action!

function addThreeNums(a, b, c) { return a + b + c; } var addOneTwo = curry(addThreeNums, [1, 2]); console.log(addOneTwo(3)); // 6

>> No. 25733 Anonymous
9th December 2016
Friday 2:21 am
25733 spacer
>>25730

Yeah, like this. You don't need the first slice.

function curry(fn, presets) { return function() { return fn.apply(null, presets.concat([].slice.call(arguments, 0))); }; }

>> No. 25734 Anonymous
9th December 2016
Friday 2:25 am
25734 spacer
function curry(fn, presets, binding) { return function() { return fn.apply(binding, presets.concat([].slice.call(arguments, 0))); }; }

>> No. 25735 Anonymous
9th December 2016
Friday 4:22 am
25735 spacer
http://stackoverflow.com/questions/218025/what-is-the-difference-between-currying-and-partial-application

Return ]
whiteline

Delete Post []
Password