diff options
-rw-r--r-- | sly/signal.scm | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/sly/signal.scm b/sly/signal.scm index a77e3bb..f8545eb 100644 --- a/sly/signal.scm +++ b/sly/signal.scm @@ -40,6 +40,7 @@ signal-fold signal-filter signal-reject + signal-drop-repeats signal-constant signal-count signal-tap @@ -243,6 +244,20 @@ SIGNAL when it satisfies the procedure PREDICATE. The value of the signal is DEFAULT when the predicate is never satisfied." (signal-filter (lambda (x) (not (predicate x))) default signal)) +(define* (signal-drop-repeats signal #:optional (equal? equal?)) + "Create a new signal that filters out new values from SIGNAL that +are equivalent to the current value. By default, equal? is used for +testing equivalence." + (signal-reject (let ((prev (signal-ref signal))) + (lambda (current) + (if (equal? prev current) + #t + (begin + (set! prev current) + #f)))) + (signal-ref signal) + signal)) + (define (signal-constant constant signal) "Create a new signal whose value is always CONSTANT regardless of what the value received from SIGNAL." |