From a7472fd0500a00bb97bf1fb0475213f49c9d57f6 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sun, 29 Jun 2014 21:19:04 -0400 Subject: Add signal-drop-repeats procedure. * sly/signal.scm (signal-drop-repeats): New procedure. --- sly/signal.scm | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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." -- cgit v1.2.3