Skip to content
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

EitherUnsafe MapLeft throws ResultIsNullException #1225

Closed
jogivanknobi opened this issue May 19, 2023 · 4 comments
Closed

EitherUnsafe MapLeft throws ResultIsNullException #1225

jogivanknobi opened this issue May 19, 2023 · 4 comments

Comments

@jogivanknobi
Copy link

Hi,

I'm a new user of this library and trying to integrate it into some of my projects.
Now I stumbled upon a behavior which I don't understand and I'm wondering whether this is a bug:

This code throws a ResultIsNullException on my system using LanguageExt v4.4.3:

RightUnsafe<Exception, object>(null).MapLeft(ex => ex);

Why is MapLeft() throwing here?

@evermanwa
Copy link

evermanwa commented May 19, 2023

Out of curiosity, what is the purpose in using a null in this use-case?

How I have been taught, null should be avoided as much as possible when it comes to FP.
My personal opinion, it should be avoided all the time, because null produces a lot of unwanted errors if you don't properly handle the null scenario every time

@jogivanknobi
Copy link
Author

jogivanknobi commented May 19, 2023

Actually I stumbled upon it while doing something like

Try(CouldReturnNullOrThrow()).ToEitherUnsafe().MapLeft(...)

@evermanwa
Copy link

Well from looking at the source code, this is an intended behavior if I am not mistaken.

@louthy
Copy link
Owner

louthy commented May 19, 2023

EitherUnsafe supports null (that's the 'unsafe' aspect of it), so this sounds like a bug. I'll take a look over the weekend.

The other comments about avoiding null is worth considering, either make the Right have a 'zero' state, or consider making null into a Left error state.

It's much better to be intentional with your type definitions than to have an 'undefined' state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants