Open ronnelreposo opened 3 years ago
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 https://github.com/monet/monet.js/issues/53 especially https://github.com/monet/monet.js/issues/53#issuecomment-212276496
Also you can check https://github.com/monet/monet.js/issues/208
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);
@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.
Finding an element with x being null throws an error.
https://codesandbox.io/s/zen-morse-fk96k?file=/src/index.js