2{-# LANGUAGE DataKinds #-}
3{-# LANGUAGE FlexibleContexts #-}
4{-# LANGUAGE FlexibleInstances #-}
6{-# LANGUAGE LambdaCase #-}
7{-# LANGUAGE MultiParamTypeClasses #-}
8{-# LANGUAGE NoMonomorphismRestriction #-}
9{-# LANGUAGE PolyKinds #-}
10{-# LANGUAGE RankNTypes #-}
11{-# LANGUAGE ScopedTypeVariables #-}
12{-# LANGUAGE StandaloneDeriving #-}
13{-# LANGUAGE TypeFamilies #-}
14{-# LANGUAGE TypeOperators #-}
15{-# LANGUAGE UndecidableInstances #-}
16#ifdef USE_REFLEX_OPTIMIZER
17{-# OPTIONS_GHC -fplugin=Reflex.Optimizer #-}
19-- | This module contains various functions for working with 'Dynamic' values.
20-- 'Dynamic' and its primitives have been moved to the 'Reflex' class.
23 Dynamic -- Abstract so we can preserve the law that the current value is always equal to the most recent update
35 , attachPromptlyDynWith
36 , attachPromptlyDynWithMaybe
45 , distributeMapOverDynPure
46 , distributeDMapOverDynPure
47 , distributeListOverDynPure
51 -- Things that probably aren't very useful:
55 , RebuildSortedHList (..)
59 , distributeFHListOverDynPure
62 -- * Deprecated functions
69 , distributeDMapOverDyn
70 , distributeFHListOverDyn
83import Prelude hiding (mapM, mapM_)
85import Data.Functor.Misc
88import Control.Applicative ((<*>))
89import Control.Monad hiding (forM, forM_, mapM, mapM_)
90import Control.Monad.Fix
91import Control.Monad.Identity hiding (forM, forM_, mapM, mapM_)
93import Data.Dependent.Map (DMap)
94import qualified Data.Dependent.Map as DMap
95import Data.Dependent.Sum (DSum (..))
96import Data.GADT.Compare ((:~:) (..), GCompare (..), GEq (..), GOrdering (..))
103-- | Create a new 'Dynamic' that only signals changes if the values actually
105uniqDyn :: (Reflex t, Eq a) => Dynamic t a -> Dynamic t a
106uniqDyn = uniqDynBy (==)
108-- | Create a new 'Dynamic' that changes only when the underlying 'Dynamic'
109-- changes and the given function returns 'False' when given both the old and
111uniqDynBy :: Reflex t => (a -> a -> Bool) -> Dynamic t a -> Dynamic t a
113 let e' = attachWithMaybe (\x x' -> if x' `eq` x then Nothing else Just x') (current d) (updated d)
114 in unsafeDynamic (current d) e'
116-- | Create a 'Dynamic' using the initial value and change it each time the
117-- 'Event' occurs using a folding function on the previous value and the value
119foldDyn :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> b) -> b -> Event t a -> m (Dynamic t b)
120foldDyn = accum . flip
122-- | Like 'foldDyn', but the combining function is a 'PushM' action, so it
123-- can 'sample' existing 'Behaviors' and 'hold' new ones.
124foldDynM :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t b) -> b -> Event t a -> m (Dynamic t b)
125foldDynM = accumM . flip
127-- | Create a 'Dynamic' using the provided initial value and change it each time
128-- the provided 'Event' occurs, using a function to combine the old value with
129-- the 'Event''s value. If the function returns 'Nothing', the value is not
130-- changed; this is distinct from returning 'Just' the old value, since the
131-- 'Dynamic''s 'updated' 'Event' will fire in the 'Just' case, and will not fire
132-- in the 'Nothing' case.
133foldDynMaybe :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> Maybe b) -> b -> Event t a -> m (Dynamic t b)
134foldDynMaybe = accumMaybe . flip
136-- | Like 'foldDynMaybe', but the combining function is a 'PushM' action, so it
137-- can 'sample' existing 'Behaviors' and 'hold' new ones.
138foldDynMaybeM :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (Maybe b)) -> b -> Event t a -> m (Dynamic t b)
139foldDynMaybeM = accumMaybeM . flip
141-- | Create a new 'Dynamic' that counts the occurences of the 'Event'.
142count :: (Reflex t, MonadHold t m, MonadFix m, Num b) => Event t a -> m (Dynamic t b)
143count e = holdDyn 0 =<< zipListWithEvent const (iterate (+1) 1) e
145-- | Create a new 'Dynamic' using the initial value that flips its
146-- value every time the 'Event' occurs.
147toggle :: (Reflex t, MonadHold t m, MonadFix m) => Bool -> Event t a -> m (Dynamic t Bool)
148toggle = foldDyn (const not)
150-- | Switches to the new 'Event' whenever it receives one. Switching occurs
151-- *before* the inner 'Event' fires - so if the 'Dynamic' changes and both the
152-- old and new inner Events fire simultaneously, the output will fire with the
153-- value of the *new* 'Event'.
154switchPromptlyDyn :: forall t a. Reflex t => Dynamic t (Event t a) -> Event t a
155switchPromptlyDyn de =
156 let eLag = switch $ current de
157 eCoincidences = coincidence $ updated de
158 in leftmost [eCoincidences, eLag]
160-- | Split a 'Dynamic' pair into a pair of 'Dynamic's
161splitDynPure :: Reflex t => Dynamic t (a, b) -> (Dynamic t a, Dynamic t b)
162splitDynPure d = (fmap fst d, fmap snd d)
164-- | Convert a 'Map' with 'Dynamic' elements into a 'Dynamic' of a 'Map' with
165-- non-'Dynamic' elements.
166distributeMapOverDynPure :: (Reflex t, Ord k) => Map k (Dynamic t v) -> Dynamic t (Map k v)
167distributeMapOverDynPure = fmap dmapToMap . distributeDMapOverDynPure . mapWithFunctorToDMap
169-- | Convert a list with 'Dynamic' elements into a 'Dynamic' of a list with
170-- non-'Dynamic' elements, preserving the order of the elements.
171distributeListOverDynPure :: Reflex t => [Dynamic t v] -> Dynamic t [v]
172distributeListOverDynPure =
173 fmap (map fromDSum . DMap.toAscList) .
174 distributeDMapOverDynPure .
175 DMap.fromDistinctAscList .
178 toDSum :: Int -> Dynamic t a -> DSum (Const2 Int a) (Dynamic t)
179 toDSum k v = Const2 k :=> v
180 fromDSum :: DSum (Const2 Int a) Identity -> a
181 fromDSum (Const2 _ :=> Identity v) = v
183--TODO: Generalize this to functors other than Maps
184-- | Combine a 'Dynamic' of a 'Map' of 'Dynamic's into a 'Dynamic'
185-- with the current values of the 'Dynamic's in a map.
186joinDynThroughMap :: forall t k a. (Reflex t, Ord k) => Dynamic t (Map k (Dynamic t a)) -> Dynamic t (Map k a)
187joinDynThroughMap = joinDyn . fmap distributeMapOverDynPure
189-- | Print the value of the 'Dynamic' when it is first read and on each
190-- subsequent change that is observed (as traceEvent), prefixed with the
191-- provided string. This should /only/ be used for debugging.
193-- Note: Just like Debug.Trace.trace, the value will only be shown if something
194-- else in the system is depending on it.
195traceDyn :: (Reflex t, Show a) => String -> Dynamic t a -> Dynamic t a
196traceDyn s = traceDynWith $ \x -> s <> ": " <> show x
198-- | Print the result of applying the provided function to the value
199-- of the 'Dynamic' when it is first read and on each subsequent change
200-- that is observed (as traceEvent). This should /only/ be used for
203-- Note: Just like Debug.Trace.trace, the value will only be shown if something
204-- else in the system is depending on it.
205traceDynWith :: Reflex t => (a -> String) -> Dynamic t a -> Dynamic t a
207 let e' = traceEventWith f $ updated d
209 x <- sample $ current d
210 trace (f x) $ return x
211 in unsafeBuildDynamic getV0 e'
213-- | Replace the value of the 'Event' with the current value of the 'Dynamic'
214-- each time the 'Event' occurs.
216-- Note: `tagPromptlyDyn d e` differs from `tag (current d) e` in the case that `e` is firing
217-- at the same time that `d` is changing. With `tagPromptlyDyn d e`, the *new* value of `d`
218-- will replace the value of `e`, whereas with `tag (current d) e`, the *old* value
219-- will be used, since the 'Behavior' won't be updated until the end of the frame.
220-- Additionally, this means that the output 'Event' may not be used to directly change
221-- the input 'Dynamic', because that would mean its value depends on itself. When creating
222-- cyclic data flows, generally `tag (current d) e` is preferred.
223tagPromptlyDyn :: Reflex t => Dynamic t a -> Event t b -> Event t a
224tagPromptlyDyn = attachPromptlyDynWith const
226-- | Attach the current value of the 'Dynamic' to the value of the
227-- 'Event' each time it occurs.
229-- Note: `attachPromptlyDyn d` is not the same as `attach (current d)`. See 'tagPromptlyDyn' for details.
230attachPromptlyDyn :: Reflex t => Dynamic t a -> Event t b -> Event t (a, b)
231attachPromptlyDyn = attachPromptlyDynWith (,)
233-- | Combine the current value of the 'Dynamic' with the value of the
234-- 'Event' each time it occurs.
236-- Note: `attachPromptlyDynWith f d` is not the same as `attachWith f (current d)`. See 'tagPromptlyDyn' for details.
237attachPromptlyDynWith :: Reflex t => (a -> b -> c) -> Dynamic t a -> Event t b -> Event t c
238attachPromptlyDynWith f = attachPromptlyDynWithMaybe $ \a b -> Just $ f a b
240-- | Create a new 'Event' by combining the value at each occurence with the
241-- current value of the 'Dynamic' value and possibly filtering if the combining
242-- function returns 'Nothing'.
244-- Note: `attachPromptlyDynWithMaybe f d` is not the same as `attachWithMaybe f
245-- (current d)`. See 'tagPromptlyDyn' for details.
246attachPromptlyDynWithMaybe :: Reflex t => (a -> b -> Maybe c) -> Dynamic t a -> Event t b -> Event t c
247attachPromptlyDynWithMaybe f d e =
248 let e' = attach (current d) e
249 in fforMaybe (align e' $ updated d) $ \case
250 This (a, b) -> f a b -- Only the tagging event is firing, so use that
251 These (_, b) a -> f a b -- Both events are firing, so use the newer value
252 That _ -> Nothing -- The tagging event isn't firing, so don't fire
254--------------------------------------------------------------------------------
256--------------------------------------------------------------------------------
258-- | Represents a time changing value together with an 'EventSelector' that can
259-- efficiently detect when the underlying 'Dynamic' has a particular value.
260-- This is useful for representing data like the current selection of a long
265-- > demuxed (demux d) k === fmap (== k) d
267-- However, the when getDemuxed is used multiple times, the complexity is only
268-- /O(log(n))/, rather than /O(n)/ for fmap.
269data Demux t k = Demux { demuxValue :: Behavior t k
270 , demuxSelector :: EventSelector t (Const2 k Bool)
273-- | Demultiplex an input value to a 'Demux' with many outputs. At any given
274-- time, whichever output is indicated by the given 'Dynamic' will be 'True'.
275demux :: (Reflex t, Ord k) => Dynamic t k -> Demux t k
276demux k = Demux (current k)
277 (fan $ attachWith (\k0 k1 -> if k0 == k1
279 else DMap.fromList [Const2 k0 :=> Identity False,
280 Const2 k1 :=> Identity True])
281 (current k) (updated k))
283-- | Select a particular output of the 'Demux'; this is equivalent to (but much
284-- faster than) mapping over the original 'Dynamic' and checking whether it is
285-- equal to the given key.
286demuxed :: (Reflex t, Eq k) => Demux t k -> k -> Dynamic t Bool
288 let e = select (demuxSelector d) (Const2 k)
289 in unsafeBuildDynamic (fmap (==k) $ sample $ demuxValue d) e
291--------------------------------------------------------------------------------
293--------------------------------------------------------------------------------
295--TODO: This whole section is badly in need of cleanup
297-- | A heterogeneous list whose type and length are fixed statically. This is
298-- reproduced from the 'HList' package due to integration issues, and because
299-- very little other functionality from that library is needed.
300data HList (l::[*]) where
302 HCons :: e -> HList l -> HList (e ': l)
306type family HRevApp (l1 :: [k]) (l2 :: [k]) :: [k]
307type instance HRevApp '[] l = l
308type instance HRevApp (e ': l) l' = HRevApp l (e ': l')
310hRevApp :: HList l1 -> HList l2 -> HList (HRevApp l1 l2)
312hRevApp (HCons x l) l' = hRevApp l (HCons x l')
314hReverse :: HList l -> HList (HRevApp l '[])
315hReverse l = hRevApp l HNil
317hBuild :: (HBuild' '[] r) => r
320class HBuild' l r where
321 hBuild' :: HList l -> r
323instance (l' ~ HRevApp l '[])
324 => HBuild' l (HList l') where
327instance HBuild' (a ': l) r
328 => HBuild' l (a->r) where
329 hBuild' l x = hBuild' (HCons x l)
331-- | Like 'HList', but with a functor wrapping each element.
333 FHNil :: FHList f '[]
334 FHCons :: f e -> FHList f l -> FHList f (e ': l)
336instance GEq (HListPtr l) where
338 geqUnify HHeadPtr HHeadPtr _ same = same
339 geqUnify (HTailPtr a) (HTailPtr b) different same = geqUnify a b different same
340 geqUnify _ _ different _ = different
341 HHeadPtr `geq` HHeadPtr = Just Refl
342 HHeadPtr `geq` HTailPtr _ = Nothing
343 HTailPtr _ `geq` HHeadPtr = Nothing
344 HTailPtr a `geq` HTailPtr b = a `geq` b
346instance GCompare (HListPtr l) where -- Warning: This ordering can't change, dmapTo*HList will break
348 HHeadPtr `gcompare` HHeadPtr = GEQ
349 HHeadPtr `gcompare` HTailPtr _ = GLT
350 HTailPtr _ `gcompare` HHeadPtr = GGT
351 HTailPtr a `gcompare` HTailPtr b = a `gcompare` b
353-- | A typed index into a typed heterogeneous list.
354data HListPtr l a where
355 HHeadPtr :: HListPtr (h ': t) h
356 HTailPtr :: HListPtr t a -> HListPtr (h ': t) a
358deriving instance Eq (HListPtr l a)
359deriving instance Ord (HListPtr l a)
361fhlistToDMap :: forall (f :: * -> *) l. FHList f l -> DMap (HListPtr l) f
362fhlistToDMap = DMap.fromList . go
363 where go :: forall l'. FHList f l' -> [DSum (HListPtr l') f]
366 FHCons h t -> (HHeadPtr :=> h) : map (\(p :=> v) -> HTailPtr p :=> v) (go t)
368-- | This class allows 'HList's and 'FHlist's to be built from regular lists;
369-- they must be contiguous and sorted.
370class RebuildSortedHList l where
371 rebuildSortedFHList :: [DSum (HListPtr l) f] -> FHList f l
372 rebuildSortedHList :: [DSum (HListPtr l) Identity] -> HList l
374instance RebuildSortedHList '[] where
375 rebuildSortedFHList l = case l of
377 _ : _ -> error "rebuildSortedFHList{'[]}: empty list expected"
378 rebuildSortedHList l = case l of
380 _ : _ -> error "rebuildSortedHList{'[]}: empty list expected"
382instance RebuildSortedHList t => RebuildSortedHList (h ': t) where
383 rebuildSortedFHList l = case l of
384 ((HHeadPtr :=> h) : t) -> FHCons h . rebuildSortedFHList . map (\(HTailPtr p :=> v) -> p :=> v) $ t
385 _ -> error "rebuildSortedFHList{h':t}: non-empty list with HHeadPtr expected"
386 rebuildSortedHList l = case l of
387 ((HHeadPtr :=> Identity h) : t) -> HCons h . rebuildSortedHList . map (\(HTailPtr p :=> v) -> p :=> v) $ t
388 _ -> error "rebuildSortedHList{h':t}: non-empty list with HHeadPtr expected"
390dmapToHList :: forall l. RebuildSortedHList l => DMap (HListPtr l) Identity -> HList l
391dmapToHList = rebuildSortedHList . DMap.toList
393-- | Collect a hetereogeneous list whose elements are all 'Dynamic's into a
394-- single 'Dynamic' whose value represents the current values of all of the
396distributeFHListOverDynPure :: (Reflex t, RebuildSortedHList l) => FHList (Dynamic t) l -> Dynamic t (HList l)
397distributeFHListOverDynPure l = fmap dmapToHList $ distributeDMapOverDynPure $ fhlistToDMap l
399-- | Indicates that all elements in a type-level list are applications of the
401class AllAreFunctors (f :: a -> *) (l :: [a]) where
402 type FunctorList f l :: [*]
403 toFHList :: HList (FunctorList f l) -> FHList f l
404 fromFHList :: FHList f l -> HList (FunctorList f l)
406instance AllAreFunctors f '[] where
407 type FunctorList f '[] = '[]
408 toFHList l = case l of
410#if !defined(__GLASGOW_HASKELL__) || __GLASGOW_HASKELL__ < 800
411 _ -> error "toFHList: impossible" -- Otherwise, GHC complains of a non-exhaustive pattern match; see https://ghc.haskell.org/trac/ghc/ticket/4139
413 fromFHList FHNil = HNil
415instance AllAreFunctors f t => AllAreFunctors f (h ': t) where
416 type FunctorList f (h ': t) = f h ': FunctorList f t
417 toFHList l = case l of
418 a `HCons` b -> a `FHCons` toFHList b
419#if !defined(__GLASGOW_HASKELL__) || __GLASGOW_HASKELL__ < 800
420 _ -> error "toFHList: impossible" -- Otherwise, GHC complains of a non-exhaustive pattern match; see https://ghc.haskell.org/trac/ghc/ticket/4139
422 fromFHList (a `FHCons` b) = a `HCons` fromFHList b
424-- | Convert a datastructure whose constituent parts are all 'Dynamic's into a
425-- single 'Dynamic' whose value represents all the current values of the input's
426-- consitutent 'Dynamic's.
427collectDynPure :: ( RebuildSortedHList (HListElems b)
428 , IsHList a, IsHList b
429 , AllAreFunctors (Dynamic t) (HListElems b)
431 , HListElems a ~ FunctorList (Dynamic t) (HListElems b)
432 ) => a -> Dynamic t b
433collectDynPure ds = fmap fromHList $ distributeFHListOverDynPure $ toFHList $ toHList ds
435-- | Poor man's 'Generic's for product types only.
437 type HListElems a :: [*]
438 toHList :: a -> HList (HListElems a)
439 fromHList :: HList (HListElems a) -> a
441instance IsHList (a, b) where
442 type HListElems (a, b) = [a, b]
443 toHList (a, b) = hBuild a b
444 fromHList l = case l of
445 a `HCons` b `HCons` HNil -> (a, b)
446#if !defined(__GLASGOW_HASKELL__) || __GLASGOW_HASKELL__ < 800
447 _ -> error "fromHList: impossible" -- Otherwise, GHC complains of a non-exhaustive pattern match; see https://ghc.haskell.org/trac/ghc/ticket/4139
450instance IsHList (a, b, c, d) where
451 type HListElems (a, b, c, d) = [a, b, c, d]
452 toHList (a, b, c, d) = hBuild a b c d
453 fromHList l = case l of
454 a `HCons` b `HCons` c `HCons` d `HCons` HNil -> (a, b, c, d)
455#if !defined(__GLASGOW_HASKELL__) || __GLASGOW_HASKELL__ < 800
456 _ -> error "fromHList: impossible" -- Otherwise, GHC complains of a non-exhaustive pattern match; see https://ghc.haskell.org/trac/ghc/ticket/4139
459instance IsHList (a, b, c, d, e, f) where
460 type HListElems (a, b, c, d, e, f) = [a, b, c, d, e, f]
461 toHList (a, b, c, d, e, f) = hBuild a b c d e f
462 fromHList l = case l of
463 a `HCons` b `HCons` c `HCons` d `HCons` e `HCons` f `HCons` HNil -> (a, b, c, d, e, f)
464#if !defined(__GLASGOW_HASKELL__) || __GLASGOW_HASKELL__ < 800
465 _ -> error "fromHList: impossible" -- Otherwise, GHC complains of a non-exhaustive pattern match; see https://ghc.haskell.org/trac/ghc/ticket/4139
468--------------------------------------------------------------------------------
469-- Deprecated functions
470--------------------------------------------------------------------------------
472-- | Map a function over a 'Dynamic'.
473{-# DEPRECATED mapDyn "Use 'return . fmap f' instead of 'mapDyn f'; consider eliminating monadic style" #-}
474mapDyn :: (Reflex t, Monad m) => (a -> b) -> Dynamic t a -> m (Dynamic t b)
475mapDyn f = return . fmap f
477-- | 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.
478{-# DEPRECATED mapDynM "Consider using the Monad instance for Dynamic instead." #-}
479mapDynM :: 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)
481 let e' = push (fmap Just . f :: a -> PushM t (Maybe b)) $ updated d
482 eb' = fmap constant e'
483 v0 = pull $ f =<< sample (current d)
484 bb' :: Behavior t (Behavior t b) <- hold v0 eb'
485 let b' = pull $ sample =<< sample bb'
486 return $ unsafeDynamic b' e'
488-- | Flipped version of 'mapDyn'.
489{-# DEPRECATED forDyn "Use 'return . ffor a' instead of 'forDyn a'; consider eliminating monadic style" #-}
490forDyn :: (Reflex t, Monad m) => Dynamic t a -> (a -> b) -> m (Dynamic t b)
491forDyn a = return . ffor a
493-- | Flipped version of 'mapDynM'
494{-# DEPRECATED forDynM "Consider using the Monad instance for Dynamic instead." #-}
495forDynM :: 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)
496forDynM d f = mapDynM f d
498-- | Split the 'Dynamic' into two 'Dynamic's, each taking the respective value
500{-# DEPRECATED splitDyn "Use 'return . splitDynPure' instead; consider eliminating monadic style" #-}
501splitDyn :: (Reflex t, Monad m) => Dynamic t (a, b) -> m (Dynamic t a, Dynamic t b)
502splitDyn = return . splitDynPure
504-- | Merge the 'Dynamic' values using their 'Monoid' instance.
505{-# DEPRECATED mconcatDyn "Use 'return . mconcat' instead; consider eliminating monadic style" #-}
506mconcatDyn :: forall t m a. (Reflex t, Monad m, Monoid a) => [Dynamic t a] -> m (Dynamic t a)
507mconcatDyn = return . mconcat
509-- | This function no longer needs to be monadic; see 'distributeMapOverDynPure'.
510{-# DEPRECATED distributeDMapOverDyn "Use 'return . distributeDMapOverDynPure' instead; consider eliminating monadic style" #-}
511distributeDMapOverDyn :: (Reflex t, Monad m, GCompare k) => DMap k (Dynamic t) -> m (Dynamic t (DMap k Identity))
512distributeDMapOverDyn = return . distributeDMapOverDynPure
514-- | Merge two 'Dynamic's into a new one using the provided function. The new
515-- 'Dynamic' changes its value each time one of the original 'Dynamic's changes
517{-# DEPRECATED combineDyn "Use 'return (zipDynWith f a b)' instead of 'combineDyn f a b'; consider eliminating monadic style" #-}
518combineDyn :: forall t m a b c. (Reflex t, Monad m) => (a -> b -> c) -> Dynamic t a -> Dynamic t b -> m (Dynamic t c)
519combineDyn f a b = return $ zipDynWith f a b
521-- | A psuedo applicative version of ap for 'Dynamic'. Example useage:
524-- > person <- Person `mapDyn` dynFirstName
525-- > `apDyn` dynListName
527-- > `apDyn` dynAddress
528{-# 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" #-}
529#ifdef USE_TEMPLATE_HASKELL
530{-# ANN apDyn "HLint: ignore Use fmap" #-}
532apDyn :: forall t m a b. (Reflex t, Monad m)
533 => m (Dynamic t (a -> b))
536apDyn m a = fmap (<*> a) m
538--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
539-- | This function no longer needs to be monadic, so it has been replaced by
540-- 'demuxed', which is pure.
541{-# DEPRECATED getDemuxed "Use 'return . demuxed d' instead of 'getDemuxed d'; consider eliminating monadic style" #-}
542getDemuxed :: (Reflex t, Monad m, Eq k) => Demux t k -> k -> m (Dynamic t Bool)
543getDemuxed d = return . demuxed d
545-- | This function no longer needs to be monadic, so it has been replaced by
546-- 'distributeFHListOverDynPure', which is pure.
547{-# DEPRECATED distributeFHListOverDyn "Use 'return . distributeFHListOverDynPure' instead; consider eliminating monadic style" #-}
548distributeFHListOverDyn :: forall t m l. (Reflex t, Monad m, RebuildSortedHList l) => FHList (Dynamic t) l -> m (Dynamic t (HList l))
549distributeFHListOverDyn = return . distributeFHListOverDynPure
551-- | This function no longer needs to be monadic, so it has been replaced by
552-- 'collectDynPure', which is pure.
553{-# DEPRECATED collectDyn "Use 'return . collectDynPure' instead; consider eliminating monadic style" #-}
554collectDyn :: ( RebuildSortedHList (HListElems b)
555 , IsHList a, IsHList b
556 , AllAreFunctors (Dynamic t) (HListElems b)
558 , HListElems a ~ FunctorList (Dynamic t) (HListElems b)
559 ) => a -> m (Dynamic t b)
560collectDyn = return . collectDynPure
562-- | This function has been renamed to 'tagPromptlyDyn' to clarify its
564{-# DEPRECATED tagDyn "Use 'tagPromptlyDyn' instead" #-}
565tagDyn :: Reflex t => Dynamic t a -> Event t b -> Event t a
566tagDyn = tagPromptlyDyn
568-- | This function has been renamed to 'attachPromptlyDyn' to clarify its
570{-# DEPRECATED attachDyn "Use 'attachPromptlyDyn' instead" #-}
571attachDyn :: Reflex t => Dynamic t a -> Event t b -> Event t (a, b)
572attachDyn = attachPromptlyDyn
574-- | This function has been renamed to 'attachPromptlyDynWith' to clarify its
576{-# DEPRECATED attachDynWith "Use 'attachPromptlyDynWith' instead" #-}
577attachDynWith :: Reflex t => (a -> b -> c) -> Dynamic t a -> Event t b -> Event t c
578attachDynWith = attachPromptlyDynWith
580-- | This function has been renamed to 'attachPromptlyDynWithMaybe' to clarify
582{-# DEPRECATED attachDynWithMaybe "Use 'attachPromptlyDynWithMaybe' instead" #-}
583attachDynWithMaybe :: Reflex t => (a -> b -> Maybe c) -> Dynamic t a -> Event t b -> Event t c
584attachDynWithMaybe = attachPromptlyDynWithMaybe
586-- | Combine an inner and outer 'Dynamic' such that the resulting 'Dynamic''s
587-- current value will always be equal to the current value's current value, and
588-- will change whenever either the inner or the outer (or both) values change.
589{-# DEPRECATED joinDyn "Use 'join' instead" #-}
590joinDyn :: Reflex t => Dynamic t (Dynamic t a) -> Dynamic t a
593-- | 'nubDyn''s behavior is not quite analogous to 'nub''s behavior, so it has
594-- been renamed to 'uniqDyn'
595{-# DEPRECATED nubDyn "Use 'uniqDyn' instead" #-}
596nubDyn :: (Reflex t, Eq a) => Dynamic t a -> Dynamic t a
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list