The map function in rescript-json-combinators accepts only uncurried functions and the functions we are using are curried.
What is the best way to go around this? I don't know if there is a way to convert curried functions to unccuried functions or if I should create a new map function that accepts curried functions.
Some exapmles of a solution I have tried :
Before:
input'(
list{
type'("text"),
on(~key="", "input", Json.Decode.map(v => v |> int_of_string |> set_value, targetValue)),
},
list{},
),
After:
input'(
list{
type'("text"),
on(~key="", "input",((. v) => v |> int_of_string |> set_value)|> Json.Decode.map(targetValue)),
},
list{},
),`
Is this a correct way to solve this issue?
This solution wouldn't always work, couldn't figure out what to do in other cases.
Example:
let onMouseDown = onCB("mousedown", ~key= "", ev =>
decodeEvent(
map(Mouse.position, dragStart),
ev,
) |> Tea_result.resultToOption
)
In general, converting a function from curried to uncurried, or vice versa, is just a matter of creating an anonymous function with one calling convention, calling a function with the other calling convention:
// curried to uncurried
v => f(. v)
// uncurried to curried
(. v) => f(v)
In your example it would be:
map(Mouse.position, (. v) => dragStart(v))