@@ -74,32 +74,12 @@ module Reflex.Dynamic
74 , distributeFHListOverDynPure
74 , distributeFHListOverDynPure
75 -- * Unsafe
75 -- * Unsafe
76 , unsafeDynamic
76 , unsafeDynamic
77− -- * Deprecated functions
84− , distributeDMapOverDyn
85− , distributeFHListOverDyn
98import Data.Functor.Compose
79import Data.Functor.Compose
99import Data.Functor.Misc
80import Data.Functor.Misc
100import Reflex.Class
81import Reflex.Class
102−import Control.Applicative ((<*>))
103import Control.Monad
83import Control.Monad
104import Control.Monad.Fix
84import Control.Monad.Fix
105import Control.Monad.Identity
85import Control.Monad.Identity
@@ -107,11 +87,10 @@ import Data.Align
107import Data.Dependent.Map (DMap)
87import Data.Dependent.Map (DMap)
108import qualified Data.Dependent.Map as DMap
88import qualified Data.Dependent.Map as DMap
109import Data.Dependent.Sum (DSum (..))
89import Data.Dependent.Sum (DSum (..))
110−import Data.Functor.Product
111import Data.GADT.Compare ((:~:) (..), GCompare (..), GEq (..), GOrdering (..))
90import Data.GADT.Compare ((:~:) (..), GCompare (..), GEq (..), GOrdering (..))
112import Data.Map (Map)
91import Data.Map (Map)
113import Data.Maybe
92import Data.Maybe
114−import Data.Monoid hiding (Product)
93+import Data.Monoid ((<>))
115import Data.These
94import Data.These
117import Debug.Trace
96import Debug.Trace
@@ -240,7 +219,7 @@ distributeListOverDynPure =
240-- | Combine a 'Dynamic' of a 'Map' of 'Dynamic's into a 'Dynamic'
219-- | Combine a 'Dynamic' of a 'Map' of 'Dynamic's into a 'Dynamic'
241-- with the current values of the 'Dynamic's in a map.
220-- with the current values of the 'Dynamic's in a map.
242joinDynThroughMap :: forall t k a. (Reflex t, Ord k) => Dynamic t (Map k (Dynamic t a)) -> Dynamic t (Map k a)
221joinDynThroughMap :: forall t k a. (Reflex t, Ord k) => Dynamic t (Map k (Dynamic t a)) -> Dynamic t (Map k a)
243−joinDynThroughMap = joinDyn . fmap distributeMapOverDynPure
222+joinDynThroughMap = join . fmap distributeMapOverDynPure
245-- | Print the value of the 'Dynamic' when it is first read and on each
224-- | Print the value of the 'Dynamic' when it is first read and on each
246-- subsequent change that is observed (as 'traceEvent'), prefixed with the
225-- subsequent change that is observed (as 'traceEvent'), prefixed with the
@@ -551,134 +530,3 @@ instance IsHList (a, b, c, d, e, f) where
551#if !defined(__GLASGOW_HASKELL__) || __GLASGOW_HASKELL__ < 800
530#if !defined(__GLASGOW_HASKELL__) || __GLASGOW_HASKELL__ < 800
552 _ -> error "fromHList: impossible" -- Otherwise, GHC complains of a non-exhaustive pattern match; see https://ghc.haskell.org/trac/ghc/ticket/4139
531 _ -> error "fromHList: impossible" -- Otherwise, GHC complains of a non-exhaustive pattern match; see https://ghc.haskell.org/trac/ghc/ticket/4139
555−--------------------------------------------------------------------------------
556−-- Deprecated functions
557−--------------------------------------------------------------------------------
559−-- | Map a function over a 'Dynamic'.
560−{-# DEPRECATED mapDyn "Use 'return . fmap f' instead of 'mapDyn f'; consider eliminating monadic style" #-}
561−mapDyn :: (Reflex t, Monad m) => (a -> b) -> Dynamic t a -> m (Dynamic t b)
562−mapDyn f = return . fmap f
564−-- | Flipped version of 'mapDyn'.
565−{-# DEPRECATED forDyn "Use 'return . ffor a' instead of 'forDyn a'; consider eliminating monadic style" #-}
566−forDyn :: (Reflex t, Monad m) => Dynamic t a -> (a -> b) -> m (Dynamic t b)
567−forDyn a = return . ffor a
569−-- | Split the 'Dynamic' into two 'Dynamic's, each taking the respective value
571−{-# DEPRECATED splitDyn "Use 'return . splitDynPure' instead; consider eliminating monadic style" #-}
572−splitDyn :: (Reflex t, Monad m) => Dynamic t (a, b) -> m (Dynamic t a, Dynamic t b)
573−splitDyn = return . splitDynPure
575−-- | Merge the 'Dynamic' values using their 'Monoid' instance.
576−{-# DEPRECATED mconcatDyn "Use 'return . mconcat' instead; consider eliminating monadic style" #-}
577−mconcatDyn :: forall t m a. (Reflex t, Monad m, Monoid a) => [Dynamic t a] -> m (Dynamic t a)
578−mconcatDyn = return . mconcat
580−-- | This function no longer needs to be monadic; see 'distributeMapOverDynPure'.
581−{-# DEPRECATED distributeDMapOverDyn "Use 'return . distributeDMapOverDynPure' instead; consider eliminating monadic style" #-}
582−distributeDMapOverDyn :: (Reflex t, Monad m, GCompare k) => DMap k (Dynamic t) -> m (Dynamic t (DMap k Identity))
583−distributeDMapOverDyn = return . distributeDMapOverDynPure
585−-- | Merge two 'Dynamic's into a new one using the provided function. The new
586−-- 'Dynamic' changes its value each time one of the original 'Dynamic's changes
588−{-# DEPRECATED combineDyn "Use 'return (zipDynWith f a b)' instead of 'combineDyn f a b'; consider eliminating monadic style" #-}
589−combineDyn :: forall t m a b c. (Reflex t, Monad m) => (a -> b -> c) -> Dynamic t a -> Dynamic t b -> m (Dynamic t c)
590−combineDyn f a b = return $ zipDynWith f a b
592−-- | A pseudo applicative version of ap for 'Dynamic'. Example useage:
595−-- > person <- Person `mapDyn` dynFirstName
596−-- > `apDyn` dynListName
598−-- > `apDyn` dynAddress
599−{-# DEPRECATED apDyn "Use 'ffor m (<*> a)' instead of 'apDyn m a'; consider eliminating monadic style, since Dynamics are now Applicative and can be used with applicative style directly" #-}
600−#ifdef USE_TEMPLATE_HASKELL
601−{-# ANN apDyn "HLint: ignore Use fmap" #-}
603−apDyn :: forall t m a b. (Reflex t, Monad m)
604− => m (Dynamic t (a -> b))
607−apDyn m a = fmap (<*> a) m
609−--TODO: The pattern of using hold (sample b0) can be reused in various places as a safe way of building certain kinds of Dynamics; see if we can factor this out
610−-- | This function no longer needs to be monadic, so it has been replaced by
611−-- 'demuxed', which is pure.
612−{-# DEPRECATED getDemuxed "Use 'return . demuxed d' instead of 'getDemuxed d'; consider eliminating monadic style" #-}
613−getDemuxed :: (Reflex t, Monad m, Eq k) => Demux t k -> k -> m (Dynamic t Bool)
614−getDemuxed d = return . demuxed d
616−-- | This function no longer needs to be monadic, so it has been replaced by
617−-- 'distributeFHListOverDynPure', which is pure.
618−{-# DEPRECATED distributeFHListOverDyn "Use 'return . distributeFHListOverDynPure' instead; consider eliminating monadic style" #-}
619−distributeFHListOverDyn :: forall t m l. (Reflex t, Monad m, RebuildSortedHList l) => FHList (Dynamic t) l -> m (Dynamic t (HList l))
620−distributeFHListOverDyn = return . distributeFHListOverDynPure
622−-- | This function no longer needs to be monadic, so it has been replaced by
623−-- 'collectDynPure', which is pure.
624−{-# DEPRECATED collectDyn "Use 'return . collectDynPure' instead; consider eliminating monadic style" #-}
625−collectDyn :: ( RebuildSortedHList (HListElems b)
626− , IsHList a, IsHList b
627− , AllAreFunctors (Dynamic t) (HListElems b)
629− , HListElems a ~ FunctorList (Dynamic t) (HListElems b)
630− ) => a -> m (Dynamic t b)
631−collectDyn = return . collectDynPure
633−-- | This function has been renamed to 'tagPromptlyDyn' to clarify its
635−{-# DEPRECATED tagDyn "Use 'tagPromptlyDyn' instead" #-}
636−tagDyn :: Reflex t => Dynamic t a -> Event t b -> Event t a
637−tagDyn = tagPromptlyDyn
639−-- | This function has been renamed to 'attachPromptlyDyn' to clarify its
641−{-# DEPRECATED attachDyn "Use 'attachPromptlyDyn' instead" #-}
642−attachDyn :: Reflex t => Dynamic t a -> Event t b -> Event t (a, b)
643−attachDyn = attachPromptlyDyn
645−-- | This function has been renamed to 'attachPromptlyDynWith' to clarify its
647−{-# DEPRECATED attachDynWith "Use 'attachPromptlyDynWith' instead" #-}
648−attachDynWith :: Reflex t => (a -> b -> c) -> Dynamic t a -> Event t b -> Event t c
649−attachDynWith = attachPromptlyDynWith
651−-- | This function has been renamed to 'attachPromptlyDynWithMaybe' to clarify
653−{-# DEPRECATED attachDynWithMaybe "Use 'attachPromptlyDynWithMaybe' instead" #-}
654−attachDynWithMaybe :: Reflex t => (a -> b -> Maybe c) -> Dynamic t a -> Event t b -> Event t c
655−attachDynWithMaybe = attachPromptlyDynWithMaybe
657−-- | Combine an inner and outer 'Dynamic' such that the resulting 'Dynamic''s
658−-- current value will always be equal to the current value's current value, and
659−-- will change whenever either the inner or the outer (or both) values change.
660−{-# DEPRECATED joinDyn "Use 'join' instead" #-}
661−joinDyn :: Reflex t => Dynamic t (Dynamic t a) -> Dynamic t a
664−-- | WARNING: This function is only pure if @a@'s 'Eq' instance tests
665−-- representational equality. Use 'holdUniqDyn' instead, which is pure in all
666−-- circumstances. Also, note that, unlike 'nub', this function does not prevent
667−-- all recurrences of a value, only consecutive recurrences.
668−{-# DEPRECATED nubDyn "Use 'holdUniqDyn' instead; note that it returns a MonadHold action rather than a pure Dynamic" #-}
669−nubDyn :: (Reflex t, Eq a) => Dynamic t a -> Dynamic t a
672−-- | WARNING: This function is only pure if @a@'s 'Eq' instance tests
673−-- representational equality. Use 'holdUniqDyn' instead, which is pure in all
675−{-# DEPRECATED uniqDyn "Use 'holdUniqDyn' instead; note that it returns a MonadHold action rather than a pure Dynamic" #-}
676−uniqDyn :: (Reflex t, Eq a) => Dynamic t a -> Dynamic t a
677−uniqDyn = uniqDynBy (==)
679−-- | WARNING: This function is impure. Use 'holdUniqDynBy' instead.
680−{-# DEPRECATED uniqDynBy "Use 'holdUniqDynBy' instead; note that it returns a MonadHold action rather than a pure Dynamic" #-}
681−uniqDynBy :: Reflex t => (a -> a -> Bool) -> Dynamic t a -> Dynamic t a
683− let e' = attachWithMaybe (\x x' -> if x' `eq` x then Nothing else Just x') (current d) (updated d)
684− in unsafeDynamic (current d) e'