reflex-frp / reflex

Interactive programs without callbacks or side-effects. Functional Reactive Programming (FRP) uses composable events and time-varying values to describe interactive systems as pure functions. Just like other pure functional code, functional reactive code is easier to get right on the first try, maintain, and reuse.
https://reflex-frp.org
BSD 3-Clause "New" or "Revised" License
1.07k stars 148 forks source link

Cheap mapping over a Dynamic #237

Open andrewthad opened 5 years ago

andrewthad commented 5 years ago

Is it possible to add:

mapDynamicCheap :: (a -> b) -> Dynamic t a -> Dynamic t b
goolord commented 5 years ago

ping, I'm also interested in this

danbornside commented 5 years ago

How would this be different from fmap? Notice that there is a Functor (Dynamic t) superclass constraint on Reflex t https://github.com/reflex-frp/reflex/blob/3605d501dd9d4049e7402122a704dbe9a65298e9/src/Reflex/Class.hs#L210

goolord commented 5 years ago

fmapCheap is implemented in terms of pushCheap

  -- | Like 'push' but intended for functions that the implementation can consider cheap to compute for performance considerations. WARNING: The function passed to 'pushCheap' may be run multiple times without any caching.
pushCheap :: (a -> PushM t (Maybe b)) -> Event t a -> Event t b