mobily / ts-belt

🔧 Fast, modern, and practical utility library for FP in TypeScript.
https://mobily.github.io/ts-belt
MIT License
1.08k stars 30 forks source link

O.Option's functions with null literal value behaves differ from with undefined literal values #97

Open JUSTIVE opened 7 months ago

JUSTIVE commented 7 months ago

From the type definition of O.Option<A> = A|null|undefined, where A is regarded as Some<A>, and null | undefined as None, I thought that literal null values should behave the same as undefined literal values.

I've just written some examples from ts-belt's live editor. nullish values O.match O.isNone
null image image
undefined image image

for example, the O.match is described as follows, where the null value could passed into someFn.

function _match(option, someFn, noneFn) {
  if (option !== undefined) {
    return someFn(Caml_option.valFromOption(option));
  } else {
    return noneFn(undefined);
  }
}

and O.isNone seems generated from the gentype utility from the rescript-compiler.

I found that O.fromNullable for every null occurring situation, but it's very cumbersome, and so unintuitive because of O.Option's type mismatches with these behaviors.

JUSTIVE commented 6 months ago

related to #85