Uh oh!
There was an error while loading. Please reload this page.
isNull, isUndefined convenience functions - #125
Conversation
tsnobip
commented
Jul 25, 2023
this could be simplified with v11 thanks to the new representation of untagged variants that will allow moduleNullable= {
@unboxedtypet<'a> =Present('a) | @as(null) Null | @as(undefined) Undefined
}Then those utility functions could be replaced with a simple pattern matching. |
DZakh
commented
Jul 25, 2023
It's not related to the post, but I've just thought of a possible problem that So maybe we should recover the @cristianoc's idea from some time ago? https://forum.rescript-lang.org/t/rfc-automatic-optional-chaining/3791/17?u=dzakh |
cristianoc
commented
Jul 25, 2023
That idea amounts to accepting that nested nullable is the same as nullable. |
jmagaram
commented
Jul 25, 2023
Even if pattern matching can be used, I still think having boolean-returning convenience functions as in this PR are useful because they are easily discoverable and can sometimes be used for more concise code than pattern matching. I don't have my code in front of me but know I have often used |
tsnobip
commented
Jul 25, 2023
yeah I agree, those utility functions can come handy from time to time (eg as a parameter of a filter function). |
I was writing some code checking for null and undefined and found it awkward. Originally I tried
%rawwhich worked but wasn't pretty. I tried a bunch ofNullable.toOptionand then checked forNoneand 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 JavaScriptnull==undefinedI think. The worst is if you are checking if something is null or undefined...So here are some convenience functions like
Nullable.isNullandNullable.isUndefinedthat are analogous toOption.isNoneandOption.isSomethat make the code more readable. Includes tests and docs.