| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Reflex.Dynamic
Contents
Description
Synopsis
- data family Dynamic (t :: k) :: Type -> Type
- current :: Reflex t => Dynamic t a -> Behavior t a
- updated :: Reflex t => Dynamic t a -> Event t a
- holdDyn :: MonadHold t m => a -> Event t a -> m (Dynamic t a)
- mapDynM :: forall {k} (t :: k) m a b. (Reflex t, MonadHold t m) => (forall (m' :: Type -> Type). MonadSample t m' => a -> m' b) -> Dynamic t a -> m (Dynamic t b)
- forDynM :: forall {k} (t :: k) m a b. (Reflex t, MonadHold t m) => Dynamic t a -> (forall (m' :: Type -> Type). MonadSample t m' => a -> m' b) -> m (Dynamic t b)
- constDyn :: forall {k} (t :: k) a. Reflex t => a -> Dynamic t a
- count :: forall {k} (t :: k) m b a. (Reflex t, MonadHold t m, MonadFix m, Num b) => Event t a -> m (Dynamic t b)
- toggle :: forall {k} (t :: k) m a. (Reflex t, MonadHold t m, MonadFix m) => Bool -> Event t a -> m (Dynamic t Bool)
- switchDyn :: forall {k} (t :: k) a. Reflex t => Dynamic t (Event t a) -> Event t a
- switchPromptlyDyn :: forall {k} (t :: k) a. Reflex t => Dynamic t (Event t a) -> Event t a
- tagPromptlyDyn :: forall {k} (t :: k) a b. Reflex t => Dynamic t a -> Event t b -> Event t a
- attachPromptlyDyn :: forall {k} (t :: k) a b. Reflex t => Dynamic t a -> Event t b -> Event t (a, b)
- attachPromptlyDynWith :: forall {k} (t :: k) a b c. Reflex t => (a -> b -> c) -> Dynamic t a -> Event t b -> Event t c
- attachPromptlyDynWithMaybe :: forall {k} (t :: k) a b c. Reflex t => (a -> b -> Maybe c) -> Dynamic t a -> Event t b -> Event t c
- maybeDyn :: forall {k} (t :: k) a m. (Reflex t, MonadFix m, MonadHold t m) => Dynamic t (Maybe a) -> m (Dynamic t (Maybe (Dynamic t a)))
- eitherDyn :: forall {k} (t :: k) a b m. (Reflex t, MonadFix m, MonadHold t m) => Dynamic t (Either a b) -> m (Dynamic t (Either (Dynamic t a) (Dynamic t b)))
- factorDyn :: forall {k1} {k2} (t :: k1) m (k3 :: k2 -> Type) (v :: k2 -> Type). (Reflex t, MonadHold t m, GEq k3) => Dynamic t (DSum k3 v) -> m (Dynamic t (DSum k3 (Compose (Dynamic t) v)))
- scanDyn :: forall {k} (t :: k) m a b. (Reflex t, MonadHold t m, MonadFix m) => (a -> b) -> (a -> b -> b) -> Dynamic t a -> m (Dynamic t b)
- scanDynMaybe :: forall {k} (t :: k) m a b. (Reflex t, MonadHold t m, MonadFix m) => (a -> b) -> (a -> b -> Maybe b) -> Dynamic t a -> m (Dynamic t b)
- holdUniqDyn :: forall {k} (t :: k) m a. (Reflex t, MonadHold t m, MonadFix m, Eq a) => Dynamic t a -> m (Dynamic t a)
- holdUniqDynBy :: forall {k} (t :: k) m a. (Reflex t, MonadHold t m, MonadFix m) => (a -> a -> Bool) -> Dynamic t a -> m (Dynamic t a)
- improvingMaybe :: forall {k} (t :: k) m a. (Reflex t, MonadHold t m, MonadFix m) => Dynamic t (Maybe a) -> m (Dynamic t (Maybe a))
- foldDyn :: forall {k} (t :: k) m a b. (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> b) -> b -> Event t a -> m (Dynamic t b)
- foldDynM :: forall {k} (t :: k) m a b. (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t b) -> b -> Event t a -> m (Dynamic t b)
- foldDynMaybe :: forall {k} (t :: k) m a b. (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> Maybe b) -> b -> Event t a -> m (Dynamic t b)
- foldDynMaybeM :: forall {k} (t :: k) m a b. (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (Maybe b)) -> b -> Event t a -> m (Dynamic t b)
- joinDynThroughMap :: forall {k1} (t :: k1) k2 a. (Reflex t, Ord k2) => Dynamic t (Map k2 (Dynamic t a)) -> Dynamic t (Map k2 a)
- joinDynThroughIntMap :: forall {k} (t :: k) a. Reflex t => Dynamic t (IntMap (Dynamic t a)) -> Dynamic t (IntMap a)
- traceDyn :: forall {k} (t :: k) a. (Reflex t, Show a) => String -> Dynamic t a -> Dynamic t a
- traceDynWith :: forall {k} (t :: k) a. Reflex t => (a -> String) -> Dynamic t a -> Dynamic t a
- splitDynPure :: forall {k} (t :: k) a b. Reflex t => Dynamic t (a, b) -> (Dynamic t a, Dynamic t b)
- distributeMapOverDynPure :: forall {k1} (t :: k1) k2 v. (Reflex t, Ord k2) => Map k2 (Dynamic t v) -> Dynamic t (Map k2 v)
- distributeIntMapOverDynPure :: forall {k} (t :: k) v. Reflex t => IntMap (Dynamic t v) -> Dynamic t (IntMap v)
- distributeDMapOverDynPure :: forall {k1} (t :: k1) (k2 :: Type -> Type). (Reflex t, GCompare k2) => DMap k2 (Dynamic t) -> Dynamic t (DMap k2 Identity)
- distributeListOverDynPure :: forall {k} (t :: k) v. Reflex t => [Dynamic t v] -> Dynamic t [v]
- data Demux (t :: k) k1
- demux :: forall {k1} (t :: k1) k2. (Reflex t, Ord k2) => Dynamic t k2 -> Demux t k2
- demuxed :: forall {k1} (t :: k1) k2. (Reflex t, Eq k2) => Demux t k2 -> k2 -> Dynamic t Bool
- data HList (l :: [Type]) where
- data FHList (f :: k -> Type) (l :: [k]) where
- collectDynPure :: forall {k} b a (t :: k). (RebuildSortedHList (HListElems b), IsHList a, IsHList b, AllAreFunctors (Dynamic t) (HListElems b), Reflex t, HListElems a ~ FunctorList (Dynamic t) (HListElems b)) => a -> Dynamic t b
- class RebuildSortedHList (l :: [Type]) where
- class IsHList a where
- type HListElems a :: [Type]
- toHList :: a -> HList (HListElems a)
- fromHList :: HList (HListElems a) -> a
- class AllAreFunctors (f :: a -> Type) (l :: [a]) where
- type FunctorList (f :: a -> Type) (l :: [a]) :: [Type]
- toFHList :: HList (FunctorList f l) -> FHList f l
- fromFHList :: FHList f l -> HList (FunctorList f l)
- data HListPtr (l :: [k]) (a :: k) where
- distributeFHListOverDynPure :: forall {k} (t :: k) (l :: [Type]). (Reflex t, RebuildSortedHList l) => FHList (Dynamic t) l -> Dynamic t (HList l)
- unsafeDynamic :: forall {k} (t :: k) a. Reflex t => Behavior t a -> Event t a -> Dynamic t a
Basics
data family Dynamic (t :: k) :: Type -> Type Source #
A container for a value that can change over time and allows
notifications on changes. Basically a combination of a Behavior and an
Event, with a rule that the Behavior will change if and only if the
Event fires.
Instances
mapDynM :: forall {k} (t :: k) m a b. (Reflex t, MonadHold t m) => (forall (m' :: Type -> Type). MonadSample t m' => a -> m' b) -> Dynamic t a -> m (Dynamic t b) Source #
Map a sampling function over a Dynamic.
forDynM :: forall {k} (t :: k) m a b. (Reflex t, MonadHold t m) => Dynamic t a -> (forall (m' :: Type -> Type). MonadSample t m' => a -> m' b) -> m (Dynamic t b) Source #
Flipped version of mapDynM
constDyn :: forall {k} (t :: k) a. Reflex t => a -> Dynamic t a Source #
Construct a Dynamic value that never changes
count :: forall {k} (t :: k) m b a. (Reflex t, MonadHold t m, MonadFix m, Num b) => Event t a -> m (Dynamic t b) Source #
toggle :: forall {k} (t :: k) m a. (Reflex t, MonadHold t m, MonadFix m) => Bool -> Event t a -> m (Dynamic t Bool) Source #
switchDyn :: forall {k} (t :: k) a. Reflex t => Dynamic t (Event t a) -> Event t a Source #
Switches to the new Event whenever it receives one. Only the old event is
considered the moment a new one is switched in; the output event will fire at
that moment if only if the old event does.
Prefer this to switchPromptlyDyn where possible. The lack of doing double
work when the outer and (new) inner fires means this imposes fewer "timing
requirements" and thus is far more easy to use without introducing fresh
failure cases. switchDyn is also more performant.
switchPromptlyDyn :: forall {k} (t :: k) a. Reflex t => Dynamic t (Event t a) -> Event t a Source #
Switches to the new Event whenever it receives one. Switching occurs
before the inner Event fires - so if the Dynamic changes and both the
old and new inner Events fire simultaneously, the output will fire with the
value of the new Event.
Prefer switchDyn to this where possible. The timing requirements that
switching before imposes are likely to bring down your app unless you are
very careful. switchDyn is also more performant.
tagPromptlyDyn :: forall {k} (t :: k) a b. Reflex t => Dynamic t a -> Event t b -> Event t a Source #
Replace the value of the Event with the current value of the Dynamic
each time the Event occurs.
Note: tagPromptlyDyn d e differs from tag (current d) e in the case that e is firing
at the same time that d is changing. With tagPromptlyDyn d e, the new value of d
will replace the value of e, whereas with tag (current d) e, the old value
will be used, since the Behavior won't be updated until the end of the frame.
Additionally, this means that the output Event may not be used to directly change
the input Dynamic, because that would mean its value depends on itself. When creating
cyclic data flows, generally tag (current d) e is preferred.
attachPromptlyDyn :: forall {k} (t :: k) a b. Reflex t => Dynamic t a -> Event t b -> Event t (a, b) Source #
Attach the current value of the Dynamic to the value of the
Event each time it occurs.
Note: attachPromptlyDyn d is not the same as attach (current d). See tagPromptlyDyn for details.
attachPromptlyDynWith :: forall {k} (t :: k) a b c. Reflex t => (a -> b -> c) -> Dynamic t a -> Event t b -> Event t c Source #
Combine the current value of the Dynamic with the value of the
Event each time it occurs.
Note: attachPromptlyDynWith f d is not the same as attachWith f (current d). See tagPromptlyDyn for details.
attachPromptlyDynWithMaybe :: forall {k} (t :: k) a b c. Reflex t => (a -> b -> Maybe c) -> Dynamic t a -> Event t b -> Event t c Source #
Create a new Event by combining the value at each occurrence with the
current value of the Dynamic value and possibly filtering if the combining
function returns Nothing.
Note: attachPromptlyDynWithMaybe f d is not the same as attachWithMaybe f (current d). See tagPromptlyDyn for details.
maybeDyn :: forall {k} (t :: k) a m. (Reflex t, MonadFix m, MonadHold t m) => Dynamic t (Maybe a) -> m (Dynamic t (Maybe (Dynamic t a))) Source #
Factor a Dynamic t (Maybe a) into a Dynamic t (Maybe (Dynamic t a)),
such that the outer Dynamic is updated only when the Maybe's constructor
chages from Nothing to Just or vice-versa. Whenever the constructor
becomes Just, an inner Dynamic will be provided, whose value will track
the a inside the Just; when the constructor becomes Nothing, the
existing inner Dynamic will become constant, and will not change when the
outer constructor changes back to Nothing.
eitherDyn :: forall {k} (t :: k) a b m. (Reflex t, MonadFix m, MonadHold t m) => Dynamic t (Either a b) -> m (Dynamic t (Either (Dynamic t a) (Dynamic t b))) Source #
factorDyn :: forall {k1} {k2} (t :: k1) m (k3 :: k2 -> Type) (v :: k2 -> Type). (Reflex t, MonadHold t m, GEq k3) => Dynamic t (DSum k3 v) -> m (Dynamic t (DSum k3 (Compose (Dynamic t) v))) Source #
scanDyn :: forall {k} (t :: k) m a b. (Reflex t, MonadHold t m, MonadFix m) => (a -> b) -> (a -> b -> b) -> Dynamic t a -> m (Dynamic t b) Source #
scanDynMaybe :: forall {k} (t :: k) m a b. (Reflex t, MonadHold t m, MonadFix m) => (a -> b) -> (a -> b -> Maybe b) -> Dynamic t a -> m (Dynamic t b) Source #
Like scanDyn, but the the accumulator function may decline to update the
result Dynamic's value.
holdUniqDyn :: forall {k} (t :: k) m a. (Reflex t, MonadHold t m, MonadFix m, Eq a) => Dynamic t a -> m (Dynamic t a) Source #
Create a new Dynamic that only signals changes if the values actually
changed.
holdUniqDynBy :: forall {k} (t :: k) m a. (Reflex t, MonadHold t m, MonadFix m) => (a -> a -> Bool) -> Dynamic t a -> m (Dynamic t a) Source #
improvingMaybe :: forall {k} (t :: k) m a. (Reflex t, MonadHold t m, MonadFix m) => Dynamic t (Maybe a) -> m (Dynamic t (Maybe a)) Source #
Dynamic Maybe that can only update from Nothing to Just or Just to Just (i.e., cannot revert to Nothing)
foldDyn :: forall {k} (t :: k) m a b. (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> b) -> b -> Event t a -> m (Dynamic t b) Source #
foldDynM :: forall {k} (t :: k) m a b. (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t b) -> b -> Event t a -> m (Dynamic t b) Source #
foldDynMaybe :: forall {k} (t :: k) m a b. (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> Maybe b) -> b -> Event t a -> m (Dynamic t b) Source #
Create a Dynamic using the provided initial value and change it each time
the provided Event occurs, using a function to combine the old value with
the Event's value. If the function returns Nothing, the value is not
changed; this is distinct from returning Just the old value, since the
Dynamic's updated Event will fire in the Just case, and will not fire
in the Nothing case.
foldDynMaybeM :: forall {k} (t :: k) m a b. (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (Maybe b)) -> b -> Event t a -> m (Dynamic t b) Source #
Like foldDynMaybe, but the combining function is a PushM action, so it
can sample existing Behaviors and hold new ones.
joinDynThroughMap :: forall {k1} (t :: k1) k2 a. (Reflex t, Ord k2) => Dynamic t (Map k2 (Dynamic t a)) -> Dynamic t (Map k2 a) Source #
joinDynThroughIntMap :: forall {k} (t :: k) a. Reflex t => Dynamic t (IntMap (Dynamic t a)) -> Dynamic t (IntMap a) Source #
traceDyn :: forall {k} (t :: k) a. (Reflex t, Show a) => String -> Dynamic t a -> Dynamic t a Source #
Print the value of the Dynamic when it is first read and on each
subsequent change that is observed (as traceEvent), prefixed with the
provided string. This should only be used for debugging.
Note: Just like Debug.Trace.trace, the value will only be shown if something else in the system is depending on it.
traceDynWith :: forall {k} (t :: k) a. Reflex t => (a -> String) -> Dynamic t a -> Dynamic t a Source #
Print the result of applying the provided function to the value
of the Dynamic when it is first read and on each subsequent change
that is observed (as traceEvent). This should only be used for
debugging.
Note: Just like Debug.Trace.trace, the value will only be shown if something else in the system is depending on it.
splitDynPure :: forall {k} (t :: k) a b. Reflex t => Dynamic t (a, b) -> (Dynamic t a, Dynamic t b) Source #
distributeMapOverDynPure :: forall {k1} (t :: k1) k2 v. (Reflex t, Ord k2) => Map k2 (Dynamic t v) -> Dynamic t (Map k2 v) Source #
distributeIntMapOverDynPure :: forall {k} (t :: k) v. Reflex t => IntMap (Dynamic t v) -> Dynamic t (IntMap v) Source #
distributeDMapOverDynPure :: forall {k1} (t :: k1) (k2 :: Type -> Type). (Reflex t, GCompare k2) => DMap k2 (Dynamic t) -> Dynamic t (DMap k2 Identity) Source #
This function converts a DMap whose elements are Dynamics into a
Dynamic DMap. Its implementation is more efficient than doing the same
through the use of multiple uses of zipDynWith or Applicative operators.
distributeListOverDynPure :: forall {k} (t :: k) v. Reflex t => [Dynamic t v] -> Dynamic t [v] Source #
Deprecated: Use distributeListOverDyn instead
Convert a list with Dynamic elements into a Dynamic of a list with
non-Dynamic elements, preserving the order of the elements.
data Demux (t :: k) k1 Source #
Represents a time changing value together with an EventSelector that can
efficiently detect when the underlying Dynamic has a particular value.
This is useful for representing data like the current selection of a long
list.
Semantically,
demuxed (demux d) k === fmap (== k) d
However, when demuxed is used multiple times, the complexity is only
O(log(n)), rather than O(n) for fmap.
demuxed :: forall {k1} (t :: k1) k2. (Reflex t, Eq k2) => Demux t k2 -> k2 -> Dynamic t Bool Source #
Miscellaneous
data HList (l :: [Type]) where Source #
A heterogeneous list whose type and length are fixed statically. This is
reproduced from the HList package due to integration issues, and because
very little other functionality from that library is needed.
data FHList (f :: k -> Type) (l :: [k]) where Source #
Like HList, but with a functor wrapping each element.
collectDynPure :: forall {k} b a (t :: k). (RebuildSortedHList (HListElems b), IsHList a, IsHList b, AllAreFunctors (Dynamic t) (HListElems b), Reflex t, HListElems a ~ FunctorList (Dynamic t) (HListElems b)) => a -> Dynamic t b Source #
class RebuildSortedHList (l :: [Type]) where Source #
This class allows HLists and FHlists to be built from regular lists;
they must be contiguous and sorted.
Methods
rebuildSortedFHList :: forall (f :: Type -> Type). [DSum (HListPtr l) f] -> FHList f l Source #
rebuildSortedHList :: [DSum (HListPtr l) Identity] -> HList l Source #
Instances
| RebuildSortedHList ('[] :: [Type]) Source # | |
| RebuildSortedHList t => RebuildSortedHList (h ': t) Source # | |
class IsHList a where Source #
Poor man's Generics for product types only.
Associated Types
type HListElems a :: [Type] Source #
Instances
| IsHList (a, b) Source # | |||||
Defined in Reflex.Dynamic Associated Types
Methods toHList :: (a, b) -> HList (HListElems (a, b)) Source # fromHList :: HList (HListElems (a, b)) -> (a, b) Source # | |||||
| IsHList (a, b, c, d) Source # | |||||
Defined in Reflex.Dynamic Associated Types
Methods toHList :: (a, b, c, d) -> HList (HListElems (a, b, c, d)) Source # fromHList :: HList (HListElems (a, b, c, d)) -> (a, b, c, d) Source # | |||||
| IsHList (a, b, c, d, e, f) Source # | |||||
Defined in Reflex.Dynamic Associated Types
Methods toHList :: (a, b, c, d, e, f) -> HList (HListElems (a, b, c, d, e, f)) Source # fromHList :: HList (HListElems (a, b, c, d, e, f)) -> (a, b, c, d, e, f) Source # | |||||
class AllAreFunctors (f :: a -> Type) (l :: [a]) where Source #
Indicates that all elements in a type-level list are applications of the same functor.
Associated Types
type FunctorList (f :: a -> Type) (l :: [a]) :: [Type] Source #
Methods
toFHList :: HList (FunctorList f l) -> FHList f l Source #
fromFHList :: FHList f l -> HList (FunctorList f l) Source #
Instances
| AllAreFunctors (f :: a -> Type) ('[] :: [a]) Source # | |||||
Defined in Reflex.Dynamic Associated Types
Methods toFHList :: HList (FunctorList f ('[] :: [a])) -> FHList f ('[] :: [a]) Source # fromFHList :: FHList f ('[] :: [a]) -> HList (FunctorList f ('[] :: [a])) Source # | |||||
| AllAreFunctors f t => AllAreFunctors (f :: a -> Type) (h ': t :: [a]) Source # | |||||
Defined in Reflex.Dynamic Associated Types
Methods toFHList :: HList (FunctorList f (h ': t)) -> FHList f (h ': t) Source # fromFHList :: FHList f (h ': t) -> HList (FunctorList f (h ': t)) Source # | |||||
data HListPtr (l :: [k]) (a :: k) where Source #
A typed index into a typed heterogeneous list.
Constructors
| HHeadPtr :: forall {k} (a :: k) (t :: [k]). HListPtr (a ': t) a | |
| HTailPtr :: forall {k} (t :: [k]) (a :: k) (h :: k). HListPtr t a -> HListPtr (h ': t) a |
Instances
| GCompare (HListPtr l :: k -> Type) Source # | |
| GEq (HListPtr l :: k -> Type) Source # | |
| Eq (HListPtr l a) Source # | |
| Ord (HListPtr l a) Source # | |
Defined in Reflex.Dynamic | |
distributeFHListOverDynPure :: forall {k} (t :: k) (l :: [Type]). (Reflex t, RebuildSortedHList l) => FHList (Dynamic t) l -> Dynamic t (HList l) Source #