From c3c5ee977acea4aa9839b15c1cfb8e110316d168 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Mon, 2 Dec 2013 09:36:46 -0500 Subject: Add signal-fold procedure. * 2d/signals.scm (signal-fold): New procedure. --- 2d/signals.scm | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to '2d') 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." -- cgit v1.2.3