haskell - reactive-banana throttling events -


i implement type of throttling of events in reactive-banana. should work such event not let through if arrives @ less delta seconds last event passed through. if not let through stored , fired after delta seconds last fired event.

below program implements lists of time stamped numbers. possible translate reactive-banana ?

also, in reactive-banana how fire event x seconds after other event comes in ?

 module main  import data.list  -- 1 second throtling -- logic never output value before 1 second has passed since last value 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 = g v (concat xs)                       (v, xs) = mapaccuml f (-50,nothing) list                g (t, x) ys = ys ++ [ (t+1,x) ]                g _ ys  = ys                f (lasttime, holdvalue) (t,x) = if t > (lasttime+1)                                if t > (lasttime + 2)                                        ( (t, nothing), [ (lasttime+1,holdvalue), (t,x)] )                                else ( (lasttime+1, x) , [ (lasttime+1,holdvalue) ] )                        else                                        ( (lasttime, x), [] )                f (lasttime, nothing) (t,x) = if t > (lasttime+1)                         ( (t,nothing) , [ (t, x ) ] )                          else ( (lasttime, x), [] ) 

as of reactive-banana-0.6, possible implement functionality desire, little involved.

basically, have use external framework wxhaskell create timer, can use schedule events. wave.hs example demonstrates how that.

at moment, have opted not include notion of time in reactive-banana library itself. reason different external framework have timers of different resolution or quality, there no one-size fits all.

i intend add common helper functions deal time , timers library itself, still need find way make generic on different timers , figure out guarantees can provide.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -