Rescript does not have a similar specialized syntax for these type of (i.e. monadic) computations.
There are some tools to help:
- If we’re processing a singular piece of data through multiple steps,
->can prevent the calls from nesting.
let result =
Some(5)
->Option.filter(n => n != 0)
->Option.flatMap(n => 10 / n)
->Option.map(n => n + 7)
- If we need to combine a small number of values, a
switchworks nicely:
let result =
switch (Some(1), Some(2)) {
| (Some(a), Some(b)) => Some(a + b)
| (_, _) => None
}
There’s not a straightforward approach to building up a scope over time, though.