-
Notifications
You must be signed in to change notification settings - Fork 15
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
foldMapOf
fails with an empty target
#6
Comments
sounds awfully familiar: fantasyland/fantasy-land#88 (comment) and i do mean "awfully" |
Yeah...same deal for traverse though it threads |
How do others feel about removing |
I'm good for that! |
alternatively we can act like JS: [1].reduce((acc, x) => acc + x)
// 1
[].reduce((acc, x) => acc + x)
Uncaught TypeError: Reduce of empty array with no initial value(…) but that's not great |
i think we have consensus; let's get move |
@buzzdecafe yes and yes 👏 |
Don't know that I'm proud of it, but I've managed to get master...scott-christopher:alt-fold The "don't look at me like that" part comes from binding the 🙈 ... but it seems to work. const
{ compose
, lensProp
} = require('ramda'),
{ foldMapOf
, over
, traversed
, view
} = require('.');
const Add = x => ({
concat: y => Add(x + y.value),
value: x
});
const l = compose(lensProp('x'), traversed, lensProp('y'));
const obj = { x: [{ y: 1 }, { y: 2 }, { y: 3 }] };
view(l, obj); //=> 1
over(l, x => x * x, obj); //=> { x: [{ y: 1 }, { y: 4 }, { y: 9 }] }
foldMapOf(l, [], x => [x], obj); //=> [1, 2, 3]
foldMapOf(l, Add(0), Add, obj).value; //=> 6 |
Haha! You brilliant bastard. Well, dynamic typing gonna dynamic. If you regard the types as an ambient environment of information, then storing this information in +1 from me |
So whats the consensus guys? I just want this to be on npm like nobodies business |
fine with me |
There's a PR for this in #8 |
The following code should evaluate to
0
, however it currently fails.The is due to
foldMap
expecting at least one pass through the reduce function to pull an empty value off the monoid instance.This should ideally be passing in a monoid type in as an argument in order to populate the initial reduce value with its
empty()
value.I'm not sure how we can work around this as gets pretty messy trying to find a suitable point in the call chain to pass in the correct monoid type.
The text was updated successfully, but these errors were encountered: