0

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
)
Fer iel
  • 23
  • 4

1 Answers1

2

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))
glennsl
  • 28,186
  • 12
  • 57
  • 75
  • 1
    I made a mistake in the order of the arguments in the post. dragStart is the function so it would be ```map( Mouse.position, (. v) =>dragStart(v))``` Thank you! – Fer iel Oct 06 '22 at 22:03
  • That does make more sense :) – glennsl Oct 06 '22 at 22:09
  • // uncurried to curried (. v) => f(v) wouldn't this be curried to uncurried since we are trying to use an uncurried function inside the map function ? – Fer iel Oct 06 '22 at 22:42
  • Depends on perspective I guess :) My perspective here is that it takes a curried function, `f`, and makes it uncurried. – glennsl Oct 07 '22 at 06:55