summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2014-06-29 21:19:04 -0400
committerDavid Thompson <dthompson2@worcester.edu>2014-06-29 21:19:04 -0400
commita7472fd0500a00bb97bf1fb0475213f49c9d57f6 (patch)
treea387605317c85634dccd09ad4e4b5328f1508052
parenta5c0e784b54d4c433209a99789950d6e156548aa (diff)
Add signal-drop-repeats procedure.
* sly/signal.scm (signal-drop-repeats): New procedure.
-rw-r--r--sly/signal.scm15
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."