summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--2d/signal.scm11
1 files changed, 11 insertions, 0 deletions
diff --git a/2d/signal.scm b/2d/signal.scm
index 53f676a..4d6fe3f 100644
--- a/2d/signal.scm
+++ b/2d/signal.scm
@@ -30,6 +30,7 @@
signal-box?
make-signal
define-signal
+ hook->signal
signal-ref
signal-ref-maybe
signal-set!
@@ -148,6 +149,16 @@ be spliced into the new signal."
;;; Higher Order Signals
;;;
+(define (hook->signal hook init proc)
+ "Return a new signal whose initial value is INIT and has future
+values calculated by applying PROC to the arguments sent when HOOK is
+run."
+ (let ((signal (make-signal init)))
+ (add-hook! hook
+ (lambda args
+ (signal-set! signal (apply proc args))))
+ signal))
+
(define (signal-merge signal1 signal2 . rest)
"Create a new signal whose value is the that of the most recently
changed signal in SIGNALs. The initial value is that of the first