-
-
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
Add isNotEmpty #3430
Add isNotEmpty #3430
Conversation
Looks like we might have kept dist and got rid of everything else? edit: 👍 btw |
@kedashoe Yeah I've been wondering why |
Ya we should have the default |
@kedashoe At work today, a dev of mine harmlessly switched an instance of Caught by a unit test, we found that
It makes since to me why That made me realize that this MR has a flaw. In that The best analogy I have for this is that Before I trhow up a second MR, was hoping to get some feedback on my assertion |
👍 , I agree with your reasoning |
errrr.... thinking about this more, I don't think we should do what I'm suggesting above Because that would also mean that |
Fair enough, really it is a type error for null/undefined, which would mean !isEmpty() == isNotEmpty() again, but not so easy considering plain js vs typescript |
This MR adds a new function
isNotEmpty
. It is implemented the same wayisNotNil
is, in how that it just returns!isNil()
, this just returns!isEmpty()
.isNotEmpty
is not a particularly useful addition to ramda when it comes to pure vanilla javascript, however, it is extremely useful in typescriptSpecifically for arrays, the typings for
isNotEmpty
can type narrow aT[]
to aNonEmptyArray<T>
. This type behavior can be combined with the usage of functions likehead
, which can be overloaded to know the difference, allowing for a strict return type ofT
instead ofT | undefined
. And that, is invaluableHere is a full example in the Typescript Playground
I'll eventually have an MR in types-ramda to compliment this one with full typings as demo'd in the playground link