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

Error on "List -> find" with single value of null #245

Open
ronnelreposo opened this issue Aug 4, 2021 · 4 comments
Open

Error on "List -> find" with single value of null #245

ronnelreposo opened this issue Aug 4, 2021 · 4 comments
Assignees

Comments

@ronnelreposo
Copy link

const xs = [null];
List.fromArray(xs).find((x) => true);

Finding an element with x being null throws an error.

https://codesandbox.io/s/zen-morse-fk96k?file=/src/index.js

@ulfryk
Copy link
Member

ulfryk commented Aug 4, 2021

Hi @ronnelreposo
thanks for pointing that out - but it seems that it's an expected behaviour of this library due to some initial decisions made about Maybe monad.

Please see this discussion #53
especially #53 (comment)

Also you can check #208

@ronnelreposo
Copy link
Author

Hi @ulfryk, thank you for your response. I was also expecting to return None / Nothing, but as I saw the discussions (specially #208), it seems that the only way to avoid this is to sanitize the inputs, filtering all the null/undefined.
e.g.

const xs = [null].filter(x => !(x == null || x == undefined))
List.fromArray(xs).find((x) => true);

@ulfryk
Copy link
Member

ulfryk commented Aug 10, 2021

@ronnelreposo - yes .filter(x => x != null) is best you can do.

But maybe we can add .findOptional or sth like this to the List to handle that special ( and probably quite common ) case.

@ulfryk ulfryk self-assigned this Aug 10, 2021
@ulfryk
Copy link
Member

ulfryk commented Nov 19, 2024

@ronnelreposo please see #258

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

No branches or pull requests

2 participants