on develop help sign in
Un-deprecate and reimplement mapDynM and forDynM
c810e6aRyan Trinkle
src/Reflex/Dynamic.hs+10−18
@@ -25,6 +25,8 @@ module Reflex.Dynamic
25 , current
25 , current
26 , updated
26 , updated
27 , holdDyn
27 , holdDyn
28+ , mapDynM
29+ , forDynM
28 , constDyn
30 , constDyn
29 , count
31 , count
30 , toggle
32 , toggle
@@ -76,11 +78,9 @@ module Reflex.Dynamic
76 , distributeDMapOverDyn
78 , distributeDMapOverDyn
77 , distributeFHListOverDyn
79 , distributeFHListOverDyn
78 , forDyn
80 , forDyn
79− , forDynM
80 , getDemuxed
81 , getDemuxed
81 , joinDyn
82 , joinDyn
82 , mapDyn
83 , mapDyn
83− , mapDynM
84 , mconcatDyn
84 , mconcatDyn
85 , nubDyn
85 , nubDyn
86 , splitDyn
86 , splitDyn
@@ -109,6 +109,14 @@ import Data.These
109
109
110import Debug.Trace
110import Debug.Trace
111
111
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+
112-- | Create a new 'Dynamic' that only signals changes if the values actually
120-- | Create a new 'Dynamic' that only signals changes if the values actually
113-- changed.
121-- changed.
114holdUniqDyn :: (Reflex t, MonadHold t m, MonadFix m, Eq a) => Dynamic t a -> m (Dynamic t a)
122holdUniqDyn :: (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
548mapDyn :: (Reflex t, Monad m) => (a -> b) -> Dynamic t a -> m (Dynamic t b)
556mapDyn :: (Reflex t, Monad m) => (a -> b) -> Dynamic t a -> m (Dynamic t b)
549mapDyn f = return . fmap f
557mapDyn f = return . fmap f
550
558
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−
562-- | Flipped version of 'mapDyn'.
559-- | Flipped version of 'mapDyn'.
563{-# DEPRECATED forDyn "Use 'return . ffor a' instead of 'forDyn a'; consider eliminating monadic style" #-}
560{-# DEPRECATED forDyn "Use 'return . ffor a' instead of 'forDyn a'; consider eliminating monadic style" #-}
564forDyn :: (Reflex t, Monad m) => Dynamic t a -> (a -> b) -> m (Dynamic t b)
561forDyn :: (Reflex t, Monad m) => Dynamic t a -> (a -> b) -> m (Dynamic t b)
565forDyn a = return . ffor a
562forDyn a = return . ffor a
566
563
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−
572-- | Split the 'Dynamic' into two 'Dynamic's, each taking the respective value
564-- | Split the 'Dynamic' into two 'Dynamic's, each taking the respective value
573-- of the tuple.
565-- of the tuple.
574{-# DEPRECATED splitDyn "Use 'return . splitDynPure' instead; consider eliminating monadic style" #-}
566{-# DEPRECATED splitDyn "Use 'return . splitDynPure' instead; consider eliminating monadic style" #-}