{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecursiveDo #-}
{-# LANGUAGE RoleAnnotations #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE Trustworthy #-}
#ifdef USE_REFLEX_OPTIMIZER
{-# OPTIONS_GHC -fplugin=Reflex.Optimizer #-}
#endif
module Reflex.Class
( module Data.Patch
, Reflex (..)
, mergeInt
, coerceBehavior
, coerceEvent
, coerceDynamic
, coerceIncremental
, MonadSample (..)
, MonadHold (..)
, EventSelector (..)
, EventSelectorG (..)
, EventSelectorInt (..)
, constDyn
, pushAlways
, leftmost
, merge
, mergeIncremental
, mergeIncrementalWithMove
, mergeMap
, mergeIntMap
, mergeMapIncremental
, mergeMapIncrementalWithMove
, mergeIntMapIncremental
, coincidencePatchMap
, coincidencePatchMapWithMove
, coincidencePatchIntMap
, mergeList
, mergeWith
, difference
, alignEventWithMaybe
, splitE
, fan
, fanEither
, fanThese
, fanMap
, dmapToThese
, EitherTag (..)
, eitherToDSum
, dsumToEither
, factorEvent
, filterEventKey
, switchHold
, switchHoldPromptly
, switchHoldPromptOnly
, switchHoldPromptOnlyIncremental
, tag
, tagMaybe
, attach
, attachWith
, attachWithMaybe
, gate
, distributeDMapOverDynPure
, distributeDMapOverDynPureG
, distributeListOverDyn
, distributeListOverDynWith
, zipDyn
, zipDynWith
, Accumulator (..)
, accumDyn
, accumMDyn
, accumMaybeDyn
, accumMaybeMDyn
, mapAccumDyn
, mapAccumMDyn
, mapAccumMaybeDyn
, mapAccumMaybeMDyn
, accumB
, accumMB
, accumMaybeB
, accumMaybeMB
, mapAccumB
, mapAccumMB
, mapAccumMaybeB
, mapAccumMaybeMB
, mapAccum_
, mapAccumM_
, mapAccumMaybe_
, mapAccumMaybeM_
, accumIncremental
, accumMIncremental
, accumMaybeIncremental
, accumMaybeMIncremental
, mapAccumIncremental
, mapAccumMIncremental
, mapAccumMaybeIncremental
, mapAccumMaybeMIncremental
, zipListWithEvent
, numberOccurrences
, numberOccurrencesFrom
, numberOccurrencesFrom_
, (<@>)
, (<@)
, tailE
, headTailE
, takeWhileE
, takeWhileJustE
, dropWhileE
, takeDropWhileJustE
, switcher
, traceEvent
, traceEventWith
, unsafeDynamic
, unsafeMapIncremental
, FunctorMaybe
, mapMaybe
, fmapMaybe
, fforMaybe
, ffilter
, filterLeft
, filterRight
, ffor
, ffor2
, ffor3
, switchPromptly
, switchPromptOnly
, fmapMaybeCheap
, mapMaybeCheap
, fmapCheap
, fforCheap
, fforMaybeCheap
, pushAlwaysCheap
, tagCheap
, mergeWithCheap
, mergeWithCheap'
, slowHeadE
) where
#ifdef MIN_VERSION_semialign
import Prelude hiding (zip, zipWith)
#if MIN_VERSION_these(0,8,0)
import Data.These.Combinators (justThese)
#endif
#if MIN_VERSION_semialign(1,1,0)
import Data.Zip (Zip (..), Unzip (..))
#endif
#endif
import Control.Applicative
import Control.Monad.Identity
import Control.Monad.Reader
import Control.Monad.State.Strict
import Control.Monad.Trans.Cont (ContT)
import Control.Monad.Trans.Except (ExceptT)
import Control.Monad.Trans.RWS (RWST)
import Control.Monad.Trans.Writer (WriterT)
import Data.Align
import Data.Bifunctor
import Data.Coerce
import Data.Default
import Data.Dependent.Map (DMap)
import Data.Dependent.Sum (DSum (..))
import qualified Data.Dependent.Map as DMap
import Data.Functor.Compose
import Data.Functor.Product
import Data.GADT.Compare (GEq (..), GCompare (..))
import Data.FastMutableIntMap (PatchIntMap)
import Data.Foldable
import Data.Functor.Bind
import Data.Functor.Misc
import Data.Functor.Plus
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IntMap
import Data.Kind (Type)
import Data.List.NonEmpty (NonEmpty (..))
import Data.Map (Map)
import Data.Semigroup (Semigroup (..))
import Data.Some (Some(Some))
import Data.String
import Data.These
import Data.Type.Coercion
import Data.Type.Equality ((:~:) (..))
import Data.Witherable (Filterable(..))
import qualified Data.Witherable as W
import Reflex.FunctorMaybe (FunctorMaybe)
import qualified Reflex.FunctorMaybe
import Data.Patch
import qualified Data.Patch.MapWithMove as PatchMapWithMove
import Debug.Trace (trace)
class ( MonadHold t (PushM t)
, MonadSample t (PullM t)
, MonadFix (PushM t)
, Functor (Dynamic t)
, Applicative (Dynamic t)
, Monad (Dynamic t)
) => Reflex t where
data Behavior t :: Type -> Type
data Event t :: Type -> Type
data Dynamic t :: Type -> Type
data Incremental t :: Type -> Type
type PushM t :: Type -> Type
type PullM t :: Type -> Type
never :: Event t a
constant :: a -> Behavior t a
push :: (a -> PushM t (Maybe b)) -> Event t a -> Event t b
pushCheap :: (a -> PushM t (Maybe b)) -> Event t a -> Event t b
pull :: PullM t a -> Behavior t a
mergeG :: GCompare k => (forall a. q a -> Event t (v a))
-> DMap k q -> Event t (DMap k v)
fanG :: GCompare k => Event t (DMap k v) -> EventSelectorG t k v
switch :: Behavior t (Event t a) -> Event t a
coincidence :: Event t (Event t a) -> Event t a
current :: Dynamic t a -> Behavior t a
updated :: Dynamic t a -> Event t a
unsafeBuildDynamic :: PullM t a -> Event t a -> Dynamic t a
unsafeBuildIncremental :: Patch p => PullM t (PatchTarget p) -> Event t p -> Incremental t p
mergeIncrementalG :: GCompare k
=> (forall a. q a -> Event t (v a))
-> Incremental t (PatchDMap k q)
-> Event t (DMap k v)
mergeIncrementalWithMoveG :: GCompare k
=> (forall a. q a -> Event t (v a))
-> Incremental t (PatchDMapWithMove k q) -> Event t (DMap k v)
currentIncremental :: Patch p => Incremental t p -> Behavior t (PatchTarget p)
updatedIncremental :: Patch p => Incremental t p -> Event t p
incrementalToDynamic :: Patch p => Incremental t p -> Dynamic t (PatchTarget p)
behaviorCoercion :: Coercion a b -> Coercion (Behavior t a) (Behavior t b)
eventCoercion :: Coercion a b -> Coercion (Event t a) (Event t b)
dynamicCoercion :: Coercion a b -> Coercion (Dynamic t a) (Dynamic t b)
incrementalCoercion
:: Coercion (PatchTarget a) (PatchTarget b) -> Coercion a b -> Coercion (Incremental t a) (Incremental t b)
mergeIntIncremental :: Incremental t (PatchIntMap (Event t a)) -> Event t (IntMap a)
fanInt :: Event t (IntMap a) -> EventSelectorInt t a
fan :: forall t k. (Reflex t, GCompare k)
=> Event t (DMap k Identity) -> EventSelector t k
fan :: forall {k} (t :: k) (k :: * -> *).
(Reflex t, GCompare k) =>
Event t (DMap k Identity) -> EventSelector t k
fan Event t (DMap k Identity)
e = (forall a. k a -> Event t a) -> EventSelector t k
forall {k} (t :: k) (k :: * -> *).
(forall a. k a -> Event t a) -> EventSelector t k
EventSelector ((k a -> Event t (Identity a)) -> k a -> Event t a
forall a. (k a -> Event t (Identity a)) -> k a -> Event t a
fixup (EventSelectorG t k Identity
-> forall a. k a -> Event t (Identity a)
forall {k} {k} (t :: k) (k :: k -> *) (v :: k -> *).
EventSelectorG t k v -> forall (a :: k). k a -> Event t (v a)
selectG (Event t (DMap k Identity) -> EventSelectorG t k Identity
forall {k} (t :: k) {k} (k :: k -> *) (v :: k -> *).
(Reflex t, GCompare k) =>
Event t (DMap k v) -> EventSelectorG t k v
forall {k} (k :: k -> *) (v :: k -> *).
GCompare k =>
Event t (DMap k v) -> EventSelectorG t k v
fanG Event t (DMap k Identity)
e) :: k a -> Event t (Identity a)) :: forall a. k a -> Event t a)
where
fixup :: forall a. (k a -> Event t (Identity a)) -> k a -> Event t a
fixup :: forall a. (k a -> Event t (Identity a)) -> k a -> Event t a
fixup = case Coercion (Identity a) a
-> Coercion (Event t (Identity a)) (Event t a)
forall {k} (t :: k) a b.
Reflex t =>
Coercion a b -> Coercion (Event t a) (Event t b)
forall a b. Coercion a b -> Coercion (Event t a) (Event t b)
eventCoercion Coercion (Identity a) a
forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion :: Coercion (Event t (Identity a)) (Event t a) of
Coercion (Event t (Identity a)) (Event t a)
Coercion -> (k a -> Event t (Identity a)) -> k a -> Event t a
forall a b. Coercible a b => a -> b
coerce
mergeInt :: Reflex t => IntMap (Event t a) -> Event t (IntMap a)
mergeInt :: forall {k} (t :: k) a.
Reflex t =>
IntMap (Event t a) -> Event t (IntMap a)
mergeInt IntMap (Event t a)
m = Incremental t (PatchIntMap (Event t a)) -> Event t (IntMap a)
forall a.
Incremental t (PatchIntMap (Event t a)) -> Event t (IntMap a)
forall {k} (t :: k) a.
Reflex t =>
Incremental t (PatchIntMap (Event t a)) -> Event t (IntMap a)
mergeIntIncremental (Incremental t (PatchIntMap (Event t a)) -> Event t (IntMap a))
-> Incremental t (PatchIntMap (Event t a)) -> Event t (IntMap a)
forall a b. (a -> b) -> a -> b
$ PullM t (PatchTarget (PatchIntMap (Event t a)))
-> Event t (PatchIntMap (Event t a))
-> Incremental t (PatchIntMap (Event t a))
forall p.
Patch p =>
PullM t (PatchTarget p) -> Event t p -> Incremental t p
forall {k} (t :: k) p.
(Reflex t, Patch p) =>
PullM t (PatchTarget p) -> Event t p -> Incremental t p
unsafeBuildIncremental (IntMap (Event t a) -> PullM t (IntMap (Event t a))
forall a. a -> PullM t a
forall (m :: * -> *) a. Monad m => a -> m a
return IntMap (Event t a)
m) Event t (PatchIntMap (Event t a))
forall a. Event t a
forall {k} (t :: k) a. Reflex t => Event t a
never
coerceBehavior :: (Reflex t, Coercible a b) => Behavior t a -> Behavior t b
coerceBehavior :: forall {k} (t :: k) a b.
(Reflex t, Coercible a b) =>
Behavior t a -> Behavior t b
coerceBehavior = Coercion (Behavior t a) (Behavior t b)
-> Behavior t a -> Behavior t b
forall a b. Coercion a b -> a -> b
coerceWith (Coercion (Behavior t a) (Behavior t b)
-> Behavior t a -> Behavior t b)
-> Coercion (Behavior t a) (Behavior t b)
-> Behavior t a
-> Behavior t b
forall a b. (a -> b) -> a -> b
$ Coercion a b -> Coercion (Behavior t a) (Behavior t b)
forall {k} (t :: k) a b.
Reflex t =>
Coercion a b -> Coercion (Behavior t a) (Behavior t b)
forall a b. Coercion a b -> Coercion (Behavior t a) (Behavior t b)
behaviorCoercion Coercion a b
forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion
coerceEvent :: (Reflex t, Coercible a b) => Event t a -> Event t b
coerceEvent :: forall {k} (t :: k) a b.
(Reflex t, Coercible a b) =>
Event t a -> Event t b
coerceEvent = Coercion (Event t a) (Event t b) -> Event t a -> Event t b
forall a b. Coercion a b -> a -> b
coerceWith (Coercion (Event t a) (Event t b) -> Event t a -> Event t b)
-> Coercion (Event t a) (Event t b) -> Event t a -> Event t b
forall a b. (a -> b) -> a -> b
$ Coercion a b -> Coercion (Event t a) (Event t b)
forall {k} (t :: k) a b.
Reflex t =>
Coercion a b -> Coercion (Event t a) (Event t b)
forall a b. Coercion a b -> Coercion (Event t a) (Event t b)
eventCoercion Coercion a b
forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion
coerceDynamic :: (Reflex t, Coercible a b) => Dynamic t a -> Dynamic t b
coerceDynamic :: forall {k} (t :: k) a b.
(Reflex t, Coercible a b) =>
Dynamic t a -> Dynamic t b
coerceDynamic = Coercion (Dynamic t a) (Dynamic t b) -> Dynamic t a -> Dynamic t b
forall a b. Coercion a b -> a -> b
coerceWith (Coercion (Dynamic t a) (Dynamic t b)
-> Dynamic t a -> Dynamic t b)
-> Coercion (Dynamic t a) (Dynamic t b)
-> Dynamic t a
-> Dynamic t b
forall a b. (a -> b) -> a -> b
$ Coercion a b -> Coercion (Dynamic t a) (Dynamic t b)
forall {k} (t :: k) a b.
Reflex t =>
Coercion a b -> Coercion (Dynamic t a) (Dynamic t b)
forall a b. Coercion a b -> Coercion (Dynamic t a) (Dynamic t b)
dynamicCoercion Coercion a b
forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion
coerceIncremental
:: (Reflex t, Coercible a b, Coercible (PatchTarget a) (PatchTarget b))
=> Incremental t a -> Incremental t b
coerceIncremental :: forall {k} (t :: k) a b.
(Reflex t, Coercible a b,
Coercible (PatchTarget a) (PatchTarget b)) =>
Incremental t a -> Incremental t b
coerceIncremental = Coercion (Incremental t a) (Incremental t b)
-> Incremental t a -> Incremental t b
forall a b. Coercion a b -> a -> b
coerceWith (Coercion (Incremental t a) (Incremental t b)
-> Incremental t a -> Incremental t b)
-> Coercion (Incremental t a) (Incremental t b)
-> Incremental t a
-> Incremental t b
forall a b. (a -> b) -> a -> b
$ Coercion (PatchTarget a) (PatchTarget b)
-> Coercion a b -> Coercion (Incremental t a) (Incremental t b)
forall {k} (t :: k) a b.
Reflex t =>
Coercion (PatchTarget a) (PatchTarget b)
-> Coercion a b -> Coercion (Incremental t a) (Incremental t b)
forall a b.
Coercion (PatchTarget a) (PatchTarget b)
-> Coercion a b -> Coercion (Incremental t a) (Incremental t b)
incrementalCoercion Coercion (PatchTarget a) (PatchTarget b)
forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion Coercion a b
forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion
unsafeDynamic :: Reflex t => Behavior t a -> Event t a -> Dynamic t a
unsafeDynamic :: forall {k} (t :: k) a.
Reflex t =>
Behavior t a -> Event t a -> Dynamic t a
unsafeDynamic = PullM t a -> Event t a -> Dynamic t a
forall a. PullM t a -> Event t a -> Dynamic t a
forall {k} (t :: k) a.
Reflex t =>
PullM t a -> Event t a -> Dynamic t a
unsafeBuildDynamic (PullM t a -> Event t a -> Dynamic t a)
-> (Behavior t a -> PullM t a)
-> Behavior t a
-> Event t a
-> Dynamic t a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Behavior t a -> PullM t a
forall a. Behavior t a -> PullM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample
constDyn :: Reflex t => a -> Dynamic t a
constDyn :: forall {k} (t :: k) a. Reflex t => a -> Dynamic t a
constDyn = a -> Dynamic t a
forall a. a -> Dynamic t a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
instance (Reflex t, Default a) => Default (Dynamic t a) where
def :: Dynamic t a
def = a -> Dynamic t a
forall a. a -> Dynamic t a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
forall a. Default a => a
def
class (Applicative m, Monad m) => MonadSample t m | m -> t where
sample :: Behavior t a -> m a
class MonadSample t m => MonadHold t m where
hold :: a -> Event t a -> m (Behavior t a)
default hold :: (m ~ f m', MonadTrans f, MonadHold t m') => a -> Event t a -> m (Behavior t a)
hold a
v0 = m' (Behavior t a) -> m (Behavior t a)
m' (Behavior t a) -> f m' (Behavior t a)
forall (m :: * -> *) a. Monad m => m a -> f m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m' (Behavior t a) -> m (Behavior t a))
-> (Event t a -> m' (Behavior t a))
-> Event t a
-> m (Behavior t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Event t a -> m' (Behavior t a)
forall a. a -> Event t a -> m' (Behavior t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Behavior t a)
hold a
v0
holdDyn :: a -> Event t a -> m (Dynamic t a)
default holdDyn :: (m ~ f m', MonadTrans f, MonadHold t m') => a -> Event t a -> m (Dynamic t a)
holdDyn a
v0 = m' (Dynamic t a) -> m (Dynamic t a)
m' (Dynamic t a) -> f m' (Dynamic t a)
forall (m :: * -> *) a. Monad m => m a -> f m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m' (Dynamic t a) -> m (Dynamic t a))
-> (Event t a -> m' (Dynamic t a)) -> Event t a -> m (Dynamic t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Event t a -> m' (Dynamic t a)
forall a. a -> Event t a -> m' (Dynamic t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Dynamic t a)
holdDyn a
v0
holdIncremental :: Patch p => PatchTarget p -> Event t p -> m (Incremental t p)
default holdIncremental :: (Patch p, m ~ f m', MonadTrans f, MonadHold t m') => PatchTarget p -> Event t p -> m (Incremental t p)
holdIncremental PatchTarget p
v0 = m' (Incremental t p) -> m (Incremental t p)
m' (Incremental t p) -> f m' (Incremental t p)
forall (m :: * -> *) a. Monad m => m a -> f m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m' (Incremental t p) -> m (Incremental t p))
-> (Event t p -> m' (Incremental t p))
-> Event t p
-> m (Incremental t p)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchTarget p -> Event t p -> m' (Incremental t p)
forall p.
Patch p =>
PatchTarget p -> Event t p -> m' (Incremental t p)
forall {k} (t :: k) (m :: * -> *) p.
(MonadHold t m, Patch p) =>
PatchTarget p -> Event t p -> m (Incremental t p)
holdIncremental PatchTarget p
v0
buildDynamic :: PushM t a -> Event t a -> m (Dynamic t a)
headE :: Event t a -> m (Event t a)
now :: m (Event t ())
default now :: (m ~ f m', MonadTrans f, MonadHold t m') => m (Event t ())
now = m' (Event t ()) -> f m' (Event t ())
forall (m :: * -> *) a. Monad m => m a -> f m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m' (Event t ())
forall {k} (t :: k) (m :: * -> *). MonadHold t m => m (Event t ())
now
accumIncremental
:: (Reflex t, Patch p, MonadHold t m, MonadFix m)
=> (PatchTarget p -> b -> p)
-> PatchTarget p
-> Event t b
-> m (Incremental t p)
accumIncremental :: forall {k} (t :: k) p (m :: * -> *) b.
(Reflex t, Patch p, MonadHold t m, MonadFix m) =>
(PatchTarget p -> b -> p)
-> PatchTarget p -> Event t b -> m (Incremental t p)
accumIncremental PatchTarget p -> b -> p
f = (PatchTarget p -> b -> Maybe p)
-> PatchTarget p -> Event t b -> m (Incremental t p)
forall {k} (t :: k) p (m :: * -> *) b.
(Reflex t, Patch p, MonadHold t m, MonadFix m) =>
(PatchTarget p -> b -> Maybe p)
-> PatchTarget p -> Event t b -> m (Incremental t p)
accumMaybeIncremental ((PatchTarget p -> b -> Maybe p)
-> PatchTarget p -> Event t b -> m (Incremental t p))
-> (PatchTarget p -> b -> Maybe p)
-> PatchTarget p
-> Event t b
-> m (Incremental t p)
forall a b. (a -> b) -> a -> b
$ \PatchTarget p
v b
o -> p -> Maybe p
forall a. a -> Maybe a
Just (p -> Maybe p) -> p -> Maybe p
forall a b. (a -> b) -> a -> b
$ PatchTarget p -> b -> p
f PatchTarget p
v b
o
accumMIncremental
:: (Reflex t, Patch p, MonadHold t m, MonadFix m)
=> (PatchTarget p -> b -> PushM t p)
-> PatchTarget p
-> Event t b
-> m (Incremental t p)
accumMIncremental :: forall {k} (t :: k) p (m :: * -> *) b.
(Reflex t, Patch p, MonadHold t m, MonadFix m) =>
(PatchTarget p -> b -> PushM t p)
-> PatchTarget p -> Event t b -> m (Incremental t p)
accumMIncremental PatchTarget p -> b -> PushM t p
f = (PatchTarget p -> b -> PushM t (Maybe p))
-> PatchTarget p -> Event t b -> m (Incremental t p)
forall {k} (t :: k) p (m :: * -> *) b.
(Reflex t, Patch p, MonadHold t m, MonadFix m) =>
(PatchTarget p -> b -> PushM t (Maybe p))
-> PatchTarget p -> Event t b -> m (Incremental t p)
accumMaybeMIncremental ((PatchTarget p -> b -> PushM t (Maybe p))
-> PatchTarget p -> Event t b -> m (Incremental t p))
-> (PatchTarget p -> b -> PushM t (Maybe p))
-> PatchTarget p
-> Event t b
-> m (Incremental t p)
forall a b. (a -> b) -> a -> b
$ \PatchTarget p
v b
o -> p -> Maybe p
forall a. a -> Maybe a
Just (p -> Maybe p) -> PushM t p -> PushM t (Maybe p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PatchTarget p -> b -> PushM t p
f PatchTarget p
v b
o
accumMaybeIncremental
:: (Reflex t, Patch p, MonadHold t m, MonadFix m)
=> (PatchTarget p -> b -> Maybe p)
-> PatchTarget p
-> Event t b
-> m (Incremental t p)
accumMaybeIncremental :: forall {k} (t :: k) p (m :: * -> *) b.
(Reflex t, Patch p, MonadHold t m, MonadFix m) =>
(PatchTarget p -> b -> Maybe p)
-> PatchTarget p -> Event t b -> m (Incremental t p)
accumMaybeIncremental PatchTarget p -> b -> Maybe p
f = (PatchTarget p -> b -> PushM t (Maybe p))
-> PatchTarget p -> Event t b -> m (Incremental t p)
forall {k} (t :: k) p (m :: * -> *) b.
(Reflex t, Patch p, MonadHold t m, MonadFix m) =>
(PatchTarget p -> b -> PushM t (Maybe p))
-> PatchTarget p -> Event t b -> m (Incremental t p)
accumMaybeMIncremental ((PatchTarget p -> b -> PushM t (Maybe p))
-> PatchTarget p -> Event t b -> m (Incremental t p))
-> (PatchTarget p -> b -> PushM t (Maybe p))
-> PatchTarget p
-> Event t b
-> m (Incremental t p)
forall a b. (a -> b) -> a -> b
$ \PatchTarget p
v b
o -> Maybe p -> PushM t (Maybe p)
forall a. a -> PushM t a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe p -> PushM t (Maybe p)) -> Maybe p -> PushM t (Maybe p)
forall a b. (a -> b) -> a -> b
$ PatchTarget p -> b -> Maybe p
f PatchTarget p
v b
o
accumMaybeMIncremental
:: (Reflex t, Patch p, MonadHold t m, MonadFix m)
=> (PatchTarget p -> b -> PushM t (Maybe p))
-> PatchTarget p
-> Event t b
-> m (Incremental t p)
accumMaybeMIncremental :: forall {k} (t :: k) p (m :: * -> *) b.
(Reflex t, Patch p, MonadHold t m, MonadFix m) =>
(PatchTarget p -> b -> PushM t (Maybe p))
-> PatchTarget p -> Event t b -> m (Incremental t p)
accumMaybeMIncremental PatchTarget p -> b -> PushM t (Maybe p)
f PatchTarget p
z Event t b
e = do
rec let e' :: Event t p
e' = ((b -> PushM t (Maybe p)) -> Event t b -> Event t p)
-> Event t b -> (b -> PushM t (Maybe p)) -> Event t p
forall a b c. (a -> b -> c) -> b -> a -> c
flip (b -> PushM t (Maybe p)) -> Event t b -> Event t p
forall {k} (t :: k) a b.
Reflex t =>
(a -> PushM t (Maybe b)) -> Event t a -> Event t b
forall a b. (a -> PushM t (Maybe b)) -> Event t a -> Event t b
push Event t b
e ((b -> PushM t (Maybe p)) -> Event t p)
-> (b -> PushM t (Maybe p)) -> Event t p
forall a b. (a -> b) -> a -> b
$ \b
o -> do
PatchTarget p
v <- Behavior t (PatchTarget p) -> PushM t (PatchTarget p)
forall a. Behavior t a -> PushM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample (Behavior t (PatchTarget p) -> PushM t (PatchTarget p))
-> Behavior t (PatchTarget p) -> PushM t (PatchTarget p)
forall a b. (a -> b) -> a -> b
$ Incremental t p -> Behavior t (PatchTarget p)
forall p. Patch p => Incremental t p -> Behavior t (PatchTarget p)
forall {k} (t :: k) p.
(Reflex t, Patch p) =>
Incremental t p -> Behavior t (PatchTarget p)
currentIncremental Incremental t p
d'
PatchTarget p -> b -> PushM t (Maybe p)
f PatchTarget p
v b
o
Incremental t p
d' <- PatchTarget p -> Event t p -> m (Incremental t p)
forall p.
Patch p =>
PatchTarget p -> Event t p -> m (Incremental t p)
forall {k} (t :: k) (m :: * -> *) p.
(MonadHold t m, Patch p) =>
PatchTarget p -> Event t p -> m (Incremental t p)
holdIncremental PatchTarget p
z Event t p
e'
Incremental t p -> m (Incremental t p)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Incremental t p
d'
mapAccumIncremental
:: (Reflex t, Patch p, MonadHold t m, MonadFix m)
=> (PatchTarget p -> b -> (p, c))
-> PatchTarget p
-> Event t b
-> m (Incremental t p, Event t c)
mapAccumIncremental :: forall {k} (t :: k) p (m :: * -> *) b c.
(Reflex t, Patch p, MonadHold t m, MonadFix m) =>
(PatchTarget p -> b -> (p, c))
-> PatchTarget p -> Event t b -> m (Incremental t p, Event t c)
mapAccumIncremental PatchTarget p -> b -> (p, c)
f = (PatchTarget p -> b -> (Maybe p, Maybe c))
-> PatchTarget p -> Event t b -> m (Incremental t p, Event t c)
forall {k} (t :: k) p (m :: * -> *) b c.
(Reflex t, Patch p, MonadHold t m, MonadFix m) =>
(PatchTarget p -> b -> (Maybe p, Maybe c))
-> PatchTarget p -> Event t b -> m (Incremental t p, Event t c)
mapAccumMaybeIncremental ((PatchTarget p -> b -> (Maybe p, Maybe c))
-> PatchTarget p -> Event t b -> m (Incremental t p, Event t c))
-> (PatchTarget p -> b -> (Maybe p, Maybe c))
-> PatchTarget p
-> Event t b
-> m (Incremental t p, Event t c)
forall a b. (a -> b) -> a -> b
$ \PatchTarget p
v b
o -> (p -> Maybe p) -> (c -> Maybe c) -> (p, c) -> (Maybe p, Maybe c)
forall a b c d. (a -> b) -> (c -> d) -> (a, c) -> (b, d)
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap p -> Maybe p
forall a. a -> Maybe a
Just c -> Maybe c
forall a. a -> Maybe a
Just ((p, c) -> (Maybe p, Maybe c)) -> (p, c) -> (Maybe p, Maybe c)
forall a b. (a -> b) -> a -> b
$ PatchTarget p -> b -> (p, c)
f PatchTarget p
v b
o
mapAccumMIncremental
:: (Reflex t, Patch p, MonadHold t m, MonadFix m)
=> (PatchTarget p -> b -> PushM t (p, c))
-> PatchTarget p
-> Event t b
-> m (Incremental t p, Event t c)
mapAccumMIncremental :: forall {k} (t :: k) p (m :: * -> *) b c.
(Reflex t, Patch p, MonadHold t m, MonadFix m) =>
(PatchTarget p -> b -> PushM t (p, c))
-> PatchTarget p -> Event t b -> m (Incremental t p, Event t c)
mapAccumMIncremental PatchTarget p -> b -> PushM t (p, c)
f = (PatchTarget p -> b -> PushM t (Maybe p, Maybe c))
-> PatchTarget p -> Event t b -> m (Incremental t p, Event t c)
forall {k} (t :: k) p (m :: * -> *) b c.
(Reflex t, Patch p, MonadHold t m, MonadFix m) =>
(PatchTarget p -> b -> PushM t (Maybe p, Maybe c))
-> PatchTarget p -> Event t b -> m (Incremental t p, Event t c)
mapAccumMaybeMIncremental ((PatchTarget p -> b -> PushM t (Maybe p, Maybe c))
-> PatchTarget p -> Event t b -> m (Incremental t p, Event t c))
-> (PatchTarget p -> b -> PushM t (Maybe p, Maybe c))
-> PatchTarget p
-> Event t b
-> m (Incremental t p, Event t c)
forall a b. (a -> b) -> a -> b
$ \PatchTarget p
v b
o -> (p -> Maybe p) -> (c -> Maybe c) -> (p, c) -> (Maybe p, Maybe c)
forall a b c d. (a -> b) -> (c -> d) -> (a, c) -> (b, d)
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap p -> Maybe p
forall a. a -> Maybe a
Just c -> Maybe c
forall a. a -> Maybe a
Just ((p, c) -> (Maybe p, Maybe c))
-> PushM t (p, c) -> PushM t (Maybe p, Maybe c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PatchTarget p -> b -> PushM t (p, c)
f PatchTarget p
v b
o
mapAccumMaybeIncremental
:: (Reflex t, Patch p, MonadHold t m, MonadFix m)
=> (PatchTarget p -> b -> (Maybe p, Maybe c))
-> PatchTarget p
-> Event t b
-> m (Incremental t p, Event t c)
mapAccumMaybeIncremental :: forall {k} (t :: k) p (m :: * -> *) b c.
(Reflex t, Patch p, MonadHold t m, MonadFix m) =>
(PatchTarget p -> b -> (Maybe p, Maybe c))
-> PatchTarget p -> Event t b -> m (Incremental t p, Event t c)
mapAccumMaybeIncremental PatchTarget p -> b -> (Maybe p, Maybe c)
f = (PatchTarget p -> b -> PushM t (Maybe p, Maybe c))
-> PatchTarget p -> Event t b -> m (Incremental t p, Event t c)
forall {k} (t :: k) p (m :: * -> *) b c.
(Reflex t, Patch p, MonadHold t m, MonadFix m) =>
(PatchTarget p -> b -> PushM t (Maybe p, Maybe c))
-> PatchTarget p -> Event t b -> m (Incremental t p, Event t c)
mapAccumMaybeMIncremental ((PatchTarget p -> b -> PushM t (Maybe p, Maybe c))
-> PatchTarget p -> Event t b -> m (Incremental t p, Event t c))
-> (PatchTarget p -> b -> PushM t (Maybe p, Maybe c))
-> PatchTarget p
-> Event t b
-> m (Incremental t p, Event t c)
forall a b. (a -> b) -> a -> b
$ \PatchTarget p
v b
o -> (Maybe p, Maybe c) -> PushM t (Maybe p, Maybe c)
forall a. a -> PushM t a
forall (m :: * -> *) a. Monad m => a -> m a
return ((Maybe p, Maybe c) -> PushM t (Maybe p, Maybe c))
-> (Maybe p, Maybe c) -> PushM t (Maybe p, Maybe c)
forall a b. (a -> b) -> a -> b
$ PatchTarget p -> b -> (Maybe p, Maybe c)
f PatchTarget p
v b
o
mapAccumMaybeMIncremental
:: (Reflex t, Patch p, MonadHold t m, MonadFix m)
=> (PatchTarget p -> b -> PushM t (Maybe p, Maybe c))
-> PatchTarget p
-> Event t b
-> m (Incremental t p, Event t c)
mapAccumMaybeMIncremental :: forall {k} (t :: k) p (m :: * -> *) b c.
(Reflex t, Patch p, MonadHold t m, MonadFix m) =>
(PatchTarget p -> b -> PushM t (Maybe p, Maybe c))
-> PatchTarget p -> Event t b -> m (Incremental t p, Event t c)
mapAccumMaybeMIncremental PatchTarget p -> b -> PushM t (Maybe p, Maybe c)
f PatchTarget p
z Event t b
e = do
rec let e' :: Event t (Maybe p, Maybe c)
e' = ((b -> PushM t (Maybe (Maybe p, Maybe c)))
-> Event t b -> Event t (Maybe p, Maybe c))
-> Event t b
-> (b -> PushM t (Maybe (Maybe p, Maybe c)))
-> Event t (Maybe p, Maybe c)
forall a b c. (a -> b -> c) -> b -> a -> c
flip (b -> PushM t (Maybe (Maybe p, Maybe c)))
-> Event t b -> Event t (Maybe p, Maybe c)
forall {k} (t :: k) a b.
Reflex t =>
(a -> PushM t (Maybe b)) -> Event t a -> Event t b
forall a b. (a -> PushM t (Maybe b)) -> Event t a -> Event t b
push Event t b
e ((b -> PushM t (Maybe (Maybe p, Maybe c)))
-> Event t (Maybe p, Maybe c))
-> (b -> PushM t (Maybe (Maybe p, Maybe c)))
-> Event t (Maybe p, Maybe c)
forall a b. (a -> b) -> a -> b
$ \b
o -> do
PatchTarget p
v <- Behavior t (PatchTarget p) -> PushM t (PatchTarget p)
forall a. Behavior t a -> PushM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample (Behavior t (PatchTarget p) -> PushM t (PatchTarget p))
-> Behavior t (PatchTarget p) -> PushM t (PatchTarget p)
forall a b. (a -> b) -> a -> b
$ Incremental t p -> Behavior t (PatchTarget p)
forall p. Patch p => Incremental t p -> Behavior t (PatchTarget p)
forall {k} (t :: k) p.
(Reflex t, Patch p) =>
Incremental t p -> Behavior t (PatchTarget p)
currentIncremental Incremental t p
d'
(Maybe p, Maybe c)
result <- PatchTarget p -> b -> PushM t (Maybe p, Maybe c)
f PatchTarget p
v b
o
Maybe (Maybe p, Maybe c) -> PushM t (Maybe (Maybe p, Maybe c))
forall a. a -> PushM t a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (Maybe p, Maybe c) -> PushM t (Maybe (Maybe p, Maybe c)))
-> Maybe (Maybe p, Maybe c) -> PushM t (Maybe (Maybe p, Maybe c))
forall a b. (a -> b) -> a -> b
$ case (Maybe p, Maybe c)
result of
(Maybe p
Nothing, Maybe c
Nothing) -> Maybe (Maybe p, Maybe c)
forall a. Maybe a
Nothing
(Maybe p, Maybe c)
_ -> (Maybe p, Maybe c) -> Maybe (Maybe p, Maybe c)
forall a. a -> Maybe a
Just (Maybe p, Maybe c)
result
Incremental t p
d' <- PatchTarget p -> Event t p -> m (Incremental t p)
forall p.
Patch p =>
PatchTarget p -> Event t p -> m (Incremental t p)
forall {k} (t :: k) (m :: * -> *) p.
(MonadHold t m, Patch p) =>
PatchTarget p -> Event t p -> m (Incremental t p)
holdIncremental PatchTarget p
z (Event t p -> m (Incremental t p))
-> Event t p -> m (Incremental t p)
forall a b. (a -> b) -> a -> b
$ ((Maybe p, Maybe c) -> Maybe p)
-> Event t (Maybe p, Maybe c) -> Event t p
forall a b. (a -> Maybe b) -> Event t a -> Event t b
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe (Maybe p, Maybe c) -> Maybe p
forall a b. (a, b) -> a
fst Event t (Maybe p, Maybe c)
e'
(Incremental t p, Event t c) -> m (Incremental t p, Event t c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Incremental t p
d', ((Maybe p, Maybe c) -> Maybe c)
-> Event t (Maybe p, Maybe c) -> Event t c
forall a b. (a -> Maybe b) -> Event t a -> Event t b
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe (Maybe p, Maybe c) -> Maybe c
forall a b. (a, b) -> b
snd Event t (Maybe p, Maybe c)
e')
slowHeadE :: (Reflex t, MonadHold t m, MonadFix m) => Event t a -> m (Event t a)
slowHeadE :: forall {k} (t :: k) (m :: * -> *) a.
(Reflex t, MonadHold t m, MonadFix m) =>
Event t a -> m (Event t a)
slowHeadE Event t a
e = do
rec Behavior t (Event t a)
be <- Event t a -> Event t (Event t a) -> m (Behavior t (Event t a))
forall a. a -> Event t a -> m (Behavior t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Behavior t a)
hold Event t a
e (Event t (Event t a) -> m (Behavior t (Event t a)))
-> Event t (Event t a) -> m (Behavior t (Event t a))
forall a b. (a -> b) -> a -> b
$ (a -> Event t a) -> Event t a -> Event t (Event t a)
forall {k} (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap (Event t a -> a -> Event t a
forall a b. a -> b -> a
const Event t a
forall a. Event t a
forall {k} (t :: k) a. Reflex t => Event t a
never) Event t a
e'
let e' :: Event t a
e' = Behavior t (Event t a) -> Event t a
forall a. Behavior t (Event t a) -> Event t a
forall {k} (t :: k) a.
Reflex t =>
Behavior t (Event t a) -> Event t a
switch Behavior t (Event t a)
be
Event t a -> m (Event t a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Event t a
e'
newtype EventSelector t k = EventSelector
{
forall {k} (t :: k) (k :: * -> *).
EventSelector t k -> forall a. k a -> Event t a
select :: forall a. k a -> Event t a
}
newtype EventSelectorG t k v = EventSelectorG
{
forall {k} {k} (t :: k) (k :: k -> *) (v :: k -> *).
EventSelectorG t k v -> forall (a :: k). k a -> Event t (v a)
selectG :: forall a. k a -> Event t (v a)
}
newtype EventSelectorInt t a = EventSelectorInt { forall {k} (t :: k) a. EventSelectorInt t a -> Int -> Event t a
selectInt :: Int -> Event t a }
instance MonadSample t m => MonadSample t (ReaderT r m) where
sample :: forall a. Behavior t a -> ReaderT r m a
sample = m a -> ReaderT r m a
forall (m :: * -> *) a. Monad m => m a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ReaderT r m a)
-> (Behavior t a -> m a) -> Behavior t a -> ReaderT r m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Behavior t a -> m a
forall a. Behavior t a -> m a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample
instance MonadHold t m => MonadHold t (ReaderT r m) where
hold :: forall a. a -> Event t a -> ReaderT r m (Behavior t a)
hold a
a0 = m (Behavior t a) -> ReaderT r m (Behavior t a)
forall (m :: * -> *) a. Monad m => m a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Behavior t a) -> ReaderT r m (Behavior t a))
-> (Event t a -> m (Behavior t a))
-> Event t a
-> ReaderT r m (Behavior t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Event t a -> m (Behavior t a)
forall a. a -> Event t a -> m (Behavior t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Behavior t a)
hold a
a0
holdDyn :: forall a. a -> Event t a -> ReaderT r m (Dynamic t a)
holdDyn a
a0 = m (Dynamic t a) -> ReaderT r m (Dynamic t a)
forall (m :: * -> *) a. Monad m => m a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Dynamic t a) -> ReaderT r m (Dynamic t a))
-> (Event t a -> m (Dynamic t a))
-> Event t a
-> ReaderT r m (Dynamic t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Event t a -> m (Dynamic t a)
forall a. a -> Event t a -> m (Dynamic t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Dynamic t a)
holdDyn a
a0
holdIncremental :: forall p.
Patch p =>
PatchTarget p -> Event t p -> ReaderT r m (Incremental t p)
holdIncremental PatchTarget p
a0 = m (Incremental t p) -> ReaderT r m (Incremental t p)
forall (m :: * -> *) a. Monad m => m a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Incremental t p) -> ReaderT r m (Incremental t p))
-> (Event t p -> m (Incremental t p))
-> Event t p
-> ReaderT r m (Incremental t p)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchTarget p -> Event t p -> m (Incremental t p)
forall p.
Patch p =>
PatchTarget p -> Event t p -> m (Incremental t p)
forall {k} (t :: k) (m :: * -> *) p.
(MonadHold t m, Patch p) =>
PatchTarget p -> Event t p -> m (Incremental t p)
holdIncremental PatchTarget p
a0
buildDynamic :: forall a. PushM t a -> Event t a -> ReaderT r m (Dynamic t a)
buildDynamic PushM t a
a0 = m (Dynamic t a) -> ReaderT r m (Dynamic t a)
forall (m :: * -> *) a. Monad m => m a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Dynamic t a) -> ReaderT r m (Dynamic t a))
-> (Event t a -> m (Dynamic t a))
-> Event t a
-> ReaderT r m (Dynamic t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PushM t a -> Event t a -> m (Dynamic t a)
forall a. PushM t a -> Event t a -> m (Dynamic t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
PushM t a -> Event t a -> m (Dynamic t a)
buildDynamic PushM t a
a0
headE :: forall a. Event t a -> ReaderT r m (Event t a)
headE = m (Event t a) -> ReaderT r m (Event t a)
forall (m :: * -> *) a. Monad m => m a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Event t a) -> ReaderT r m (Event t a))
-> (Event t a -> m (Event t a))
-> Event t a
-> ReaderT r m (Event t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Event t a -> m (Event t a)
forall a. Event t a -> m (Event t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
Event t a -> m (Event t a)
headE
now :: ReaderT r m (Event t ())
now = m (Event t ()) -> ReaderT r m (Event t ())
forall (m :: * -> *) a. Monad m => m a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m (Event t ())
forall {k} (t :: k) (m :: * -> *). MonadHold t m => m (Event t ())
now
instance (MonadSample t m, Monoid r) => MonadSample t (WriterT r m) where
sample :: forall a. Behavior t a -> WriterT r m a
sample = m a -> WriterT r m a
forall (m :: * -> *) a. Monad m => m a -> WriterT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> WriterT r m a)
-> (Behavior t a -> m a) -> Behavior t a -> WriterT r m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Behavior t a -> m a
forall a. Behavior t a -> m a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample
instance (MonadHold t m, Monoid r) => MonadHold t (WriterT r m) where
hold :: forall a. a -> Event t a -> WriterT r m (Behavior t a)
hold a
a0 = m (Behavior t a) -> WriterT r m (Behavior t a)
forall (m :: * -> *) a. Monad m => m a -> WriterT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Behavior t a) -> WriterT r m (Behavior t a))
-> (Event t a -> m (Behavior t a))
-> Event t a
-> WriterT r m (Behavior t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Event t a -> m (Behavior t a)
forall a. a -> Event t a -> m (Behavior t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Behavior t a)
hold a
a0
holdDyn :: forall a. a -> Event t a -> WriterT r m (Dynamic t a)
holdDyn a
a0 = m (Dynamic t a) -> WriterT r m (Dynamic t a)
forall (m :: * -> *) a. Monad m => m a -> WriterT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Dynamic t a) -> WriterT r m (Dynamic t a))
-> (Event t a -> m (Dynamic t a))
-> Event t a
-> WriterT r m (Dynamic t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Event t a -> m (Dynamic t a)
forall a. a -> Event t a -> m (Dynamic t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Dynamic t a)
holdDyn a
a0
holdIncremental :: forall p.
Patch p =>
PatchTarget p -> Event t p -> WriterT r m (Incremental t p)
holdIncremental PatchTarget p
a0 = m (Incremental t p) -> WriterT r m (Incremental t p)
forall (m :: * -> *) a. Monad m => m a -> WriterT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Incremental t p) -> WriterT r m (Incremental t p))
-> (Event t p -> m (Incremental t p))
-> Event t p
-> WriterT r m (Incremental t p)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchTarget p -> Event t p -> m (Incremental t p)
forall p.
Patch p =>
PatchTarget p -> Event t p -> m (Incremental t p)
forall {k} (t :: k) (m :: * -> *) p.
(MonadHold t m, Patch p) =>
PatchTarget p -> Event t p -> m (Incremental t p)
holdIncremental PatchTarget p
a0
buildDynamic :: forall a. PushM t a -> Event t a -> WriterT r m (Dynamic t a)
buildDynamic PushM t a
a0 = m (Dynamic t a) -> WriterT r m (Dynamic t a)
forall (m :: * -> *) a. Monad m => m a -> WriterT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Dynamic t a) -> WriterT r m (Dynamic t a))
-> (Event t a -> m (Dynamic t a))
-> Event t a
-> WriterT r m (Dynamic t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PushM t a -> Event t a -> m (Dynamic t a)
forall a. PushM t a -> Event t a -> m (Dynamic t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
PushM t a -> Event t a -> m (Dynamic t a)
buildDynamic PushM t a
a0
headE :: forall a. Event t a -> WriterT r m (Event t a)
headE = m (Event t a) -> WriterT r m (Event t a)
forall (m :: * -> *) a. Monad m => m a -> WriterT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Event t a) -> WriterT r m (Event t a))
-> (Event t a -> m (Event t a))
-> Event t a
-> WriterT r m (Event t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Event t a -> m (Event t a)
forall a. Event t a -> m (Event t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
Event t a -> m (Event t a)
headE
now :: WriterT r m (Event t ())
now = m (Event t ()) -> WriterT r m (Event t ())
forall (m :: * -> *) a. Monad m => m a -> WriterT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m (Event t ())
forall {k} (t :: k) (m :: * -> *). MonadHold t m => m (Event t ())
now
instance MonadSample t m => MonadSample t (StateT s m) where
sample :: forall a. Behavior t a -> StateT s m a
sample = m a -> StateT s m a
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> StateT s m a)
-> (Behavior t a -> m a) -> Behavior t a -> StateT s m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Behavior t a -> m a
forall a. Behavior t a -> m a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample
instance MonadHold t m => MonadHold t (StateT s m) where
hold :: forall a. a -> Event t a -> StateT s m (Behavior t a)
hold a
a0 = m (Behavior t a) -> StateT s m (Behavior t a)
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Behavior t a) -> StateT s m (Behavior t a))
-> (Event t a -> m (Behavior t a))
-> Event t a
-> StateT s m (Behavior t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Event t a -> m (Behavior t a)
forall a. a -> Event t a -> m (Behavior t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Behavior t a)
hold a
a0
holdDyn :: forall a. a -> Event t a -> StateT s m (Dynamic t a)
holdDyn a
a0 = m (Dynamic t a) -> StateT s m (Dynamic t a)
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Dynamic t a) -> StateT s m (Dynamic t a))
-> (Event t a -> m (Dynamic t a))
-> Event t a
-> StateT s m (Dynamic t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Event t a -> m (Dynamic t a)
forall a. a -> Event t a -> m (Dynamic t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Dynamic t a)
holdDyn a
a0
holdIncremental :: forall p.
Patch p =>
PatchTarget p -> Event t p -> StateT s m (Incremental t p)
holdIncremental PatchTarget p
a0 = m (Incremental t p) -> StateT s m (Incremental t p)
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Incremental t p) -> StateT s m (Incremental t p))
-> (Event t p -> m (Incremental t p))
-> Event t p
-> StateT s m (Incremental t p)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchTarget p -> Event t p -> m (Incremental t p)
forall p.
Patch p =>
PatchTarget p -> Event t p -> m (Incremental t p)
forall {k} (t :: k) (m :: * -> *) p.
(MonadHold t m, Patch p) =>
PatchTarget p -> Event t p -> m (Incremental t p)
holdIncremental PatchTarget p
a0
buildDynamic :: forall a. PushM t a -> Event t a -> StateT s m (Dynamic t a)
buildDynamic PushM t a
a0 = m (Dynamic t a) -> StateT s m (Dynamic t a)
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Dynamic t a) -> StateT s m (Dynamic t a))
-> (Event t a -> m (Dynamic t a))
-> Event t a
-> StateT s m (Dynamic t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PushM t a -> Event t a -> m (Dynamic t a)
forall a. PushM t a -> Event t a -> m (Dynamic t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
PushM t a -> Event t a -> m (Dynamic t a)
buildDynamic PushM t a
a0
headE :: forall a. Event t a -> StateT s m (Event t a)
headE = m (Event t a) -> StateT s m (Event t a)
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Event t a) -> StateT s m (Event t a))
-> (Event t a -> m (Event t a))
-> Event t a
-> StateT s m (Event t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Event t a -> m (Event t a)
forall a. Event t a -> m (Event t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
Event t a -> m (Event t a)
headE
now :: StateT s m (Event t ())
now = m (Event t ()) -> StateT s m (Event t ())
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m (Event t ())
forall {k} (t :: k) (m :: * -> *). MonadHold t m => m (Event t ())
now
instance MonadSample t m => MonadSample t (ExceptT e m) where
sample :: forall a. Behavior t a -> ExceptT e m a
sample = m a -> ExceptT e m a
forall (m :: * -> *) a. Monad m => m a -> ExceptT e m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ExceptT e m a)
-> (Behavior t a -> m a) -> Behavior t a -> ExceptT e m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Behavior t a -> m a
forall a. Behavior t a -> m a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample
instance MonadHold t m => MonadHold t (ExceptT e m) where
hold :: forall a. a -> Event t a -> ExceptT e m (Behavior t a)
hold a
a0 = m (Behavior t a) -> ExceptT e m (Behavior t a)
forall (m :: * -> *) a. Monad m => m a -> ExceptT e m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Behavior t a) -> ExceptT e m (Behavior t a))
-> (Event t a -> m (Behavior t a))
-> Event t a
-> ExceptT e m (Behavior t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Event t a -> m (Behavior t a)
forall a. a -> Event t a -> m (Behavior t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Behavior t a)
hold a
a0
holdDyn :: forall a. a -> Event t a -> ExceptT e m (Dynamic t a)
holdDyn a
a0 = m (Dynamic t a) -> ExceptT e m (Dynamic t a)
forall (m :: * -> *) a. Monad m => m a -> ExceptT e m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Dynamic t a) -> ExceptT e m (Dynamic t a))
-> (Event t a -> m (Dynamic t a))
-> Event t a
-> ExceptT e m (Dynamic t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Event t a -> m (Dynamic t a)
forall a. a -> Event t a -> m (Dynamic t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Dynamic t a)
holdDyn a
a0
holdIncremental :: forall p.
Patch p =>
PatchTarget p -> Event t p -> ExceptT e m (Incremental t p)
holdIncremental PatchTarget p
a0 = m (Incremental t p) -> ExceptT e m (Incremental t p)
forall (m :: * -> *) a. Monad m => m a -> ExceptT e m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Incremental t p) -> ExceptT e m (Incremental t p))
-> (Event t p -> m (Incremental t p))
-> Event t p
-> ExceptT e m (Incremental t p)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchTarget p -> Event t p -> m (Incremental t p)
forall p.
Patch p =>
PatchTarget p -> Event t p -> m (Incremental t p)
forall {k} (t :: k) (m :: * -> *) p.
(MonadHold t m, Patch p) =>
PatchTarget p -> Event t p -> m (Incremental t p)
holdIncremental PatchTarget p
a0
buildDynamic :: forall a. PushM t a -> Event t a -> ExceptT e m (Dynamic t a)
buildDynamic PushM t a
a0 = m (Dynamic t a) -> ExceptT e m (Dynamic t a)
forall (m :: * -> *) a. Monad m => m a -> ExceptT e m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Dynamic t a) -> ExceptT e m (Dynamic t a))
-> (Event t a -> m (Dynamic t a))
-> Event t a
-> ExceptT e m (Dynamic t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PushM t a -> Event t a -> m (Dynamic t a)
forall a. PushM t a -> Event t a -> m (Dynamic t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
PushM t a -> Event t a -> m (Dynamic t a)
buildDynamic PushM t a
a0
headE :: forall a. Event t a -> ExceptT e m (Event t a)
headE = m (Event t a) -> ExceptT e m (Event t a)
forall (m :: * -> *) a. Monad m => m a -> ExceptT e m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Event t a) -> ExceptT e m (Event t a))
-> (Event t a -> m (Event t a))
-> Event t a
-> ExceptT e m (Event t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Event t a -> m (Event t a)
forall a. Event t a -> m (Event t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
Event t a -> m (Event t a)
headE
now :: ExceptT e m (Event t ())
now = m (Event t ()) -> ExceptT e m (Event t ())
forall (m :: * -> *) a. Monad m => m a -> ExceptT e m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m (Event t ())
forall {k} (t :: k) (m :: * -> *). MonadHold t m => m (Event t ())
now
instance (MonadSample t m, Monoid w) => MonadSample t (RWST r w s m) where
sample :: forall a. Behavior t a -> RWST r w s m a
sample = m a -> RWST r w s m a
forall (m :: * -> *) a. Monad m => m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> RWST r w s m a)
-> (Behavior t a -> m a) -> Behavior t a -> RWST r w s m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Behavior t a -> m a
forall a. Behavior t a -> m a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample
instance (MonadHold t m, Monoid w) => MonadHold t (RWST r w s m) where
hold :: forall a. a -> Event t a -> RWST r w s m (Behavior t a)
hold a
a0 = m (Behavior t a) -> RWST r w s m (Behavior t a)
forall (m :: * -> *) a. Monad m => m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Behavior t a) -> RWST r w s m (Behavior t a))
-> (Event t a -> m (Behavior t a))
-> Event t a
-> RWST r w s m (Behavior t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Event t a -> m (Behavior t a)
forall a. a -> Event t a -> m (Behavior t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Behavior t a)
hold a
a0
holdDyn :: forall a. a -> Event t a -> RWST r w s m (Dynamic t a)
holdDyn a
a0 = m (Dynamic t a) -> RWST r w s m (Dynamic t a)
forall (m :: * -> *) a. Monad m => m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Dynamic t a) -> RWST r w s m (Dynamic t a))
-> (Event t a -> m (Dynamic t a))
-> Event t a
-> RWST r w s m (Dynamic t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Event t a -> m (Dynamic t a)
forall a. a -> Event t a -> m (Dynamic t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Dynamic t a)
holdDyn a
a0
holdIncremental :: forall p.
Patch p =>
PatchTarget p -> Event t p -> RWST r w s m (Incremental t p)
holdIncremental PatchTarget p
a0 = m (Incremental t p) -> RWST r w s m (Incremental t p)
forall (m :: * -> *) a. Monad m => m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Incremental t p) -> RWST r w s m (Incremental t p))
-> (Event t p -> m (Incremental t p))
-> Event t p
-> RWST r w s m (Incremental t p)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchTarget p -> Event t p -> m (Incremental t p)
forall p.
Patch p =>
PatchTarget p -> Event t p -> m (Incremental t p)
forall {k} (t :: k) (m :: * -> *) p.
(MonadHold t m, Patch p) =>
PatchTarget p -> Event t p -> m (Incremental t p)
holdIncremental PatchTarget p
a0
buildDynamic :: forall a. PushM t a -> Event t a -> RWST r w s m (Dynamic t a)
buildDynamic PushM t a
a0 = m (Dynamic t a) -> RWST r w s m (Dynamic t a)
forall (m :: * -> *) a. Monad m => m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Dynamic t a) -> RWST r w s m (Dynamic t a))
-> (Event t a -> m (Dynamic t a))
-> Event t a
-> RWST r w s m (Dynamic t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PushM t a -> Event t a -> m (Dynamic t a)
forall a. PushM t a -> Event t a -> m (Dynamic t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
PushM t a -> Event t a -> m (Dynamic t a)
buildDynamic PushM t a
a0
headE :: forall a. Event t a -> RWST r w s m (Event t a)
headE = m (Event t a) -> RWST r w s m (Event t a)
forall (m :: * -> *) a. Monad m => m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Event t a) -> RWST r w s m (Event t a))
-> (Event t a -> m (Event t a))
-> Event t a
-> RWST r w s m (Event t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Event t a -> m (Event t a)
forall a. Event t a -> m (Event t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
Event t a -> m (Event t a)
headE
now :: RWST r w s m (Event t ())
now = m (Event t ()) -> RWST r w s m (Event t ())
forall (m :: * -> *) a. Monad m => m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m (Event t ())
forall {k} (t :: k) (m :: * -> *). MonadHold t m => m (Event t ())
now
instance MonadSample t m => MonadSample t (ContT r m) where
sample :: forall a. Behavior t a -> ContT r m a
sample = m a -> ContT r m a
forall (m :: * -> *) a. Monad m => m a -> ContT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ContT r m a)
-> (Behavior t a -> m a) -> Behavior t a -> ContT r m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Behavior t a -> m a
forall a. Behavior t a -> m a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample
instance MonadHold t m => MonadHold t (ContT r m) where
hold :: forall a. a -> Event t a -> ContT r m (Behavior t a)
hold a
a0 = m (Behavior t a) -> ContT r m (Behavior t a)
forall (m :: * -> *) a. Monad m => m a -> ContT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Behavior t a) -> ContT r m (Behavior t a))
-> (Event t a -> m (Behavior t a))
-> Event t a
-> ContT r m (Behavior t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Event t a -> m (Behavior t a)
forall a. a -> Event t a -> m (Behavior t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Behavior t a)
hold a
a0
holdDyn :: forall a. a -> Event t a -> ContT r m (Dynamic t a)
holdDyn a
a0 = m (Dynamic t a) -> ContT r m (Dynamic t a)
forall (m :: * -> *) a. Monad m => m a -> ContT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Dynamic t a) -> ContT r m (Dynamic t a))
-> (Event t a -> m (Dynamic t a))
-> Event t a
-> ContT r m (Dynamic t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Event t a -> m (Dynamic t a)
forall a. a -> Event t a -> m (Dynamic t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Dynamic t a)
holdDyn a
a0
holdIncremental :: forall p.
Patch p =>
PatchTarget p -> Event t p -> ContT r m (Incremental t p)
holdIncremental PatchTarget p
a0 = m (Incremental t p) -> ContT r m (Incremental t p)
forall (m :: * -> *) a. Monad m => m a -> ContT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Incremental t p) -> ContT r m (Incremental t p))
-> (Event t p -> m (Incremental t p))
-> Event t p
-> ContT r m (Incremental t p)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchTarget p -> Event t p -> m (Incremental t p)
forall p.
Patch p =>
PatchTarget p -> Event t p -> m (Incremental t p)
forall {k} (t :: k) (m :: * -> *) p.
(MonadHold t m, Patch p) =>
PatchTarget p -> Event t p -> m (Incremental t p)
holdIncremental PatchTarget p
a0
buildDynamic :: forall a. PushM t a -> Event t a -> ContT r m (Dynamic t a)
buildDynamic PushM t a
a0 = m (Dynamic t a) -> ContT r m (Dynamic t a)
forall (m :: * -> *) a. Monad m => m a -> ContT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Dynamic t a) -> ContT r m (Dynamic t a))
-> (Event t a -> m (Dynamic t a))
-> Event t a
-> ContT r m (Dynamic t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PushM t a -> Event t a -> m (Dynamic t a)
forall a. PushM t a -> Event t a -> m (Dynamic t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
PushM t a -> Event t a -> m (Dynamic t a)
buildDynamic PushM t a
a0
headE :: forall a. Event t a -> ContT r m (Event t a)
headE = m (Event t a) -> ContT r m (Event t a)
forall (m :: * -> *) a. Monad m => m a -> ContT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Event t a) -> ContT r m (Event t a))
-> (Event t a -> m (Event t a))
-> Event t a
-> ContT r m (Event t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Event t a -> m (Event t a)
forall a. Event t a -> m (Event t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
Event t a -> m (Event t a)
headE
now :: ContT r m (Event t ())
now = m (Event t ()) -> ContT r m (Event t ())
forall (m :: * -> *) a. Monad m => m a -> ContT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m (Event t ())
forall {k} (t :: k) (m :: * -> *). MonadHold t m => m (Event t ())
now
pushAlways :: Reflex t => (a -> PushM t b) -> Event t a -> Event t b
pushAlways :: forall {k} (t :: k) a b.
Reflex t =>
(a -> PushM t b) -> Event t a -> Event t b
pushAlways a -> PushM t b
f = (a -> PushM t (Maybe b)) -> Event t a -> Event t b
forall {k} (t :: k) a b.
Reflex t =>
(a -> PushM t (Maybe b)) -> Event t a -> Event t b
forall a b. (a -> PushM t (Maybe b)) -> Event t a -> Event t b
push ((b -> Maybe b) -> PushM t b -> PushM t (Maybe b)
forall a b. (a -> b) -> PushM t a -> PushM t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> Maybe b
forall a. a -> Maybe a
Just (PushM t b -> PushM t (Maybe b))
-> (a -> PushM t b) -> a -> PushM t (Maybe b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> PushM t b
f)
ffor :: Functor f => f a -> (a -> b) -> f b
ffor :: forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
ffor = ((a -> b) -> f a -> f b) -> f a -> (a -> b) -> f b
forall a b c. (a -> b -> c) -> b -> a -> c
flip (a -> b) -> f a -> f b
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
ffor2 :: Applicative f => f a -> f b -> (a -> b -> c) -> f c
ffor2 :: forall (f :: * -> *) a b c.
Applicative f =>
f a -> f b -> (a -> b -> c) -> f c
ffor2 f a
a f b
b a -> b -> c
f = (a -> b -> c) -> f a -> f b -> f c
forall a b c. (a -> b -> c) -> f a -> f b -> f c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 a -> b -> c
f f a
a f b
b
ffor3 :: Applicative f => f a -> f b -> f c -> (a -> b -> c -> d) -> f d
ffor3 :: forall (f :: * -> *) a b c d.
Applicative f =>
f a -> f b -> f c -> (a -> b -> c -> d) -> f d
ffor3 f a
a f b
b f c
c a -> b -> c -> d
f = (a -> b -> c -> d) -> f a -> f b -> f c -> f d
forall (f :: * -> *) a b c d.
Applicative f =>
(a -> b -> c -> d) -> f a -> f b -> f c -> f d
liftA3 a -> b -> c -> d
f f a
a f b
b f c
c
instance Reflex t => Applicative (Behavior t) where
pure :: forall a. a -> Behavior t a
pure = a -> Behavior t a
forall a. a -> Behavior t a
forall k (t :: k) a. Reflex t => a -> Behavior t a
constant
Behavior t (a -> b)
f <*> :: forall a b. Behavior t (a -> b) -> Behavior t a -> Behavior t b
<*> Behavior t a
x = PullM t b -> Behavior t b
forall a. PullM t a -> Behavior t a
forall {k} (t :: k) a. Reflex t => PullM t a -> Behavior t a
pull (PullM t b -> Behavior t b) -> PullM t b -> Behavior t b
forall a b. (a -> b) -> a -> b
$ Behavior t (a -> b) -> PullM t (a -> b)
forall a. Behavior t a -> PullM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample Behavior t (a -> b)
f PullM t (a -> b) -> PullM t a -> PullM t b
forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` Behavior t a -> PullM t a
forall a. Behavior t a -> PullM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample Behavior t a
x
Behavior t a
_ *> :: forall a b. Behavior t a -> Behavior t b -> Behavior t b
*> Behavior t b
b = Behavior t b
b
Behavior t a
a <* :: forall a b. Behavior t a -> Behavior t b -> Behavior t a
<* Behavior t b
_ = Behavior t a
a
instance Reflex t => Apply (Behavior t) where
<.> :: forall a b. Behavior t (a -> b) -> Behavior t a -> Behavior t b
(<.>) = Behavior t (a -> b) -> Behavior t a -> Behavior t b
forall a b. Behavior t (a -> b) -> Behavior t a -> Behavior t b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
(<*>)
instance Reflex t => Bind (Behavior t) where
>>- :: forall a b. Behavior t a -> (a -> Behavior t b) -> Behavior t b
(>>-) = Behavior t a -> (a -> Behavior t b) -> Behavior t b
forall a b. Behavior t a -> (a -> Behavior t b) -> Behavior t b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
(>>=)
instance (Reflex t, Fractional a) => Fractional (Behavior t a) where
/ :: Behavior t a -> Behavior t a -> Behavior t a
(/) = (a -> a -> a) -> Behavior t a -> Behavior t a -> Behavior t a
forall a b c.
(a -> b -> c) -> Behavior t a -> Behavior t b -> Behavior t c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 a -> a -> a
forall a. Fractional a => a -> a -> a
(/)
fromRational :: Rational -> Behavior t a
fromRational = a -> Behavior t a
forall a. a -> Behavior t a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> Behavior t a) -> (Rational -> a) -> Rational -> Behavior t a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rational -> a
forall a. Fractional a => Rational -> a
fromRational
recip :: Behavior t a -> Behavior t a
recip = (a -> a) -> Behavior t a -> Behavior t a
forall a b. (a -> b) -> Behavior t a -> Behavior t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> a
forall a. Fractional a => a -> a
recip
instance Reflex t => Functor (Behavior t) where
fmap :: forall a b. (a -> b) -> Behavior t a -> Behavior t b
fmap a -> b
f = PullM t b -> Behavior t b
forall a. PullM t a -> Behavior t a
forall {k} (t :: k) a. Reflex t => PullM t a -> Behavior t a
pull (PullM t b -> Behavior t b)
-> (Behavior t a -> PullM t b) -> Behavior t a -> Behavior t b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> PullM t a -> PullM t b
forall a b. (a -> b) -> PullM t a -> PullM t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f (PullM t a -> PullM t b)
-> (Behavior t a -> PullM t a) -> Behavior t a -> PullM t b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Behavior t a -> PullM t a
forall a. Behavior t a -> PullM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample
instance (Reflex t, IsString a) => IsString (Behavior t a) where
fromString :: String -> Behavior t a
fromString = a -> Behavior t a
forall a. a -> Behavior t a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> Behavior t a) -> (String -> a) -> String -> Behavior t a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> a
forall a. IsString a => String -> a
fromString
instance Reflex t => Monad (Behavior t) where
Behavior t a
a >>= :: forall a b. Behavior t a -> (a -> Behavior t b) -> Behavior t b
>>= a -> Behavior t b
f = PullM t b -> Behavior t b
forall a. PullM t a -> Behavior t a
forall {k} (t :: k) a. Reflex t => PullM t a -> Behavior t a
pull (PullM t b -> Behavior t b) -> PullM t b -> Behavior t b
forall a b. (a -> b) -> a -> b
$ Behavior t a -> PullM t a
forall a. Behavior t a -> PullM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample Behavior t a
a PullM t a -> (a -> PullM t b) -> PullM t b
forall a b. PullM t a -> (a -> PullM t b) -> PullM t b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Behavior t b -> PullM t b
forall a. Behavior t a -> PullM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample (Behavior t b -> PullM t b)
-> (a -> Behavior t b) -> a -> PullM t b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Behavior t b
f
return :: forall a. a -> Behavior t a
return = a -> Behavior t a
forall a. a -> Behavior t a
forall k (t :: k) a. Reflex t => a -> Behavior t a
constant
#if !MIN_VERSION_base(4,13,0)
fail = error "Monad (Behavior t) does not support fail"
#endif
instance (Reflex t, Monoid a) => Monoid (Behavior t a) where
mempty :: Behavior t a
mempty = a -> Behavior t a
forall a. a -> Behavior t a
forall k (t :: k) a. Reflex t => a -> Behavior t a
constant a
forall a. Monoid a => a
mempty
mappend :: Behavior t a -> Behavior t a -> Behavior t a
mappend Behavior t a
a Behavior t a
b = PullM t a -> Behavior t a
forall a. PullM t a -> Behavior t a
forall {k} (t :: k) a. Reflex t => PullM t a -> Behavior t a
pull (PullM t a -> Behavior t a) -> PullM t a -> Behavior t a
forall a b. (a -> b) -> a -> b
$ (a -> a -> a) -> PullM t a -> PullM t a -> PullM t a
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 a -> a -> a
forall a. Monoid a => a -> a -> a
mappend (Behavior t a -> PullM t a
forall a. Behavior t a -> PullM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample Behavior t a
a) (Behavior t a -> PullM t a
forall a. Behavior t a -> PullM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample Behavior t a
b)
mconcat :: [Behavior t a] -> Behavior t a
mconcat = PullM t a -> Behavior t a
forall a. PullM t a -> Behavior t a
forall {k} (t :: k) a. Reflex t => PullM t a -> Behavior t a
pull (PullM t a -> Behavior t a)
-> ([Behavior t a] -> PullM t a) -> [Behavior t a] -> Behavior t a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([a] -> a) -> PullM t [a] -> PullM t a
forall a b. (a -> b) -> PullM t a -> PullM t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [a] -> a
forall a. Monoid a => [a] -> a
mconcat (PullM t [a] -> PullM t a)
-> ([Behavior t a] -> PullM t [a]) -> [Behavior t a] -> PullM t a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Behavior t a -> PullM t a) -> [Behavior t a] -> PullM t [a]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Behavior t a -> PullM t a
forall a. Behavior t a -> PullM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample
instance (Reflex t, Num a) => Num (Behavior t a) where
+ :: Behavior t a -> Behavior t a -> Behavior t a
(+) = (a -> a -> a) -> Behavior t a -> Behavior t a -> Behavior t a
forall a b c.
(a -> b -> c) -> Behavior t a -> Behavior t b -> Behavior t c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 a -> a -> a
forall a. Num a => a -> a -> a
(+)
(-) = (a -> a -> a) -> Behavior t a -> Behavior t a -> Behavior t a
forall a b c.
(a -> b -> c) -> Behavior t a -> Behavior t b -> Behavior t c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (-)
* :: Behavior t a -> Behavior t a -> Behavior t a
(*) = (a -> a -> a) -> Behavior t a -> Behavior t a -> Behavior t a
forall a b c.
(a -> b -> c) -> Behavior t a -> Behavior t b -> Behavior t c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 a -> a -> a
forall a. Num a => a -> a -> a
(*)
abs :: Behavior t a -> Behavior t a
abs = (a -> a) -> Behavior t a -> Behavior t a
forall a b. (a -> b) -> Behavior t a -> Behavior t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> a
forall a. Num a => a -> a
abs
fromInteger :: Integer -> Behavior t a
fromInteger = a -> Behavior t a
forall a. a -> Behavior t a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> Behavior t a) -> (Integer -> a) -> Integer -> Behavior t a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> a
forall a. Num a => Integer -> a
fromInteger
negate :: Behavior t a -> Behavior t a
negate = (a -> a) -> Behavior t a -> Behavior t a
forall a b. (a -> b) -> Behavior t a -> Behavior t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> a
forall a. Num a => a -> a
negate
signum :: Behavior t a -> Behavior t a
signum = (a -> a) -> Behavior t a -> Behavior t a
forall a b. (a -> b) -> Behavior t a -> Behavior t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> a
forall a. Num a => a -> a
signum
instance (Num a, Reflex t) => Num (Dynamic t a) where
+ :: Dynamic t a -> Dynamic t a -> Dynamic t a
(+) = (a -> a -> a) -> Dynamic t a -> Dynamic t a -> Dynamic t a
forall a b c.
(a -> b -> c) -> Dynamic t a -> Dynamic t b -> Dynamic t c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 a -> a -> a
forall a. Num a => a -> a -> a
(+)
* :: Dynamic t a -> Dynamic t a -> Dynamic t a
(*) = (a -> a -> a) -> Dynamic t a -> Dynamic t a -> Dynamic t a
forall a b c.
(a -> b -> c) -> Dynamic t a -> Dynamic t b -> Dynamic t c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 a -> a -> a
forall a. Num a => a -> a -> a
(*)
abs :: Dynamic t a -> Dynamic t a
abs = (a -> a) -> Dynamic t a -> Dynamic t a
forall a b. (a -> b) -> Dynamic t a -> Dynamic t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> a
forall a. Num a => a -> a
abs
signum :: Dynamic t a -> Dynamic t a
signum = (a -> a) -> Dynamic t a -> Dynamic t a
forall a b. (a -> b) -> Dynamic t a -> Dynamic t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> a
forall a. Num a => a -> a
signum
fromInteger :: Integer -> Dynamic t a
fromInteger = a -> Dynamic t a
forall a. a -> Dynamic t a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> Dynamic t a) -> (Integer -> a) -> Integer -> Dynamic t a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> a
forall a. Num a => Integer -> a
fromInteger
negate :: Dynamic t a -> Dynamic t a
negate = (a -> a) -> Dynamic t a -> Dynamic t a
forall a b. (a -> b) -> Dynamic t a -> Dynamic t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> a
forall a. Num a => a -> a
negate
(-) = (a -> a -> a) -> Dynamic t a -> Dynamic t a -> Dynamic t a
forall a b c.
(a -> b -> c) -> Dynamic t a -> Dynamic t b -> Dynamic t c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (-)
instance (Reflex t, Semigroup a) => Semigroup (Behavior t a) where
Behavior t a
a <> :: Behavior t a -> Behavior t a -> Behavior t a
<> Behavior t a
b = PullM t a -> Behavior t a
forall a. PullM t a -> Behavior t a
forall {k} (t :: k) a. Reflex t => PullM t a -> Behavior t a
pull (PullM t a -> Behavior t a) -> PullM t a -> Behavior t a
forall a b. (a -> b) -> a -> b
$ (a -> a -> a) -> PullM t a -> PullM t a -> PullM t a
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 a -> a -> a
forall a. Semigroup a => a -> a -> a
(<>) (Behavior t a -> PullM t a
forall a. Behavior t a -> PullM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample Behavior t a
a) (Behavior t a -> PullM t a
forall a. Behavior t a -> PullM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample Behavior t a
b)
sconcat :: NonEmpty (Behavior t a) -> Behavior t a
sconcat = PullM t a -> Behavior t a
forall a. PullM t a -> Behavior t a
forall {k} (t :: k) a. Reflex t => PullM t a -> Behavior t a
pull (PullM t a -> Behavior t a)
-> (NonEmpty (Behavior t a) -> PullM t a)
-> NonEmpty (Behavior t a)
-> Behavior t a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NonEmpty a -> a) -> PullM t (NonEmpty a) -> PullM t a
forall a b. (a -> b) -> PullM t a -> PullM t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap NonEmpty a -> a
forall a. Semigroup a => NonEmpty a -> a
sconcat (PullM t (NonEmpty a) -> PullM t a)
-> (NonEmpty (Behavior t a) -> PullM t (NonEmpty a))
-> NonEmpty (Behavior t a)
-> PullM t a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Behavior t a -> PullM t a)
-> NonEmpty (Behavior t a) -> PullM t (NonEmpty a)
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> NonEmpty a -> m (NonEmpty b)
mapM Behavior t a -> PullM t a
forall a. Behavior t a -> PullM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample
stimes :: forall b. Integral b => b -> Behavior t a -> Behavior t a
stimes b
n = (a -> a) -> Behavior t a -> Behavior t a
forall a b. (a -> b) -> Behavior t a -> Behavior t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((a -> a) -> Behavior t a -> Behavior t a)
-> (a -> a) -> Behavior t a -> Behavior t a
forall a b. (a -> b) -> a -> b
$ b -> a -> a
forall b. Integral b => b -> a -> a
forall a b. (Semigroup a, Integral b) => b -> a -> a
stimes b
n
fmapMaybe :: Filterable f => (a -> Maybe b) -> f a -> f b
fmapMaybe :: forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
fmapMaybe = (a -> Maybe b) -> f a -> f b
forall a b. (a -> Maybe b) -> f a -> f b
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe
fforMaybe :: Filterable f => f a -> (a -> Maybe b) -> f b
fforMaybe :: forall (f :: * -> *) a b.
Filterable f =>
f a -> (a -> Maybe b) -> f b
fforMaybe = ((a -> Maybe b) -> f a -> f b) -> f a -> (a -> Maybe b) -> f b
forall a b c. (a -> b -> c) -> b -> a -> c
flip (a -> Maybe b) -> f a -> f b
forall a b. (a -> Maybe b) -> f a -> f b
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe
ffilter :: Filterable f => (a -> Bool) -> f a -> f a
ffilter :: forall (f :: * -> *) a. Filterable f => (a -> Bool) -> f a -> f a
ffilter = (a -> Bool) -> f a -> f a
forall a. (a -> Bool) -> f a -> f a
forall (f :: * -> *) a. Filterable f => (a -> Bool) -> f a -> f a
W.filter
filterLeft :: Filterable f => f (Either a b) -> f a
filterLeft :: forall (f :: * -> *) a b. Filterable f => f (Either a b) -> f a
filterLeft = (Either a b -> Maybe a) -> f (Either a b) -> f a
forall a b. (a -> Maybe b) -> f a -> f b
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe ((a -> Maybe a) -> (b -> Maybe a) -> Either a b -> Maybe a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either a -> Maybe a
forall a. a -> Maybe a
Just (Maybe a -> b -> Maybe a
forall a b. a -> b -> a
const Maybe a
forall a. Maybe a
Nothing))
filterRight :: Filterable f => f (Either a b) -> f b
filterRight :: forall (f :: * -> *) a b. Filterable f => f (Either a b) -> f b
filterRight = (Either a b -> Maybe b) -> f (Either a b) -> f b
forall a b. (a -> Maybe b) -> f a -> f b
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe ((a -> Maybe b) -> (b -> Maybe b) -> Either a b -> Maybe b
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Maybe b -> a -> Maybe b
forall a b. a -> b -> a
const Maybe b
forall a. Maybe a
Nothing) b -> Maybe b
forall a. a -> Maybe a
Just)
instance Reflex t => Alt (Event t) where
Event t a
ev1 <!> :: forall a. Event t a -> Event t a -> Event t a
<!> Event t a
ev2 = [Event t a] -> Event t a
forall {k} (t :: k) a. Reflex t => [Event t a] -> Event t a
leftmost [Event t a
ev1, Event t a
ev2]
instance Reflex t => Apply (Event t) where
Event t (a -> b)
evf <.> :: forall a b. Event t (a -> b) -> Event t a -> Event t b
<.> Event t a
evx = (These (a -> b) a -> Maybe b)
-> Event t (These (a -> b) a) -> Event t b
forall a b. (a -> Maybe b) -> Event t a -> Event t b
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe These (a -> b) a -> Maybe b
forall {t} {a}. These (t -> a) t -> Maybe a
f (Event t (a -> b) -> Event t a -> Event t (These (a -> b) a)
forall a b. Event t a -> Event t b -> Event t (These a b)
forall (f :: * -> *) a b.
Semialign f =>
f a -> f b -> f (These a b)
align Event t (a -> b)
evf Event t a
evx) where
f :: These (t -> a) t -> Maybe a
f (These t -> a
g t
a) = a -> Maybe a
forall a. a -> Maybe a
Just (t -> a
g t
a)
f These (t -> a) t
_ = Maybe a
forall a. Maybe a
Nothing
instance Reflex t => Bind (Event t) where
Event t a
evx >>- :: forall a b. Event t a -> (a -> Event t b) -> Event t b
>>- a -> Event t b
f = Event t (Event t b) -> Event t b
forall a. Event t (Event t a) -> Event t a
forall k (t :: k) a. Reflex t => Event t (Event t a) -> Event t a
coincidence (a -> Event t b
f (a -> Event t b) -> Event t a -> Event t (Event t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Event t a
evx)
join :: forall a. Event t (Event t a) -> Event t a
join = Event t (Event t a) -> Event t a
forall a. Event t (Event t a) -> Event t a
forall k (t :: k) a. Reflex t => Event t (Event t a) -> Event t a
coincidence
instance Reflex t => Functor (Event t) where
{-# INLINE fmap #-}
fmap :: forall a b. (a -> b) -> Event t a -> Event t b
fmap a -> b
f = (a -> Maybe b) -> Event t a -> Event t b
forall a b. (a -> Maybe b) -> Event t a -> Event t b
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe ((a -> Maybe b) -> Event t a -> Event t b)
-> (a -> Maybe b) -> Event t a -> Event t b
forall a b. (a -> b) -> a -> b
$ b -> Maybe b
forall a. a -> Maybe a
Just (b -> Maybe b) -> (a -> b) -> a -> Maybe b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f
{-# INLINE (<$) #-}
a
x <$ :: forall a b. a -> Event t b -> Event t a
<$ Event t b
e = (b -> a) -> Event t b -> Event t a
forall {k} (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap (a -> b -> a
forall a b. a -> b -> a
const a
x) Event t b
e
instance Reflex t => FunctorMaybe (Event t) where
{-# INLINE fmapMaybe #-}
fmapMaybe :: forall a b. (a -> Maybe b) -> Event t a -> Event t b
fmapMaybe = (a -> Maybe b) -> Event t a -> Event t b
forall a b. (a -> Maybe b) -> Event t a -> Event t b
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe
instance Reflex t => Filterable (Event t) where
{-# INLINE mapMaybe #-}
mapMaybe :: forall a b. (a -> Maybe b) -> Event t a -> Event t b
mapMaybe a -> Maybe b
f = (a -> PushM t (Maybe b)) -> Event t a -> Event t b
forall {k} (t :: k) a b.
Reflex t =>
(a -> PushM t (Maybe b)) -> Event t a -> Event t b
forall a b. (a -> PushM t (Maybe b)) -> Event t a -> Event t b
push ((a -> PushM t (Maybe b)) -> Event t a -> Event t b)
-> (a -> PushM t (Maybe b)) -> Event t a -> Event t b
forall a b. (a -> b) -> a -> b
$ Maybe b -> PushM t (Maybe b)
forall a. a -> PushM t a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe b -> PushM t (Maybe b))
-> (a -> Maybe b) -> a -> PushM t (Maybe b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Maybe b
f
instance Reflex t => Plus (Event t) where
zero :: forall a. Event t a
zero = Event t a
forall a. Event t a
forall {k} (t :: k) a. Reflex t => Event t a
never
tag :: Reflex t => Behavior t b -> Event t a -> Event t b
tag :: forall {k} (t :: k) b a.
Reflex t =>
Behavior t b -> Event t a -> Event t b
tag Behavior t b
b = (a -> PushM t b) -> Event t a -> Event t b
forall {k} (t :: k) a b.
Reflex t =>
(a -> PushM t b) -> Event t a -> Event t b
pushAlways ((a -> PushM t b) -> Event t a -> Event t b)
-> (a -> PushM t b) -> Event t a -> Event t b
forall a b. (a -> b) -> a -> b
$ \a
_ -> Behavior t b -> PushM t b
forall a. Behavior t a -> PushM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample Behavior t b
b
tagMaybe :: Reflex t => Behavior t (Maybe b) -> Event t a -> Event t b
tagMaybe :: forall {k} (t :: k) b a.
Reflex t =>
Behavior t (Maybe b) -> Event t a -> Event t b
tagMaybe Behavior t (Maybe b)
b = (a -> PushM t (Maybe b)) -> Event t a -> Event t b
forall {k} (t :: k) a b.
Reflex t =>
(a -> PushM t (Maybe b)) -> Event t a -> Event t b
forall a b. (a -> PushM t (Maybe b)) -> Event t a -> Event t b
push ((a -> PushM t (Maybe b)) -> Event t a -> Event t b)
-> (a -> PushM t (Maybe b)) -> Event t a -> Event t b
forall a b. (a -> b) -> a -> b
$ \a
_ -> Behavior t (Maybe b) -> PushM t (Maybe b)
forall a. Behavior t a -> PushM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample Behavior t (Maybe b)
b
attach :: Reflex t => Behavior t a -> Event t b -> Event t (a, b)
attach :: forall {k} (t :: k) a b.
Reflex t =>
Behavior t a -> Event t b -> Event t (a, b)
attach = (a -> b -> (a, b)) -> Behavior t a -> Event t b -> Event t (a, b)
forall {k} (t :: k) a b c.
Reflex t =>
(a -> b -> c) -> Behavior t a -> Event t b -> Event t c
attachWith (,)
attachWith :: Reflex t => (a -> b -> c) -> Behavior t a -> Event t b -> Event t c
attachWith :: forall {k} (t :: k) a b c.
Reflex t =>
(a -> b -> c) -> Behavior t a -> Event t b -> Event t c
attachWith a -> b -> c
f = (a -> b -> Maybe c) -> Behavior t a -> Event t b -> Event t c
forall {k} (t :: k) a b c.
Reflex t =>
(a -> b -> Maybe c) -> Behavior t a -> Event t b -> Event t c
attachWithMaybe ((a -> b -> Maybe c) -> Behavior t a -> Event t b -> Event t c)
-> (a -> b -> Maybe c) -> Behavior t a -> Event t b -> Event t c
forall a b. (a -> b) -> a -> b
$ \a
a b
b -> c -> Maybe c
forall a. a -> Maybe a
Just (c -> Maybe c) -> c -> Maybe c
forall a b. (a -> b) -> a -> b
$ a -> b -> c
f a
a b
b
attachWithMaybe :: Reflex t => (a -> b -> Maybe c) -> Behavior t a -> Event t b -> Event t c
attachWithMaybe :: forall {k} (t :: k) a b c.
Reflex t =>
(a -> b -> Maybe c) -> Behavior t a -> Event t b -> Event t c
attachWithMaybe a -> b -> Maybe c
f Behavior t a
b Event t b
e = ((b -> PushM t (Maybe c)) -> Event t b -> Event t c)
-> Event t b -> (b -> PushM t (Maybe c)) -> Event t c
forall a b c. (a -> b -> c) -> b -> a -> c
flip (b -> PushM t (Maybe c)) -> Event t b -> Event t c
forall {k} (t :: k) a b.
Reflex t =>
(a -> PushM t (Maybe b)) -> Event t a -> Event t b
forall a b. (a -> PushM t (Maybe b)) -> Event t a -> Event t b
push Event t b
e ((b -> PushM t (Maybe c)) -> Event t c)
-> (b -> PushM t (Maybe c)) -> Event t c
forall a b. (a -> b) -> a -> b
$ \b
o -> (a -> b -> Maybe c
`f` b
o) (a -> Maybe c) -> PushM t a -> PushM t (Maybe c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Behavior t a -> PushM t a
forall a. Behavior t a -> PushM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample Behavior t a
b
tailE :: (Reflex t, MonadHold t m) => Event t a -> m (Event t a)
tailE :: forall {k} (t :: k) (m :: * -> *) a.
(Reflex t, MonadHold t m) =>
Event t a -> m (Event t a)
tailE Event t a
e = (Event t a, Event t a) -> Event t a
forall a b. (a, b) -> b
snd ((Event t a, Event t a) -> Event t a)
-> m (Event t a, Event t a) -> m (Event t a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Event t a -> m (Event t a, Event t a)
forall {k} (t :: k) (m :: * -> *) a.
(Reflex t, MonadHold t m) =>
Event t a -> m (Event t a, Event t a)
headTailE Event t a
e
headTailE :: (Reflex t, MonadHold t m) => Event t a -> m (Event t a, Event t a)
headTailE :: forall {k} (t :: k) (m :: * -> *) a.
(Reflex t, MonadHold t m) =>
Event t a -> m (Event t a, Event t a)
headTailE Event t a
e = do
Event t a
eHead <- Event t a -> m (Event t a)
forall a. Event t a -> m (Event t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
Event t a -> m (Event t a)
headE Event t a
e
Behavior t (Event t a)
be <- Event t a -> Event t (Event t a) -> m (Behavior t (Event t a))
forall a. a -> Event t a -> m (Behavior t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Behavior t a)
hold Event t a
forall a. Event t a
forall {k} (t :: k) a. Reflex t => Event t a
never (Event t (Event t a) -> m (Behavior t (Event t a)))
-> Event t (Event t a) -> m (Behavior t (Event t a))
forall a b. (a -> b) -> a -> b
$ (a -> Event t a) -> Event t a -> Event t (Event t a)
forall a b. (a -> b) -> Event t a -> Event t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Event t a -> a -> Event t a
forall a b. a -> b -> a
const Event t a
e) Event t a
eHead
(Event t a, Event t a) -> m (Event t a, Event t a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Event t a
eHead, Behavior t (Event t a) -> Event t a
forall a. Behavior t (Event t a) -> Event t a
forall {k} (t :: k) a.
Reflex t =>
Behavior t (Event t a) -> Event t a
switch Behavior t (Event t a)
be)
takeWhileE
:: forall t m a
. (Reflex t, MonadFix m, MonadHold t m)
=> (a -> Bool)
-> Event t a
-> m (Event t a)
takeWhileE :: forall {k} (t :: k) (m :: * -> *) a.
(Reflex t, MonadFix m, MonadHold t m) =>
(a -> Bool) -> Event t a -> m (Event t a)
takeWhileE a -> Bool
f = (a -> Maybe a) -> Event t a -> m (Event t a)
forall {k} (t :: k) (m :: * -> *) a b.
(Reflex t, MonadFix m, MonadHold t m) =>
(a -> Maybe b) -> Event t a -> m (Event t b)
takeWhileJustE ((a -> Maybe a) -> Event t a -> m (Event t a))
-> (a -> Maybe a) -> Event t a -> m (Event t a)
forall a b. (a -> b) -> a -> b
$ \a
v -> Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (a -> Bool
f a
v) Maybe () -> a -> Maybe a
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> a
v
takeWhileJustE
:: forall t m a b
. (Reflex t, MonadFix m, MonadHold t m)
=> (a -> Maybe b)
-> Event t a
-> m (Event t b)
takeWhileJustE :: forall {k} (t :: k) (m :: * -> *) a b.
(Reflex t, MonadFix m, MonadHold t m) =>
(a -> Maybe b) -> Event t a -> m (Event t b)
takeWhileJustE a -> Maybe b
f Event t a
e = do
rec let (Event t (Event t a)
eBad, Event t b
eTrue) = Event t (Either (Event t a) b) -> (Event t (Event t a), Event t b)
forall {k} (t :: k) a b.
Reflex t =>
Event t (Either a b) -> (Event t a, Event t b)
fanEither (Event t (Either (Event t a) b)
-> (Event t (Event t a), Event t b))
-> Event t (Either (Event t a) b)
-> (Event t (Event t a), Event t b)
forall a b. (a -> b) -> a -> b
$ Event t a
-> (a -> Either (Event t a) b) -> Event t (Either (Event t a) b)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
ffor Event t a
e' ((a -> Either (Event t a) b) -> Event t (Either (Event t a) b))
-> (a -> Either (Event t a) b) -> Event t (Either (Event t a) b)
forall a b. (a -> b) -> a -> b
$ \a
a -> case a -> Maybe b
f a
a of
Maybe b
Nothing -> Event t a -> Either (Event t a) b
forall a b. a -> Either a b
Left Event t a
forall a. Event t a
forall {k} (t :: k) a. Reflex t => Event t a
never
Just b
b -> b -> Either (Event t a) b
forall a b. b -> Either a b
Right b
b
Event t (Event t a)
eFirstBad <- Event t (Event t a) -> m (Event t (Event t a))
forall a. Event t a -> m (Event t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
Event t a -> m (Event t a)
headE Event t (Event t a)
eBad
Event t a
e' <- Event t a -> Event t (Event t a) -> m (Event t a)
forall {k} (t :: k) (m :: * -> *) a.
(Reflex t, MonadHold t m) =>
Event t a -> Event t (Event t a) -> m (Event t a)
switchHold Event t a
e Event t (Event t a)
eFirstBad
Event t b -> m (Event t b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Event t b
eTrue
dropWhileE
:: forall t m a
. (Reflex t, MonadFix m, MonadHold t m)
=> (a -> Bool)
-> Event t a
-> m (Event t a)
dropWhileE :: forall {k} (t :: k) (m :: * -> *) a.
(Reflex t, MonadFix m, MonadHold t m) =>
(a -> Bool) -> Event t a -> m (Event t a)
dropWhileE a -> Bool
f Event t a
e = (Event t a, Event t a) -> Event t a
forall a b. (a, b) -> b
snd ((Event t a, Event t a) -> Event t a)
-> m (Event t a, Event t a) -> m (Event t a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a -> Maybe a) -> Event t a -> m (Event t a, Event t a)
forall {k} (t :: k) (m :: * -> *) a b.
(Reflex t, MonadFix m, MonadHold t m) =>
(a -> Maybe b) -> Event t a -> m (Event t b, Event t a)
takeDropWhileJustE (\a
v -> Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (a -> Bool
f a
v) Maybe () -> a -> Maybe a
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> a
v) Event t a
e
takeDropWhileJustE
:: forall t m a b
. (Reflex t, MonadFix m, MonadHold t m)
=> (a -> Maybe b)
-> Event t a
-> m (Event t b, Event t a)
takeDropWhileJustE :: forall {k} (t :: k) (m :: * -> *) a b.
(Reflex t, MonadFix m, MonadHold t m) =>
(a -> Maybe b) -> Event t a -> m (Event t b, Event t a)
takeDropWhileJustE a -> Maybe b
f Event t a
e = do
rec let (Event t ()
eBad, Event t b
eGood) = Event t (Either () b) -> (Event t (), Event t b)
forall {k} (t :: k) a b.
Reflex t =>
Event t (Either a b) -> (Event t a, Event t b)
fanEither (Event t (Either () b) -> (Event t (), Event t b))
-> Event t (Either () b) -> (Event t (), Event t b)
forall a b. (a -> b) -> a -> b
$ Event t a -> (a -> Either () b) -> Event t (Either () b)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
ffor Event t a
e' ((a -> Either () b) -> Event t (Either () b))
-> (a -> Either () b) -> Event t (Either () b)
forall a b. (a -> b) -> a -> b
$ \a
a -> case a -> Maybe b
f a
a of
Maybe b
Nothing -> () -> Either () b
forall a b. a -> Either a b
Left ()
Just b
b -> b -> Either () b
forall a b. b -> Either a b
Right b
b
Event t ()
eFirstBad <- Event t () -> m (Event t ())
forall a. Event t a -> m (Event t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
Event t a -> m (Event t a)
headE Event t ()
eBad
Event t a
e' <- Event t a -> Event t (Event t a) -> m (Event t a)
forall {k} (t :: k) (m :: * -> *) a.
(Reflex t, MonadHold t m) =>
Event t a -> Event t (Event t a) -> m (Event t a)
switchHold Event t a
e (Event t a
forall a. Event t a
forall {k} (t :: k) a. Reflex t => Event t a
never Event t a -> Event t () -> Event t (Event t a)
forall a b. a -> Event t b -> Event t a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Event t ()
eFirstBad)
Event t a
eRest <- Event t a -> Event t (Event t a) -> m (Event t a)
forall {k} (t :: k) (m :: * -> *) a.
(Reflex t, MonadHold t m) =>
Event t a -> Event t (Event t a) -> m (Event t a)
switchHoldPromptOnly Event t a
forall a. Event t a
forall {k} (t :: k) a. Reflex t => Event t a
never (Event t a
e Event t a -> Event t () -> Event t (Event t a)
forall a b. a -> Event t b -> Event t a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Event t ()
eFirstBad)
(Event t b, Event t a) -> m (Event t b, Event t a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Event t b
eGood, Event t a
eRest)
splitE :: Reflex t => Event t (a, b) -> (Event t a, Event t b)
splitE :: forall {k} (t :: k) a b.
Reflex t =>
Event t (a, b) -> (Event t a, Event t b)
splitE Event t (a, b)
e = (((a, b) -> a) -> Event t (a, b) -> Event t a
forall a b. (a -> b) -> Event t a -> Event t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a, b) -> a
forall a b. (a, b) -> a
fst Event t (a, b)
e, ((a, b) -> b) -> Event t (a, b) -> Event t b
forall a b. (a -> b) -> Event t a -> Event t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a, b) -> b
forall a b. (a, b) -> b
snd Event t (a, b)
e)
traceEvent :: (Reflex t, Show a) => String -> Event t a -> Event t a
traceEvent :: forall {k} (t :: k) a.
(Reflex t, Show a) =>
String -> Event t a -> Event t a
traceEvent String
s = (a -> String) -> Event t a -> Event t a
forall {k} (t :: k) a.
Reflex t =>
(a -> String) -> Event t a -> Event t a
traceEventWith ((a -> String) -> Event t a -> Event t a)
-> (a -> String) -> Event t a -> Event t a
forall a b. (a -> b) -> a -> b
$ \a
x -> String
s String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
": " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> a -> String
forall a. Show a => a -> String
show a
x
traceEventWith :: Reflex t => (a -> String) -> Event t a -> Event t a
traceEventWith :: forall {k} (t :: k) a.
Reflex t =>
(a -> String) -> Event t a -> Event t a
traceEventWith a -> String
f = (a -> PushM t (Maybe a)) -> Event t a -> Event t a
forall {k} (t :: k) a b.
Reflex t =>
(a -> PushM t (Maybe b)) -> Event t a -> Event t b
forall a b. (a -> PushM t (Maybe b)) -> Event t a -> Event t b
push ((a -> PushM t (Maybe a)) -> Event t a -> Event t a)
-> (a -> PushM t (Maybe a)) -> Event t a -> Event t a
forall a b. (a -> b) -> a -> b
$ \a
x -> String -> PushM t (Maybe a) -> PushM t (Maybe a)
forall a. String -> a -> a
trace (a -> String
f a
x) (PushM t (Maybe a) -> PushM t (Maybe a))
-> PushM t (Maybe a) -> PushM t (Maybe a)
forall a b. (a -> b) -> a -> b
$ Maybe a -> PushM t (Maybe a)
forall a. a -> PushM t a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe a -> PushM t (Maybe a)) -> Maybe a -> PushM t (Maybe a)
forall a b. (a -> b) -> a -> b
$ a -> Maybe a
forall a. a -> Maybe a
Just a
x
instance (Semigroup a, Reflex t) => Semigroup (Event t a) where
<> :: Event t a -> Event t a -> Event t a
(<>) = (These a a -> a) -> Event t a -> Event t a -> Event t a
forall a b c.
(These a b -> c) -> Event t a -> Event t b -> Event t c
forall (f :: * -> *) a b c.
Semialign f =>
(These a b -> c) -> f a -> f b -> f c
alignWith ((a -> a -> a) -> These a a -> a
forall a. (a -> a -> a) -> These a a -> a
mergeThese a -> a -> a
forall a. Semigroup a => a -> a -> a
(<>))
sconcat :: NonEmpty (Event t a) -> Event t a
sconcat = (NonEmpty a -> a) -> Event t (NonEmpty a) -> Event t a
forall a b. (a -> b) -> Event t a -> Event t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap NonEmpty a -> a
forall a. Semigroup a => NonEmpty a -> a
sconcat (Event t (NonEmpty a) -> Event t a)
-> (NonEmpty (Event t a) -> Event t (NonEmpty a))
-> NonEmpty (Event t a)
-> Event t a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Event t a] -> Event t (NonEmpty a)
forall {k} (t :: k) a.
Reflex t =>
[Event t a] -> Event t (NonEmpty a)
mergeList ([Event t a] -> Event t (NonEmpty a))
-> (NonEmpty (Event t a) -> [Event t a])
-> NonEmpty (Event t a)
-> Event t (NonEmpty a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty (Event t a) -> [Event t a]
forall a. NonEmpty a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList
stimes :: forall b. Integral b => b -> Event t a -> Event t a
stimes b
n = (a -> a) -> Event t a -> Event t a
forall a b. (a -> b) -> Event t a -> Event t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((a -> a) -> Event t a -> Event t a)
-> (a -> a) -> Event t a -> Event t a
forall a b. (a -> b) -> a -> b
$ b -> a -> a
forall b. Integral b => b -> a -> a
forall a b. (Semigroup a, Integral b) => b -> a -> a
stimes b
n
instance (Semigroup a, Reflex t) => Monoid (Event t a) where
mempty :: Event t a
mempty = Event t a
forall a. Event t a
forall {k} (t :: k) a. Reflex t => Event t a
never
mappend :: Event t a -> Event t a -> Event t a
mappend = Event t a -> Event t a -> Event t a
forall a. Semigroup a => a -> a -> a
(<>)
mconcat :: [Event t a] -> Event t a
mconcat = (NonEmpty a -> a) -> Event t (NonEmpty a) -> Event t a
forall a b. (a -> b) -> Event t a -> Event t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap NonEmpty a -> a
forall a. Semigroup a => NonEmpty a -> a
sconcat (Event t (NonEmpty a) -> Event t a)
-> ([Event t a] -> Event t (NonEmpty a))
-> [Event t a]
-> Event t a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Event t a] -> Event t (NonEmpty a)
forall {k} (t :: k) a.
Reflex t =>
[Event t a] -> Event t (NonEmpty a)
mergeList
{-# INLINE mergeWith #-}
mergeWith :: Reflex t => (a -> a -> a) -> [Event t a] -> Event t a
mergeWith :: forall {k} (t :: k) a.
Reflex t =>
(a -> a -> a) -> [Event t a] -> Event t a
mergeWith = (a -> a) -> (a -> a -> a) -> [Event t a] -> Event t a
forall {k} (t :: k) a b.
Reflex t =>
(a -> b) -> (b -> b -> b) -> [Event t a] -> Event t b
mergeWith' a -> a
forall a. a -> a
id
{-# INLINE mergeWith' #-}
mergeWith' :: Reflex t => (a -> b) -> (b -> b -> b) -> [Event t a] -> Event t b
mergeWith' :: forall {k} (t :: k) a b.
Reflex t =>
(a -> b) -> (b -> b -> b) -> [Event t a] -> Event t b
mergeWith' a -> b
f b -> b -> b
g [Event t a]
es = (IntMap a -> b) -> Event t (IntMap a) -> Event t b
forall a b. (a -> b) -> Event t a -> Event t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((b -> b -> b) -> IntMap b -> b
forall a. (a -> a -> a) -> IntMap a -> a
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
Prelude.foldl1 b -> b -> b
g (IntMap b -> b) -> (IntMap a -> IntMap b) -> IntMap a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> IntMap a -> IntMap b
forall a b. (a -> b) -> IntMap a -> IntMap b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f)
(Event t (IntMap a) -> Event t b)
-> ([(Int, Event t a)] -> Event t (IntMap a))
-> [(Int, Event t a)]
-> Event t b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IntMap (Event t a) -> Event t (IntMap a)
forall {k} (t :: k) a.
Reflex t =>
IntMap (Event t a) -> Event t (IntMap a)
mergeInt
(IntMap (Event t a) -> Event t (IntMap a))
-> ([(Int, Event t a)] -> IntMap (Event t a))
-> [(Int, Event t a)]
-> Event t (IntMap a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Int, Event t a)] -> IntMap (Event t a)
forall a. [(Int, a)] -> IntMap a
IntMap.fromDistinctAscList
([(Int, Event t a)] -> Event t b)
-> [(Int, Event t a)] -> Event t b
forall a b. (a -> b) -> a -> b
$ [Int] -> [Event t a] -> [(Int, Event t a)]
forall a b. [a] -> [b] -> [(a, b)]
forall (f :: * -> *) a b. Zip f => f a -> f b -> f (a, b)
zip [Int
0 :: Int ..] [Event t a]
es
{-# INLINE leftmost #-}
leftmost :: Reflex t => [Event t a] -> Event t a
leftmost :: forall {k} (t :: k) a. Reflex t => [Event t a] -> Event t a
leftmost = (a -> a -> a) -> [Event t a] -> Event t a
forall {k} (t :: k) a.
Reflex t =>
(a -> a -> a) -> [Event t a] -> Event t a
mergeWith a -> a -> a
forall a b. a -> b -> a
const
mergeList :: Reflex t => [Event t a] -> Event t (NonEmpty a)
mergeList :: forall {k} (t :: k) a.
Reflex t =>
[Event t a] -> Event t (NonEmpty a)
mergeList [] = Event t (NonEmpty a)
forall a. Event t a
forall {k} (t :: k) a. Reflex t => Event t a
never
mergeList [Event t a]
es = (NonEmpty a -> NonEmpty a) -> [Event t a] -> Event t (NonEmpty a)
forall {k} (t :: k) a b.
Reflex t =>
(NonEmpty a -> b) -> [Event t a] -> Event t b
mergeWithFoldCheap' NonEmpty a -> NonEmpty a
forall a. a -> a
id [Event t a]
es
unsafeMapIncremental
:: (Reflex t, Patch p, Patch p')
=> (PatchTarget p -> PatchTarget p')
-> (p -> p')
-> Incremental t p
-> Incremental t p'
unsafeMapIncremental :: forall {k} (t :: k) p p'.
(Reflex t, Patch p, Patch p') =>
(PatchTarget p -> PatchTarget p')
-> (p -> p') -> Incremental t p -> Incremental t p'
unsafeMapIncremental PatchTarget p -> PatchTarget p'
f p -> p'
g Incremental t p
a = PullM t (PatchTarget p') -> Event t p' -> Incremental t p'
forall p.
Patch p =>
PullM t (PatchTarget p) -> Event t p -> Incremental t p
forall {k} (t :: k) p.
(Reflex t, Patch p) =>
PullM t (PatchTarget p) -> Event t p -> Incremental t p
unsafeBuildIncremental ((PatchTarget p -> PatchTarget p')
-> PullM t (PatchTarget p) -> PullM t (PatchTarget p')
forall a b. (a -> b) -> PullM t a -> PullM t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap PatchTarget p -> PatchTarget p'
f (PullM t (PatchTarget p) -> PullM t (PatchTarget p'))
-> PullM t (PatchTarget p) -> PullM t (PatchTarget p')
forall a b. (a -> b) -> a -> b
$ Behavior t (PatchTarget p) -> PullM t (PatchTarget p)
forall a. Behavior t a -> PullM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample (Behavior t (PatchTarget p) -> PullM t (PatchTarget p))
-> Behavior t (PatchTarget p) -> PullM t (PatchTarget p)
forall a b. (a -> b) -> a -> b
$ Incremental t p -> Behavior t (PatchTarget p)
forall p. Patch p => Incremental t p -> Behavior t (PatchTarget p)
forall {k} (t :: k) p.
(Reflex t, Patch p) =>
Incremental t p -> Behavior t (PatchTarget p)
currentIncremental Incremental t p
a) (Event t p' -> Incremental t p') -> Event t p' -> Incremental t p'
forall a b. (a -> b) -> a -> b
$ p -> p'
g (p -> p') -> Event t p -> Event t p'
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Incremental t p -> Event t p
forall p. Patch p => Incremental t p -> Event t p
forall {k} (t :: k) p.
(Reflex t, Patch p) =>
Incremental t p -> Event t p
updatedIncremental Incremental t p
a
mergeMap :: (Reflex t, Ord k) => Map k (Event t a) -> Event t (Map k a)
mergeMap :: forall {k} (t :: k) k a.
(Reflex t, Ord k) =>
Map k (Event t a) -> Event t (Map k a)
mergeMap = (DMap (Const2 k a) Identity -> Map k a)
-> Event t (DMap (Const2 k a) Identity) -> Event t (Map k a)
forall a b. (a -> b) -> Event t a -> Event t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap DMap (Const2 k a) Identity -> Map k a
forall k v. DMap (Const2 k v) Identity -> Map k v
dmapToMap (Event t (DMap (Const2 k a) Identity) -> Event t (Map k a))
-> (Map k (Event t a) -> Event t (DMap (Const2 k a) Identity))
-> Map k (Event t a)
-> Event t (Map k a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DMap (Const2 k a) (Event t) -> Event t (DMap (Const2 k a) Identity)
forall {k} (t :: k) (k :: * -> *).
(Reflex t, GCompare k) =>
DMap k (Event t) -> Event t (DMap k Identity)
merge (DMap (Const2 k a) (Event t)
-> Event t (DMap (Const2 k a) Identity))
-> (Map k (Event t a) -> DMap (Const2 k a) (Event t))
-> Map k (Event t a)
-> Event t (DMap (Const2 k a) Identity)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map k (Event t a) -> DMap (Const2 k a) (Event t)
forall {k1} k2 (f :: k1 -> *) (v :: k1).
Map k2 (f v) -> DMap (Const2 k2 v) f
mapWithFunctorToDMap
mergeIntMap :: Reflex t => IntMap (Event t a) -> Event t (IntMap a)
mergeIntMap :: forall {k} (t :: k) a.
Reflex t =>
IntMap (Event t a) -> Event t (IntMap a)
mergeIntMap = (DMap (Const2 Int a) Identity -> IntMap a)
-> Event t (DMap (Const2 Int a) Identity) -> Event t (IntMap a)
forall a b. (a -> b) -> Event t a -> Event t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap DMap (Const2 Int a) Identity -> IntMap a
forall v. DMap (Const2 Int v) Identity -> IntMap v
dmapToIntMap (Event t (DMap (Const2 Int a) Identity) -> Event t (IntMap a))
-> (IntMap (Event t a) -> Event t (DMap (Const2 Int a) Identity))
-> IntMap (Event t a)
-> Event t (IntMap a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DMap (Const2 Int a) (Event t)
-> Event t (DMap (Const2 Int a) Identity)
forall {k} (t :: k) (k :: * -> *).
(Reflex t, GCompare k) =>
DMap k (Event t) -> Event t (DMap k Identity)
merge (DMap (Const2 Int a) (Event t)
-> Event t (DMap (Const2 Int a) Identity))
-> (IntMap (Event t a) -> DMap (Const2 Int a) (Event t))
-> IntMap (Event t a)
-> Event t (DMap (Const2 Int a) Identity)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IntMap (Event t a) -> DMap (Const2 Int a) (Event t)
forall {k} (f :: k -> *) (v :: k).
IntMap (f v) -> DMap (Const2 Int v) f
intMapWithFunctorToDMap
mergeMapIncremental :: (Reflex t, Ord k) => Incremental t (PatchMap k (Event t a)) -> Event t (Map k a)
mergeMapIncremental :: forall {k} (t :: k) k a.
(Reflex t, Ord k) =>
Incremental t (PatchMap k (Event t a)) -> Event t (Map k a)
mergeMapIncremental = (DMap (Const2 k a) Identity -> Map k a)
-> Event t (DMap (Const2 k a) Identity) -> Event t (Map k a)
forall a b. (a -> b) -> Event t a -> Event t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap DMap (Const2 k a) Identity -> Map k a
forall k v. DMap (Const2 k v) Identity -> Map k v
dmapToMap (Event t (DMap (Const2 k a) Identity) -> Event t (Map k a))
-> (Incremental t (PatchMap k (Event t a))
-> Event t (DMap (Const2 k a) Identity))
-> Incremental t (PatchMap k (Event t a))
-> Event t (Map k a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Incremental t (PatchDMap (Const2 k a) (Event t))
-> Event t (DMap (Const2 k a) Identity)
forall {k} (t :: k) (k :: * -> *).
(Reflex t, GCompare k) =>
Incremental t (PatchDMap k (Event t)) -> Event t (DMap k Identity)
mergeIncremental (Incremental t (PatchDMap (Const2 k a) (Event t))
-> Event t (DMap (Const2 k a) Identity))
-> (Incremental t (PatchMap k (Event t a))
-> Incremental t (PatchDMap (Const2 k a) (Event t)))
-> Incremental t (PatchMap k (Event t a))
-> Event t (DMap (Const2 k a) Identity)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PatchTarget (PatchMap k (Event t a))
-> PatchTarget (PatchDMap (Const2 k a) (Event t)))
-> (PatchMap k (Event t a) -> PatchDMap (Const2 k a) (Event t))
-> Incremental t (PatchMap k (Event t a))
-> Incremental t (PatchDMap (Const2 k a) (Event t))
forall {k} (t :: k) p p'.
(Reflex t, Patch p, Patch p') =>
(PatchTarget p -> PatchTarget p')
-> (p -> p') -> Incremental t p -> Incremental t p'
unsafeMapIncremental Map k (Event t a) -> DMap (Const2 k a) (Event t)
PatchTarget (PatchMap k (Event t a))
-> PatchTarget (PatchDMap (Const2 k a) (Event t))
forall {k1} k2 (f :: k1 -> *) (v :: k1).
Map k2 (f v) -> DMap (Const2 k2 v) f
mapWithFunctorToDMap ((Event t a -> Event t a)
-> PatchMap k (Event t a) -> PatchDMap (Const2 k a) (Event t)
forall {k1} k2 v (v' :: k1 -> *) (a :: k1).
(v -> v' a) -> PatchMap k2 v -> PatchDMap (Const2 k2 a) v'
const2PatchDMapWith Event t a -> Event t a
forall a. a -> a
id)
mergeIntMapIncremental :: Reflex t => Incremental t (PatchIntMap (Event t a)) -> Event t (IntMap a)
mergeIntMapIncremental :: forall {k} (t :: k) a.
Reflex t =>
Incremental t (PatchIntMap (Event t a)) -> Event t (IntMap a)
mergeIntMapIncremental = (DMap (Const2 Int a) Identity -> IntMap a)
-> Event t (DMap (Const2 Int a) Identity) -> Event t (IntMap a)
forall a b. (a -> b) -> Event t a -> Event t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap DMap (Const2 Int a) Identity -> IntMap a
forall v. DMap (Const2 Int v) Identity -> IntMap v
dmapToIntMap (Event t (DMap (Const2 Int a) Identity) -> Event t (IntMap a))
-> (Incremental t (PatchIntMap (Event t a))
-> Event t (DMap (Const2 Int a) Identity))
-> Incremental t (PatchIntMap (Event t a))
-> Event t (IntMap a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Incremental t (PatchDMap (Const2 Int a) (Event t))
-> Event t (DMap (Const2 Int a) Identity)
forall {k} (t :: k) (k :: * -> *).
(Reflex t, GCompare k) =>
Incremental t (PatchDMap k (Event t)) -> Event t (DMap k Identity)
mergeIncremental (Incremental t (PatchDMap (Const2 Int a) (Event t))
-> Event t (DMap (Const2 Int a) Identity))
-> (Incremental t (PatchIntMap (Event t a))
-> Incremental t (PatchDMap (Const2 Int a) (Event t)))
-> Incremental t (PatchIntMap (Event t a))
-> Event t (DMap (Const2 Int a) Identity)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PatchTarget (PatchIntMap (Event t a))
-> PatchTarget (PatchDMap (Const2 Int a) (Event t)))
-> (PatchIntMap (Event t a) -> PatchDMap (Const2 Int a) (Event t))
-> Incremental t (PatchIntMap (Event t a))
-> Incremental t (PatchDMap (Const2 Int a) (Event t))
forall {k} (t :: k) p p'.
(Reflex t, Patch p, Patch p') =>
(PatchTarget p -> PatchTarget p')
-> (p -> p') -> Incremental t p -> Incremental t p'
unsafeMapIncremental IntMap (Event t a) -> DMap (Const2 Int a) (Event t)
PatchTarget (PatchIntMap (Event t a))
-> PatchTarget (PatchDMap (Const2 Int a) (Event t))
forall {k} (f :: k -> *) (v :: k).
IntMap (f v) -> DMap (Const2 Int v) f
intMapWithFunctorToDMap ((Event t a -> Event t a)
-> PatchIntMap (Event t a) -> PatchDMap (Const2 Int a) (Event t)
forall {k} v (f :: k -> *) (a :: k).
(v -> f a) -> PatchIntMap v -> PatchDMap (Const2 Int a) f
const2IntPatchDMapWith Event t a -> Event t a
forall a. a -> a
id)
mergeMapIncrementalWithMove :: (Reflex t, Ord k) => Incremental t (PatchMapWithMove k (Event t a)) -> Event t (Map k a)
mergeMapIncrementalWithMove :: forall {k} (t :: k) k a.
(Reflex t, Ord k) =>
Incremental t (PatchMapWithMove k (Event t a)) -> Event t (Map k a)
mergeMapIncrementalWithMove = (DMap (Const2 k a) Identity -> Map k a)
-> Event t (DMap (Const2 k a) Identity) -> Event t (Map k a)
forall a b. (a -> b) -> Event t a -> Event t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap DMap (Const2 k a) Identity -> Map k a
forall k v. DMap (Const2 k v) Identity -> Map k v
dmapToMap (Event t (DMap (Const2 k a) Identity) -> Event t (Map k a))
-> (Incremental t (PatchMapWithMove k (Event t a))
-> Event t (DMap (Const2 k a) Identity))
-> Incremental t (PatchMapWithMove k (Event t a))
-> Event t (Map k a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Incremental t (PatchDMapWithMove (Const2 k a) (Event t))
-> Event t (DMap (Const2 k a) Identity)
forall {k} (t :: k) (k :: * -> *).
(Reflex t, GCompare k) =>
Incremental t (PatchDMapWithMove k (Event t))
-> Event t (DMap k Identity)
mergeIncrementalWithMove (Incremental t (PatchDMapWithMove (Const2 k a) (Event t))
-> Event t (DMap (Const2 k a) Identity))
-> (Incremental t (PatchMapWithMove k (Event t a))
-> Incremental t (PatchDMapWithMove (Const2 k a) (Event t)))
-> Incremental t (PatchMapWithMove k (Event t a))
-> Event t (DMap (Const2 k a) Identity)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PatchTarget (PatchMapWithMove k (Event t a))
-> PatchTarget (PatchDMapWithMove (Const2 k a) (Event t)))
-> (PatchMapWithMove k (Event t a)
-> PatchDMapWithMove (Const2 k a) (Event t))
-> Incremental t (PatchMapWithMove k (Event t a))
-> Incremental t (PatchDMapWithMove (Const2 k a) (Event t))
forall {k} (t :: k) p p'.
(Reflex t, Patch p, Patch p') =>
(PatchTarget p -> PatchTarget p')
-> (p -> p') -> Incremental t p -> Incremental t p'
unsafeMapIncremental Map k (Event t a) -> DMap (Const2 k a) (Event t)
PatchTarget (PatchMapWithMove k (Event t a))
-> PatchTarget (PatchDMapWithMove (Const2 k a) (Event t))
forall {k1} k2 (f :: k1 -> *) (v :: k1).
Map k2 (f v) -> DMap (Const2 k2 v) f
mapWithFunctorToDMap ((Event t a -> Event t a)
-> PatchMapWithMove k (Event t a)
-> PatchDMapWithMove (Const2 k a) (Event t)
forall {k1} k2 v (v' :: k1 -> *) (a :: k1).
(v -> v' a)
-> PatchMapWithMove k2 v -> PatchDMapWithMove (Const2 k2 a) v'
const2PatchDMapWithMoveWith Event t a -> Event t a
forall a. a -> a
id)
fanEither :: Reflex t => Event t (Either a b) -> (Event t a, Event t b)
fanEither :: forall {k} (t :: k) a b.
Reflex t =>
Event t (Either a b) -> (Event t a, Event t b)
fanEither Event t (Either a b)
e =
let justLeft :: Either a b -> Maybe a
justLeft = (a -> Maybe a) -> (b -> Maybe a) -> Either a b -> Maybe a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either a -> Maybe a
forall a. a -> Maybe a
Just (Maybe a -> b -> Maybe a
forall a b. a -> b -> a
const Maybe a
forall a. Maybe a
Nothing)
justRight :: Either a a -> Maybe a
justRight = (a -> Maybe a) -> (a -> Maybe a) -> Either a a -> Maybe a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Maybe a -> a -> Maybe a
forall a b. a -> b -> a
const Maybe a
forall a. Maybe a
Nothing) a -> Maybe a
forall a. a -> Maybe a
Just
in ((Either a b -> Maybe a) -> Event t (Either a b) -> Event t a
forall a b. (a -> Maybe b) -> Event t a -> Event t b
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe Either a b -> Maybe a
forall {a} {b}. Either a b -> Maybe a
justLeft Event t (Either a b)
e, (Either a b -> Maybe b) -> Event t (Either a b) -> Event t b
forall a b. (a -> Maybe b) -> Event t a -> Event t b
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe Either a b -> Maybe b
forall {a} {a}. Either a a -> Maybe a
justRight Event t (Either a b)
e)
fanThese :: Reflex t => Event t (These a b) -> (Event t a, Event t b)
fanThese :: forall {k} (t :: k) a b.
Reflex t =>
Event t (These a b) -> (Event t a, Event t b)
fanThese Event t (These a b)
e =
let this :: These a b -> Maybe a
this (This a
x) = a -> Maybe a
forall a. a -> Maybe a
Just a
x
this (These a
x b
_) = a -> Maybe a
forall a. a -> Maybe a
Just a
x
this These a b
_ = Maybe a
forall a. Maybe a
Nothing
that :: These a a -> Maybe a
that (That a
y) = a -> Maybe a
forall a. a -> Maybe a
Just a
y
that (These a
_ a
y) = a -> Maybe a
forall a. a -> Maybe a
Just a
y
that These a a
_ = Maybe a
forall a. Maybe a
Nothing
in ((These a b -> Maybe a) -> Event t (These a b) -> Event t a
forall a b. (a -> Maybe b) -> Event t a -> Event t b
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe These a b -> Maybe a
forall {a} {b}. These a b -> Maybe a
this Event t (These a b)
e, (These a b -> Maybe b) -> Event t (These a b) -> Event t b
forall a b. (a -> Maybe b) -> Event t a -> Event t b
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe These a b -> Maybe b
forall {a} {a}. These a a -> Maybe a
that Event t (These a b)
e)
fanMap :: (Reflex t, Ord k) => Event t (Map k a) -> EventSelector t (Const2 k a)
fanMap :: forall {k} (t :: k) k a.
(Reflex t, Ord k) =>
Event t (Map k a) -> EventSelector t (Const2 k a)
fanMap = Event t (DMap (Const2 k a) Identity)
-> EventSelector t (Const2 k a)
forall {k} (t :: k) (k :: * -> *).
(Reflex t, GCompare k) =>
Event t (DMap k Identity) -> EventSelector t k
fan (Event t (DMap (Const2 k a) Identity)
-> EventSelector t (Const2 k a))
-> (Event t (Map k a) -> Event t (DMap (Const2 k a) Identity))
-> Event t (Map k a)
-> EventSelector t (Const2 k a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map k a -> DMap (Const2 k a) Identity)
-> Event t (Map k a) -> Event t (DMap (Const2 k a) Identity)
forall a b. (a -> b) -> Event t a -> Event t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Map k a -> DMap (Const2 k a) Identity
forall k v. Map k v -> DMap (Const2 k v) Identity
mapToDMap
switchHold :: (Reflex t, MonadHold t m) => Event t a -> Event t (Event t a) -> m (Event t a)
switchHold :: forall {k} (t :: k) (m :: * -> *) a.
(Reflex t, MonadHold t m) =>
Event t a -> Event t (Event t a) -> m (Event t a)
switchHold Event t a
ea0 Event t (Event t a)
eea = Behavior t (Event t a) -> Event t a
forall a. Behavior t (Event t a) -> Event t a
forall {k} (t :: k) a.
Reflex t =>
Behavior t (Event t a) -> Event t a
switch (Behavior t (Event t a) -> Event t a)
-> m (Behavior t (Event t a)) -> m (Event t a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Event t a -> Event t (Event t a) -> m (Behavior t (Event t a))
forall a. a -> Event t a -> m (Behavior t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Behavior t a)
hold Event t a
ea0 Event t (Event t a)
eea
switchHoldPromptly :: (Reflex t, MonadHold t m) => Event t a -> Event t (Event t a) -> m (Event t a)
switchHoldPromptly :: forall {k} (t :: k) (m :: * -> *) a.
(Reflex t, MonadHold t m) =>
Event t a -> Event t (Event t a) -> m (Event t a)
switchHoldPromptly Event t a
ea0 Event t (Event t a)
eea = do
Behavior t (Event t a)
bea <- Event t a -> Event t (Event t a) -> m (Behavior t (Event t a))
forall a. a -> Event t a -> m (Behavior t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Behavior t a)
hold Event t a
ea0 Event t (Event t a)
eea
let eLag :: Event t a
eLag = Behavior t (Event t a) -> Event t a
forall a. Behavior t (Event t a) -> Event t a
forall {k} (t :: k) a.
Reflex t =>
Behavior t (Event t a) -> Event t a
switch Behavior t (Event t a)
bea
eCoincidences :: Event t a
eCoincidences = Event t (Event t a) -> Event t a
forall a. Event t (Event t a) -> Event t a
forall k (t :: k) a. Reflex t => Event t (Event t a) -> Event t a
coincidence Event t (Event t a)
eea
Event t a -> m (Event t a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Event t a -> m (Event t a)) -> Event t a -> m (Event t a)
forall a b. (a -> b) -> a -> b
$ [Event t a] -> Event t a
forall {k} (t :: k) a. Reflex t => [Event t a] -> Event t a
leftmost [Event t a
eCoincidences, Event t a
eLag]
switchHoldPromptOnly :: (Reflex t, MonadHold t m) => Event t a -> Event t (Event t a) -> m (Event t a)
switchHoldPromptOnly :: forall {k} (t :: k) (m :: * -> *) a.
(Reflex t, MonadHold t m) =>
Event t a -> Event t (Event t a) -> m (Event t a)
switchHoldPromptOnly Event t a
e0 Event t (Event t a)
e' = do
Event t a
eLag <- Behavior t (Event t a) -> Event t a
forall a. Behavior t (Event t a) -> Event t a
forall {k} (t :: k) a.
Reflex t =>
Behavior t (Event t a) -> Event t a
switch (Behavior t (Event t a) -> Event t a)
-> m (Behavior t (Event t a)) -> m (Event t a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Event t a -> Event t (Event t a) -> m (Behavior t (Event t a))
forall a. a -> Event t a -> m (Behavior t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Behavior t a)
hold Event t a
e0 Event t (Event t a)
e'
Event t a -> m (Event t a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Event t a -> m (Event t a)) -> Event t a -> m (Event t a)
forall a b. (a -> b) -> a -> b
$ Event t (Event t a) -> Event t a
forall a. Event t (Event t a) -> Event t a
forall k (t :: k) a. Reflex t => Event t (Event t a) -> Event t a
coincidence (Event t (Event t a) -> Event t a)
-> Event t (Event t a) -> Event t a
forall a b. (a -> b) -> a -> b
$ [Event t (Event t a)] -> Event t (Event t a)
forall {k} (t :: k) a. Reflex t => [Event t a] -> Event t a
leftmost [Event t (Event t a)
e', Event t a
eLag Event t a -> Event t a -> Event t (Event t a)
forall a b. a -> Event t b -> Event t a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Event t a
eLag]
coincidencePatchMap :: (Reflex t, Ord k) => Event t (PatchMap k (Event t v)) -> Event t (PatchMap k v)
coincidencePatchMap :: forall {k} (t :: k) k v.
(Reflex t, Ord k) =>
Event t (PatchMap k (Event t v)) -> Event t (PatchMap k v)
coincidencePatchMap Event t (PatchMap k (Event t v))
e = (Map k (Maybe v) -> PatchMap k v)
-> Event t (Map k (Maybe v)) -> Event t (PatchMap k v)
forall {k} (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap Map k (Maybe v) -> PatchMap k v
forall k v. Map k (Maybe v) -> PatchMap k v
PatchMap (Event t (Map k (Maybe v)) -> Event t (PatchMap k v))
-> Event t (Map k (Maybe v)) -> Event t (PatchMap k v)
forall a b. (a -> b) -> a -> b
$ Event t (Event t (Map k (Maybe v))) -> Event t (Map k (Maybe v))
forall a. Event t (Event t a) -> Event t a
forall k (t :: k) a. Reflex t => Event t (Event t a) -> Event t a
coincidence (Event t (Event t (Map k (Maybe v))) -> Event t (Map k (Maybe v)))
-> Event t (Event t (Map k (Maybe v))) -> Event t (Map k (Maybe v))
forall a b. (a -> b) -> a -> b
$ Event t (PatchMap k (Event t v))
-> (PatchMap k (Event t v) -> Event t (Map k (Maybe v)))
-> Event t (Event t (Map k (Maybe v)))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
ffor Event t (PatchMap k (Event t v))
e ((PatchMap k (Event t v) -> Event t (Map k (Maybe v)))
-> Event t (Event t (Map k (Maybe v))))
-> (PatchMap k (Event t v) -> Event t (Map k (Maybe v)))
-> Event t (Event t (Map k (Maybe v)))
forall a b. (a -> b) -> a -> b
$ \(PatchMap Map k (Maybe (Event t v))
m) -> Map k (Event t (Maybe v)) -> Event t (Map k (Maybe v))
forall {k} (t :: k) k a.
(Reflex t, Ord k) =>
Map k (Event t a) -> Event t (Map k a)
mergeMap (Map k (Event t (Maybe v)) -> Event t (Map k (Maybe v)))
-> Map k (Event t (Maybe v)) -> Event t (Map k (Maybe v))
forall a b. (a -> b) -> a -> b
$ Map k (Maybe (Event t v))
-> (Maybe (Event t v) -> Event t (Maybe v))
-> Map k (Event t (Maybe v))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
ffor Map k (Maybe (Event t v))
m ((Maybe (Event t v) -> Event t (Maybe v))
-> Map k (Event t (Maybe v)))
-> (Maybe (Event t v) -> Event t (Maybe v))
-> Map k (Event t (Maybe v))
forall a b. (a -> b) -> a -> b
$ \case
Maybe (Event t v)
Nothing -> (PatchMap k (Event t v) -> Maybe v)
-> Event t (PatchMap k (Event t v)) -> Event t (Maybe v)
forall {k} (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap (Maybe v -> PatchMap k (Event t v) -> Maybe v
forall a b. a -> b -> a
const Maybe v
forall a. Maybe a
Nothing) Event t (PatchMap k (Event t v))
e
Just Event t v
ev -> [Event t (Maybe v)] -> Event t (Maybe v)
forall {k} (t :: k) a. Reflex t => [Event t a] -> Event t a
leftmost [(v -> Maybe v) -> Event t v -> Event t (Maybe v)
forall {k} (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap v -> Maybe v
forall a. a -> Maybe a
Just Event t v
ev, (PatchMap k (Event t v) -> Maybe v)
-> Event t (PatchMap k (Event t v)) -> Event t (Maybe v)
forall {k} (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap (Maybe v -> PatchMap k (Event t v) -> Maybe v
forall a b. a -> b -> a
const Maybe v
forall a. Maybe a
Nothing) Event t (PatchMap k (Event t v))
e]
coincidencePatchIntMap :: Reflex t => Event t (PatchIntMap (Event t v)) -> Event t (PatchIntMap v)
coincidencePatchIntMap :: forall {k} (t :: k) v.
Reflex t =>
Event t (PatchIntMap (Event t v)) -> Event t (PatchIntMap v)
coincidencePatchIntMap Event t (PatchIntMap (Event t v))
e = (IntMap (Maybe v) -> PatchIntMap v)
-> Event t (IntMap (Maybe v)) -> Event t (PatchIntMap v)
forall {k} (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap IntMap (Maybe v) -> PatchIntMap v
forall a. IntMap (Maybe a) -> PatchIntMap a
PatchIntMap (Event t (IntMap (Maybe v)) -> Event t (PatchIntMap v))
-> Event t (IntMap (Maybe v)) -> Event t (PatchIntMap v)
forall a b. (a -> b) -> a -> b
$ Event t (Event t (IntMap (Maybe v))) -> Event t (IntMap (Maybe v))
forall a. Event t (Event t a) -> Event t a
forall k (t :: k) a. Reflex t => Event t (Event t a) -> Event t a
coincidence (Event t (Event t (IntMap (Maybe v)))
-> Event t (IntMap (Maybe v)))
-> Event t (Event t (IntMap (Maybe v)))
-> Event t (IntMap (Maybe v))
forall a b. (a -> b) -> a -> b
$ Event t (PatchIntMap (Event t v))
-> (PatchIntMap (Event t v) -> Event t (IntMap (Maybe v)))
-> Event t (Event t (IntMap (Maybe v)))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
ffor Event t (PatchIntMap (Event t v))
e ((PatchIntMap (Event t v) -> Event t (IntMap (Maybe v)))
-> Event t (Event t (IntMap (Maybe v))))
-> (PatchIntMap (Event t v) -> Event t (IntMap (Maybe v)))
-> Event t (Event t (IntMap (Maybe v)))
forall a b. (a -> b) -> a -> b
$ \(PatchIntMap IntMap (Maybe (Event t v))
m) -> IntMap (Event t (Maybe v)) -> Event t (IntMap (Maybe v))
forall {k} (t :: k) a.
Reflex t =>
IntMap (Event t a) -> Event t (IntMap a)
mergeIntMap (IntMap (Event t (Maybe v)) -> Event t (IntMap (Maybe v)))
-> IntMap (Event t (Maybe v)) -> Event t (IntMap (Maybe v))
forall a b. (a -> b) -> a -> b
$ IntMap (Maybe (Event t v))
-> (Maybe (Event t v) -> Event t (Maybe v))
-> IntMap (Event t (Maybe v))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
ffor IntMap (Maybe (Event t v))
m ((Maybe (Event t v) -> Event t (Maybe v))
-> IntMap (Event t (Maybe v)))
-> (Maybe (Event t v) -> Event t (Maybe v))
-> IntMap (Event t (Maybe v))
forall a b. (a -> b) -> a -> b
$ \case
Maybe (Event t v)
Nothing -> (PatchIntMap (Event t v) -> Maybe v)
-> Event t (PatchIntMap (Event t v)) -> Event t (Maybe v)
forall {k} (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap (Maybe v -> PatchIntMap (Event t v) -> Maybe v
forall a b. a -> b -> a
const Maybe v
forall a. Maybe a
Nothing) Event t (PatchIntMap (Event t v))
e
Just Event t v
ev -> [Event t (Maybe v)] -> Event t (Maybe v)
forall {k} (t :: k) a. Reflex t => [Event t a] -> Event t a
leftmost [(v -> Maybe v) -> Event t v -> Event t (Maybe v)
forall {k} (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap v -> Maybe v
forall a. a -> Maybe a
Just Event t v
ev, (PatchIntMap (Event t v) -> Maybe v)
-> Event t (PatchIntMap (Event t v)) -> Event t (Maybe v)
forall {k} (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap (Maybe v -> PatchIntMap (Event t v) -> Maybe v
forall a b. a -> b -> a
const Maybe v
forall a. Maybe a
Nothing) Event t (PatchIntMap (Event t v))
e]
coincidencePatchMapWithMove :: (Reflex t, Ord k) => Event t (PatchMapWithMove k (Event t v)) -> Event t (PatchMapWithMove k v)
coincidencePatchMapWithMove :: forall {k} (t :: k) k v.
(Reflex t, Ord k) =>
Event t (PatchMapWithMove k (Event t v))
-> Event t (PatchMapWithMove k v)
coincidencePatchMapWithMove Event t (PatchMapWithMove k (Event t v))
e = (Map k (NodeInfo k v) -> PatchMapWithMove k v)
-> Event t (Map k (NodeInfo k v)) -> Event t (PatchMapWithMove k v)
forall {k} (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap Map k (NodeInfo k v) -> PatchMapWithMove k v
forall k v. Map k (NodeInfo k v) -> PatchMapWithMove k v
unsafePatchMapWithMove (Event t (Map k (NodeInfo k v)) -> Event t (PatchMapWithMove k v))
-> Event t (Map k (NodeInfo k v)) -> Event t (PatchMapWithMove k v)
forall a b. (a -> b) -> a -> b
$ Event t (Event t (Map k (NodeInfo k v)))
-> Event t (Map k (NodeInfo k v))
forall a. Event t (Event t a) -> Event t a
forall k (t :: k) a. Reflex t => Event t (Event t a) -> Event t a
coincidence (Event t (Event t (Map k (NodeInfo k v)))
-> Event t (Map k (NodeInfo k v)))
-> Event t (Event t (Map k (NodeInfo k v)))
-> Event t (Map k (NodeInfo k v))
forall a b. (a -> b) -> a -> b
$ Event t (PatchMapWithMove k (Event t v))
-> (PatchMapWithMove k (Event t v)
-> Event t (Map k (NodeInfo k v)))
-> Event t (Event t (Map k (NodeInfo k v)))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
ffor Event t (PatchMapWithMove k (Event t v))
e ((PatchMapWithMove k (Event t v) -> Event t (Map k (NodeInfo k v)))
-> Event t (Event t (Map k (NodeInfo k v))))
-> (PatchMapWithMove k (Event t v)
-> Event t (Map k (NodeInfo k v)))
-> Event t (Event t (Map k (NodeInfo k v)))
forall a b. (a -> b) -> a -> b
$ \PatchMapWithMove k (Event t v)
p -> Map k (Event t (NodeInfo k v)) -> Event t (Map k (NodeInfo k v))
forall {k} (t :: k) k a.
(Reflex t, Ord k) =>
Map k (Event t a) -> Event t (Map k a)
mergeMap (Map k (Event t (NodeInfo k v)) -> Event t (Map k (NodeInfo k v)))
-> Map k (Event t (NodeInfo k v)) -> Event t (Map k (NodeInfo k v))
forall a b. (a -> b) -> a -> b
$ Map k (NodeInfo k (Event t v))
-> (NodeInfo k (Event t v) -> Event t (NodeInfo k v))
-> Map k (Event t (NodeInfo k v))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
ffor (PatchMapWithMove k (Event t v) -> Map k (NodeInfo k (Event t v))
forall k v. PatchMapWithMove k v -> Map k (NodeInfo k v)
unPatchMapWithMove PatchMapWithMove k (Event t v)
p) ((NodeInfo k (Event t v) -> Event t (NodeInfo k v))
-> Map k (Event t (NodeInfo k v)))
-> (NodeInfo k (Event t v) -> Event t (NodeInfo k v))
-> Map k (Event t (NodeInfo k v))
forall a b. (a -> b) -> a -> b
$ \NodeInfo k (Event t v)
ni -> case NodeInfo k (Event t v) -> From k (Event t v)
forall k v. NodeInfo k v -> From k v
PatchMapWithMove._nodeInfo_from NodeInfo k (Event t v)
ni of
From k (Event t v)
PatchMapWithMove.From_Delete -> Event t (PatchMapWithMove k (Event t v))
-> (PatchMapWithMove k (Event t v) -> NodeInfo k v)
-> Event t (NodeInfo k v)
forall {k} (t :: k) a b.
Reflex t =>
Event t a -> (a -> b) -> Event t b
fforCheap Event t (PatchMapWithMove k (Event t v))
e ((PatchMapWithMove k (Event t v) -> NodeInfo k v)
-> Event t (NodeInfo k v))
-> (PatchMapWithMove k (Event t v) -> NodeInfo k v)
-> Event t (NodeInfo k v)
forall a b. (a -> b) -> a -> b
$ \PatchMapWithMove k (Event t v)
_ ->
NodeInfo k (Event t v)
ni { _nodeInfo_from :: From k v
PatchMapWithMove._nodeInfo_from = From k v
forall k v. From k v
PatchMapWithMove.From_Delete }
PatchMapWithMove.From_Move k
k -> Event t (PatchMapWithMove k (Event t v))
-> (PatchMapWithMove k (Event t v) -> NodeInfo k v)
-> Event t (NodeInfo k v)
forall {k} (t :: k) a b.
Reflex t =>
Event t a -> (a -> b) -> Event t b
fforCheap Event t (PatchMapWithMove k (Event t v))
e ((PatchMapWithMove k (Event t v) -> NodeInfo k v)
-> Event t (NodeInfo k v))
-> (PatchMapWithMove k (Event t v) -> NodeInfo k v)
-> Event t (NodeInfo k v)
forall a b. (a -> b) -> a -> b
$ \PatchMapWithMove k (Event t v)
_ ->
NodeInfo k (Event t v)
ni { _nodeInfo_from :: From k v
PatchMapWithMove._nodeInfo_from = k -> From k v
forall k v. k -> From k v
PatchMapWithMove.From_Move k
k }
PatchMapWithMove.From_Insert Event t v
ev -> [Event t (NodeInfo k v)] -> Event t (NodeInfo k v)
forall {k} (t :: k) a. Reflex t => [Event t a] -> Event t a
leftmost
[ Event t v -> (v -> NodeInfo k v) -> Event t (NodeInfo k v)
forall {k} (t :: k) a b.
Reflex t =>
Event t a -> (a -> b) -> Event t b
fforCheap Event t v
ev ((v -> NodeInfo k v) -> Event t (NodeInfo k v))
-> (v -> NodeInfo k v) -> Event t (NodeInfo k v)
forall a b. (a -> b) -> a -> b
$ \v
v ->
NodeInfo k (Event t v)
ni { _nodeInfo_from :: From k v
PatchMapWithMove._nodeInfo_from = v -> From k v
forall v k. v -> From k v
PatchMapWithMove.From_Insert v
v }
, Event t (PatchMapWithMove k (Event t v))
-> (PatchMapWithMove k (Event t v) -> NodeInfo k v)
-> Event t (NodeInfo k v)
forall {k} (t :: k) a b.
Reflex t =>
Event t a -> (a -> b) -> Event t b
fforCheap Event t (PatchMapWithMove k (Event t v))
e ((PatchMapWithMove k (Event t v) -> NodeInfo k v)
-> Event t (NodeInfo k v))
-> (PatchMapWithMove k (Event t v) -> NodeInfo k v)
-> Event t (NodeInfo k v)
forall a b. (a -> b) -> a -> b
$ \PatchMapWithMove k (Event t v)
_ ->
NodeInfo k (Event t v)
ni { _nodeInfo_from :: From k v
PatchMapWithMove._nodeInfo_from = From k v
forall k v. From k v
PatchMapWithMove.From_Delete }
]
switchHoldPromptOnlyIncremental
:: forall t m p pt w
. ( Reflex t
, MonadHold t m
, Patch (p (Event t w))
, PatchTarget (p (Event t w)) ~ pt (Event t w)
, Patch (p w)
, PatchTarget (p w) ~ pt w
, Monoid (pt w)
)
=> (Incremental t (p (Event t w)) -> Event t (pt w))
-> (Event t (p (Event t w)) -> Event t (p w))
-> pt (Event t w)
-> Event t (p (Event t w))
-> m (Event t (pt w))
switchHoldPromptOnlyIncremental :: forall {k} (t :: k) (m :: * -> *) (p :: * -> *) (pt :: * -> *) w.
(Reflex t, MonadHold t m, Patch (p (Event t w)),
PatchTarget (p (Event t w)) ~ pt (Event t w), Patch (p w),
PatchTarget (p w) ~ pt w, Monoid (pt w)) =>
(Incremental t (p (Event t w)) -> Event t (pt w))
-> (Event t (p (Event t w)) -> Event t (p w))
-> pt (Event t w)
-> Event t (p (Event t w))
-> m (Event t (pt w))
switchHoldPromptOnlyIncremental Incremental t (p (Event t w)) -> Event t (pt w)
mergePatchIncremental Event t (p (Event t w)) -> Event t (p w)
coincidencePatch pt (Event t w)
e0 Event t (p (Event t w))
e' = do
Event t (pt w)
lag <- Incremental t (p (Event t w)) -> Event t (pt w)
mergePatchIncremental (Incremental t (p (Event t w)) -> Event t (pt w))
-> m (Incremental t (p (Event t w))) -> m (Event t (pt w))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PatchTarget (p (Event t w))
-> Event t (p (Event t w)) -> m (Incremental t (p (Event t w)))
forall p.
Patch p =>
PatchTarget p -> Event t p -> m (Incremental t p)
forall {k} (t :: k) (m :: * -> *) p.
(MonadHold t m, Patch p) =>
PatchTarget p -> Event t p -> m (Incremental t p)
holdIncremental pt (Event t w)
PatchTarget (p (Event t w))
e0 Event t (p (Event t w))
e'
Event t (pt w) -> m (Event t (pt w))
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Event t (pt w) -> m (Event t (pt w)))
-> Event t (pt w) -> m (Event t (pt w))
forall a b. (a -> b) -> a -> b
$ Event t (These (pt w) (p w))
-> (These (pt w) (p w) -> pt w) -> Event t (pt w)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
ffor (Event t (pt w) -> Event t (p w) -> Event t (These (pt w) (p w))
forall a b. Event t a -> Event t b -> Event t (These a b)
forall (f :: * -> *) a b.
Semialign f =>
f a -> f b -> f (These a b)
align Event t (pt w)
lag (Event t (p (Event t w)) -> Event t (p w)
coincidencePatch Event t (p (Event t w))
e')) ((These (pt w) (p w) -> pt w) -> Event t (pt w))
-> (These (pt w) (p w) -> pt w) -> Event t (pt w)
forall a b. (a -> b) -> a -> b
$ \case
This pt w
old -> pt w
old
That p w
new -> p w
new p w -> PatchTarget (p w) -> PatchTarget (p w)
forall p. Patch p => p -> PatchTarget p -> PatchTarget p
`applyAlways` pt w
PatchTarget (p w)
forall a. Monoid a => a
mempty
These pt w
old p w
new -> p w
new p w -> PatchTarget (p w) -> PatchTarget (p w)
forall p. Patch p => p -> PatchTarget p -> PatchTarget p
`applyAlways` pt w
PatchTarget (p w)
old
instance Reflex t => Align (Event t) where
nil :: forall a. Event t a
nil = Event t a
forall a. Event t a
forall {k} (t :: k) a. Reflex t => Event t a
never
#if MIN_VERSION_these(0, 8, 0)
instance Reflex t => Semialign (Event t) where
#endif
align :: forall a b. Event t a -> Event t b -> Event t (These a b)
align = (These a b -> Maybe (These a b))
-> Event t a -> Event t b -> Event t (These a b)
forall {k} (t :: k) a b c.
Reflex t =>
(These a b -> Maybe c) -> Event t a -> Event t b -> Event t c
alignEventWithMaybe These a b -> Maybe (These a b)
forall a. a -> Maybe a
Just
#ifdef MIN_VERSION_semialign
#if MIN_VERSION_semialign(1,1,0)
instance Reflex t => Zip (Event t) where
#endif
zip :: forall a b. Event t a -> Event t b -> Event t (a, b)
zip Event t a
x Event t b
y = (These a b -> Maybe (a, b))
-> Event t (These a b) -> Event t (a, b)
forall a b. (a -> Maybe b) -> Event t a -> Event t b
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe These a b -> Maybe (a, b)
forall a b. These a b -> Maybe (a, b)
justThese (Event t (These a b) -> Event t (a, b))
-> Event t (These a b) -> Event t (a, b)
forall a b. (a -> b) -> a -> b
$ Event t a -> Event t b -> Event t (These a b)
forall a b. Event t a -> Event t b -> Event t (These a b)
forall (f :: * -> *) a b.
Semialign f =>
f a -> f b -> f (These a b)
align Event t a
x Event t b
y
#endif
#ifdef MIN_VERSION_semialign
#if MIN_VERSION_semialign(1,1,0)
instance Reflex t => Unzip (Event t) where
unzip :: forall a b. Event t (a, b) -> (Event t a, Event t b)
unzip = Event t (a, b) -> (Event t a, Event t b)
forall {k} (t :: k) a b.
Reflex t =>
Event t (a, b) -> (Event t a, Event t b)
splitE
#endif
#endif
gate :: Reflex t => Behavior t Bool -> Event t a -> Event t a
gate :: forall {k} (t :: k) a.
Reflex t =>
Behavior t Bool -> Event t a -> Event t a
gate = (Bool -> a -> Maybe a) -> Behavior t Bool -> Event t a -> Event t a
forall {k} (t :: k) a b c.
Reflex t =>
(a -> b -> Maybe c) -> Behavior t a -> Event t b -> Event t c
attachWithMaybe ((Bool -> a -> Maybe a)
-> Behavior t Bool -> Event t a -> Event t a)
-> (Bool -> a -> Maybe a)
-> Behavior t Bool
-> Event t a
-> Event t a
forall a b. (a -> b) -> a -> b
$ \Bool
allow a
a -> if Bool
allow then a -> Maybe a
forall a. a -> Maybe a
Just a
a else Maybe a
forall a. Maybe a
Nothing
switcher :: (Reflex t, MonadHold t m)
=> Behavior t a -> Event t (Behavior t a) -> m (Behavior t a)
switcher :: forall {k} (t :: k) (m :: * -> *) a.
(Reflex t, MonadHold t m) =>
Behavior t a -> Event t (Behavior t a) -> m (Behavior t a)
switcher Behavior t a
b Event t (Behavior t a)
eb = PullM t a -> Behavior t a
forall a. PullM t a -> Behavior t a
forall {k} (t :: k) a. Reflex t => PullM t a -> Behavior t a
pull (PullM t a -> Behavior t a)
-> (Behavior t (Behavior t a) -> PullM t a)
-> Behavior t (Behavior t a)
-> Behavior t a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Behavior t a -> PullM t a
forall a. Behavior t a -> PullM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample (Behavior t a -> PullM t a)
-> (Behavior t (Behavior t a) -> PullM t (Behavior t a))
-> Behavior t (Behavior t a)
-> PullM t a
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Behavior t (Behavior t a) -> PullM t (Behavior t a)
forall a. Behavior t a -> PullM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample) (Behavior t (Behavior t a) -> Behavior t a)
-> m (Behavior t (Behavior t a)) -> m (Behavior t a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Behavior t a
-> Event t (Behavior t a) -> m (Behavior t (Behavior t a))
forall a. a -> Event t a -> m (Behavior t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Behavior t a)
hold Behavior t a
b Event t (Behavior t a)
eb
instance (Reflex t, IsString a) => IsString (Dynamic t a) where
fromString :: String -> Dynamic t a
fromString = a -> Dynamic t a
forall a. a -> Dynamic t a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> Dynamic t a) -> (String -> a) -> String -> Dynamic t a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> a
forall a. IsString a => String -> a
fromString
zipDyn :: Reflex t => Dynamic t a -> Dynamic t b -> Dynamic t (a, b)
zipDyn :: forall {k} (t :: k) a b.
Reflex t =>
Dynamic t a -> Dynamic t b -> Dynamic t (a, b)
zipDyn = (a -> b -> (a, b))
-> Dynamic t a -> Dynamic t b -> Dynamic t (a, b)
forall {k} (t :: k) a b c.
Reflex t =>
(a -> b -> c) -> Dynamic t a -> Dynamic t b -> Dynamic t c
zipDynWith (,)
zipDynWith :: Reflex t => (a -> b -> c) -> Dynamic t a -> Dynamic t b -> Dynamic t c
zipDynWith :: forall {k} (t :: k) a b c.
Reflex t =>
(a -> b -> c) -> Dynamic t a -> Dynamic t b -> Dynamic t c
zipDynWith a -> b -> c
f Dynamic t a
da Dynamic t b
db =
let eab :: Event t (These a b)
eab = Event t a -> Event t b -> Event t (These a b)
forall a b. Event t a -> Event t b -> Event t (These a b)
forall (f :: * -> *) a b.
Semialign f =>
f a -> f b -> f (These a b)
align (Dynamic t a -> Event t a
forall a. Dynamic t a -> Event t a
forall {k} (t :: k) a. Reflex t => Dynamic t a -> Event t a
updated Dynamic t a
da) (Dynamic t b -> Event t b
forall a. Dynamic t a -> Event t a
forall {k} (t :: k) a. Reflex t => Dynamic t a -> Event t a
updated Dynamic t b
db)
ec :: Event t c
ec = ((These a b -> PushM t (Maybe c))
-> Event t (These a b) -> Event t c)
-> Event t (These a b)
-> (These a b -> PushM t (Maybe c))
-> Event t c
forall a b c. (a -> b -> c) -> b -> a -> c
flip (These a b -> PushM t (Maybe c))
-> Event t (These a b) -> Event t c
forall {k} (t :: k) a b.
Reflex t =>
(a -> PushM t (Maybe b)) -> Event t a -> Event t b
forall a b. (a -> PushM t (Maybe b)) -> Event t a -> Event t b
push Event t (These a b)
eab ((These a b -> PushM t (Maybe c)) -> Event t c)
-> (These a b -> PushM t (Maybe c)) -> Event t c
forall a b. (a -> b) -> a -> b
$ \These a b
o -> do
(a
a, b
b) <- case These a b
o of
This a
a -> do
b
b <- Behavior t b -> PushM t b
forall a. Behavior t a -> PushM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample (Behavior t b -> PushM t b) -> Behavior t b -> PushM t b
forall a b. (a -> b) -> a -> b
$ Dynamic t b -> Behavior t b
forall a. Dynamic t a -> Behavior t a
forall {k} (t :: k) a. Reflex t => Dynamic t a -> Behavior t a
current Dynamic t b
db
(a, b) -> PushM t (a, b)
forall a. a -> PushM t a
forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, b
b)
That b
b -> do
a
a <- Behavior t a -> PushM t a
forall a. Behavior t a -> PushM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample (Behavior t a -> PushM t a) -> Behavior t a -> PushM t a
forall a b. (a -> b) -> a -> b
$ Dynamic t a -> Behavior t a
forall a. Dynamic t a -> Behavior t a
forall {k} (t :: k) a. Reflex t => Dynamic t a -> Behavior t a
current Dynamic t a
da
(a, b) -> PushM t (a, b)
forall a. a -> PushM t a
forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, b
b)
These a
a b
b -> (a, b) -> PushM t (a, b)
forall a. a -> PushM t a
forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, b
b)
Maybe c -> PushM t (Maybe c)
forall a. a -> PushM t a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe c -> PushM t (Maybe c)) -> Maybe c -> PushM t (Maybe c)
forall a b. (a -> b) -> a -> b
$ c -> Maybe c
forall a. a -> Maybe a
Just (c -> Maybe c) -> c -> Maybe c
forall a b. (a -> b) -> a -> b
$ a -> b -> c
f a
a b
b
in PullM t c -> Event t c -> Dynamic t c
forall a. PullM t a -> Event t a -> Dynamic t a
forall {k} (t :: k) a.
Reflex t =>
PullM t a -> Event t a -> Dynamic t a
unsafeBuildDynamic (a -> b -> c
f (a -> b -> c) -> PullM t a -> PullM t (b -> c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Behavior t a -> PullM t a
forall a. Behavior t a -> PullM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample (Dynamic t a -> Behavior t a
forall a. Dynamic t a -> Behavior t a
forall {k} (t :: k) a. Reflex t => Dynamic t a -> Behavior t a
current Dynamic t a
da) PullM t (b -> c) -> PullM t b -> PullM t c
forall a b. PullM t (a -> b) -> PullM t a -> PullM t b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Behavior t b -> PullM t b
forall a. Behavior t a -> PullM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample (Dynamic t b -> Behavior t b
forall a. Dynamic t a -> Behavior t a
forall {k} (t :: k) a. Reflex t => Dynamic t a -> Behavior t a
current Dynamic t b
db)) Event t c
ec
instance (Reflex t, Semigroup a) => Semigroup (Dynamic t a) where
<> :: Dynamic t a -> Dynamic t a -> Dynamic t a
(<>) = (a -> a -> a) -> Dynamic t a -> Dynamic t a -> Dynamic t a
forall {k} (t :: k) a b c.
Reflex t =>
(a -> b -> c) -> Dynamic t a -> Dynamic t b -> Dynamic t c
zipDynWith a -> a -> a
forall a. Semigroup a => a -> a -> a
(<>)
stimes :: forall b. Integral b => b -> Dynamic t a -> Dynamic t a
stimes b
n = (a -> a) -> Dynamic t a -> Dynamic t a
forall a b. (a -> b) -> Dynamic t a -> Dynamic t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((a -> a) -> Dynamic t a -> Dynamic t a)
-> (a -> a) -> Dynamic t a -> Dynamic t a
forall a b. (a -> b) -> a -> b
$ b -> a -> a
forall b. Integral b => b -> a -> a
forall a b. (Semigroup a, Integral b) => b -> a -> a
stimes b
n
instance (Reflex t, Monoid a) => Monoid (Dynamic t a) where
mconcat :: [Dynamic t a] -> Dynamic t a
mconcat = ([a] -> a) -> [Dynamic t a] -> Dynamic t a
forall {k} (t :: k) a b.
Reflex t =>
([a] -> b) -> [Dynamic t a] -> Dynamic t b
distributeListOverDynWith [a] -> a
forall a. Monoid a => [a] -> a
mconcat
mempty :: Dynamic t a
mempty = a -> Dynamic t a
forall {k} (t :: k) a. Reflex t => a -> Dynamic t a
constDyn a
forall a. Monoid a => a
mempty
mappend :: Dynamic t a -> Dynamic t a -> Dynamic t a
mappend = (a -> a -> a) -> Dynamic t a -> Dynamic t a -> Dynamic t a
forall {k} (t :: k) a b c.
Reflex t =>
(a -> b -> c) -> Dynamic t a -> Dynamic t b -> Dynamic t c
zipDynWith a -> a -> a
forall a. Monoid a => a -> a -> a
mappend
distributeDMapOverDynPure :: forall t k. (Reflex t, GCompare k) => DMap k (Dynamic t) -> Dynamic t (DMap k Identity)
distributeDMapOverDynPure :: forall {k} (t :: k) (k :: * -> *).
(Reflex t, GCompare k) =>
DMap k (Dynamic t) -> Dynamic t (DMap k Identity)
distributeDMapOverDynPure = (forall a. Dynamic t a -> Dynamic t (Identity a))
-> DMap k (Dynamic t) -> Dynamic t (DMap k Identity)
forall {k} {k} (t :: k) (k :: k -> *) (q :: k -> *) (v :: k -> *).
(Reflex t, GCompare k) =>
(forall (a :: k). q a -> Dynamic t (v a))
-> DMap k q -> Dynamic t (DMap k v)
distributeDMapOverDynPureG Dynamic t a -> Dynamic t (Identity a)
forall a. Dynamic t a -> Dynamic t (Identity a)
forall {k} (t :: k) a b.
(Reflex t, Coercible a b) =>
Dynamic t a -> Dynamic t b
coerceDynamic
distributeDMapOverDynPureG
:: forall t k q v. (Reflex t, GCompare k)
=> (forall a. q a -> Dynamic t (v a))
-> DMap k q -> Dynamic t (DMap k v)
distributeDMapOverDynPureG :: forall {k} {k} (t :: k) (k :: k -> *) (q :: k -> *) (v :: k -> *).
(Reflex t, GCompare k) =>
(forall (a :: k). q a -> Dynamic t (v a))
-> DMap k q -> Dynamic t (DMap k v)
distributeDMapOverDynPureG forall (a :: k). q a -> Dynamic t (v a)
nt DMap k q
dm = case DMap k q -> [DSum k q]
forall {k1} (k2 :: k1 -> *) (f :: k1 -> *).
DMap k2 f -> [DSum k2 f]
DMap.toList DMap k q
dm of
[] -> DMap k v -> Dynamic t (DMap k v)
forall {k} (t :: k) a. Reflex t => a -> Dynamic t a
constDyn DMap k v
forall {k1} (k2 :: k1 -> *) (f :: k1 -> *). DMap k2 f
DMap.empty
[k a
k :=> q a
v] -> k a -> v a -> DMap k v
forall {k1} (k2 :: k1 -> *) (v :: k1) (f :: k1 -> *).
k2 v -> f v -> DMap k2 f
DMap.singleton k a
k (v a -> DMap k v) -> Dynamic t (v a) -> Dynamic t (DMap k v)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> q a -> Dynamic t (v a)
forall (a :: k). q a -> Dynamic t (v a)
nt q a
v
[DSum k q]
_ ->
let getInitial :: PullM t (DMap k v)
getInitial = (forall (v :: k). k v -> q v -> PullM t (v v))
-> DMap k q -> PullM t (DMap k v)
forall {k1} (t :: * -> *) (k2 :: k1 -> *) (f :: k1 -> *)
(g :: k1 -> *).
Applicative t =>
(forall (v :: k1). k2 v -> f v -> t (g v))
-> DMap k2 f -> t (DMap k2 g)
DMap.traverseWithKey (\k v
_ -> Behavior t (v v) -> PullM t (v v)
forall a. Behavior t a -> PullM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample (Behavior t (v v) -> PullM t (v v))
-> (q v -> Behavior t (v v)) -> q v -> PullM t (v v)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dynamic t (v v) -> Behavior t (v v)
forall a. Dynamic t a -> Behavior t a
forall {k} (t :: k) a. Reflex t => Dynamic t a -> Behavior t a
current (Dynamic t (v v) -> Behavior t (v v))
-> (q v -> Dynamic t (v v)) -> q v -> Behavior t (v v)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. q v -> Dynamic t (v v)
forall (a :: k). q a -> Dynamic t (v a)
nt) DMap k q
dm
edmPre :: Event t (DMap k v)
edmPre = (forall (a :: k). Compose (Event t) v a -> Event t (v a))
-> DMap k (Compose (Event t) v) -> Event t (DMap k v)
forall {k} (t :: k) {k} (k :: k -> *) (q :: k -> *) (v :: k -> *).
(Reflex t, GCompare k) =>
(forall (a :: k). q a -> Event t (v a))
-> DMap k q -> Event t (DMap k v)
forall {k} (k :: k -> *) (q :: k -> *) (v :: k -> *).
GCompare k =>
(forall (a :: k). q a -> Event t (v a))
-> DMap k q -> Event t (DMap k v)
mergeG Compose (Event t) v a -> Event t (v a)
forall (a :: k). Compose (Event t) v a -> Event t (v a)
forall {k1} {k2} (f :: k1 -> *) (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose (DMap k (Compose (Event t) v) -> Event t (DMap k v))
-> DMap k (Compose (Event t) v) -> Event t (DMap k v)
forall a b. (a -> b) -> a -> b
$ (forall (v :: k). q v -> Compose (Event t) v v)
-> DMap k q -> DMap k (Compose (Event t) v)
forall {k1} (f :: k1 -> *) (g :: k1 -> *) (k2 :: k1 -> *).
(forall (v :: k1). f v -> g v) -> DMap k2 f -> DMap k2 g
DMap.map (Event t (v v) -> Compose (Event t) v v
forall {k} {k1} (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose (Event t (v v) -> Compose (Event t) v v)
-> (q v -> Event t (v v)) -> q v -> Compose (Event t) v v
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dynamic t (v v) -> Event t (v v)
forall a. Dynamic t a -> Event t a
forall {k} (t :: k) a. Reflex t => Dynamic t a -> Event t a
updated (Dynamic t (v v) -> Event t (v v))
-> (q v -> Dynamic t (v v)) -> q v -> Event t (v v)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. q v -> Dynamic t (v v)
forall (a :: k). q a -> Dynamic t (v a)
nt) DMap k q
dm
result :: Dynamic t (DMap k v)
result = PullM t (DMap k v) -> Event t (DMap k v) -> Dynamic t (DMap k v)
forall a. PullM t a -> Event t a -> Dynamic t a
forall {k} (t :: k) a.
Reflex t =>
PullM t a -> Event t a -> Dynamic t a
unsafeBuildDynamic PullM t (DMap k v)
getInitial (Event t (DMap k v) -> Dynamic t (DMap k v))
-> Event t (DMap k v) -> Dynamic t (DMap k v)
forall a b. (a -> b) -> a -> b
$ ((DMap k v -> PushM t (DMap k v))
-> Event t (DMap k v) -> Event t (DMap k v))
-> Event t (DMap k v)
-> (DMap k v -> PushM t (DMap k v))
-> Event t (DMap k v)
forall a b c. (a -> b -> c) -> b -> a -> c
flip (DMap k v -> PushM t (DMap k v))
-> Event t (DMap k v) -> Event t (DMap k v)
forall {k} (t :: k) a b.
Reflex t =>
(a -> PushM t b) -> Event t a -> Event t b
pushAlways Event t (DMap k v)
edmPre ((DMap k v -> PushM t (DMap k v)) -> Event t (DMap k v))
-> (DMap k v -> PushM t (DMap k v)) -> Event t (DMap k v)
forall a b. (a -> b) -> a -> b
$ \DMap k v
news -> do
DMap k v
olds <- Behavior t (DMap k v) -> PushM t (DMap k v)
forall a. Behavior t a -> PushM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample (Behavior t (DMap k v) -> PushM t (DMap k v))
-> Behavior t (DMap k v) -> PushM t (DMap k v)
forall a b. (a -> b) -> a -> b
$ Dynamic t (DMap k v) -> Behavior t (DMap k v)
forall a. Dynamic t a -> Behavior t a
forall {k} (t :: k) a. Reflex t => Dynamic t a -> Behavior t a
current Dynamic t (DMap k v)
result
DMap k v -> PushM t (DMap k v)
forall a. a -> PushM t a
forall (m :: * -> *) a. Monad m => a -> m a
return (DMap k v -> PushM t (DMap k v)) -> DMap k v -> PushM t (DMap k v)
forall a b. (a -> b) -> a -> b
$ (forall (v :: k). k v -> v v -> v v -> v v)
-> DMap k v -> DMap k v -> DMap k v
forall {k1} (k2 :: k1 -> *) (f :: k1 -> *).
GCompare k2 =>
(forall (v :: k1). k2 v -> f v -> f v -> f v)
-> DMap k2 f -> DMap k2 f -> DMap k2 f
DMap.unionWithKey (\k v
_ v v
_ v v
new -> v v
new) DMap k v
olds DMap k v
news
in Dynamic t (DMap k v)
result
distributeListOverDyn :: Reflex t => [Dynamic t a] -> Dynamic t [a]
distributeListOverDyn :: forall {k} (t :: k) a. Reflex t => [Dynamic t a] -> Dynamic t [a]
distributeListOverDyn = ([a] -> [a]) -> [Dynamic t a] -> Dynamic t [a]
forall {k} (t :: k) a b.
Reflex t =>
([a] -> b) -> [Dynamic t a] -> Dynamic t b
distributeListOverDynWith [a] -> [a]
forall a. a -> a
id
distributeListOverDynWith :: Reflex t => ([a] -> b) -> [Dynamic t a] -> Dynamic t b
distributeListOverDynWith :: forall {k} (t :: k) a b.
Reflex t =>
([a] -> b) -> [Dynamic t a] -> Dynamic t b
distributeListOverDynWith [a] -> b
f =
(DMap (Const2 Int a) Identity -> b)
-> Dynamic t (DMap (Const2 Int a) Identity) -> Dynamic t b
forall a b. (a -> b) -> Dynamic t a -> Dynamic t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ([a] -> b
f ([a] -> b)
-> (DMap (Const2 Int a) Identity -> [a])
-> DMap (Const2 Int a) Identity
-> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (DSum (Const2 Int a) Identity -> a)
-> [DSum (Const2 Int a) Identity] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map DSum (Const2 Int a) Identity -> a
forall a. DSum (Const2 Int a) Identity -> a
fromDSum ([DSum (Const2 Int a) Identity] -> [a])
-> (DMap (Const2 Int a) Identity -> [DSum (Const2 Int a) Identity])
-> DMap (Const2 Int a) Identity
-> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DMap (Const2 Int a) Identity -> [DSum (Const2 Int a) Identity]
forall {k1} (k2 :: k1 -> *) (f :: k1 -> *).
DMap k2 f -> [DSum k2 f]
DMap.toAscList) (Dynamic t (DMap (Const2 Int a) Identity) -> Dynamic t b)
-> ([Dynamic t a] -> Dynamic t (DMap (Const2 Int a) Identity))
-> [Dynamic t a]
-> Dynamic t b
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
DMap (Const2 Int a) (Dynamic t)
-> Dynamic t (DMap (Const2 Int a) Identity)
forall {k} (t :: k) (k :: * -> *).
(Reflex t, GCompare k) =>
DMap k (Dynamic t) -> Dynamic t (DMap k Identity)
distributeDMapOverDynPure (DMap (Const2 Int a) (Dynamic t)
-> Dynamic t (DMap (Const2 Int a) Identity))
-> ([Dynamic t a] -> DMap (Const2 Int a) (Dynamic t))
-> [Dynamic t a]
-> Dynamic t (DMap (Const2 Int a) Identity)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
[DSum (Const2 Int a) (Dynamic t)]
-> DMap (Const2 Int a) (Dynamic t)
forall {k1} (k2 :: k1 -> *) (f :: k1 -> *).
[DSum k2 f] -> DMap k2 f
DMap.fromDistinctAscList ([DSum (Const2 Int a) (Dynamic t)]
-> DMap (Const2 Int a) (Dynamic t))
-> ([Dynamic t a] -> [DSum (Const2 Int a) (Dynamic t)])
-> [Dynamic t a]
-> DMap (Const2 Int a) (Dynamic t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
(Int -> Dynamic t a -> DSum (Const2 Int a) (Dynamic t))
-> [Int] -> [Dynamic t a] -> [DSum (Const2 Int a) (Dynamic t)]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
forall (f :: * -> *) a b c.
Zip f =>
(a -> b -> c) -> f a -> f b -> f c
zipWith Int -> Dynamic t a -> DSum (Const2 Int a) (Dynamic t)
forall {k} (t :: k) a.
Int -> Dynamic t a -> DSum (Const2 Int a) (Dynamic t)
toDSum [Int
0..]
where
toDSum :: Int -> Dynamic t a -> DSum (Const2 Int a) (Dynamic t)
toDSum :: forall {k} (t :: k) a.
Int -> Dynamic t a -> DSum (Const2 Int a) (Dynamic t)
toDSum Int
k Dynamic t a
v = Int -> Const2 Int a a
forall {x} a (b :: x). a -> Const2 a b b
Const2 Int
k Const2 Int a a -> Dynamic t a -> DSum (Const2 Int a) (Dynamic t)
forall {k} (tag :: k -> *) (f :: k -> *) (a :: k).
tag a -> f a -> DSum tag f
:=> Dynamic t a
v
fromDSum :: DSum (Const2 Int a) Identity -> a
fromDSum :: forall a. DSum (Const2 Int a) Identity -> a
fromDSum (Const2 Int
_ :=> Identity a
v) = a
a
v
difference :: Reflex t => Event t a -> Event t b -> Event t a
difference :: forall {k} (t :: k) a b.
Reflex t =>
Event t a -> Event t b -> Event t a
difference = (These a b -> Maybe a) -> Event t a -> Event t b -> Event t a
forall {k} (t :: k) a b c.
Reflex t =>
(These a b -> Maybe c) -> Event t a -> Event t b -> Event t c
alignEventWithMaybe ((These a b -> Maybe a) -> Event t a -> Event t b -> Event t a)
-> (These a b -> Maybe a) -> Event t a -> Event t b -> Event t a
forall a b. (a -> b) -> a -> b
$ \case
This a
a -> a -> Maybe a
forall a. a -> Maybe a
Just a
a
These a b
_ -> Maybe a
forall a. Maybe a
Nothing
alignEventWithMaybe :: Reflex t => (These a b -> Maybe c) -> Event t a -> Event t b -> Event t c
alignEventWithMaybe :: forall {k} (t :: k) a b c.
Reflex t =>
(These a b -> Maybe c) -> Event t a -> Event t b -> Event t c
alignEventWithMaybe These a b -> Maybe c
f Event t a
ea Event t b
eb = (DMap (EitherTag a b) Identity -> Maybe c)
-> Event t (DMap (EitherTag a b) Identity) -> Event t c
forall a b. (a -> Maybe b) -> Event t a -> Event t b
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe (These a b -> Maybe c
f (These a b -> Maybe c)
-> (DMap (EitherTag a b) Identity -> Maybe (These a b))
-> DMap (EitherTag a b) Identity
-> Maybe c
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< DMap (EitherTag a b) Identity -> Maybe (These a b)
forall a b. DMap (EitherTag a b) Identity -> Maybe (These a b)
dmapToThese) (Event t (DMap (EitherTag a b) Identity) -> Event t c)
-> Event t (DMap (EitherTag a b) Identity) -> Event t c
forall a b. (a -> b) -> a -> b
$
DMap (EitherTag a b) (Event t)
-> Event t (DMap (EitherTag a b) Identity)
forall {k} (t :: k) (k :: * -> *).
(Reflex t, GCompare k) =>
DMap k (Event t) -> Event t (DMap k Identity)
merge (DMap (EitherTag a b) (Event t)
-> Event t (DMap (EitherTag a b) Identity))
-> DMap (EitherTag a b) (Event t)
-> Event t (DMap (EitherTag a b) Identity)
forall a b. (a -> b) -> a -> b
$ [DSum (EitherTag a b) (Event t)] -> DMap (EitherTag a b) (Event t)
forall {k1} (k2 :: k1 -> *) (f :: k1 -> *).
GCompare k2 =>
[DSum k2 f] -> DMap k2 f
DMap.fromList [EitherTag a b a
forall {k} (l :: k) (r :: k). EitherTag l r l
LeftTag EitherTag a b a -> Event t a -> DSum (EitherTag a b) (Event t)
forall {k} (tag :: k -> *) (f :: k -> *) (a :: k).
tag a -> f a -> DSum tag f
:=> Event t a
ea, EitherTag a b b
forall {k} (l :: k) (r :: k). EitherTag l r r
RightTag EitherTag a b b -> Event t b -> DSum (EitherTag a b) (Event t)
forall {k} (tag :: k -> *) (f :: k -> *) (a :: k).
tag a -> f a -> DSum tag f
:=> Event t b
eb]
filterEventKey
:: forall t m k v a.
( Reflex t
, MonadFix m
, MonadHold t m
, GEq k
)
=> k a
-> Event t (DSum k v)
-> m (Event t (v a))
filterEventKey :: forall {k} {k} (t :: k) (m :: * -> *) (k :: k -> *) (v :: k -> *)
(a :: k).
(Reflex t, MonadFix m, MonadHold t m, GEq k) =>
k a -> Event t (DSum k v) -> m (Event t (v a))
filterEventKey k a
k Event t (DSum k v)
kv' = do
let f :: DSum k v -> Maybe (v a)
f :: DSum k v -> Maybe (v a)
f (k a
newK :=> v a
newV) = case k a
newK k a -> k a -> Maybe (a :~: a)
forall (a :: k) (b :: k). k a -> k b -> Maybe (a :~: b)
forall k (f :: k -> *) (a :: k) (b :: k).
GEq f =>
f a -> f b -> Maybe (a :~: b)
`geq` k a
k of
Just a :~: a
Refl -> v a -> Maybe (v a)
forall a. a -> Maybe a
Just v a
v a
newV
Maybe (a :~: a)
Nothing -> Maybe (v a)
forall a. Maybe a
Nothing
(DSum k v -> Maybe (v a))
-> Event t (DSum k v) -> m (Event t (v a))
forall {k} (t :: k) (m :: * -> *) a b.
(Reflex t, MonadFix m, MonadHold t m) =>
(a -> Maybe b) -> Event t a -> m (Event t b)
takeWhileJustE DSum k v -> Maybe (v a)
f Event t (DSum k v)
kv'
factorEvent
:: forall t m k v a.
( Reflex t
, MonadFix m
, MonadHold t m
, GEq k
)
=> k a
-> Event t (DSum k v)
-> m (Event t (v a), Event t (DSum k (Product v (Compose (Event t) v))))
factorEvent :: forall {k} {k1} (t :: k) (m :: * -> *) (k :: k1 -> *)
(v :: k1 -> *) (a :: k1).
(Reflex t, MonadFix m, MonadHold t m, GEq k) =>
k a
-> Event t (DSum k v)
-> m (Event t (v a),
Event t (DSum k (Product v (Compose (Event t) v))))
factorEvent k a
k0 Event t (DSum k v)
kv' = do
Behavior t (Some k)
key :: Behavior t (Some k) <- Some k -> Event t (Some k) -> m (Behavior t (Some k))
forall a. a -> Event t a -> m (Behavior t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Behavior t a)
hold (k a -> Some k
forall {k} (tag :: k -> *) (a :: k). tag a -> Some tag
Some k a
k0) (Event t (Some k) -> m (Behavior t (Some k)))
-> Event t (Some k) -> m (Behavior t (Some k))
forall a b. (a -> b) -> a -> b
$ (DSum k v -> Some k) -> Event t (DSum k v) -> Event t (Some k)
forall {k} (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap (\(k a
k :=> v a
_) -> k a -> Some k
forall {k} (tag :: k -> *) (a :: k). tag a -> Some tag
Some k a
k) Event t (DSum k v)
kv'
let update :: Event t (DSum k (Product v (Compose (Event t) v)))
update = ((DSum k v
-> PushM t (Maybe (DSum k (Product v (Compose (Event t) v)))))
-> Event t (DSum k v)
-> Event t (DSum k (Product v (Compose (Event t) v))))
-> Event t (DSum k v)
-> (DSum k v
-> PushM t (Maybe (DSum k (Product v (Compose (Event t) v)))))
-> Event t (DSum k (Product v (Compose (Event t) v)))
forall a b c. (a -> b -> c) -> b -> a -> c
flip (DSum k v
-> PushM t (Maybe (DSum k (Product v (Compose (Event t) v)))))
-> Event t (DSum k v)
-> Event t (DSum k (Product v (Compose (Event t) v)))
forall {k} (t :: k) a b.
Reflex t =>
(a -> PushM t (Maybe b)) -> Event t a -> Event t b
forall a b. (a -> PushM t (Maybe b)) -> Event t a -> Event t b
push Event t (DSum k v)
kv' ((DSum k v
-> PushM t (Maybe (DSum k (Product v (Compose (Event t) v)))))
-> Event t (DSum k (Product v (Compose (Event t) v))))
-> (DSum k v
-> PushM t (Maybe (DSum k (Product v (Compose (Event t) v)))))
-> Event t (DSum k (Product v (Compose (Event t) v)))
forall a b. (a -> b) -> a -> b
$ \(k a
newKey :=> v a
newVal) -> Behavior t (Some k) -> PushM t (Some k)
forall a. Behavior t a -> PushM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample Behavior t (Some k)
key PushM t (Some k)
-> (Some k
-> PushM t (Maybe (DSum k (Product v (Compose (Event t) v)))))
-> PushM t (Maybe (DSum k (Product v (Compose (Event t) v))))
forall a b. PushM t a -> (a -> PushM t b) -> PushM t b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Some k a
oldKey -> case k a
newKey k a -> k a -> Maybe (a :~: a)
forall (a :: k1) (b :: k1). k a -> k b -> Maybe (a :~: b)
forall k (f :: k -> *) (a :: k) (b :: k).
GEq f =>
f a -> f b -> Maybe (a :~: b)
`geq` k a
oldKey of
Just a :~: a
Refl -> Maybe (DSum k (Product v (Compose (Event t) v)))
-> PushM t (Maybe (DSum k (Product v (Compose (Event t) v))))
forall a. a -> PushM t a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (DSum k (Product v (Compose (Event t) v)))
forall a. Maybe a
Nothing
Maybe (a :~: a)
Nothing -> do
Event t (v a)
newInner <- k a -> Event t (DSum k v) -> PushM t (Event t (v a))
forall {k} {k} (t :: k) (m :: * -> *) (k :: k -> *) (v :: k -> *)
(a :: k).
(Reflex t, MonadFix m, MonadHold t m, GEq k) =>
k a -> Event t (DSum k v) -> m (Event t (v a))
filterEventKey k a
newKey Event t (DSum k v)
kv'
Maybe (DSum k (Product v (Compose (Event t) v)))
-> PushM t (Maybe (DSum k (Product v (Compose (Event t) v))))
forall a. a -> PushM t a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (DSum k (Product v (Compose (Event t) v)))
-> PushM t (Maybe (DSum k (Product v (Compose (Event t) v)))))
-> Maybe (DSum k (Product v (Compose (Event t) v)))
-> PushM t (Maybe (DSum k (Product v (Compose (Event t) v))))
forall a b. (a -> b) -> a -> b
$ DSum k (Product v (Compose (Event t) v))
-> Maybe (DSum k (Product v (Compose (Event t) v)))
forall a. a -> Maybe a
Just (DSum k (Product v (Compose (Event t) v))
-> Maybe (DSum k (Product v (Compose (Event t) v))))
-> DSum k (Product v (Compose (Event t) v))
-> Maybe (DSum k (Product v (Compose (Event t) v)))
forall a b. (a -> b) -> a -> b
$ k a
newKey k a
-> Product v (Compose (Event t) v) a
-> DSum k (Product v (Compose (Event t) v))
forall {k} (tag :: k -> *) (f :: k -> *) (a :: k).
tag a -> f a -> DSum tag f
:=> v a -> Compose (Event t) v a -> Product v (Compose (Event t) v) a
forall {k} (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Pair v a
newVal (Event t (v a) -> Compose (Event t) v a
forall {k} {k1} (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose Event t (v a)
newInner)
Event t (v a)
eInitial <- k a -> Event t (DSum k v) -> m (Event t (v a))
forall {k} {k} (t :: k) (m :: * -> *) (k :: k -> *) (v :: k -> *)
(a :: k).
(Reflex t, MonadFix m, MonadHold t m, GEq k) =>
k a -> Event t (DSum k v) -> m (Event t (v a))
filterEventKey k a
k0 Event t (DSum k v)
kv'
(Event t (v a), Event t (DSum k (Product v (Compose (Event t) v))))
-> m (Event t (v a),
Event t (DSum k (Product v (Compose (Event t) v))))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Event t (v a)
eInitial, Event t (DSum k (Product v (Compose (Event t) v)))
update)
#if __GLASGOW_HASKELL__ < 802
{-# WARNING accum "ghc < 8.2.1 doesn't seem to be able to specialize functions in this class, which can lead to poor performance" #-}
{-# WARNING accumM "ghc < 8.2.1 doesn't seem to be able to specialize functions in this class, which can lead to poor performance" #-}
{-# WARNING accumMaybe "ghc < 8.2.1 doesn't seem to be able to specialize functions in this class, which can lead to poor performance" #-}
{-# WARNING accumMaybeM "ghc < 8.2.1 doesn't seem to be able to specialize functions in this class, which can lead to poor performance" #-}
#endif
class Reflex t => Accumulator t f | f -> t where
accum :: (MonadHold t m, MonadFix m) => (a -> b -> a) -> a -> Event t b -> m (f a)
accum a -> b -> a
f = (a -> b -> Maybe a) -> a -> Event t b -> m (f a)
forall {k} (t :: k) (f :: * -> *) (m :: * -> *) a b.
(Accumulator t f, MonadHold t m, MonadFix m) =>
(a -> b -> Maybe a) -> a -> Event t b -> m (f a)
forall (m :: * -> *) a b.
(MonadHold t m, MonadFix m) =>
(a -> b -> Maybe a) -> a -> Event t b -> m (f a)
accumMaybe ((a -> b -> Maybe a) -> a -> Event t b -> m (f a))
-> (a -> b -> Maybe a) -> a -> Event t b -> m (f a)
forall a b. (a -> b) -> a -> b
$ \a
v b
o -> a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> a -> Maybe a
forall a b. (a -> b) -> a -> b
$ a -> b -> a
f a
v b
o
accumM :: (MonadHold t m, MonadFix m) => (a -> b -> PushM t a) -> a -> Event t b -> m (f a)
accumM a -> b -> PushM t a
f = (a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (f a)
forall {k} (t :: k) (f :: * -> *) (m :: * -> *) a b.
(Accumulator t f, MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (f a)
forall (m :: * -> *) a b.
(MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (f a)
accumMaybeM ((a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (f a))
-> (a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (f a)
forall a b. (a -> b) -> a -> b
$ \a
v b
o -> a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> PushM t a -> PushM t (Maybe a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> b -> PushM t a
f a
v b
o
accumMaybe :: (MonadHold t m, MonadFix m) => (a -> b -> Maybe a) -> a -> Event t b -> m (f a)
accumMaybe a -> b -> Maybe a
f = (a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (f a)
forall {k} (t :: k) (f :: * -> *) (m :: * -> *) a b.
(Accumulator t f, MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (f a)
forall (m :: * -> *) a b.
(MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (f a)
accumMaybeM ((a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (f a))
-> (a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (f a)
forall a b. (a -> b) -> a -> b
$ \a
v b
o -> Maybe a -> PushM t (Maybe a)
forall a. a -> PushM t a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe a -> PushM t (Maybe a)) -> Maybe a -> PushM t (Maybe a)
forall a b. (a -> b) -> a -> b
$ a -> b -> Maybe a
f a
v b
o
accumMaybeM :: (MonadHold t m, MonadFix m) => (a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (f a)
mapAccum :: (MonadHold t m, MonadFix m) => (a -> b -> (a, c)) -> a -> Event t b -> m (f a, Event t c)
mapAccum a -> b -> (a, c)
f = (a -> b -> (Maybe a, Maybe c))
-> a -> Event t b -> m (f a, Event t c)
forall {k} (t :: k) (f :: * -> *) (m :: * -> *) a b c.
(Accumulator t f, MonadHold t m, MonadFix m) =>
(a -> b -> (Maybe a, Maybe c))
-> a -> Event t b -> m (f a, Event t c)
forall (m :: * -> *) a b c.
(MonadHold t m, MonadFix m) =>
(a -> b -> (Maybe a, Maybe c))
-> a -> Event t b -> m (f a, Event t c)
mapAccumMaybe ((a -> b -> (Maybe a, Maybe c))
-> a -> Event t b -> m (f a, Event t c))
-> (a -> b -> (Maybe a, Maybe c))
-> a
-> Event t b
-> m (f a, Event t c)
forall a b. (a -> b) -> a -> b
$ \a
v b
o -> (a -> Maybe a) -> (c -> Maybe c) -> (a, c) -> (Maybe a, Maybe c)
forall a b c d. (a -> b) -> (c -> d) -> (a, c) -> (b, d)
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap a -> Maybe a
forall a. a -> Maybe a
Just c -> Maybe c
forall a. a -> Maybe a
Just ((a, c) -> (Maybe a, Maybe c)) -> (a, c) -> (Maybe a, Maybe c)
forall a b. (a -> b) -> a -> b
$ a -> b -> (a, c)
f a
v b
o
mapAccumM :: (MonadHold t m, MonadFix m) => (a -> b -> PushM t (a, c)) -> a -> Event t b -> m (f a, Event t c)
mapAccumM a -> b -> PushM t (a, c)
f = (a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (f a, Event t c)
forall {k} (t :: k) (f :: * -> *) (m :: * -> *) a b c.
(Accumulator t f, MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (f a, Event t c)
forall (m :: * -> *) a b c.
(MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (f a, Event t c)
mapAccumMaybeM ((a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (f a, Event t c))
-> (a -> b -> PushM t (Maybe a, Maybe c))
-> a
-> Event t b
-> m (f a, Event t c)
forall a b. (a -> b) -> a -> b
$ \a
v b
o -> (a -> Maybe a) -> (c -> Maybe c) -> (a, c) -> (Maybe a, Maybe c)
forall a b c d. (a -> b) -> (c -> d) -> (a, c) -> (b, d)
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap a -> Maybe a
forall a. a -> Maybe a
Just c -> Maybe c
forall a. a -> Maybe a
Just ((a, c) -> (Maybe a, Maybe c))
-> PushM t (a, c) -> PushM t (Maybe a, Maybe c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> b -> PushM t (a, c)
f a
v b
o
mapAccumMaybe :: (MonadHold t m, MonadFix m) => (a -> b -> (Maybe a, Maybe c)) -> a -> Event t b -> m (f a, Event t c)
mapAccumMaybe a -> b -> (Maybe a, Maybe c)
f = (a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (f a, Event t c)
forall {k} (t :: k) (f :: * -> *) (m :: * -> *) a b c.
(Accumulator t f, MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (f a, Event t c)
forall (m :: * -> *) a b c.
(MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (f a, Event t c)
mapAccumMaybeM ((a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (f a, Event t c))
-> (a -> b -> PushM t (Maybe a, Maybe c))
-> a
-> Event t b
-> m (f a, Event t c)
forall a b. (a -> b) -> a -> b
$ \a
v b
o -> (Maybe a, Maybe c) -> PushM t (Maybe a, Maybe c)
forall a. a -> PushM t a
forall (m :: * -> *) a. Monad m => a -> m a
return ((Maybe a, Maybe c) -> PushM t (Maybe a, Maybe c))
-> (Maybe a, Maybe c) -> PushM t (Maybe a, Maybe c)
forall a b. (a -> b) -> a -> b
$ a -> b -> (Maybe a, Maybe c)
f a
v b
o
mapAccumMaybeM :: (MonadHold t m, MonadFix m) => (a -> b -> PushM t (Maybe a, Maybe c)) -> a -> Event t b -> m (f a, Event t c)
accumDyn
:: (Reflex t, MonadHold t m, MonadFix m)
=> (a -> b -> a)
-> a
-> Event t b
-> m (Dynamic t a)
accumDyn :: forall {k} (t :: k) (m :: * -> *) a b.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> a) -> a -> Event t b -> m (Dynamic t a)
accumDyn a -> b -> a
f = (a -> b -> Maybe a) -> a -> Event t b -> m (Dynamic t a)
forall {k} (t :: k) (m :: * -> *) a b.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> Maybe a) -> a -> Event t b -> m (Dynamic t a)
accumMaybeDyn ((a -> b -> Maybe a) -> a -> Event t b -> m (Dynamic t a))
-> (a -> b -> Maybe a) -> a -> Event t b -> m (Dynamic t a)
forall a b. (a -> b) -> a -> b
$ \a
v b
o -> a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> a -> Maybe a
forall a b. (a -> b) -> a -> b
$ a -> b -> a
f a
v b
o
accumMDyn
:: (Reflex t, MonadHold t m, MonadFix m)
=> (a -> b -> PushM t a)
-> a
-> Event t b
-> m (Dynamic t a)
accumMDyn :: forall {k} (t :: k) (m :: * -> *) a b.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> PushM t a) -> a -> Event t b -> m (Dynamic t a)
accumMDyn a -> b -> PushM t a
f = (a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (Dynamic t a)
forall {k} (t :: k) (m :: * -> *) a b.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (Dynamic t a)
accumMaybeMDyn ((a -> b -> PushM t (Maybe a))
-> a -> Event t b -> m (Dynamic t a))
-> (a -> b -> PushM t (Maybe a))
-> a
-> Event t b
-> m (Dynamic t a)
forall a b. (a -> b) -> a -> b
$ \a
v b
o -> a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> PushM t a -> PushM t (Maybe a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> b -> PushM t a
f a
v b
o
accumMaybeDyn
:: (Reflex t, MonadHold t m, MonadFix m)
=> (a -> b -> Maybe a)
-> a
-> Event t b
-> m (Dynamic t a)
accumMaybeDyn :: forall {k} (t :: k) (m :: * -> *) a b.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> Maybe a) -> a -> Event t b -> m (Dynamic t a)
accumMaybeDyn a -> b -> Maybe a
f = (a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (Dynamic t a)
forall {k} (t :: k) (m :: * -> *) a b.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (Dynamic t a)
accumMaybeMDyn ((a -> b -> PushM t (Maybe a))
-> a -> Event t b -> m (Dynamic t a))
-> (a -> b -> PushM t (Maybe a))
-> a
-> Event t b
-> m (Dynamic t a)
forall a b. (a -> b) -> a -> b
$ \a
v b
o -> Maybe a -> PushM t (Maybe a)
forall a. a -> PushM t a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe a -> PushM t (Maybe a)) -> Maybe a -> PushM t (Maybe a)
forall a b. (a -> b) -> a -> b
$ a -> b -> Maybe a
f a
v b
o
accumMaybeMDyn
:: (Reflex t, MonadHold t m, MonadFix m)
=> (a -> b -> PushM t (Maybe a))
-> a
-> Event t b
-> m (Dynamic t a)
accumMaybeMDyn :: forall {k} (t :: k) (m :: * -> *) a b.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (Dynamic t a)
accumMaybeMDyn a -> b -> PushM t (Maybe a)
f a
z Event t b
e = do
rec let e' :: Event t a
e' = ((b -> PushM t (Maybe a)) -> Event t b -> Event t a)
-> Event t b -> (b -> PushM t (Maybe a)) -> Event t a
forall a b c. (a -> b -> c) -> b -> a -> c
flip (b -> PushM t (Maybe a)) -> Event t b -> Event t a
forall {k} (t :: k) a b.
Reflex t =>
(a -> PushM t (Maybe b)) -> Event t a -> Event t b
forall a b. (a -> PushM t (Maybe b)) -> Event t a -> Event t b
push Event t b
e ((b -> PushM t (Maybe a)) -> Event t a)
-> (b -> PushM t (Maybe a)) -> Event t a
forall a b. (a -> b) -> a -> b
$ \b
o -> do
a
v <- Behavior t a -> PushM t a
forall a. Behavior t a -> PushM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample (Behavior t a -> PushM t a) -> Behavior t a -> PushM t a
forall a b. (a -> b) -> a -> b
$ Dynamic t a -> Behavior t a
forall a. Dynamic t a -> Behavior t a
forall {k} (t :: k) a. Reflex t => Dynamic t a -> Behavior t a
current Dynamic t a
d'
a -> b -> PushM t (Maybe a)
f a
v b
o
Dynamic t a
d' <- a -> Event t a -> m (Dynamic t a)
forall a. a -> Event t a -> m (Dynamic t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Dynamic t a)
holdDyn a
z Event t a
e'
Dynamic t a -> m (Dynamic t a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Dynamic t a
d'
mapAccumDyn
:: (Reflex t, MonadHold t m, MonadFix m)
=> (a -> b -> (a, c))
-> a
-> Event t b
-> m (Dynamic t a, Event t c)
mapAccumDyn :: forall {k} (t :: k) (m :: * -> *) a b c.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> (a, c)) -> a -> Event t b -> m (Dynamic t a, Event t c)
mapAccumDyn a -> b -> (a, c)
f = (a -> b -> (Maybe a, Maybe c))
-> a -> Event t b -> m (Dynamic t a, Event t c)
forall {k} (t :: k) (m :: * -> *) a b c.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> (Maybe a, Maybe c))
-> a -> Event t b -> m (Dynamic t a, Event t c)
mapAccumMaybeDyn ((a -> b -> (Maybe a, Maybe c))
-> a -> Event t b -> m (Dynamic t a, Event t c))
-> (a -> b -> (Maybe a, Maybe c))
-> a
-> Event t b
-> m (Dynamic t a, Event t c)
forall a b. (a -> b) -> a -> b
$ \a
v b
o -> (a -> Maybe a) -> (c -> Maybe c) -> (a, c) -> (Maybe a, Maybe c)
forall a b c d. (a -> b) -> (c -> d) -> (a, c) -> (b, d)
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap a -> Maybe a
forall a. a -> Maybe a
Just c -> Maybe c
forall a. a -> Maybe a
Just ((a, c) -> (Maybe a, Maybe c)) -> (a, c) -> (Maybe a, Maybe c)
forall a b. (a -> b) -> a -> b
$ a -> b -> (a, c)
f a
v b
o
mapAccumMDyn
:: (Reflex t, MonadHold t m, MonadFix m)
=> (a -> b -> PushM t (a, c))
-> a
-> Event t b
-> m (Dynamic t a, Event t c)
mapAccumMDyn :: forall {k} (t :: k) (m :: * -> *) a b c.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (a, c))
-> a -> Event t b -> m (Dynamic t a, Event t c)
mapAccumMDyn a -> b -> PushM t (a, c)
f = (a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (Dynamic t a, Event t c)
forall {k} (t :: k) (m :: * -> *) a b c.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (Dynamic t a, Event t c)
mapAccumMaybeMDyn ((a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (Dynamic t a, Event t c))
-> (a -> b -> PushM t (Maybe a, Maybe c))
-> a
-> Event t b
-> m (Dynamic t a, Event t c)
forall a b. (a -> b) -> a -> b
$ \a
v b
o -> (a -> Maybe a) -> (c -> Maybe c) -> (a, c) -> (Maybe a, Maybe c)
forall a b c d. (a -> b) -> (c -> d) -> (a, c) -> (b, d)
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap a -> Maybe a
forall a. a -> Maybe a
Just c -> Maybe c
forall a. a -> Maybe a
Just ((a, c) -> (Maybe a, Maybe c))
-> PushM t (a, c) -> PushM t (Maybe a, Maybe c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> b -> PushM t (a, c)
f a
v b
o
mapAccumMaybeDyn
:: (Reflex t, MonadHold t m, MonadFix m)
=> (a -> b -> (Maybe a, Maybe c))
-> a
-> Event t b
-> m (Dynamic t a, Event t c)
mapAccumMaybeDyn :: forall {k} (t :: k) (m :: * -> *) a b c.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> (Maybe a, Maybe c))
-> a -> Event t b -> m (Dynamic t a, Event t c)
mapAccumMaybeDyn a -> b -> (Maybe a, Maybe c)
f = (a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (Dynamic t a, Event t c)
forall {k} (t :: k) (m :: * -> *) a b c.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (Dynamic t a, Event t c)
mapAccumMaybeMDyn ((a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (Dynamic t a, Event t c))
-> (a -> b -> PushM t (Maybe a, Maybe c))
-> a
-> Event t b
-> m (Dynamic t a, Event t c)
forall a b. (a -> b) -> a -> b
$ \a
v b
o -> (Maybe a, Maybe c) -> PushM t (Maybe a, Maybe c)
forall a. a -> PushM t a
forall (m :: * -> *) a. Monad m => a -> m a
return ((Maybe a, Maybe c) -> PushM t (Maybe a, Maybe c))
-> (Maybe a, Maybe c) -> PushM t (Maybe a, Maybe c)
forall a b. (a -> b) -> a -> b
$ a -> b -> (Maybe a, Maybe c)
f a
v b
o
mapAccumMaybeMDyn
:: (Reflex t, MonadHold t m, MonadFix m)
=> (a -> b -> PushM t (Maybe a, Maybe c))
-> a
-> Event t b
-> m (Dynamic t a, Event t c)
mapAccumMaybeMDyn :: forall {k} (t :: k) (m :: * -> *) a b c.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (Dynamic t a, Event t c)
mapAccumMaybeMDyn a -> b -> PushM t (Maybe a, Maybe c)
f a
z Event t b
e = do
rec let e' :: Event t (Maybe a, Maybe c)
e' = ((b -> PushM t (Maybe (Maybe a, Maybe c)))
-> Event t b -> Event t (Maybe a, Maybe c))
-> Event t b
-> (b -> PushM t (Maybe (Maybe a, Maybe c)))
-> Event t (Maybe a, Maybe c)
forall a b c. (a -> b -> c) -> b -> a -> c
flip (b -> PushM t (Maybe (Maybe a, Maybe c)))
-> Event t b -> Event t (Maybe a, Maybe c)
forall {k} (t :: k) a b.
Reflex t =>
(a -> PushM t (Maybe b)) -> Event t a -> Event t b
forall a b. (a -> PushM t (Maybe b)) -> Event t a -> Event t b
push Event t b
e ((b -> PushM t (Maybe (Maybe a, Maybe c)))
-> Event t (Maybe a, Maybe c))
-> (b -> PushM t (Maybe (Maybe a, Maybe c)))
-> Event t (Maybe a, Maybe c)
forall a b. (a -> b) -> a -> b
$ \b
o -> do
a
v <- Behavior t a -> PushM t a
forall a. Behavior t a -> PushM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample (Behavior t a -> PushM t a) -> Behavior t a -> PushM t a
forall a b. (a -> b) -> a -> b
$ Dynamic t a -> Behavior t a
forall a. Dynamic t a -> Behavior t a
forall {k} (t :: k) a. Reflex t => Dynamic t a -> Behavior t a
current Dynamic t a
d'
(Maybe a, Maybe c)
result <- a -> b -> PushM t (Maybe a, Maybe c)
f a
v b
o
Maybe (Maybe a, Maybe c) -> PushM t (Maybe (Maybe a, Maybe c))
forall a. a -> PushM t a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (Maybe a, Maybe c) -> PushM t (Maybe (Maybe a, Maybe c)))
-> Maybe (Maybe a, Maybe c) -> PushM t (Maybe (Maybe a, Maybe c))
forall a b. (a -> b) -> a -> b
$ case (Maybe a, Maybe c)
result of
(Maybe a
Nothing, Maybe c
Nothing) -> Maybe (Maybe a, Maybe c)
forall a. Maybe a
Nothing
(Maybe a, Maybe c)
_ -> (Maybe a, Maybe c) -> Maybe (Maybe a, Maybe c)
forall a. a -> Maybe a
Just (Maybe a, Maybe c)
result
Dynamic t a
d' <- a -> Event t a -> m (Dynamic t a)
forall a. a -> Event t a -> m (Dynamic t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Dynamic t a)
holdDyn a
z (Event t a -> m (Dynamic t a)) -> Event t a -> m (Dynamic t a)
forall a b. (a -> b) -> a -> b
$ ((Maybe a, Maybe c) -> Maybe a)
-> Event t (Maybe a, Maybe c) -> Event t a
forall a b. (a -> Maybe b) -> Event t a -> Event t b
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe (Maybe a, Maybe c) -> Maybe a
forall a b. (a, b) -> a
fst Event t (Maybe a, Maybe c)
e'
(Dynamic t a, Event t c) -> m (Dynamic t a, Event t c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Dynamic t a
d', ((Maybe a, Maybe c) -> Maybe c)
-> Event t (Maybe a, Maybe c) -> Event t c
forall a b. (a -> Maybe b) -> Event t a -> Event t b
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe (Maybe a, Maybe c) -> Maybe c
forall a b. (a, b) -> b
snd Event t (Maybe a, Maybe c)
e')
{-# INLINE accumB #-}
accumB
:: (Reflex t, MonadHold t m, MonadFix m)
=> (a -> b -> a)
-> a
-> Event t b
-> m (Behavior t a)
accumB :: forall {k} (t :: k) (m :: * -> *) a b.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> a) -> a -> Event t b -> m (Behavior t a)
accumB a -> b -> a
f = (a -> b -> Maybe a) -> a -> Event t b -> m (Behavior t a)
forall {k} (t :: k) (m :: * -> *) a b.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> Maybe a) -> a -> Event t b -> m (Behavior t a)
accumMaybeB ((a -> b -> Maybe a) -> a -> Event t b -> m (Behavior t a))
-> (a -> b -> Maybe a) -> a -> Event t b -> m (Behavior t a)
forall a b. (a -> b) -> a -> b
$ \a
v b
o -> a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> a -> Maybe a
forall a b. (a -> b) -> a -> b
$ a -> b -> a
f a
v b
o
{-# INLINE accumMB #-}
accumMB
:: (Reflex t, MonadHold t m, MonadFix m)
=> (a -> b -> PushM t a)
-> a
-> Event t b
-> m (Behavior t a)
accumMB :: forall {k} (t :: k) (m :: * -> *) a b.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> PushM t a) -> a -> Event t b -> m (Behavior t a)
accumMB a -> b -> PushM t a
f = (a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (Behavior t a)
forall {k} (t :: k) (m :: * -> *) a b.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (Behavior t a)
accumMaybeMB ((a -> b -> PushM t (Maybe a))
-> a -> Event t b -> m (Behavior t a))
-> (a -> b -> PushM t (Maybe a))
-> a
-> Event t b
-> m (Behavior t a)
forall a b. (a -> b) -> a -> b
$ \a
v b
o -> a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> PushM t a -> PushM t (Maybe a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> b -> PushM t a
f a
v b
o
{-# INLINE accumMaybeB #-}
accumMaybeB
:: (Reflex t, MonadHold t m, MonadFix m)
=> (a -> b -> Maybe a)
-> a
-> Event t b
-> m (Behavior t a)
accumMaybeB :: forall {k} (t :: k) (m :: * -> *) a b.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> Maybe a) -> a -> Event t b -> m (Behavior t a)
accumMaybeB a -> b -> Maybe a
f = (a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (Behavior t a)
forall {k} (t :: k) (m :: * -> *) a b.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (Behavior t a)
accumMaybeMB ((a -> b -> PushM t (Maybe a))
-> a -> Event t b -> m (Behavior t a))
-> (a -> b -> PushM t (Maybe a))
-> a
-> Event t b
-> m (Behavior t a)
forall a b. (a -> b) -> a -> b
$ \a
v b
o -> Maybe a -> PushM t (Maybe a)
forall a. a -> PushM t a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe a -> PushM t (Maybe a)) -> Maybe a -> PushM t (Maybe a)
forall a b. (a -> b) -> a -> b
$ a -> b -> Maybe a
f a
v b
o
{-# INLINE accumMaybeMB #-}
accumMaybeMB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (Behavior t a)
accumMaybeMB :: forall {k} (t :: k) (m :: * -> *) a b.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (Behavior t a)
accumMaybeMB a -> b -> PushM t (Maybe a)
f a
z Event t b
e = do
rec let e' :: Event t a
e' = ((b -> PushM t (Maybe a)) -> Event t b -> Event t a)
-> Event t b -> (b -> PushM t (Maybe a)) -> Event t a
forall a b c. (a -> b -> c) -> b -> a -> c
flip (b -> PushM t (Maybe a)) -> Event t b -> Event t a
forall {k} (t :: k) a b.
Reflex t =>
(a -> PushM t (Maybe b)) -> Event t a -> Event t b
forall a b. (a -> PushM t (Maybe b)) -> Event t a -> Event t b
push Event t b
e ((b -> PushM t (Maybe a)) -> Event t a)
-> (b -> PushM t (Maybe a)) -> Event t a
forall a b. (a -> b) -> a -> b
$ \b
o -> do
a
v <- Behavior t a -> PushM t a
forall a. Behavior t a -> PushM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample Behavior t a
d'
a -> b -> PushM t (Maybe a)
f a
v b
o
Behavior t a
d' <- a -> Event t a -> m (Behavior t a)
forall a. a -> Event t a -> m (Behavior t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Behavior t a)
hold a
z Event t a
e'
Behavior t a -> m (Behavior t a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Behavior t a
d'
{-# INLINE mapAccumB #-}
mapAccumB
:: (Reflex t, MonadHold t m, MonadFix m)
=> (a -> b -> (a, c))
-> a
-> Event t b
-> m (Behavior t a, Event t c)
mapAccumB :: forall {k} (t :: k) (m :: * -> *) a b c.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> (a, c)) -> a -> Event t b -> m (Behavior t a, Event t c)
mapAccumB a -> b -> (a, c)
f = (a -> b -> (Maybe a, Maybe c))
-> a -> Event t b -> m (Behavior t a, Event t c)
forall {k} (t :: k) (m :: * -> *) a b c.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> (Maybe a, Maybe c))
-> a -> Event t b -> m (Behavior t a, Event t c)
mapAccumMaybeB ((a -> b -> (Maybe a, Maybe c))
-> a -> Event t b -> m (Behavior t a, Event t c))
-> (a -> b -> (Maybe a, Maybe c))
-> a
-> Event t b
-> m (Behavior t a, Event t c)
forall a b. (a -> b) -> a -> b
$ \a
v b
o -> (a -> Maybe a) -> (c -> Maybe c) -> (a, c) -> (Maybe a, Maybe c)
forall a b c d. (a -> b) -> (c -> d) -> (a, c) -> (b, d)
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap a -> Maybe a
forall a. a -> Maybe a
Just c -> Maybe c
forall a. a -> Maybe a
Just ((a, c) -> (Maybe a, Maybe c)) -> (a, c) -> (Maybe a, Maybe c)
forall a b. (a -> b) -> a -> b
$ a -> b -> (a, c)
f a
v b
o
{-# INLINE mapAccumMB #-}
mapAccumMB
:: (Reflex t, MonadHold t m, MonadFix m)
=> (a -> b -> PushM t (a, c))
-> a
-> Event t b
-> m (Behavior t a, Event t c)
mapAccumMB :: forall {k} (t :: k) (m :: * -> *) a b c.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (a, c))
-> a -> Event t b -> m (Behavior t a, Event t c)
mapAccumMB a -> b -> PushM t (a, c)
f = (a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (Behavior t a, Event t c)
forall {k} (t :: k) (m :: * -> *) a b c.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (Behavior t a, Event t c)
mapAccumMaybeMB ((a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (Behavior t a, Event t c))
-> (a -> b -> PushM t (Maybe a, Maybe c))
-> a
-> Event t b
-> m (Behavior t a, Event t c)
forall a b. (a -> b) -> a -> b
$ \a
v b
o -> (a -> Maybe a) -> (c -> Maybe c) -> (a, c) -> (Maybe a, Maybe c)
forall a b c d. (a -> b) -> (c -> d) -> (a, c) -> (b, d)
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap a -> Maybe a
forall a. a -> Maybe a
Just c -> Maybe c
forall a. a -> Maybe a
Just ((a, c) -> (Maybe a, Maybe c))
-> PushM t (a, c) -> PushM t (Maybe a, Maybe c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> b -> PushM t (a, c)
f a
v b
o
{-# INLINE mapAccumMaybeB #-}
mapAccumMaybeB
:: (Reflex t, MonadHold t m, MonadFix m)
=> (a -> b -> (Maybe a, Maybe c))
-> a
-> Event t b
-> m (Behavior t a, Event t c)
mapAccumMaybeB :: forall {k} (t :: k) (m :: * -> *) a b c.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> (Maybe a, Maybe c))
-> a -> Event t b -> m (Behavior t a, Event t c)
mapAccumMaybeB a -> b -> (Maybe a, Maybe c)
f = (a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (Behavior t a, Event t c)
forall {k} (t :: k) (m :: * -> *) a b c.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (Behavior t a, Event t c)
mapAccumMaybeMB ((a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (Behavior t a, Event t c))
-> (a -> b -> PushM t (Maybe a, Maybe c))
-> a
-> Event t b
-> m (Behavior t a, Event t c)
forall a b. (a -> b) -> a -> b
$ \a
v b
o -> (Maybe a, Maybe c) -> PushM t (Maybe a, Maybe c)
forall a. a -> PushM t a
forall (m :: * -> *) a. Monad m => a -> m a
return ((Maybe a, Maybe c) -> PushM t (Maybe a, Maybe c))
-> (Maybe a, Maybe c) -> PushM t (Maybe a, Maybe c)
forall a b. (a -> b) -> a -> b
$ a -> b -> (Maybe a, Maybe c)
f a
v b
o
{-# INLINE mapAccumMaybeMB #-}
mapAccumMaybeMB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (Maybe a, Maybe c)) -> a -> Event t b -> m (Behavior t a, Event t c)
mapAccumMaybeMB :: forall {k} (t :: k) (m :: * -> *) a b c.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (Behavior t a, Event t c)
mapAccumMaybeMB a -> b -> PushM t (Maybe a, Maybe c)
f a
z Event t b
e = do
rec let e' :: Event t (Maybe a, Maybe c)
e' = ((b -> PushM t (Maybe (Maybe a, Maybe c)))
-> Event t b -> Event t (Maybe a, Maybe c))
-> Event t b
-> (b -> PushM t (Maybe (Maybe a, Maybe c)))
-> Event t (Maybe a, Maybe c)
forall a b c. (a -> b -> c) -> b -> a -> c
flip (b -> PushM t (Maybe (Maybe a, Maybe c)))
-> Event t b -> Event t (Maybe a, Maybe c)
forall {k} (t :: k) a b.
Reflex t =>
(a -> PushM t (Maybe b)) -> Event t a -> Event t b
forall a b. (a -> PushM t (Maybe b)) -> Event t a -> Event t b
push Event t b
e ((b -> PushM t (Maybe (Maybe a, Maybe c)))
-> Event t (Maybe a, Maybe c))
-> (b -> PushM t (Maybe (Maybe a, Maybe c)))
-> Event t (Maybe a, Maybe c)
forall a b. (a -> b) -> a -> b
$ \b
o -> do
a
v <- Behavior t a -> PushM t a
forall a. Behavior t a -> PushM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample Behavior t a
d'
(Maybe a, Maybe c)
result <- a -> b -> PushM t (Maybe a, Maybe c)
f a
v b
o
Maybe (Maybe a, Maybe c) -> PushM t (Maybe (Maybe a, Maybe c))
forall a. a -> PushM t a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (Maybe a, Maybe c) -> PushM t (Maybe (Maybe a, Maybe c)))
-> Maybe (Maybe a, Maybe c) -> PushM t (Maybe (Maybe a, Maybe c))
forall a b. (a -> b) -> a -> b
$ case (Maybe a, Maybe c)
result of
(Maybe a
Nothing, Maybe c
Nothing) -> Maybe (Maybe a, Maybe c)
forall a. Maybe a
Nothing
(Maybe a, Maybe c)
_ -> (Maybe a, Maybe c) -> Maybe (Maybe a, Maybe c)
forall a. a -> Maybe a
Just (Maybe a, Maybe c)
result
Behavior t a
d' <- a -> Event t a -> m (Behavior t a)
forall a. a -> Event t a -> m (Behavior t a)
forall {k} (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Behavior t a)
hold a
z (Event t a -> m (Behavior t a)) -> Event t a -> m (Behavior t a)
forall a b. (a -> b) -> a -> b
$ ((Maybe a, Maybe c) -> Maybe a)
-> Event t (Maybe a, Maybe c) -> Event t a
forall a b. (a -> Maybe b) -> Event t a -> Event t b
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe (Maybe a, Maybe c) -> Maybe a
forall a b. (a, b) -> a
fst Event t (Maybe a, Maybe c)
e'
(Behavior t a, Event t c) -> m (Behavior t a, Event t c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Behavior t a
d', ((Maybe a, Maybe c) -> Maybe c)
-> Event t (Maybe a, Maybe c) -> Event t c
forall a b. (a -> Maybe b) -> Event t a -> Event t b
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe (Maybe a, Maybe c) -> Maybe c
forall a b. (a, b) -> b
snd Event t (Maybe a, Maybe c)
e')
{-# INLINE mapAccum_ #-}
mapAccum_ :: forall t m a b c. (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> (a, c)) -> a -> Event t b -> m (Event t c)
mapAccum_ :: forall {k} (t :: k) (m :: * -> *) a b c.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> (a, c)) -> a -> Event t b -> m (Event t c)
mapAccum_ a -> b -> (a, c)
f a
z Event t b
e = do
(Behavior t a
_, Event t c
result) <- (a -> b -> (a, c)) -> a -> Event t b -> m (Behavior t a, Event t c)
forall {k} (t :: k) (m :: * -> *) a b c.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> (a, c)) -> a -> Event t b -> m (Behavior t a, Event t c)
mapAccumB a -> b -> (a, c)
f a
z Event t b
e
Event t c -> m (Event t c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Event t c
result
{-# INLINE mapAccumMaybe_ #-}
mapAccumMaybe_ :: forall t m a b c. (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> (Maybe a, Maybe c)) -> a -> Event t b -> m (Event t c)
mapAccumMaybe_ :: forall {k} (t :: k) (m :: * -> *) a b c.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> (Maybe a, Maybe c)) -> a -> Event t b -> m (Event t c)
mapAccumMaybe_ a -> b -> (Maybe a, Maybe c)
f a
z Event t b
e = do
(Behavior t a
_, Event t c
result) <- (a -> b -> (Maybe a, Maybe c))
-> a -> Event t b -> m (Behavior t a, Event t c)
forall {k} (t :: k) (m :: * -> *) a b c.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> (Maybe a, Maybe c))
-> a -> Event t b -> m (Behavior t a, Event t c)
mapAccumMaybeB a -> b -> (Maybe a, Maybe c)
f a
z Event t b
e
Event t c -> m (Event t c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Event t c
result
{-# INLINE mapAccumM_ #-}
mapAccumM_ :: forall t m a b c. (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (a, c)) -> a -> Event t b -> m (Event t c)
mapAccumM_ :: forall {k} (t :: k) (m :: * -> *) a b c.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (a, c)) -> a -> Event t b -> m (Event t c)
mapAccumM_ a -> b -> PushM t (a, c)
f a
z Event t b
e = do
(Behavior t a
_, Event t c
result) <- (a -> b -> PushM t (a, c))
-> a -> Event t b -> m (Behavior t a, Event t c)
forall {k} (t :: k) (m :: * -> *) a b c.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (a, c))
-> a -> Event t b -> m (Behavior t a, Event t c)
mapAccumMB a -> b -> PushM t (a, c)
f a
z Event t b
e
Event t c -> m (Event t c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Event t c
result
{-# INLINE mapAccumMaybeM_ #-}
mapAccumMaybeM_ :: forall t m a b c. (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (Maybe a, Maybe c)) -> a -> Event t b -> m (Event t c)
mapAccumMaybeM_ :: forall {k} (t :: k) (m :: * -> *) a b c.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (Event t c)
mapAccumMaybeM_ a -> b -> PushM t (Maybe a, Maybe c)
f a
z Event t b
e = do
(Behavior t a
_, Event t c
result) <- (a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (Behavior t a, Event t c)
forall {k} (t :: k) (m :: * -> *) a b c.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (Behavior t a, Event t c)
mapAccumMaybeMB a -> b -> PushM t (Maybe a, Maybe c)
f a
z Event t b
e
Event t c -> m (Event t c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Event t c
result
instance Reflex t => Accumulator t (Dynamic t) where
accumMaybeM :: forall (m :: * -> *) a b.
(MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (Dynamic t a)
accumMaybeM = (a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (Dynamic t a)
forall {k} (t :: k) (m :: * -> *) a b.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (Dynamic t a)
accumMaybeMDyn
mapAccumMaybeM :: forall (m :: * -> *) a b c.
(MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (Dynamic t a, Event t c)
mapAccumMaybeM = (a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (Dynamic t a, Event t c)
forall {k} (t :: k) (m :: * -> *) a b c.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (Dynamic t a, Event t c)
mapAccumMaybeMDyn
instance Reflex t => Accumulator t (Behavior t) where
accumMaybeM :: forall (m :: * -> *) a b.
(MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (Behavior t a)
accumMaybeM = (a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (Behavior t a)
forall {k} (t :: k) (m :: * -> *) a b.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (Behavior t a)
accumMaybeMB
mapAccumMaybeM :: forall (m :: * -> *) a b c.
(MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (Behavior t a, Event t c)
mapAccumMaybeM = (a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (Behavior t a, Event t c)
forall {k} (t :: k) (m :: * -> *) a b c.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (Behavior t a, Event t c)
mapAccumMaybeMB
instance Reflex t => Accumulator t (Event t) where
accumMaybeM :: forall (m :: * -> *) a b.
(MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (Event t a)
accumMaybeM a -> b -> PushM t (Maybe a)
f a
z Event t b
e = Dynamic t a -> Event t a
forall a. Dynamic t a -> Event t a
forall {k} (t :: k) a. Reflex t => Dynamic t a -> Event t a
updated (Dynamic t a -> Event t a) -> m (Dynamic t a) -> m (Event t a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (Dynamic t a)
forall {k} (t :: k) (f :: * -> *) (m :: * -> *) a b.
(Accumulator t f, MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (f a)
forall (m :: * -> *) a b.
(MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (Dynamic t a)
accumMaybeM a -> b -> PushM t (Maybe a)
f a
z Event t b
e
mapAccumMaybeM :: forall (m :: * -> *) a b c.
(MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (Event t a, Event t c)
mapAccumMaybeM a -> b -> PushM t (Maybe a, Maybe c)
f a
z Event t b
e = (Dynamic t a -> Event t a)
-> (Dynamic t a, Event t c) -> (Event t a, Event t c)
forall a b c. (a -> b) -> (a, c) -> (b, c)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first Dynamic t a -> Event t a
forall a. Dynamic t a -> Event t a
forall {k} (t :: k) a. Reflex t => Dynamic t a -> Event t a
updated ((Dynamic t a, Event t c) -> (Event t a, Event t c))
-> m (Dynamic t a, Event t c) -> m (Event t a, Event t c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (Dynamic t a, Event t c)
forall {k} (t :: k) (f :: * -> *) (m :: * -> *) a b c.
(Accumulator t f, MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (f a, Event t c)
forall (m :: * -> *) a b c.
(MonadHold t m, MonadFix m) =>
(a -> b -> PushM t (Maybe a, Maybe c))
-> a -> Event t b -> m (Dynamic t a, Event t c)
mapAccumMaybeM a -> b -> PushM t (Maybe a, Maybe c)
f a
z Event t b
e
zipListWithEvent :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> c) -> [a] -> Event t b -> m (Event t c)
zipListWithEvent :: forall {k} (t :: k) (m :: * -> *) a b c.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> c) -> [a] -> Event t b -> m (Event t c)
zipListWithEvent a -> b -> c
f [a]
l Event t b
e = do
let f' :: [a] -> b -> (Maybe [a], Maybe c)
f' [a]
a b
b = case [a]
a of
a
h:[a]
t -> ([a] -> Maybe [a]
forall a. a -> Maybe a
Just [a]
t, c -> Maybe c
forall a. a -> Maybe a
Just (c -> Maybe c) -> c -> Maybe c
forall a b. (a -> b) -> a -> b
$ a -> b -> c
f a
h b
b)
[a]
_ -> (Maybe [a]
forall a. Maybe a
Nothing, Maybe c
forall a. Maybe a
Nothing)
([a] -> b -> (Maybe [a], Maybe c))
-> [a] -> Event t b -> m (Event t c)
forall {k} (t :: k) (m :: * -> *) a b c.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> (Maybe a, Maybe c)) -> a -> Event t b -> m (Event t c)
mapAccumMaybe_ [a] -> b -> (Maybe [a], Maybe c)
f' [a]
l Event t b
e
{-# INLINE numberOccurrences #-}
numberOccurrences :: (Reflex t, MonadHold t m, MonadFix m, Num b) => Event t a -> m (Event t (b, a))
numberOccurrences :: forall {k} (t :: k) (m :: * -> *) b a.
(Reflex t, MonadHold t m, MonadFix m, Num b) =>
Event t a -> m (Event t (b, a))
numberOccurrences = b -> Event t a -> m (Event t (b, a))
forall {k} (t :: k) (m :: * -> *) b a.
(Reflex t, MonadHold t m, MonadFix m, Num b) =>
b -> Event t a -> m (Event t (b, a))
numberOccurrencesFrom b
0
{-# INLINE numberOccurrencesFrom #-}
numberOccurrencesFrom :: (Reflex t, MonadHold t m, MonadFix m, Num b) => b -> Event t a -> m (Event t (b, a))
numberOccurrencesFrom :: forall {k} (t :: k) (m :: * -> *) b a.
(Reflex t, MonadHold t m, MonadFix m, Num b) =>
b -> Event t a -> m (Event t (b, a))
numberOccurrencesFrom = (b -> a -> (b, (b, a))) -> b -> Event t a -> m (Event t (b, a))
forall {k} (t :: k) (m :: * -> *) a b c.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> (a, c)) -> a -> Event t b -> m (Event t c)
mapAccum_ (\b
n a
a -> let !next :: b
next = b
n b -> b -> b
forall a. Num a => a -> a -> a
+ b
1 in (b
next, (b
n, a
a)))
{-# INLINE numberOccurrencesFrom_ #-}
numberOccurrencesFrom_ :: (Reflex t, MonadHold t m, MonadFix m, Num b) => b -> Event t a -> m (Event t b)
numberOccurrencesFrom_ :: forall {k} (t :: k) (m :: * -> *) b a.
(Reflex t, MonadHold t m, MonadFix m, Num b) =>
b -> Event t a -> m (Event t b)
numberOccurrencesFrom_ = (b -> a -> (b, b)) -> b -> Event t a -> m (Event t b)
forall {k} (t :: k) (m :: * -> *) a b c.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> (a, c)) -> a -> Event t b -> m (Event t c)
mapAccum_ (\b
n a
_ -> let !next :: b
next = b
n b -> b -> b
forall a. Num a => a -> a -> a
+ b
1 in (b
next, b
n))
(<@>) :: Reflex t => Behavior t (a -> b) -> Event t a -> Event t b
<@> :: forall {k} (t :: k) a b.
Reflex t =>
Behavior t (a -> b) -> Event t a -> Event t b
(<@>) Behavior t (a -> b)
b = (a -> PushM t (Maybe b)) -> Event t a -> Event t b
forall {k} (t :: k) a b.
Reflex t =>
(a -> PushM t (Maybe b)) -> Event t a -> Event t b
forall a b. (a -> PushM t (Maybe b)) -> Event t a -> Event t b
push ((a -> PushM t (Maybe b)) -> Event t a -> Event t b)
-> (a -> PushM t (Maybe b)) -> Event t a -> Event t b
forall a b. (a -> b) -> a -> b
$ \a
x -> do
a -> b
f <- Behavior t (a -> b) -> PushM t (a -> b)
forall a. Behavior t a -> PushM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample Behavior t (a -> b)
b
Maybe b -> PushM t (Maybe b)
forall a. a -> PushM t a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe b -> PushM t (Maybe b))
-> (a -> Maybe b) -> a -> PushM t (Maybe b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> Maybe b
forall a. a -> Maybe a
Just (b -> Maybe b) -> (a -> b) -> a -> Maybe b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f (a -> PushM t (Maybe b)) -> a -> PushM t (Maybe b)
forall a b. (a -> b) -> a -> b
$ a
x
infixl 4 <@>
(<@) :: (Reflex t) => Behavior t b -> Event t a -> Event t b
<@ :: forall {k} (t :: k) b a.
Reflex t =>
Behavior t b -> Event t a -> Event t b
(<@) = Behavior t b -> Event t a -> Event t b
forall {k} (t :: k) b a.
Reflex t =>
Behavior t b -> Event t a -> Event t b
tag
infixl 4 <@
{-# INLINE pushAlwaysCheap #-}
pushAlwaysCheap :: Reflex t => (a -> PushM t b) -> Event t a -> Event t b
pushAlwaysCheap :: forall {k} (t :: k) a b.
Reflex t =>
(a -> PushM t b) -> Event t a -> Event t b
pushAlwaysCheap a -> PushM t b
f = (a -> PushM t (Maybe b)) -> Event t a -> Event t b
forall {k} (t :: k) a b.
Reflex t =>
(a -> PushM t (Maybe b)) -> Event t a -> Event t b
forall a b. (a -> PushM t (Maybe b)) -> Event t a -> Event t b
pushCheap ((b -> Maybe b) -> PushM t b -> PushM t (Maybe b)
forall a b. (a -> b) -> PushM t a -> PushM t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> Maybe b
forall a. a -> Maybe a
Just (PushM t b -> PushM t (Maybe b))
-> (a -> PushM t b) -> a -> PushM t (Maybe b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> PushM t b
f)
{-# INLINE mapMaybeCheap #-}
mapMaybeCheap :: Reflex t => (a -> Maybe b) -> Event t a -> Event t b
mapMaybeCheap :: forall {k} (t :: k) a b.
Reflex t =>
(a -> Maybe b) -> Event t a -> Event t b
mapMaybeCheap a -> Maybe b
f = (a -> PushM t (Maybe b)) -> Event t a -> Event t b
forall {k} (t :: k) a b.
Reflex t =>
(a -> PushM t (Maybe b)) -> Event t a -> Event t b
forall a b. (a -> PushM t (Maybe b)) -> Event t a -> Event t b
pushCheap ((a -> PushM t (Maybe b)) -> Event t a -> Event t b)
-> (a -> PushM t (Maybe b)) -> Event t a -> Event t b
forall a b. (a -> b) -> a -> b
$ Maybe b -> PushM t (Maybe b)
forall a. a -> PushM t a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe b -> PushM t (Maybe b))
-> (a -> Maybe b) -> a -> PushM t (Maybe b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Maybe b
f
{-# INLINE fmapMaybeCheap #-}
fmapMaybeCheap :: Reflex t => (a -> Maybe b) -> Event t a -> Event t b
fmapMaybeCheap :: forall {k} (t :: k) a b.
Reflex t =>
(a -> Maybe b) -> Event t a -> Event t b
fmapMaybeCheap = (a -> Maybe b) -> Event t a -> Event t b
forall {k} (t :: k) a b.
Reflex t =>
(a -> Maybe b) -> Event t a -> Event t b
mapMaybeCheap
{-# INLINE fforMaybeCheap #-}
fforMaybeCheap :: Reflex t => Event t a -> (a -> Maybe b) -> Event t b
fforMaybeCheap :: forall {k} (t :: k) a b.
Reflex t =>
Event t a -> (a -> Maybe b) -> Event t b
fforMaybeCheap = ((a -> Maybe b) -> Event t a -> Event t b)
-> Event t a -> (a -> Maybe b) -> Event t b
forall a b c. (a -> b -> c) -> b -> a -> c
flip (a -> Maybe b) -> Event t a -> Event t b
forall {k} (t :: k) a b.
Reflex t =>
(a -> Maybe b) -> Event t a -> Event t b
mapMaybeCheap
{-# INLINE fforCheap #-}
fforCheap :: Reflex t => Event t a -> (a -> b) -> Event t b
fforCheap :: forall {k} (t :: k) a b.
Reflex t =>
Event t a -> (a -> b) -> Event t b
fforCheap = ((a -> b) -> Event t a -> Event t b)
-> Event t a -> (a -> b) -> Event t b
forall a b c. (a -> b -> c) -> b -> a -> c
flip (a -> b) -> Event t a -> Event t b
forall {k} (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap
{-# INLINE fmapCheap #-}
fmapCheap :: Reflex t => (a -> b) -> Event t a -> Event t b
fmapCheap :: forall {k} (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap a -> b
f = (a -> PushM t (Maybe b)) -> Event t a -> Event t b
forall {k} (t :: k) a b.
Reflex t =>
(a -> PushM t (Maybe b)) -> Event t a -> Event t b
forall a b. (a -> PushM t (Maybe b)) -> Event t a -> Event t b
pushCheap ((a -> PushM t (Maybe b)) -> Event t a -> Event t b)
-> (a -> PushM t (Maybe b)) -> Event t a -> Event t b
forall a b. (a -> b) -> a -> b
$ Maybe b -> PushM t (Maybe b)
forall a. a -> PushM t a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe b -> PushM t (Maybe b))
-> (a -> Maybe b) -> a -> PushM t (Maybe b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> Maybe b
forall a. a -> Maybe a
Just (b -> Maybe b) -> (a -> b) -> a -> Maybe b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f
{-# INLINE tagCheap #-}
tagCheap :: Reflex t => Behavior t b -> Event t a -> Event t b
tagCheap :: forall {k} (t :: k) b a.
Reflex t =>
Behavior t b -> Event t a -> Event t b
tagCheap Behavior t b
b = (a -> PushM t b) -> Event t a -> Event t b
forall {k} (t :: k) a b.
Reflex t =>
(a -> PushM t b) -> Event t a -> Event t b
pushAlwaysCheap ((a -> PushM t b) -> Event t a -> Event t b)
-> (a -> PushM t b) -> Event t a -> Event t b
forall a b. (a -> b) -> a -> b
$ \a
_ -> Behavior t b -> PushM t b
forall a. Behavior t a -> PushM t a
forall {k} (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample Behavior t b
b
merge :: (Reflex t, GCompare k) => DMap k (Event t) -> Event t (DMap k Identity)
merge :: forall {k} (t :: k) (k :: * -> *).
(Reflex t, GCompare k) =>
DMap k (Event t) -> Event t (DMap k Identity)
merge = (forall a. Event t a -> Event t (Identity a))
-> DMap k (Event t) -> Event t (DMap k Identity)
forall {k} (t :: k) {k} (k :: k -> *) (q :: k -> *) (v :: k -> *).
(Reflex t, GCompare k) =>
(forall (a :: k). q a -> Event t (v a))
-> DMap k q -> Event t (DMap k v)
forall {k} (k :: k -> *) (q :: k -> *) (v :: k -> *).
GCompare k =>
(forall (a :: k). q a -> Event t (v a))
-> DMap k q -> Event t (DMap k v)
mergeG Event t a -> Event t (Identity a)
forall a. Event t a -> Event t (Identity a)
forall {k} (t :: k) a b.
(Reflex t, Coercible a b) =>
Event t a -> Event t b
coerceEvent
{-# INLINE merge #-}
mergeIncremental :: (Reflex t, GCompare k)
=> Incremental t (PatchDMap k (Event t)) -> Event t (DMap k Identity)
mergeIncremental :: forall {k} (t :: k) (k :: * -> *).
(Reflex t, GCompare k) =>
Incremental t (PatchDMap k (Event t)) -> Event t (DMap k Identity)
mergeIncremental = (forall a. Event t a -> Event t (Identity a))
-> Incremental t (PatchDMap k (Event t))
-> Event t (DMap k Identity)
forall {k} (t :: k) {k} (k :: k -> *) (q :: k -> *) (v :: k -> *).
(Reflex t, GCompare k) =>
(forall (a :: k). q a -> Event t (v a))
-> Incremental t (PatchDMap k q) -> Event t (DMap k v)
forall {k} (k :: k -> *) (q :: k -> *) (v :: k -> *).
GCompare k =>
(forall (a :: k). q a -> Event t (v a))
-> Incremental t (PatchDMap k q) -> Event t (DMap k v)
mergeIncrementalG Event t a -> Event t (Identity a)
forall a. Event t a -> Event t (Identity a)
forall {k} (t :: k) a b.
(Reflex t, Coercible a b) =>
Event t a -> Event t b
coerceEvent
mergeIncrementalWithMove :: (Reflex t, GCompare k)
=> Incremental t (PatchDMapWithMove k (Event t)) -> Event t (DMap k Identity)
mergeIncrementalWithMove :: forall {k} (t :: k) (k :: * -> *).
(Reflex t, GCompare k) =>
Incremental t (PatchDMapWithMove k (Event t))
-> Event t (DMap k Identity)
mergeIncrementalWithMove = (forall a. Event t a -> Event t (Identity a))
-> Incremental t (PatchDMapWithMove k (Event t))
-> Event t (DMap k Identity)
forall {k} (t :: k) {k} (k :: k -> *) (q :: k -> *) (v :: k -> *).
(Reflex t, GCompare k) =>
(forall (a :: k). q a -> Event t (v a))
-> Incremental t (PatchDMapWithMove k q) -> Event t (DMap k v)
forall {k} (k :: k -> *) (q :: k -> *) (v :: k -> *).
GCompare k =>
(forall (a :: k). q a -> Event t (v a))
-> Incremental t (PatchDMapWithMove k q) -> Event t (DMap k v)
mergeIncrementalWithMoveG Event t a -> Event t (Identity a)
forall a. Event t a -> Event t (Identity a)
forall {k} (t :: k) a b.
(Reflex t, Coercible a b) =>
Event t a -> Event t b
coerceEvent
{-# INLINE mergeWithCheap #-}
mergeWithCheap :: Reflex t => (a -> a -> a) -> [Event t a] -> Event t a
mergeWithCheap :: forall {k} (t :: k) a.
Reflex t =>
(a -> a -> a) -> [Event t a] -> Event t a
mergeWithCheap = (a -> a) -> (a -> a -> a) -> [Event t a] -> Event t a
forall {k} (t :: k) a b.
Reflex t =>
(a -> b) -> (b -> b -> b) -> [Event t a] -> Event t b
mergeWithCheap' a -> a
forall a. a -> a
id
{-# INLINE mergeWithCheap' #-}
mergeWithCheap' :: Reflex t => (a -> b) -> (b -> b -> b) -> [Event t a] -> Event t b
mergeWithCheap' :: forall {k} (t :: k) a b.
Reflex t =>
(a -> b) -> (b -> b -> b) -> [Event t a] -> Event t b
mergeWithCheap' a -> b
f b -> b -> b
g = (NonEmpty a -> b) -> [Event t a] -> Event t b
forall {k} (t :: k) a b.
Reflex t =>
(NonEmpty a -> b) -> [Event t a] -> Event t b
mergeWithFoldCheap' ((NonEmpty a -> b) -> [Event t a] -> Event t b)
-> (NonEmpty a -> b) -> [Event t a] -> Event t b
forall a b. (a -> b) -> a -> b
$ (b -> b -> b) -> NonEmpty b -> b
forall a. (a -> a -> a) -> NonEmpty a -> a
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldl1 b -> b -> b
g (NonEmpty b -> b) -> (NonEmpty a -> NonEmpty b) -> NonEmpty a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> NonEmpty a -> NonEmpty b
forall a b. (a -> b) -> NonEmpty a -> NonEmpty b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f
{-# INLINE mergeWithFoldCheap' #-}
mergeWithFoldCheap' :: Reflex t => (NonEmpty a -> b) -> [Event t a] -> Event t b
mergeWithFoldCheap' :: forall {k} (t :: k) a b.
Reflex t =>
(NonEmpty a -> b) -> [Event t a] -> Event t b
mergeWithFoldCheap' NonEmpty a -> b
f [Event t a]
es =
(IntMap a -> b) -> Event t (IntMap a) -> Event t b
forall {k} (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap (NonEmpty a -> b
f (NonEmpty a -> b) -> (IntMap a -> NonEmpty a) -> IntMap a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\(a
h : [a]
t) -> a
h a -> [a] -> NonEmpty a
forall a. a -> [a] -> NonEmpty a
:| [a]
t) ([a] -> NonEmpty a) -> (IntMap a -> [a]) -> IntMap a -> NonEmpty a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IntMap a -> [a]
forall a. IntMap a -> [a]
IntMap.elems)
(Event t (IntMap a) -> Event t b)
-> ([(Int, Event t a)] -> Event t (IntMap a))
-> [(Int, Event t a)]
-> Event t b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IntMap (Event t a) -> Event t (IntMap a)
forall {k} (t :: k) a.
Reflex t =>
IntMap (Event t a) -> Event t (IntMap a)
mergeInt
(IntMap (Event t a) -> Event t (IntMap a))
-> ([(Int, Event t a)] -> IntMap (Event t a))
-> [(Int, Event t a)]
-> Event t (IntMap a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Int, Event t a)] -> IntMap (Event t a)
forall a. [(Int, a)] -> IntMap a
IntMap.fromDistinctAscList
([(Int, Event t a)] -> Event t b)
-> [(Int, Event t a)] -> Event t b
forall a b. (a -> b) -> a -> b
$ [Int] -> [Event t a] -> [(Int, Event t a)]
forall a b. [a] -> [b] -> [(a, b)]
forall (f :: * -> *) a b. Zip f => f a -> f b -> f (a, b)
zip [Int
0 :: Int ..] [Event t a]
es
{-# DEPRECATED switchPromptly "Use 'switchHoldPromptly' instead. The 'switchHold*' naming convention was chosen because those functions are more closely related to each other than they are to 'switch'. " #-}
switchPromptly :: (Reflex t, MonadHold t m) => Event t a -> Event t (Event t a) -> m (Event t a)
switchPromptly :: forall {k} (t :: k) (m :: * -> *) a.
(Reflex t, MonadHold t m) =>
Event t a -> Event t (Event t a) -> m (Event t a)
switchPromptly = Event t a -> Event t (Event t a) -> m (Event t a)
forall {k} (t :: k) (m :: * -> *) a.
(Reflex t, MonadHold t m) =>
Event t a -> Event t (Event t a) -> m (Event t a)
switchHoldPromptly
{-# DEPRECATED switchPromptOnly "Use 'switchHoldPromptOnly' instead. The 'switchHold*' naming convention was chosen because those functions are more closely related to each other than they are to 'switch'. " #-}
switchPromptOnly :: (Reflex t, MonadHold t m) => Event t a -> Event t (Event t a) -> m (Event t a)
switchPromptOnly :: forall {k} (t :: k) (m :: * -> *) a.
(Reflex t, MonadHold t m) =>
Event t a -> Event t (Event t a) -> m (Event t a)
switchPromptOnly = Event t a -> Event t (Event t a) -> m (Event t a)
forall {k} (t :: k) (m :: * -> *) a.
(Reflex t, MonadHold t m) =>
Event t a -> Event t (Event t a) -> m (Event t a)
switchHoldPromptOnly