Let’s say one has:
let x = Some ("hello world")
let y = Some ("!")
And a function like this:
let f = (x:string, y:string) => x ++ y
How do I apply more than an Option
to some function like f
?
Some attemp:
open Belt
let f = (x:string, y:string) => x ++ y
let x = Some ("hello world")
let y = Some ("!")
let z = x->Option.flatMap (x => y->Option.map(y => f (x, y)))->Option.getWithDefault ("")
Does Rescript offers some other alternative? It would be nice to have Option.lift2
:
let z = Option.lift2 (f, x, y)->Option.getWithDefault ("")