'Getting expected a function error in Lodash's flow

I need to use lodash's flow function in my project and started learning from an example below it looks ok but getting Expected a function error.

Source Code:

const foundUser = {
    charData: []
};
const rows = [{ok: 1, blah: 'nope'}];
const myFunction = d => ({ ...d, myProp: 4 });

_.flow([
 _.assign(rows[0]),
 myFunction,
 _.omit('blah'),
])(foundUser);

Can anyone help me, please?



Solution 1:[1]

_.flow expects all values in the array to be functions. Your first and third elements are already applied functions and produced a value.

You need to make them functions and supply the proper argument at the right position:

_.flow([
 x => _.assign(rows[0], x),
 myFunction,
 x => _.omit(x, 'blah'),
])(foundUser);

Edit: use _.curry instead of inline function

_.flow([
 _.curry(_.assign, 2)(rows[0]),
 myFunction,
 _.curryRight(_.omit, 2)('blah'),
])(foundUser);

I leave it up to you to decide which you like more.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1