我想在反应香蕉中实现某种类型的事件限制。它应该这样工作,如果从最后一个通过的事件到达的时间少于 delta 秒,则不会让事件通过。如果它没有通过,那么它会被存储并在最后一次触发事件的 delta 秒后触发。
下面是一个为时间戳数字列表实现此功能的程序。有没有可能把它翻译成 reactive-banana ?
另外,在反应香蕉中,我如何在其他事件出现后 x 秒触发一个事件?
模块主要在哪里
导入数据列表
-- 1 秒节流
-- 逻辑是在输出最后一个值后 1 秒之前永远不会输出一个值。
主要 :: IO()
主要 = 打印 $ 测试 [ (0.0, 1.0), (1.1, 2.0), (1.5,3.0), (1.7,4.0), (2.2, 5.0) ]
--应该输出 [ (0.0, 1.0), (1.1, 2.0), (2.1,4.0), (3.1, 5.0) ]
测试 :: [(Double,Double)] -> [(Double,Double)]
测试列表 = gv (concat xs)
在哪里
(v, xs) = mapAccumL f (-50,Nothing) 列表
g (t, Just x) ys = ys ++ [ (t+1,x) ]
g _ ys = ys
f (lasttime, Just holdvalue) (t,x) = if t > (lasttime+1) then
如果 t > (lasttime + 2) 那么
( (t, Nothing), [ (lasttime+1,holdvalue), (t,x)] )
else ( (lasttime+1, Just x) , [ (lasttime+1,holdvalue) ] )
别的
((上次,只是 x),[])
f (lasttime, Nothing) (t,x) = 如果 t > (lasttime+1) 那么
( (t,Nothing) , [ (t, x ) ] )
else ( (lasttime, Just x), [] )