Lwt_react: update a signal asynchronously?



Hi all,

I can’t figure out how to implement a function that takes as arguments

  • f : 'a -> 'b -> 'c Lwt.t
  • x : 'a React.signal
  • y : 'b React.signal
  • (probably: init : 'c)

and returns a 'c React.signal containing (initially init and then) the successive values of f [x]_t [y]_t once they are computed.

In the unary case, I achieve what I want by

let map_async ?eq init f x =
  React.S.hold ?eq init (Lwt_react.E.map_s f (React.S.changes x))

but I’ve failed for hours to solve to the binary case…

Is it because it is forbidden? why? or am I missing something completely obvious?

Subsidiary question that might help me understanding where my mental representation is wrong: Why the Lwt_react.E.l*_s functions return “regular” 'a React.event whereas the Lwt_react.S.l*_s functions return some 'a React.signal Lwt.t?


You can use S.Pair.pair to make a ('a * 'b) signal and then use your map_async function


Thank you.
This is what I implemented but it is a bit ugly (and heavy when, like in my case, you specify the equality functions by hand and therefore you have to give them explicitly each time you use S.Pair.pair…)