-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add optional obj
parameter to Evolver
?
#615
Comments
i like this, but this is a breaking change in cases like: R.pipe(
{ a: { b: 0 } },
R.evolve({
a: R.merge,
}),
value => value.a({ c: 1 }),
); (in particular, this would work now, but would break if we did add the optional |
Yes, I see. It could get considered for Slightly unrelated, but would you consider exporting (at least some) types from |
Hmm thinking about it some more, maybe it should actually be considered a special case of "evolve |
It's hard to answer without more context. I was supportive of adding This is to say that if you need the object in your evolvers, I wonder if you'd be better off simply doing the mutations "bare-bones." It'll be more readable to anyone on your codebase who doesn't know how evolve works. The only line here which is shorter using evolve than the bare-bones impl is the simple one that simply mutates a prop based on it's own value. const x = pipe(
...
(myObj) => ({
...myObj,
justAConst: 3,
mutatedProp: myObj.mutatedProp + 3,
fromAnotherProp: myObj.isAnotherProp ? 3 : 4,
aCombination: myObj.a + myObj.b - myObj.aCombination + 3,
}),
...
);
// Instead of
const x = pipe(
...
evolve({
justAConst: constant(3),
mutatedProp: add(3),
fromAnotherProp: (_, { isAnotherProp }) => isAnotherProp ? 3 : 4,
aCombination: (aCombination, { a, b }) => a + b - aCombination + 3,
}),
...
); |
Would it make sense for the
Evolver
to accept the entire object as a second parameter? This would be useful if you need to use other properties to evolve one. A simple example would be to evolveusing evolver
I'm aware this example is a bit too simple, but I have many use-cases where I want to manipulate properties conditionally based on values of other properties (before evolution, that is).
Or is there a way to achieve this simply already? The only way I could think of is to have an "evolver factory" which closes over the original value of the object like this:
and then using it like this
Edit: typo
The text was updated successfully, but these errors were encountered: