-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
breaking(isEmpty, isNotEmpty) - isEmpty to return true
for null | undefined
#3475
base: master
Are you sure you want to change the base?
Conversation
Coverage Summary> ramda@0.30.1 coverage:summary
> BABEL_ENV=cjs nyc --reporter=text-summary mocha -- --reporter=min --require @babel/register
�[2J�[1;3H
1192 passing (1s)
=============================== Coverage summary ===============================
Statements : 94.06% ( 2486/2643 )
Branches : 85.76% ( 970/1131 )
Functions : 93.28% ( 555/595 )
Lines : 94.34% ( 2332/2472 )
================================================================================ |
#2507 (and linked issues) I think it is correct in this case that we go against what the large majority of javascript devs would consider the natural response |
an empty array is
also citing @Bradcomp :
I think |
^^ is a good analog for
IMHO this argument is paradoxical because the same can be said for If we were to actually implement that then |
That was just to question the "Falsiness" example in your argumentation.
Yes, imo many Ramda functions should. But we have the "garbage-in garbage-out" principle |
I think the mental model of "isEmpty" is tied up in type theory a bit too much, particularly monoids. For exotic objects, the fantasy-land spec of implementing For these, I think it makes more sense to think of them as iterables. Arrays are iterables, can have
Currently, I think the logic should be:
I honestly believe this is an issue worth re-discussing. I personally have found the current implementation to be error-prone. I've seen multiple people break code migrating from Alternatively, non-enumerables should type-error. It solves the control-flow errors you'd get from my refactoring examples |
I'm going to make one more argument here. Right now, the criteria for what is considered to "be empty" is defined by the ability for something to be able to contain, or hold things.
By this logic, and the logic in ramda's code, all things are "not empty" by default until you can prove them to be "empty" I think this logic is backwards.All things should be "empty" by default. The criteria should be around what is considered "non-empty" If I have a basket of apples, it's a non-empty basket. If I have no apples in the basket, it's empty. If I don't have a basket, it's still empty. I wouldn't say I have a non-empty non-existent basket. Javascript is special in this way, and something that has to be compensated for a bit. While this doesn't line up directly with monoids and the concept that |
I usually create |
Then But really, that function should be |
I like This has also only been raised as an issue once (now twice!) in all the many years of ramda vs the numerous times some other issues have come up (fold instance for objects, order of arguments for gt/lt/etc, etc..), which to my mind is another reason not to introduce a breaking change. |
That's fair. And I do concede to the fact that the current implementation of Eg,
This is also why @kedashoe let's split the difference and do something like having sibling functions for this, eg I'll update this MR to that when I get some free time next week to sit and think about how this new |
Something else to keep in mind is how const someArr = undefined;
if(R.isNotEmpty(someArr)) {
doWork(someArr); // we're trying to do work on undefined because we said it wasn't empty.
} So, I also have |
Yes this is exactly what I am trying to point out in the PR description. I used The literal implementation of My implementation then would be const isNilOrEmpty = either(isNil, isEmpty);
const isNotNilOrEmpty = (a) => !isNilOrEmpty(a); |
I'm sure this has been discussed in the past, though searching through issues and PRs I couldn't find anything specific... So I figured I'd through my hat in the ring here...
isEmpty(undefined)
andisEmpty(null)
should returntrue
I believe it to be what the large majority of javascript devs would consider the natural response. Why? Falsyness in javascript
Consider refactoring
Additionally,
lodash.isEmpty
returnstrue
fornull | undefined
, as well as virtually ever other utility library I looked itThis, of course, is a MAJOR BREAKING change and we should hold off to merge until
1.0
is finally ready, but I'd like to get it on the books now is we can. thank you