Search code examples
javascriptfunctional-programminglodash

Pass additional parameters to functions within lodash's flow()


If I want to change the delimiter of join() to something other than the default, how do I pass that to that specific function within this chain?

const evens = (x) => _.filter(x, y => y % 2 === 0)

console.log(
  _.flow(
    evens,
    _.join,
  )([1, 2, 3, 4, 5, 6])
) 
// expected output: ('2+4+6')
// actual output: ('2,4,6')

Solution

  • This works

    const evens = (x) => _.filter(x, y => y % 2 === 0)
    
    console.log(
      _.flow(
        evens,
        (a) => _.join(a, '+'),
      )([1, 2, 3, 4, 5, 6])
    ) 
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/lodash.min.js"></script>