New to lodash and playing around with it to gain more understanding. I don't understand the behavior of the following code.
After learning about the arity argument to _.curry
, I have a code snippet that produces results that seems strange to me.
const words = ['jim', 'john'];
const pad10 = words =>
_.map(words, word => _.pad(word, 10));
console.log(pad10(words)); // [ ' jim ', ' john ' ]
const flipMap = _.flip(_.map);
const flipPad = _.flip(_.pad);
const curriedFlipMap = _.curry(flipMap, 2);
const pad10v2 = curriedFlipMap(word => flipPad(' ', 10, word));
console.log(pad10v2(words)); // [ ' jim ', ' john ' ]
const curriedFlipPad = _.curry(flipPad, 3);
const padWord10 = curriedFlipPad(' ', 10);
const pad10v3 = curriedFlipMap(word => padWord10(word));
console.log(pad10v3(words)); // [ ' jim ', ' john ' ]
const pad10v4 = curriedFlipMap(padWord10);
console.log(pad10v4(words)); // [ 'jim,john', 'jim,john' ]
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.min.js"></script>
I don't understand the output of the last console.log. Looks to me like I'm just replacing a => f(a) with f when a one arg function is expected.