Dear functional-reactive camlers,
In order to change the dependencies between signals dynamically, one can use the switch function whose type is:
utop $ React.S.switch;;
- : ?eq:('a -> 'a -> bool) -> 'a React.signal -> 'a React.signal React.event -> 'a React.signal = <fun>
However I often find myself wanting to write signals of signals, and I wrote the following definition to cope with them:
val bind_s : 'a React.signal -> ('a -> 'b React.signal) -> 'b React.signal
let bind_s s f =
let s' = S.map ~eq:( == ) f s in
let init = S.value s'
and changes = S.changes s' in
S.switch init changes
So far it worked as I thought it would, but still I'm not really confident this is a safe use of signals. Does anyone see a potential pitfall here?
Cheers,
Philippe.
PS at least, there should be an eq optional attribute to [bind_s], and the last line should be [S.switch ~eq init changes]