summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson@member.fsf.org>2013-12-02 09:36:46 -0500
committerDavid Thompson <dthompson@member.fsf.org>2013-12-02 09:36:46 -0500
commitc3c5ee977acea4aa9839b15c1cfb8e110316d168 (patch)
tree8c0c91c150c0bc07f6ffa08d99219bb2f74050c2
parent2d6b4200cf731e17f144e86d8b52615e6e78c85b (diff)
Add signal-fold procedure.
* 2d/signals.scm (signal-fold): New procedure.
-rw-r--r--2d/signals.scm10
1 files changed, 10 insertions, 0 deletions
diff --git a/2d/signals.scm b/2d/signals.scm
index 400f61e..0d7c75b 100644
--- a/2d/signals.scm
+++ b/2d/signals.scm
@@ -45,6 +45,7 @@
signal-lift4
signal-merge
signal-combine
+ signal-fold
signal-count
signal-if
signal-and
@@ -202,6 +203,15 @@ list."
(map signal-ref signals))
#:connectors signals))
+(define (signal-fold proc init signal)
+ "Create a new signal that accumulates the current and previous
+values of SIGNAL using PROC."
+ (make-signal
+ #:init init
+ #:transformer (lambda (value prev from)
+ (proc value prev))
+ #:connectors (list signal)))
+
(define (signal-count signal)
"Create a new signal that increments a counter every time the value
of SIGNAL changes."