Why can't I map the constructor `Some` over an Array?

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?

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

Too bad _ doesnt work here…Js.Array2.map(Some(_)) would be nice.

FWIW, there is also Js.Option.some

1 Like