summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sly/signal.scm13
1 files changed, 13 insertions, 0 deletions
diff --git a/sly/signal.scm b/sly/signal.scm
index f8545eb..3e5ce26 100644
--- a/sly/signal.scm
+++ b/sly/signal.scm
@@ -41,6 +41,7 @@
signal-filter
signal-reject
signal-drop-repeats
+ signal-switch
signal-constant
signal-count
signal-tap
@@ -258,6 +259,18 @@ testing equivalence."
(signal-ref signal)
signal))
+(define (signal-switch pred on off)
+ "Create a new signal whose value is that of the signal ON when the
+signal PRED is true, or the value of the signal OFF otherwise."
+ (define (current-value)
+ (if (signal-ref pred)
+ (signal-ref on)
+ (signal-ref off)))
+ (make-boxed-signal (current-value)
+ (lambda (self value)
+ (%signal-set! self (current-value)))
+ (list pred)))
+
(define (signal-constant constant signal)
"Create a new signal whose value is always CONSTANT regardless of
what the value received from SIGNAL."