I would like to implement a certain type of throttling event in a reactive banana. It should work in such a way that the event is not skipped if it arrives in less than delta seconds from the last event. If it is not skipped, it is saved and started after delta seconds from the last past event.
Below is a program that implements this for time stamped lists of numbers. Can this be translated into reactive banana?
Also, in a reactive banana, how do I fire an event a few seconds after some other event happens?
module Main where import Data.List - 1 second throtling - logic is to never output a value before 1 second has passed since last value was outputed. main :: IO () main = print $ test [(0.0, 1.0), (1.1, 2.0), (1.5,3.0), (1.7,4.0), (2.2, 5.0)] --should output [(0.0, 1.0), (1.1, 2.0), (2.1,4.0), (3.1, 5.0)] test :: [(Double, Double)] -> [(Double, Double)] test list = gv (concat xs) where ( v, xs) = mapAccumL f (-50, Nothing) list g (t, Just x) ys = ys ++ [(t + 1, x)] g _ ys = ys f (lasttime, Just holdvalue) (t, x) = if t> (lasttime + 1) then if t> (lasttime + 2) then ((t, Nothing), [(lasttime + 1, holdvalue), (t, x)]) else ((lasttime + 1 , Just x), [(lasttime + 1, holdvalue)]) else ((lasttime, Just x), []) f (lasttime, Nothing) (t, x) = if t> (lasttime + 1) then (( t, Nothing), [(t, x)]) else ((lasttime, Just x), [])