February 2019
Beginner to intermediate
180 pages
4h 4m
English
Belt's Option module is a collection of utility functions for working with the option type. For example, to unwrap an option and throw a runtime exception if the option's value is None, we can use getExn:
let foo = Some(3)->Belt.Option.getExn;Js.log(foo); /* 3 */let foo = None->Belt.Option.getExn;Js.log(foo); /* raises getExn exception */
An alternative function to unwrap an option that isn't able to throw a runtime exception is getWithDefault:
let foo = None->Belt.Option.getWithDefault(0);Js.log(foo); /* 0 */
The Option module provides several other functions such as isSome, isNone, map, mapWithDefault, and more. Check the documentation for ...
Read now
Unlock full access