kirabo
1
The following code gives the error This variant constructor, Some, expects 1 argument; here, we've only found 0.
let xs = [1, 2, 3]
let optXs = Belt.Array.map(xs, Some)
But this feels like it should be right? Is there a way to do this without using a lambda function?
johnj
2
Variant constructors are not functions. So yes, you would need to define a function for this.
let xs = [1, 2, 3]
let some = x => Some(x)
let optXs = Belt.Array.map(xs, some)
1 Like
mouton
3
Too bad _ doesnt work here…Js.Array2.map(Some(_)) would be nice.
fham
4
FWIW, there is also Js.Option.some
1 Like