on develop help sign in
Un-deprecate and reimplement mapDynM and forDynM
commitc810e6a20310e1e681bd11511e59eaae393c68df authorRyan Trinkle <ryan.trinkle@gmail.com> dateTue 24 Oct 2017, 19:06 (9 years ago) parent4a59bfa
1 file changed+10−18
src/Reflex/Dynamic.hs+10−18
src/Reflex/Dynamic.hs+10−18
@@ -25,6 +25,8 @@ module Reflex.Dynamic
2525 , current
2626 , updated
2727 , holdDyn
28+ , mapDynM
29+ , forDynM
2830 , constDyn
2931 , count
3032 , toggle
@@ -76,11 +78,9 @@ module Reflex.Dynamic
7678 , distributeDMapOverDyn
7779 , distributeFHListOverDyn
7880 , forDyn
79− , forDynM
8081 , getDemuxed
8182 , joinDyn
8283 , mapDyn
83− , mapDynM
8484 , mconcatDyn
8585 , nubDyn
8686 , splitDyn
@@ -109,6 +109,14 @@ import Data.These
109109
110110import Debug.Trace
111111
112+-- | Map a sampling function over a 'Dynamic'.
113+mapDynM :: forall t m a b. (Reflex t, MonadHold t m) => (forall m'. MonadSample t m' => a -> m' b) -> Dynamic t a -> m (Dynamic t b)
114+mapDynM f d = buildDynamic (f =<< sample (current d)) $ pushAlways f (updated d)
115+
116+-- | Flipped version of 'mapDynM'
117+forDynM :: forall t m a b. (Reflex t, MonadHold t m) => Dynamic t a -> (forall m'. MonadSample t m' => a -> m' b) -> m (Dynamic t b)
118+forDynM d f = mapDynM f d
119+
112120-- | Create a new 'Dynamic' that only signals changes if the values actually
113121-- changed.
114122holdUniqDyn :: (Reflex t, MonadHold t m, MonadFix m, Eq a) => Dynamic t a -> m (Dynamic t a)
@@ -548,27 +556,11 @@ instance IsHList (a, b, c, d, e, f) where
548556mapDyn :: (Reflex t, Monad m) => (a -> b) -> Dynamic t a -> m (Dynamic t b)
549557mapDyn f = return . fmap f
550558
551−-- | Map a sampling function over a 'Dynamic'. The sampling function will use the input 'Dynamic''s 'current' 'Behavior' until the first time its 'updated' 'Event' fires, at which point it will be invoked only once each time the 'Event' fires.
552−{-# DEPRECATED mapDynM "Consider using the Monad instance for Dynamic instead." #-}
553−mapDynM :: forall t m a b. (Reflex t, MonadHold t m) => (forall m'. MonadSample t m' => a -> m' b) -> Dynamic t a -> m (Dynamic t b)
554−mapDynM f d = do
555− let e' = push (fmap Just . f :: a -> PushM t (Maybe b)) $ updated d
556− eb' = fmap constant e'
557− v0 = pull $ f =<< sample (current d)
558− bb' :: Behavior t (Behavior t b) <- hold v0 eb'
559− let b' = pull $ sample =<< sample bb'
560− return $ unsafeDynamic b' e'
561−
562559-- | Flipped version of 'mapDyn'.
563560{-# DEPRECATED forDyn "Use 'return . ffor a' instead of 'forDyn a'; consider eliminating monadic style" #-}
564561forDyn :: (Reflex t, Monad m) => Dynamic t a -> (a -> b) -> m (Dynamic t b)
565562forDyn a = return . ffor a
566563
567−-- | Flipped version of 'mapDynM'
568−{-# DEPRECATED forDynM "Consider using the Monad instance for Dynamic instead." #-}
569−forDynM :: forall t m a b. (Reflex t, MonadHold t m) => Dynamic t a -> (forall m'. MonadSample t m' => a -> m' b) -> m (Dynamic t b)
570−forDynM d f = mapDynM f d
571−
572564-- | Split the 'Dynamic' into two 'Dynamic's, each taking the respective value
573565-- of the tuple.
574566{-# DEPRECATED splitDyn "Use 'return . splitDynPure' instead; consider eliminating monadic style" #-}