import { reduce } from 'lodash/fp';
import { reduce as normReduce } from 'lodash';
const testObj = { hello: 12, hi: 21 };
const red = reduce((arr, n, key) => {
arr.push({ [n]: key });
return arr;
}, []);
const redNorm = normReduce(testObj, (arr, n, key) => {
arr.push({ [n]: key });
return arr;
}, []);
const resultFP = red(testObj);
console.log(resultFP); // => [ { '12': undefined }, { '21': undefined } ]
console.log(redNorm); // => [ { '12': 'hello' }, { '21': 'hi' } ]
The FP version of reduce, as you can see, does not return the key correctly. Judging from the release notes, it should work like I imported it, right?
We introduced the convert method to simply things:
var map = require('lodash/fp/map').convert({ 'cap': false });
There's also an ESLint rule to warn you when you declare too many args for your iteratee function:
jfmengels/eslint-plugin-lodash-fp/rules/no-extraneous-iteratee-args
Why 'cap': true as default? Why not default as false so that it can match with nonfunctional programming definition?
Hi @dilipkumar2k6!
FP composition favors capping of callback arguments because many don't account for things like index, object parameters which can unintentionally complete curries with unexpected inputs.
Most helpful comment
We introduced the convert method to simply things:
There's also an ESLint rule to warn you when you declare too many args for your iteratee function:
jfmengels/eslint-plugin-lodash-fp/rules/no-extraneous-iteratee-args