DEV Community

Discussion on: Lodash chaining alternative

Collapse
 
miketalbot profile image
Mike Talbot ⭐

I think the point of flow is that it defines a proper functional pipeline as a callable, that you will call later with the data. In functional programming, the data is normally last and the flow itself is also chainable and can be included inside a wider functional pipe. Chaining is the other way around. I'd argue that flow in the order it is presented by lodash is perfectly correct and makes total logical sense if you use it to define the function:

const processInputData = flow(
  map(x => [x, x*2]),
  flatten,
  sortBy(x => x) 
)

processInputData([1,2,3])
processInputData([4,5,6])

const complexProcess = flow(
   processInputData,
   map(([a,b])=>[a,b,a*b,a+b])
)

complexProcess([7,8,9])
Enter fullscreen mode Exit fullscreen mode
Collapse
 
munawwar profile image
Munawwar

Got it. Yet it still leaves for a closer alternative for chain for the front end.

Collapse
 
seanmclem profile image
Seanmclem

but the function still uses chain()

Thread Thread
 
munawwar profile image
Munawwar

Where? That's my own chain implementation not using lodash chain.