In scala, we can write the following by comprehension notation.
val result = for {
a <- Some(1)
b <- Some(2)
} yield a + b
In fsharp, we can use computation expressions.
let result =
option {
let! a = Some 1
let! b = Some 2
return a + b
}
In fp-ts, it is as follows
const result = pipe(
O.bindTo("a")(O.some(1)),
O.bind("b", () => O.some(2)),
O.map(({ a, b }) => a + b)
);
}
Can I write a similar process in rescript?
I don’t want the nesting to be too deep when chaining flatMaps.