ramda: `all` fails on objects?
Is this intentional?
all(x=>x<5)([1,5]) // false
all(x=>x<5)({a:1, b:5}) // true
In lodash
there is very handy all = every
method which acts equally on arrays and objects, so it is surprising to see that Ramda’s all
behaves differently.
About this issue
- Original URL
- State: open
- Created 7 years ago
- Comments: 30 (24 by maintainers)
@dmitriz, you might prefer
S.all
:@dmitriz:
A proposed implementation is only the start of a PR…
If you want much stricter guarantees, you should take a look at Sanctuary.
@ivenmarquardt:
I make a big distinction between how Ramda acts on its own and what we expect from users working with Ramda. While Ramda won’t mutate your data, it works perfectly well, for instance, with a function passed to
reduce
that mutates the accumulator object. Ramda simply doesn’t care. While I don’t feel any need forfoldObj
, it’s a very common request, and my only objections have to do with the issue of commutativity. If that’s removed, then it seems to me a reasonable request.By mentioning LISP, I was trying to point out that there are languages widely considered to be functional that don’t follow the ML strongly typed style. Category theory is certainly a useful basis for some FP languages, but it’s not the only one.
@dmitriz:
I see two problems with using
Set
s for any of our work.First, Ramda has been trying to maintain compatibility with older versions of the language, something I want to give up as soon as we pass version 1.0. But we never seem to be getting to that.
Second,
Set
s are designed around reference equality, not the value equality that suffuses Ramda. That makes it quite difficult to use them for these purposes. But we do have an internal implementation that might do in_Set
.Nonetheless, I really like the idea of adding a
CFold
implementation alongside our currentreduce
. Obviously it would be up to the user to enforce commutativity in their fold functions, but for those who really wantfoldObj
, we could finally give them something useful.For what it’s worth,
all
is justfoldMap
using the booleanand
as the monoid. The other ones listed could also be implemented viafoldMap
with a suitable choice of monoid.That could lead the way to a suitable abstraction here.
https://goo.gl/Hf7tBB