开发者

FRP (reactive): How to use filterE?

开发者 https://www.devze.com 2023-01-23 14:55 出处:网络
I expect the next will print \"()\" 10 times in a seco开发者_如何学Gond. But it hangs after a second. Why?

I expect the next will print "()" 10 times in a seco开发者_如何学Gond. But it hangs after a second. Why?

adaptE $ fmap print $ filterE (const True) $ atTimes [0.1, 0.2 ..]

I found that it is related to liftM used in filterE:

filterE :: (Ord t, Bounded t) => (a -> Bool) -> EventG t a -> EventG t a
filterE p m = justE (liftM f m)
 where
   f a | p a        = Just a
       | otherwise  = Nothing

I tried to reimplement filterE using fmap and it seems to work. Why? How the standard filterE is designed to be used?

I found myself reimplementing a lot of standard functions provided by the reactive package (e.g. diffE, integrate). Does it mean that the package is buggy or I use it in a wrong way?

Thanks!


In my experience reactive is buggy, especially with regard to the Monad instance of Event (the monad join operation is slightly too strict and we're not exactly sure why). Avoid that if possible. Reactive was an experiment, and represents what might be possible with more runtime support. See Yampa for a more stable, reliable, and well-traveled FRP library, even if it is a bit less expressive.

0

精彩评论

暂无评论...
验证码 换一张
取 消