Reputation: 5010
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?
Upvotes: 2
Views: 1152
Reputation: 1056
_.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);
_.flow([
_.curry(_.assign, 2)(rows[0]),
myFunction,
_.curryRight(_.omit, 2)('blah'),
])(foundUser);
I leave it up to you to decide which you like more.
Upvotes: 2