The Option type expresses that a value may be present or not.
The code is organized through the class None (value not
present), the class Some (value present), and the type alias
Option (Some or None).
Finally, "static" functions on Option are arranged in the class
OptionStatic and are accessed through the global constant Option.
To get the value out of an option, you can use Some.getOrThrow,
or Some.get. The latter is available if you've checked that you
indeed have a some, for example:
The Option type expresses that a value may be present or not. The code is organized through the class None (value not present), the class Some (value present), and the type alias Option (Some or None).
Finally, "static" functions on Option are arranged in the class OptionStatic and are accessed through the global constant Option.
Examples:
Option.of(5); Option.none<number>(); Option.of(5).map(x => x*2);
To get the value out of an option, you can use Some.getOrThrow, or Some.get. The latter is available if you've checked that you indeed have a some, for example:
const opt = Option.of(5); if (opt.isSome()) { opt.get(); }
You also have other options like Some.getOrElse, Some.getOrUndefined and so on. Some and None have the same methods, except that Some has the extra Some.get method that None doesn't have.