Would it be weird to have a new constructor method on Option to create an option from truthy?
itstheandre opened this issue · comments
André de Albuquerque commented
Don't know if this is something smart, but would it be interesting to have an API like this:
Option.fromTruthy('') // Option<string> // effectively would be a None
Option.fromTruthy(0) // Option<number> // effectively would be a None
Option.fromTruthy(-0) // Option<number> // effectively would be a None
Option.fromTruthy(undefined) // Option<undefined> // effectively would be a None
Option.fromTruthy(null) // Option<null> // effectively would be a None
Option.fromTruthy(NaN) // Option<number> // effectively would be a None
If theres interest I can make a PR and test it as well
Matthias Le Brun commented
I'd prefer to avoid that kind of implicit behavior, Option
will for the foreseeable future only expose fromNullable
, fromUndefined
& fromNull