title: javascript: Using lodash/fp flow to return objects
body: <p>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 </p>
  
  <ol>
  <li>Reduce an array of objects with some grouped function (e.g. <code>countBy</code>/<code>sumBy</code>) into a object/dictionary (e.g. <code>{ group1:10, group2:15... }</code> )</li>
  <li>Map it into an array of key/value pairs (e.g. <code>[{column: 'group1', value: '10'}, ...]</code>)</li>
  <li>Sort by some variable into <code>asc/desc</code> order</li>
  </ol>
  
  <p>but right now the resulting object ends up being flattened into a long array. A sample of the code is below. The <code>reducer</code> function in the code below is working correctly and grouping the values as I intended, but then I think the currying between the <code>each</code> step and <code>orderBy</code> is flattening the object somehow (the desired object is formed correctly after <code>_.each</code> in the <code>console.log</code>. </p>
  
  <p>I've put a sample of the code in the attached JSFiddle.</p>
  
  <pre><code>const inData = [{
    target: 123,
    groupby: 'a'
  },...
  }];
  
  const colData = _.flow(
    _.reduce(reducer, {}),
    _.toPairs,
    _.each(([value, column]) =&gt; {
      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);
  </code></pre>
  
  <p>PS: I am using ES6 syntax and React in my main project, if that makes a difference. </p>
  
  <p><a href="https://jsfiddle.net/moc0L5ac/" rel="nofollow noreferrer">https://jsfiddle.net/moc0L5ac/</a></p>