-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
String isNilOrEmpty #37
Comments
Is there a related discussion on the Swift forums? What do they think about such a thing? |
Good question, I will take a look later today. I just came over the idea to introduce this extension not only to On the other hand, |
Yeah, if implemented at all, it should be implemented at the level where Also note that I got inspired for the |
You're right, |
But that's no misunderstanding, if it's true, that actually means that it's non-nil. Only in the Collection case it additionally means it's not empty, since something is present. 😁 |
But it solves the same issue as your suggestion plus it needs no negation in guard statements. |
True, you're right :D |
Well, maybe
It is just a plain negation of |
Since |
How would you define |
Why? On collections we would simply override it. 😉 |
Hmm... it would be a bit confusing if it is a general non-nil operator, but behaves differently only on Collections 😁 |
It's not a non-nil operator. It's an operator, that informs you about presence. For |
Well, I would argue that even an empty collection is I think there is a potential for misunderstandings... |
Is there a design rationale on why Ruby called it |
There sure had been. No idea if it can be found anywhere. Please also note that we could first introduce |
Yeah, sounds good. But this doesn't solve the problem yet, as Therefore, I think it does not suffice to just extend |
This would allow me, coming back to the original example, to write:
, which would eliminate the chaining with |
(Or |
Sometimes, when dealing with viewModels with contain optional values, I find myself writing code like this:
An equivalent alternative is this:
Still, I think it is not as concise as it should be.
C# provides a method
String.IsNullOrEmpty
. What do you think about a respective Swift method? E.g. an extension toOptional where Wrapped == StringProtocol
providing a propertyisNilOrEmpty
?Also, because HandySwift already provides an
isBlank
property, this could be extended to also provide aisNilOrBlank
property, if this is a common use-case.The text was updated successfully, but these errors were encountered: