on develop help sign in
Add deprecated functions mapDynM and forDynM
211008dRyan Trinkle
src/Reflex/Dynamic.hs+18
@@ -59,9 +59,11 @@ module Reflex.Dynamic
59 , distributeDMapOverDyn
59 , distributeDMapOverDyn
60 , distributeFHListOverDyn
60 , distributeFHListOverDyn
61 , forDyn
61 , forDyn
62+ , forDynM
62 , getDemuxed
63 , getDemuxed
63 , joinDyn
64 , joinDyn
64 , mapDyn
65 , mapDyn
66+ , mapDynM
65 , mconcatDyn
67 , mconcatDyn
66 , nubDyn
68 , nubDyn
67 , splitDyn
69 , splitDyn
@@ -438,11 +440,27 @@ instance IsHList (a, b, c, d, e, f) where
438mapDyn :: (Reflex t, Monad m) => (a -> b) -> Dynamic t a -> m (Dynamic t b)
440mapDyn :: (Reflex t, Monad m) => (a -> b) -> Dynamic t a -> m (Dynamic t b)
439mapDyn f = return . fmap f
441mapDyn f = return . fmap f
440
442
443+-- | 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.
444+{-# DEPRECATED mapDynM "Consider using the Monad instance for Dynamic instead." #-}
445+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)
446+mapDynM f d = do
447+ let e' = push (liftM Just . f :: a -> PushM t (Maybe b)) $ updated d
448+ eb' = fmap constant e'
449+ v0 = pull $ f =<< sample (current d)
450+ bb' :: Behavior t (Behavior t b) <- hold v0 eb'
451+ let b' = pull $ sample =<< sample bb'
452+ return $ unsafeDynamic b' e'
453+
441-- | Flipped version of 'mapDyn'.
454-- | Flipped version of 'mapDyn'.
442{-# DEPRECATED forDyn "Use 'return . ffor a' instead of 'forDyn a'; consider eliminating monadic style" #-}
455{-# DEPRECATED forDyn "Use 'return . ffor a' instead of 'forDyn a'; consider eliminating monadic style" #-}
443forDyn :: (Reflex t, Monad m) => Dynamic t a -> (a -> b) -> m (Dynamic t b)
456forDyn :: (Reflex t, Monad m) => Dynamic t a -> (a -> b) -> m (Dynamic t b)
444forDyn a = return . ffor a
457forDyn a = return . ffor a
445
458
459+-- | Flipped version of 'mapDynM'
460+{-# DEPRECATED forDynM "Consider using the Monad instance for Dynamic instead." #-}
461+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)
462+forDynM d f = mapDynM f d
463+
446-- | Split the 'Dynamic' into two 'Dynamic's, each taking the respective value
464-- | Split the 'Dynamic' into two 'Dynamic's, each taking the respective value
447-- of the tuple.
465-- of the tuple.
448{-# DEPRECATED splitDyn "Use 'return . splitDynPure' instead; consider eliminating monadic style" #-}
466{-# DEPRECATED splitDyn "Use 'return . splitDynPure' instead; consider eliminating monadic style" #-}