I am converting a _.chain group of functions to use _fp.flow, but am having some difficulty dealing with the way flow curries complex objects. I am trying to
- Reduce an array of objects with some grouped function (e.g.
countBy/sumBy) into a object/dictionary (e.g.{ group1:10, group2:15... }) - Map it into an array of key/value pairs (e.g.
[{column: 'group1', value: '10'}, ...]) - Sort by some variable into
asc/descorder
but right now the resulting object ends up being flattened into a long array. A sample of the code is below. The reducer function in the code below is working correctly and grouping the values as I intended, but then I think the currying between the each step and orderBy is flattening the object somehow (the desired object is formed correctly after _.each in the console.log.
I've put a sample of the code in the attached JSFiddle.
const inData = [{ target: 123, groupby: 'a' },... }]; const colData = _.flow( _.reduce(reducer, {}), _.toPairs, _.each(([value, column]) => { console.log(value); console.log(column); const outObj = { value: value, column: column } console.log(outObj) return (outObj); }), _.orderBy(['value'], [sortDir]), // Have tried result with or without fromPairs _.fromPairs )(inData); PS: I am using ES6 syntax and React in my main project, if that makes a difference.