Skip to content
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

bugfix: groupBy transducer functionality #3233

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jaawerth
Copy link

@jaawerth jaawerth commented Feb 8, 2022

Fixes #3232
Reverts code change in 9b5d892

Setting an absent absent/nullish accumulator, rather than passing an empty on to reduceBy, appears to correct the cached copy behavior causing pollution in the accumulators on subsequent invocations, as well as the "passthrough" behavior dumping every value in every group; I believe this is due due the cached shallow-copying combined with the currying of reduceBy.

It may be more desirable to correct the copy caching to prevent the error while still deterministically setting the accumulator, but for what it's worth, it's at least in line with traditional transducer behavior to get the initial value from the transformer, albeit not quite this way!

Fixes ramda#3232
Reverts code change in #9b5d8925

Setting an absent absent/nullish accumulator, rather than pasing an
empty on to reduceBy, appears to correct the cached copy behavior
causing pollution in the accumulators on subsequent invocations, as well
as the "passthrough"; I believe this is due due the cached
shallow-copying combined with the currying of `reduceBy`.

It may be more desirable to correct the copy caching to prevent the
error while still deterministically setting the accumulator, but for
what it's worth, it's at least in line with traditional transducer
behavior to get the initial value from the transformer, albeit not
*quite* this way!
@xgbuils
Copy link
Contributor

xgbuils commented Feb 8, 2022

Hi @jaawerth

I've seen the fallback function of reduceBy is using _clone. Then maybe could be done as same way is done in _xReduceBy. Let's see what the mantainers say.

Thanks!

@jaawerth
Copy link
Author

jaawerth commented Feb 8, 2022

Yep - this is a quick fix but it probably doesn't address similar problems in other transducers. I think the PR you closed may be on track of a better solution ;).

acc.push(item);
return acc;
}, [])));
}, null)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmmh I think the change introduced in 9b5d892 might have been breaking changes:

[].reduce(() => 42, null);
//=> null

// but

[].reduce(() => 42, []);
//=> []

So reverting this definitely fixes the bug? Your repro case doesn't have empty lists as far as I can tell so I don't see an obvious connection here unless I'm looking at this from the wrong angle?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The connection insofar as I saw it was that in reduceBy - not so much a problem of passing an empty list, but the fact that the list accumulator is being re-cloned for each group in a way that's memoized and holds onto the original values.

Reverting the change makes the tests pass for groupby, but only for groupBy, though, so I suspect this may be ignoring other places where the same bug is showing up, which may need further digging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

groupBy (permanently?) enters a broken state when used as transducer
3 participants