I’ve been getting started with ReScript and am missing some common functions available in the F# Option module. Little things - just a few lines of code that I had to write myself and put in my own “OptionUtil” module. For example, the orElse
function is useful to avoid nesting when you want to chain a few parsers together until the first one returns a value. combine
is useful to reduce an array of options. There are a handful of useful other ones that would be handy if they were baked in. What is the process for making these kinds of improvements?
let orElseWith = (o, f) =>
switch o {
| Some(_) => o
| None => f()
}
let orElse = (o, v) =>
switch o {
| Some(_) => o
| None => Some(v)
}
let combine = (f, a, b) =>
switch (a, b) {
| (None, b) => b
| (_, None) => a
| (Some(a), Some(b)) => Some(f(a, b))
}
let toArray = o =>
switch o {
| None => []
| Some(x) => [x]
}