-
Notifications
You must be signed in to change notification settings - Fork 114
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
Maybe from null map error #208
Comments
You can’t map to an undefined/null value. You should flatMap to a new Maybe. |
Thanks, |
@pedroth - sorry for long time to response.. See #53 |
[Newbie alert] - Hi, I am new to functional programming, so i may be completely off the mark. Using this as a reference https://jrsinclair.com/articles/2016/marvellously-mysterious-javascript-maybe-monad/
If i understand correctly, the maybe monad is supposed to be able to handle all the null and undefined stuff. Thus,
should instead return me a Please correct me if i'm wrong; If not, let me know if i can submit a PR with the desired behavior. Regards. |
@turingcreep you are definitely on a good path thinking that Maybe is So in case of Monet implementation of Maybe you need to do: Maybe.fromNull({
current: AnythingThatMayBeNullableOrUndefined
}).flatMap(x => Maybe.formNull(x.current)) See my comment above your question - it links to a discussion that describes this decision in detail :) side note: you can |
I found that when writing the following code:
I receive the error: Can not create Some with illegal value: undefined.
I guess the issue is on the map function, that composes a function with Maybe.of instead of Maybe.fromNull
Thanks
The text was updated successfully, but these errors were encountered: