caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Signals of signals in react
@ 2013-03-08  9:43 Philippe Veber
  2013-03-08 11:51 ` Lukasz Stafiniak
  2013-03-08 14:21 ` Daniel Bünzli
  0 siblings, 2 replies; 7+ messages in thread
From: Philippe Veber @ 2013-03-08  9:43 UTC (permalink / raw)
  To: caml users

[-- Attachment #1: Type: text/plain, Size: 900 bytes --]

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]

[-- Attachment #2: Type: text/html, Size: 1177 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-03-08 22:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-08  9:43 [Caml-list] Signals of signals in react Philippe Veber
2013-03-08 11:51 ` Lukasz Stafiniak
2013-03-08 13:55   ` Philippe Veber
2013-03-08 14:21 ` Daniel Bünzli
2013-03-08 15:02   ` Daniel Bünzli
2013-03-08 22:21     ` Philippe Veber
2013-03-08 22:17   ` Philippe Veber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).