rescript-core
rescript-core copied to clipboard
isNull, isUndefined convenience functions
I was writing some code checking for null and undefined and found it awkward. Originally I tried %raw
which worked but wasn't pretty. I tried a bunch of Nullable.toOption
and then checked for None
and that was a mess. Then I realized I could use the ==
operator, but that also wasn't pretty. There was the uncertainty of do I use ==
or ===
. In JavaScript null==undefined
I think. The worst is if you are checking if something is null or undefined...
Nullable.make(obj)==Nullable.null || Nullable.make(obj)==Nullable.undefined
Nullable.make(obj).isNullOrUndefined
So here are some convenience functions like Nullable.isNull
and Nullable.isUndefined
that are analogous to Option.isNone
and Option.isSome
that make the code more readable. Includes tests and docs.