on develop help sign in
Add deprecated functions mapDynM and forDynM
commit211008d0cde45838f4ca01a050a1b7bb1b2383e9 authorRyan Trinkle <ryan.trinkle@gmail.com> dateTue 9 Aug 2016, 15:25 (10 years ago) parent43b16a6
1 file changed+18
src/Reflex/Dynamic.hs+18
src/Reflex/Dynamic.hs+18
@@ -59,9 +59,11 @@ module Reflex.Dynamic
5959 , distributeDMapOverDyn
6060 , distributeFHListOverDyn
6161 , forDyn
62+ , forDynM
6263 , getDemuxed
6364 , joinDyn
6465 , mapDyn
66+ , mapDynM
6567 , mconcatDyn
6668 , nubDyn
6769 , splitDyn
@@ -438,11 +440,27 @@ instance IsHList (a, b, c, d, e, f) where
438440mapDyn :: (Reflex t, Monad m) => (a -> b) -> Dynamic t a -> m (Dynamic t b)
439441mapDyn f = return . fmap f
440442
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+
441454-- | Flipped version of 'mapDyn'.
442455{-# DEPRECATED forDyn "Use 'return . ffor a' instead of 'forDyn a'; consider eliminating monadic style" #-}
443456forDyn :: (Reflex t, Monad m) => Dynamic t a -> (a -> b) -> m (Dynamic t b)
444457forDyn a = return . ffor a
445458
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+
446464-- | Split the 'Dynamic' into two 'Dynamic's, each taking the respective value
447465-- of the tuple.
448466{-# DEPRECATED splitDyn "Use 'return . splitDynPure' instead; consider eliminating monadic style" #-}