How can I destructure a tuple into a List.map in ReasonML?

156 Views Asked by At
 let numbers = [1, 5, 6, 12, 52, 25];                                                                
 let state: list((int, bool)) =  numbers |> List.map(n => (n, false));                                                         
 state |> List.map((n, b) => <NumberCard number=n picked=b onClick />);

What could be doing wrong because the type checker says:

 51 ┆
  52 ┆ let elems =
  53 ┆   state |> List.map((n, b) => <NumberCard number=n picked=b onClick />
       );
  54 ┆
  55 ┆ <div className="flex flex-column">

  This has type:
    list(int) => list(bool => React.element)
  But somewhere wanted:
    list((int, bool)) => 'a

  The incompatible parts:
    int
    vs
    (int, bool)

1

There are 1 best solutions below

0
On

You need more parenthesis around your argument:

List.map( ((n, b)) =>

Otherwise, it's a function of 2 arguments, and it gets curried on the first argument with the elements in your state.