-
Notifications
You must be signed in to change notification settings - Fork 16
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
Monoid.reduce has different signatures for objects and arrays #18
Comments
The "signature" for reduce is So testcase To get the behavior of const Values = type(class Values {
values(holder) {
return this(holder).values(holder);
}
);
Values.instance(Array, {
values(array) { return array; }
});
Values.instance(Object, {
values(object) { return Object.values(object); }
}); |
Yes, this would work nicely! I'll make a PR. |
We can close this issue and PR. I'll make another and reference this one. |
Maybe we should try it out in libraries consuming it first, a-la Also, I think that this highlights a weakness with error handling and messaging. |
Same monoid reduce will produce a different result for
[1, 2, 3, 4]
than{ "1": 1, "2": 2, "3": 3, "4": 4 }
. This makes it inconvenient when trying to use the same monoid for both arrays and objects. I would expect to be able to use the same monoid for both without having to make special accommodation for both types.When reducing arrays, the append function for the array receives a value for
a
andb
. Reducing objects, sends memo fora
andb
. This is caused by the difference in implementation offoldl
for Arrays and Objects.I believe that both
foldl
for Arrays and Objects should send data of same shape to the folding function. It should be other value or memo, not either.Failing test: https://github.com/taras/funcadelic.js/blob/monoid-signature-failing-test/tests/funcadelic-test.js#L67
The text was updated successfully, but these errors were encountered: