-
Notifications
You must be signed in to change notification settings - Fork 10
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
Explicitly returning null in .map() #12
Comments
Why would |
Thanks for getting back so quickly. I probably should have used a less convoluted example! But basically what I mean is: there are some situations where we might need to return null. Is there a good way to do that? |
Put another way: we are allowed to do |
You need to use flatmap and return nothing.
map doesn't allow you to return a nil value and doesn't implicitly convert null to nothing. It's expected behaviour - I thought through this use case and tested other languages to compare. The problem with allowing null inside Maybe is that you will then need to check or wrap it again which kind of defeats the purpose.
… On 20 Jun 2017, at 15:28, Ben Styles ***@***.***> wrote:
Put another way: we are allowed to do .orJust(null) My use case above is really just the inverse of that, but the flowtyping won't allow it.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Ok, I guess I can't use maybe for this. Just to be clear though, I can't use flatmap and return nothing because that would trigger the I guess treating |
Would this work?
I think you can return This lets you:
The vanilla equivalent is:
which to be honest, is much simpler, if you're ok with |
The problem is the default should be props.truncate == null ? 1 : (props.truncate ? 1 : null) ...which is why I wanted to use maybe! |
I am using
maybe
in React Native, in the props of a custom text component. The custom component should set the underlyingText
component propnumberOfLines
to1
by default, ornull
if the user passesfalse
into the custom component'struncate
prop:However, flow understandably complains about returning
null
in.map()
:Is there an "idiomatic" way to handle this, or is it simply a case of putting an
// $ExpectError
comment and forgetting about it?The text was updated successfully, but these errors were encountered: