-- | This module provides 'EventWriterT', the standard implementation of
-- 'EventWriter'.
{-# LANGUAGE CPP #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
#ifdef USE_REFLEX_OPTIMIZER
{-# OPTIONS_GHC -fplugin=Reflex.Optimizer #-}
#endif
module Reflex.EventWriter.Base
  ( EventWriterT (..)
  , runEventWriterT
  , runWithReplaceEventWriterTWith
  , sequenceDMapWithAdjustEventWriterTWith
  , mapEventWriterT
  , withEventWriterT
  ) where

import Reflex.Adjustable.Class
import Reflex.Class
import Reflex.EventWriter.Class (EventWriter, tellEvent)
import Reflex.DynamicWriter.Class (DynamicWriter, tellDyn)
import Reflex.Host.Class
import Reflex.PerformEvent.Class
import Reflex.PostBuild.Class
import Reflex.Query.Class
import Reflex.Requester.Class
import Reflex.TriggerEvent.Class

import Control.Monad.Exception
import Control.Monad.Identity
import Control.Monad.Morph
import Control.Monad.Primitive
import Control.Monad.Reader
import Control.Monad.Ref
import Control.Monad.State.Strict
import Data.Dependent.Map (DMap)
import qualified Data.Dependent.Map as DMap
import Data.Dependent.Sum (DSum (..))
import Data.Functor.Compose
import Data.Functor.Misc
import Data.GADT.Compare (GCompare (..), GEq (..), GOrdering (..))
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IntMap
import Data.List.NonEmpty (NonEmpty (..))
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Semigroup
import Data.Some (Some)
import Data.Tuple
import Data.Type.Equality

import Unsafe.Coerce

{-# DEPRECATED TellId "Do not construct this directly; use tellId instead" #-}
newtype TellId w x
  = TellId Int -- ^ WARNING: Do not construct this directly; use 'tellId' instead
  deriving (Int -> TellId w x -> ShowS
[TellId w x] -> ShowS
TellId w x -> String
(Int -> TellId w x -> ShowS)
-> (TellId w x -> String)
-> ([TellId w x] -> ShowS)
-> Show (TellId w x)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall w x. Int -> TellId w x -> ShowS
forall w x. [TellId w x] -> ShowS
forall w x. TellId w x -> String
showList :: [TellId w x] -> ShowS
$cshowList :: forall w x. [TellId w x] -> ShowS
show :: TellId w x -> String
$cshow :: forall w x. TellId w x -> String
showsPrec :: Int -> TellId w x -> ShowS
$cshowsPrec :: forall w x. Int -> TellId w x -> ShowS
Show, TellId w x -> TellId w x -> Bool
(TellId w x -> TellId w x -> Bool)
-> (TellId w x -> TellId w x -> Bool) -> Eq (TellId w x)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall w x. TellId w x -> TellId w x -> Bool
/= :: TellId w x -> TellId w x -> Bool
$c/= :: forall w x. TellId w x -> TellId w x -> Bool
== :: TellId w x -> TellId w x -> Bool
$c== :: forall w x. TellId w x -> TellId w x -> Bool
Eq, Eq (TellId w x)
Eq (TellId w x)
-> (TellId w x -> TellId w x -> Ordering)
-> (TellId w x -> TellId w x -> Bool)
-> (TellId w x -> TellId w x -> Bool)
-> (TellId w x -> TellId w x -> Bool)
-> (TellId w x -> TellId w x -> Bool)
-> (TellId w x -> TellId w x -> TellId w x)
-> (TellId w x -> TellId w x -> TellId w x)
-> Ord (TellId w x)
TellId w x -> TellId w x -> Bool
TellId w x -> TellId w x -> Ordering
TellId w x -> TellId w x -> TellId w x
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall w x. Eq (TellId w x)
forall w x. TellId w x -> TellId w x -> Bool
forall w x. TellId w x -> TellId w x -> Ordering
forall w x. TellId w x -> TellId w x -> TellId w x
min :: TellId w x -> TellId w x -> TellId w x
$cmin :: forall w x. TellId w x -> TellId w x -> TellId w x
max :: TellId w x -> TellId w x -> TellId w x
$cmax :: forall w x. TellId w x -> TellId w x -> TellId w x
>= :: TellId w x -> TellId w x -> Bool
$c>= :: forall w x. TellId w x -> TellId w x -> Bool
> :: TellId w x -> TellId w x -> Bool
$c> :: forall w x. TellId w x -> TellId w x -> Bool
<= :: TellId w x -> TellId w x -> Bool
$c<= :: forall w x. TellId w x -> TellId w x -> Bool
< :: TellId w x -> TellId w x -> Bool
$c< :: forall w x. TellId w x -> TellId w x -> Bool
compare :: TellId w x -> TellId w x -> Ordering
$ccompare :: forall w x. TellId w x -> TellId w x -> Ordering
$cp1Ord :: forall w x. Eq (TellId w x)
Ord, Int -> TellId w x
TellId w x -> Int
TellId w x -> [TellId w x]
TellId w x -> TellId w x
TellId w x -> TellId w x -> [TellId w x]
TellId w x -> TellId w x -> TellId w x -> [TellId w x]
(TellId w x -> TellId w x)
-> (TellId w x -> TellId w x)
-> (Int -> TellId w x)
-> (TellId w x -> Int)
-> (TellId w x -> [TellId w x])
-> (TellId w x -> TellId w x -> [TellId w x])
-> (TellId w x -> TellId w x -> [TellId w x])
-> (TellId w x -> TellId w x -> TellId w x -> [TellId w x])
-> Enum (TellId w x)
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
forall w x. Int -> TellId w x
forall w x. TellId w x -> Int
forall w x. TellId w x -> [TellId w x]
forall w x. TellId w x -> TellId w x
forall w x. TellId w x -> TellId w x -> [TellId w x]
forall w x. TellId w x -> TellId w x -> TellId w x -> [TellId w x]
enumFromThenTo :: TellId w x -> TellId w x -> TellId w x -> [TellId w x]
$cenumFromThenTo :: forall w x. TellId w x -> TellId w x -> TellId w x -> [TellId w x]
enumFromTo :: TellId w x -> TellId w x -> [TellId w x]
$cenumFromTo :: forall w x. TellId w x -> TellId w x -> [TellId w x]
enumFromThen :: TellId w x -> TellId w x -> [TellId w x]
$cenumFromThen :: forall w x. TellId w x -> TellId w x -> [TellId w x]
enumFrom :: TellId w x -> [TellId w x]
$cenumFrom :: forall w x. TellId w x -> [TellId w x]
fromEnum :: TellId w x -> Int
$cfromEnum :: forall w x. TellId w x -> Int
toEnum :: Int -> TellId w x
$ctoEnum :: forall w x. Int -> TellId w x
pred :: TellId w x -> TellId w x
$cpred :: forall w x. TellId w x -> TellId w x
succ :: TellId w x -> TellId w x
$csucc :: forall w x. TellId w x -> TellId w x
Enum)

tellId :: Int -> TellId w w
tellId :: Int -> TellId w w
tellId = Int -> TellId w w
forall w x. Int -> TellId w x
TellId
{-# INLINE tellId #-}

tellIdRefl :: TellId w x -> w :~: x
tellIdRefl :: TellId w x -> w :~: x
tellIdRefl TellId w x
_ = (Any :~: Any) -> w :~: x
forall a b. a -> b
unsafeCoerce Any :~: Any
forall k (a :: k). a :~: a
Refl

withTellIdRefl :: TellId w x -> (w ~ x => r) -> r
withTellIdRefl :: TellId w x -> ((w ~ x) => r) -> r
withTellIdRefl TellId w x
tid (w ~ x) => r
r = case TellId w x -> w :~: x
forall w x. TellId w x -> w :~: x
tellIdRefl TellId w x
tid of
  w :~: x
Refl -> r
(w ~ x) => r
r

instance GEq (TellId w) where
  TellId w a
a geq :: TellId w a -> TellId w b -> Maybe (a :~: b)
`geq` TellId w b
b =
    TellId w a -> ((w ~ a) => Maybe (a :~: b)) -> Maybe (a :~: b)
forall w x r. TellId w x -> ((w ~ x) => r) -> r
withTellIdRefl TellId w a
a (((w ~ a) => Maybe (a :~: b)) -> Maybe (a :~: b))
-> ((w ~ a) => Maybe (a :~: b)) -> Maybe (a :~: b)
forall a b. (a -> b) -> a -> b
$
    TellId w b -> ((w ~ b) => Maybe (a :~: b)) -> Maybe (a :~: b)
forall w x r. TellId w x -> ((w ~ x) => r) -> r
withTellIdRefl TellId w b
b (((w ~ b) => Maybe (a :~: b)) -> Maybe (a :~: b))
-> ((w ~ b) => Maybe (a :~: b)) -> Maybe (a :~: b)
forall a b. (a -> b) -> a -> b
$
    if TellId w a
a TellId w a -> TellId w a -> Bool
forall a. Eq a => a -> a -> Bool
== TellId w a
TellId w b
b
    then (w :~: w) -> Maybe (w :~: w)
forall a. a -> Maybe a
Just w :~: w
forall k (a :: k). a :~: a
Refl
    else Maybe (a :~: b)
forall a. Maybe a
Nothing

instance GCompare (TellId w) where
  TellId w a
a gcompare :: TellId w a -> TellId w b -> GOrdering a b
`gcompare` TellId w b
b =
    TellId w a -> ((w ~ a) => GOrdering a b) -> GOrdering a b
forall w x r. TellId w x -> ((w ~ x) => r) -> r
withTellIdRefl TellId w a
a (((w ~ a) => GOrdering a b) -> GOrdering a b)
-> ((w ~ a) => GOrdering a b) -> GOrdering a b
forall a b. (a -> b) -> a -> b
$
    TellId w b -> ((w ~ b) => GOrdering a b) -> GOrdering a b
forall w x r. TellId w x -> ((w ~ x) => r) -> r
withTellIdRefl TellId w b
b (((w ~ b) => GOrdering a b) -> GOrdering a b)
-> ((w ~ b) => GOrdering a b) -> GOrdering a b
forall a b. (a -> b) -> a -> b
$
    case TellId w a
a TellId w a -> TellId w a -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` TellId w a
TellId w b
b of
      Ordering
LT -> GOrdering a b
forall k (a :: k) (b :: k). GOrdering a b
GLT
      Ordering
EQ -> GOrdering a b
forall k (a :: k). GOrdering a a
GEQ
      Ordering
GT -> GOrdering a b
forall k (a :: k) (b :: k). GOrdering a b
GGT

data EventWriterState t w = EventWriterState
  { EventWriterState t w -> Int
_eventWriterState_nextId :: {-# UNPACK #-} !Int -- Always negative (and decreasing over time)
  , EventWriterState t w -> [DSum (TellId w) (Event t)]
_eventWriterState_told :: ![DSum (TellId w) (Event t)] -- In increasing order
  }

-- | A basic implementation of 'EventWriter'.
newtype EventWriterT t w m a = EventWriterT { EventWriterT t w m a -> StateT (EventWriterState t w) m a
unEventWriterT :: StateT (EventWriterState t w) m a }
  deriving
    ( a -> EventWriterT t w m b -> EventWriterT t w m a
(a -> b) -> EventWriterT t w m a -> EventWriterT t w m b
(forall a b.
 (a -> b) -> EventWriterT t w m a -> EventWriterT t w m b)
-> (forall a b. a -> EventWriterT t w m b -> EventWriterT t w m a)
-> Functor (EventWriterT t w m)
forall a b. a -> EventWriterT t w m b -> EventWriterT t w m a
forall a b.
(a -> b) -> EventWriterT t w m a -> EventWriterT t w m b
forall t w (m :: * -> *) a b.
Functor m =>
a -> EventWriterT t w m b -> EventWriterT t w m a
forall t w (m :: * -> *) a b.
Functor m =>
(a -> b) -> EventWriterT t w m a -> EventWriterT t w m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> EventWriterT t w m b -> EventWriterT t w m a
$c<$ :: forall t w (m :: * -> *) a b.
Functor m =>
a -> EventWriterT t w m b -> EventWriterT t w m a
fmap :: (a -> b) -> EventWriterT t w m a -> EventWriterT t w m b
$cfmap :: forall t w (m :: * -> *) a b.
Functor m =>
(a -> b) -> EventWriterT t w m a -> EventWriterT t w m b
Functor
    , Functor (EventWriterT t w m)
a -> EventWriterT t w m a
Functor (EventWriterT t w m)
-> (forall a. a -> EventWriterT t w m a)
-> (forall a b.
    EventWriterT t w m (a -> b)
    -> EventWriterT t w m a -> EventWriterT t w m b)
-> (forall a b c.
    (a -> b -> c)
    -> EventWriterT t w m a
    -> EventWriterT t w m b
    -> EventWriterT t w m c)
-> (forall a b.
    EventWriterT t w m a
    -> EventWriterT t w m b -> EventWriterT t w m b)
-> (forall a b.
    EventWriterT t w m a
    -> EventWriterT t w m b -> EventWriterT t w m a)
-> Applicative (EventWriterT t w m)
EventWriterT t w m a
-> EventWriterT t w m b -> EventWriterT t w m b
EventWriterT t w m a
-> EventWriterT t w m b -> EventWriterT t w m a
EventWriterT t w m (a -> b)
-> EventWriterT t w m a -> EventWriterT t w m b
(a -> b -> c)
-> EventWriterT t w m a
-> EventWriterT t w m b
-> EventWriterT t w m c
forall a. a -> EventWriterT t w m a
forall a b.
EventWriterT t w m a
-> EventWriterT t w m b -> EventWriterT t w m a
forall a b.
EventWriterT t w m a
-> EventWriterT t w m b -> EventWriterT t w m b
forall a b.
EventWriterT t w m (a -> b)
-> EventWriterT t w m a -> EventWriterT t w m b
forall a b c.
(a -> b -> c)
-> EventWriterT t w m a
-> EventWriterT t w m b
-> EventWriterT t w m c
forall t w (m :: * -> *). Monad m => Functor (EventWriterT t w m)
forall t w (m :: * -> *) a. Monad m => a -> EventWriterT t w m a
forall t w (m :: * -> *) a b.
Monad m =>
EventWriterT t w m a
-> EventWriterT t w m b -> EventWriterT t w m a
forall t w (m :: * -> *) a b.
Monad m =>
EventWriterT t w m a
-> EventWriterT t w m b -> EventWriterT t w m b
forall t w (m :: * -> *) a b.
Monad m =>
EventWriterT t w m (a -> b)
-> EventWriterT t w m a -> EventWriterT t w m b
forall t w (m :: * -> *) a b c.
Monad m =>
(a -> b -> c)
-> EventWriterT t w m a
-> EventWriterT t w m b
-> EventWriterT t w m c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
<* :: EventWriterT t w m a
-> EventWriterT t w m b -> EventWriterT t w m a
$c<* :: forall t w (m :: * -> *) a b.
Monad m =>
EventWriterT t w m a
-> EventWriterT t w m b -> EventWriterT t w m a
*> :: EventWriterT t w m a
-> EventWriterT t w m b -> EventWriterT t w m b
$c*> :: forall t w (m :: * -> *) a b.
Monad m =>
EventWriterT t w m a
-> EventWriterT t w m b -> EventWriterT t w m b
liftA2 :: (a -> b -> c)
-> EventWriterT t w m a
-> EventWriterT t w m b
-> EventWriterT t w m c
$cliftA2 :: forall t w (m :: * -> *) a b c.
Monad m =>
(a -> b -> c)
-> EventWriterT t w m a
-> EventWriterT t w m b
-> EventWriterT t w m c
<*> :: EventWriterT t w m (a -> b)
-> EventWriterT t w m a -> EventWriterT t w m b
$c<*> :: forall t w (m :: * -> *) a b.
Monad m =>
EventWriterT t w m (a -> b)
-> EventWriterT t w m a -> EventWriterT t w m b
pure :: a -> EventWriterT t w m a
$cpure :: forall t w (m :: * -> *) a. Monad m => a -> EventWriterT t w m a
$cp1Applicative :: forall t w (m :: * -> *). Monad m => Functor (EventWriterT t w m)
Applicative
    , Applicative (EventWriterT t w m)
a -> EventWriterT t w m a
Applicative (EventWriterT t w m)
-> (forall a b.
    EventWriterT t w m a
    -> (a -> EventWriterT t w m b) -> EventWriterT t w m b)
-> (forall a b.
    EventWriterT t w m a
    -> EventWriterT t w m b -> EventWriterT t w m b)
-> (forall a. a -> EventWriterT t w m a)
-> Monad (EventWriterT t w m)
EventWriterT t w m a
-> (a -> EventWriterT t w m b) -> EventWriterT t w m b
EventWriterT t w m a
-> EventWriterT t w m b -> EventWriterT t w m b
forall a. a -> EventWriterT t w m a
forall a b.
EventWriterT t w m a
-> EventWriterT t w m b -> EventWriterT t w m b
forall a b.
EventWriterT t w m a
-> (a -> EventWriterT t w m b) -> EventWriterT t w m b
forall t w (m :: * -> *).
Monad m =>
Applicative (EventWriterT t w m)
forall t w (m :: * -> *) a. Monad m => a -> EventWriterT t w m a
forall t w (m :: * -> *) a b.
Monad m =>
EventWriterT t w m a
-> EventWriterT t w m b -> EventWriterT t w m b
forall t w (m :: * -> *) a b.
Monad m =>
EventWriterT t w m a
-> (a -> EventWriterT t w m b) -> EventWriterT t w m b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: a -> EventWriterT t w m a
$creturn :: forall t w (m :: * -> *) a. Monad m => a -> EventWriterT t w m a
>> :: EventWriterT t w m a
-> EventWriterT t w m b -> EventWriterT t w m b
$c>> :: forall t w (m :: * -> *) a b.
Monad m =>
EventWriterT t w m a
-> EventWriterT t w m b -> EventWriterT t w m b
>>= :: EventWriterT t w m a
-> (a -> EventWriterT t w m b) -> EventWriterT t w m b
$c>>= :: forall t w (m :: * -> *) a b.
Monad m =>
EventWriterT t w m a
-> (a -> EventWriterT t w m b) -> EventWriterT t w m b
$cp1Monad :: forall t w (m :: * -> *).
Monad m =>
Applicative (EventWriterT t w m)
Monad
    , m a -> EventWriterT t w m a
(forall (m :: * -> *) a. Monad m => m a -> EventWriterT t w m a)
-> MonadTrans (EventWriterT t w)
forall t w (m :: * -> *) a. Monad m => m a -> EventWriterT t w m a
forall (m :: * -> *) a. Monad m => m a -> EventWriterT t w m a
forall (t :: (* -> *) -> * -> *).
(forall (m :: * -> *) a. Monad m => m a -> t m a) -> MonadTrans t
lift :: m a -> EventWriterT t w m a
$clift :: forall t w (m :: * -> *) a. Monad m => m a -> EventWriterT t w m a
MonadTrans
    , (forall a. m a -> n a)
-> EventWriterT t w m b -> EventWriterT t w n b
(forall (m :: * -> *) (n :: * -> *) b.
 Monad m =>
 (forall a. m a -> n a)
 -> EventWriterT t w m b -> EventWriterT t w n b)
-> MFunctor (EventWriterT t w)
forall t w (m :: * -> *) (n :: * -> *) b.
Monad m =>
(forall a. m a -> n a)
-> EventWriterT t w m b -> EventWriterT t w n b
forall k (t :: (* -> *) -> k -> *).
(forall (m :: * -> *) (n :: * -> *) (b :: k).
 Monad m =>
 (forall a. m a -> n a) -> t m b -> t n b)
-> MFunctor t
forall (m :: * -> *) (n :: * -> *) b.
Monad m =>
(forall a. m a -> n a)
-> EventWriterT t w m b -> EventWriterT t w n b
hoist :: (forall a. m a -> n a)
-> EventWriterT t w m b -> EventWriterT t w n b
$choist :: forall t w (m :: * -> *) (n :: * -> *) b.
Monad m =>
(forall a. m a -> n a)
-> EventWriterT t w m b -> EventWriterT t w n b
MFunctor
    , Monad (EventWriterT t w m)
Monad (EventWriterT t w m)
-> (forall a. (a -> EventWriterT t w m a) -> EventWriterT t w m a)
-> MonadFix (EventWriterT t w m)
(a -> EventWriterT t w m a) -> EventWriterT t w m a
forall a. (a -> EventWriterT t w m a) -> EventWriterT t w m a
forall t w (m :: * -> *). MonadFix m => Monad (EventWriterT t w m)
forall t w (m :: * -> *) a.
MonadFix m =>
(a -> EventWriterT t w m a) -> EventWriterT t w m a
forall (m :: * -> *).
Monad m -> (forall a. (a -> m a) -> m a) -> MonadFix m
mfix :: (a -> EventWriterT t w m a) -> EventWriterT t w m a
$cmfix :: forall t w (m :: * -> *) a.
MonadFix m =>
(a -> EventWriterT t w m a) -> EventWriterT t w m a
$cp1MonadFix :: forall t w (m :: * -> *). MonadFix m => Monad (EventWriterT t w m)
MonadFix
    , Monad (EventWriterT t w m)
Monad (EventWriterT t w m)
-> (forall a. IO a -> EventWriterT t w m a)
-> MonadIO (EventWriterT t w m)
IO a -> EventWriterT t w m a
forall a. IO a -> EventWriterT t w m a
forall t w (m :: * -> *). MonadIO m => Monad (EventWriterT t w m)
forall t w (m :: * -> *) a.
MonadIO m =>
IO a -> EventWriterT t w m a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
liftIO :: IO a -> EventWriterT t w m a
$cliftIO :: forall t w (m :: * -> *) a.
MonadIO m =>
IO a -> EventWriterT t w m a
$cp1MonadIO :: forall t w (m :: * -> *). MonadIO m => Monad (EventWriterT t w m)
MonadIO
    , Monad (EventWriterT t w m)
e -> EventWriterT t w m a
Monad (EventWriterT t w m)
-> (forall e a. Exception e => e -> EventWriterT t w m a)
-> (forall e a.
    Exception e =>
    EventWriterT t w m a
    -> (e -> EventWriterT t w m a) -> EventWriterT t w m a)
-> (forall a b.
    EventWriterT t w m a
    -> EventWriterT t w m b -> EventWriterT t w m a)
-> MonadException (EventWriterT t w m)
EventWriterT t w m a
-> (e -> EventWriterT t w m a) -> EventWriterT t w m a
EventWriterT t w m a
-> EventWriterT t w m b -> EventWriterT t w m a
forall e a. Exception e => e -> EventWriterT t w m a
forall e a.
Exception e =>
EventWriterT t w m a
-> (e -> EventWriterT t w m a) -> EventWriterT t w m a
forall a b.
EventWriterT t w m a
-> EventWriterT t w m b -> EventWriterT t w m a
forall t w (m :: * -> *).
MonadException m =>
Monad (EventWriterT t w m)
forall t w (m :: * -> *) e a.
(MonadException m, Exception e) =>
e -> EventWriterT t w m a
forall t w (m :: * -> *) e a.
(MonadException m, Exception e) =>
EventWriterT t w m a
-> (e -> EventWriterT t w m a) -> EventWriterT t w m a
forall t w (m :: * -> *) a b.
MonadException m =>
EventWriterT t w m a
-> EventWriterT t w m b -> EventWriterT t w m a
forall (m :: * -> *).
Monad m
-> (forall e a. Exception e => e -> m a)
-> (forall e a. Exception e => m a -> (e -> m a) -> m a)
-> (forall a b. m a -> m b -> m a)
-> MonadException m
finally :: EventWriterT t w m a
-> EventWriterT t w m b -> EventWriterT t w m a
$cfinally :: forall t w (m :: * -> *) a b.
MonadException m =>
EventWriterT t w m a
-> EventWriterT t w m b -> EventWriterT t w m a
catch :: EventWriterT t w m a
-> (e -> EventWriterT t w m a) -> EventWriterT t w m a
$ccatch :: forall t w (m :: * -> *) e a.
(MonadException m, Exception e) =>
EventWriterT t w m a
-> (e -> EventWriterT t w m a) -> EventWriterT t w m a
throw :: e -> EventWriterT t w m a
$cthrow :: forall t w (m :: * -> *) e a.
(MonadException m, Exception e) =>
e -> EventWriterT t w m a
$cp1MonadException :: forall t w (m :: * -> *).
MonadException m =>
Monad (EventWriterT t w m)
MonadException
    , MonadIO (EventWriterT t w m)
MonadException (EventWriterT t w m)
MonadIO (EventWriterT t w m)
-> MonadException (EventWriterT t w m)
-> (forall b.
    ((forall a. EventWriterT t w m a -> EventWriterT t w m a)
     -> EventWriterT t w m b)
    -> EventWriterT t w m b)
-> MonadAsyncException (EventWriterT t w m)
((forall a. EventWriterT t w m a -> EventWriterT t w m a)
 -> EventWriterT t w m b)
-> EventWriterT t w m b
forall b.
((forall a. EventWriterT t w m a -> EventWriterT t w m a)
 -> EventWriterT t w m b)
-> EventWriterT t w m b
forall t w (m :: * -> *).
MonadAsyncException m =>
MonadIO (EventWriterT t w m)
forall t w (m :: * -> *).
MonadAsyncException m =>
MonadException (EventWriterT t w m)
forall t w (m :: * -> *) b.
MonadAsyncException m =>
((forall a. EventWriterT t w m a -> EventWriterT t w m a)
 -> EventWriterT t w m b)
-> EventWriterT t w m b
forall (m :: * -> *).
MonadIO m
-> MonadException m
-> (forall b. ((forall a. m a -> m a) -> m b) -> m b)
-> MonadAsyncException m
mask :: ((forall a. EventWriterT t w m a -> EventWriterT t w m a)
 -> EventWriterT t w m b)
-> EventWriterT t w m b
$cmask :: forall t w (m :: * -> *) b.
MonadAsyncException m =>
((forall a. EventWriterT t w m a -> EventWriterT t w m a)
 -> EventWriterT t w m b)
-> EventWriterT t w m b
$cp2MonadAsyncException :: forall t w (m :: * -> *).
MonadAsyncException m =>
MonadException (EventWriterT t w m)
$cp1MonadAsyncException :: forall t w (m :: * -> *).
MonadAsyncException m =>
MonadIO (EventWriterT t w m)
MonadAsyncException
    )

-- | Run a 'EventWriterT' action.
runEventWriterT :: forall t m w a. (Reflex t, Monad m, Semigroup w) => EventWriterT t w m a -> m (a, Event t w)
runEventWriterT :: EventWriterT t w m a -> m (a, Event t w)
runEventWriterT (EventWriterT StateT (EventWriterState t w) m a
a) = do
  (a
result, EventWriterState t w
requests) <- StateT (EventWriterState t w) m a
-> EventWriterState t w -> m (a, EventWriterState t w)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
runStateT StateT (EventWriterState t w) m a
a (EventWriterState t w -> m (a, EventWriterState t w))
-> EventWriterState t w -> m (a, EventWriterState t w)
forall a b. (a -> b) -> a -> b
$ Int -> [DSum (TellId w) (Event t)] -> EventWriterState t w
forall t w.
Int -> [DSum (TellId w) (Event t)] -> EventWriterState t w
EventWriterState (-Int
1) []
  let combineResults :: DMap (TellId w) Identity -> w
      combineResults :: DMap (TellId w) Identity -> w
combineResults = NonEmpty w -> w
forall a. Semigroup a => NonEmpty a -> a
sconcat
        (NonEmpty w -> w)
-> (DMap (TellId w) Identity -> NonEmpty w)
-> DMap (TellId w) Identity
-> w
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\(w
h : [w]
t) -> w
h w -> [w] -> NonEmpty w
forall a. a -> [a] -> NonEmpty a
:| [w]
t) -- Unconditional; 'merge' guarantees that it will only fire with non-empty DMaps
        ([w] -> NonEmpty w)
-> (DMap (TellId w) Identity -> [w])
-> DMap (TellId w) Identity
-> NonEmpty w
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall v. [w] -> TellId w v -> Identity v -> [w])
-> [w] -> DMap (TellId w) Identity -> [w]
forall k1 b (k2 :: k1 -> *) (f :: k1 -> *).
(forall (v :: k1). b -> k2 v -> f v -> b) -> b -> DMap k2 f -> b
DMap.foldlWithKey (\[w]
vs TellId w v
tid (Identity v) -> TellId w v -> ((w ~ v) => [w]) -> [w]
forall w x r. TellId w x -> ((w ~ x) => r) -> r
withTellIdRefl TellId w v
tid (((w ~ v) => [w]) -> [w]) -> ((w ~ v) => [w]) -> [w]
forall a b. (a -> b) -> a -> b
$ v
v v -> [v] -> [v]
forall a. a -> [a] -> [a]
: [w]
[v]
vs) [] -- This is where we finally reverse the DMap to get things in the correct order
  (a, Event t w) -> m (a, Event t w)
forall (m :: * -> *) a. Monad m => a -> m a
return (a
result, (DMap (TellId w) Identity -> w)
-> Event t (DMap (TellId w) Identity) -> Event t w
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap DMap (TellId w) Identity -> w
combineResults (Event t (DMap (TellId w) Identity) -> Event t w)
-> Event t (DMap (TellId w) Identity) -> Event t w
forall a b. (a -> b) -> a -> b
$ DMap (TellId w) (Event t) -> Event t (DMap (TellId w) Identity)
forall k1 (t :: k1) (k2 :: * -> *).
(Reflex t, GCompare k2) =>
DMap k2 (Event t) -> Event t (DMap k2 Identity)
merge (DMap (TellId w) (Event t) -> Event t (DMap (TellId w) Identity))
-> DMap (TellId w) (Event t) -> Event t (DMap (TellId w) Identity)
forall a b. (a -> b) -> a -> b
$ [DSum (TellId w) (Event t)] -> DMap (TellId w) (Event t)
forall k1 (k2 :: k1 -> *) (f :: k1 -> *). [DSum k2 f] -> DMap k2 f
DMap.fromDistinctAscList ([DSum (TellId w) (Event t)] -> DMap (TellId w) (Event t))
-> [DSum (TellId w) (Event t)] -> DMap (TellId w) (Event t)
forall a b. (a -> b) -> a -> b
$ EventWriterState t w -> [DSum (TellId w) (Event t)]
forall t w. EventWriterState t w -> [DSum (TellId w) (Event t)]
_eventWriterState_told EventWriterState t w
requests) --TODO: We can probably make this fromDistinctAscList more efficient by knowing the length in advance, but this will require exposing internals of DMap; also converting it to use a strict list might help

instance (Reflex t, Monad m, Semigroup w) => EventWriter t w (EventWriterT t w m) where
  tellEvent :: Event t w -> EventWriterT t w m ()
tellEvent Event t w
w = StateT (EventWriterState t w) m () -> EventWriterT t w m ()
forall t w (m :: * -> *) a.
StateT (EventWriterState t w) m a -> EventWriterT t w m a
EventWriterT (StateT (EventWriterState t w) m () -> EventWriterT t w m ())
-> StateT (EventWriterState t w) m () -> EventWriterT t w m ()
forall a b. (a -> b) -> a -> b
$ (EventWriterState t w -> EventWriterState t w)
-> StateT (EventWriterState t w) m ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((EventWriterState t w -> EventWriterState t w)
 -> StateT (EventWriterState t w) m ())
-> (EventWriterState t w -> EventWriterState t w)
-> StateT (EventWriterState t w) m ()
forall a b. (a -> b) -> a -> b
$ \EventWriterState t w
old ->
    let myId :: Int
myId = EventWriterState t w -> Int
forall t w. EventWriterState t w -> Int
_eventWriterState_nextId EventWriterState t w
old
    in EventWriterState :: forall t w.
Int -> [DSum (TellId w) (Event t)] -> EventWriterState t w
EventWriterState
       { _eventWriterState_nextId :: Int
_eventWriterState_nextId = Int -> Int
forall a. Enum a => a -> a
pred Int
myId
       , _eventWriterState_told :: [DSum (TellId w) (Event t)]
_eventWriterState_told = (Int -> TellId w w
forall w. Int -> TellId w w
tellId Int
myId TellId w w -> Event t w -> DSum (TellId w) (Event t)
forall k (tag :: k -> *) (f :: k -> *) (a :: k).
tag a -> f a -> DSum tag f
:=> Event t w
w) DSum (TellId w) (Event t)
-> [DSum (TellId w) (Event t)] -> [DSum (TellId w) (Event t)]
forall a. a -> [a] -> [a]
: EventWriterState t w -> [DSum (TellId w) (Event t)]
forall t w. EventWriterState t w -> [DSum (TellId w) (Event t)]
_eventWriterState_told EventWriterState t w
old
       }

instance MonadSample t m => MonadSample t (EventWriterT t w m) where
  sample :: Behavior t a -> EventWriterT t w m a
sample = m a -> EventWriterT t w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> EventWriterT t w m a)
-> (Behavior t a -> m a) -> Behavior t a -> EventWriterT t w m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 (EventWriterT t w m) where
  {-# INLINABLE hold #-}
  hold :: a -> Event t a -> EventWriterT t w m (Behavior t a)
hold a
v0 = m (Behavior t a) -> EventWriterT t w m (Behavior t a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Behavior t a) -> EventWriterT t w m (Behavior t a))
-> (Event t a -> m (Behavior t a))
-> Event t a
-> EventWriterT t w m (Behavior t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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
  {-# INLINABLE holdDyn #-}
  holdDyn :: a -> Event t a -> EventWriterT t w m (Dynamic t a)
holdDyn a
v0 = m (Dynamic t a) -> EventWriterT t w m (Dynamic t a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Dynamic t a) -> EventWriterT t w m (Dynamic t a))
-> (Event t a -> m (Dynamic t a))
-> Event t a
-> EventWriterT t w m (Dynamic t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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
  {-# INLINABLE holdIncremental #-}
  holdIncremental :: PatchTarget p -> Event t p -> EventWriterT t w m (Incremental t p)
holdIncremental PatchTarget p
v0 = m (Incremental t p) -> EventWriterT t w m (Incremental t p)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Incremental t p) -> EventWriterT t w m (Incremental t p))
-> (Event t p -> m (Incremental t p))
-> Event t p
-> EventWriterT t w m (Incremental t p)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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
  {-# INLINABLE buildDynamic #-}
  buildDynamic :: PushM t a -> Event t a -> EventWriterT t w m (Dynamic t a)
buildDynamic PushM t a
a0 = m (Dynamic t a) -> EventWriterT t w m (Dynamic t a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Dynamic t a) -> EventWriterT t w m (Dynamic t a))
-> (Event t a -> m (Dynamic t a))
-> Event t a
-> EventWriterT t w 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 k (t :: k) (m :: * -> *) a.
MonadHold t m =>
PushM t a -> Event t a -> m (Dynamic t a)
buildDynamic PushM t a
a0
  {-# INLINABLE headE #-}
  headE :: Event t a -> EventWriterT t w m (Event t a)
headE = m (Event t a) -> EventWriterT t w m (Event t a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Event t a) -> EventWriterT t w m (Event t a))
-> (Event t a -> m (Event t a))
-> Event t a
-> EventWriterT t w m (Event t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Event t a -> m (Event t a)
forall k (t :: k) (m :: * -> *) a.
MonadHold t m =>
Event t a -> m (Event t a)
headE
  {-# INLINABLE now #-}
  now :: EventWriterT t w m (Event t ())
now = m (Event t ()) -> EventWriterT t w m (Event t ())
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 (Reflex t, Adjustable t m, MonadHold t m, Semigroup w) => Adjustable t (EventWriterT t w m) where
  runWithReplace :: EventWriterT t w m a
-> Event t (EventWriterT t w m b)
-> EventWriterT t w m (a, Event t b)
runWithReplace = (forall a' b'.
 m a' -> Event t (m b') -> EventWriterT t w m (a', Event t b'))
-> EventWriterT t w m a
-> Event t (EventWriterT t w m b)
-> EventWriterT t w m (a, Event t b)
forall (m :: * -> *) t w a b.
(Reflex t, MonadHold t m, Semigroup w) =>
(forall a' b'.
 m a' -> Event t (m b') -> EventWriterT t w m (a', Event t b'))
-> EventWriterT t w m a
-> Event t (EventWriterT t w m b)
-> EventWriterT t w m (a, Event t b)
runWithReplaceEventWriterTWith ((forall a' b'.
  m a' -> Event t (m b') -> EventWriterT t w m (a', Event t b'))
 -> EventWriterT t w m a
 -> Event t (EventWriterT t w m b)
 -> EventWriterT t w m (a, Event t b))
-> (forall a' b'.
    m a' -> Event t (m b') -> EventWriterT t w m (a', Event t b'))
-> EventWriterT t w m a
-> Event t (EventWriterT t w m b)
-> EventWriterT t w m (a, Event t b)
forall a b. (a -> b) -> a -> b
$ \m a'
dm0 Event t (m b')
dm' -> m (a', Event t b') -> EventWriterT t w m (a', Event t b')
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (a', Event t b') -> EventWriterT t w m (a', Event t b'))
-> m (a', Event t b') -> EventWriterT t w m (a', Event t b')
forall a b. (a -> b) -> a -> b
$ m a' -> Event t (m b') -> m (a', Event t b')
forall t (m :: * -> *) a b.
Adjustable t m =>
m a -> Event t (m b) -> m (a, Event t b)
runWithReplace m a'
dm0 Event t (m b')
dm'
  traverseIntMapWithKeyWithAdjust :: (Int -> v -> EventWriterT t w m v')
-> IntMap v
-> Event t (PatchIntMap v)
-> EventWriterT t w m (IntMap v', Event t (PatchIntMap v'))
traverseIntMapWithKeyWithAdjust = ((Int -> v -> m (Event t w, v'))
 -> IntMap v
 -> Event t (PatchIntMap v)
 -> EventWriterT
      t
      w
      m
      (IntMap (Event t w, v'), Event t (PatchIntMap (Event t w, v'))))
-> (Incremental t (PatchIntMap (Event t w))
    -> Event t (PatchTarget (PatchIntMap w)))
-> (Event t (PatchIntMap (Event t w)) -> Event t (PatchIntMap w))
-> (Int -> v -> EventWriterT t w m v')
-> IntMap v
-> Event t (PatchIntMap v)
-> EventWriterT t w m (IntMap v', Event t (PatchIntMap v'))
forall t (m :: * -> *) (p :: * -> *) w v v'.
(Reflex t, MonadHold t m, Semigroup w, Functor p,
 Patch (p (Event t w)),
 PatchTarget (p (Event t w)) ~ IntMap (Event t w), Patch (p w),
 PatchTarget (p w) ~ IntMap w) =>
((Int -> v -> m (Event t w, v'))
 -> IntMap v
 -> Event t (p v)
 -> EventWriterT
      t w m (IntMap (Event t w, v'), Event t (p (Event t w, v'))))
-> (Incremental t (p (Event t w)) -> Event t (PatchTarget (p w)))
-> (Event t (p (Event t w)) -> Event t (p w))
-> (Int -> v -> EventWriterT t w m v')
-> IntMap v
-> Event t (p v)
-> EventWriterT t w m (IntMap v', Event t (p v'))
sequenceIntMapWithAdjustEventWriterTWith (\Int -> v -> m (Event t w, v')
f IntMap v
dm0 Event t (PatchIntMap v)
dm' -> m (IntMap (Event t w, v'), Event t (PatchIntMap (Event t w, v')))
-> EventWriterT
     t
     w
     m
     (IntMap (Event t w, v'), Event t (PatchIntMap (Event t w, v')))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (IntMap (Event t w, v'), Event t (PatchIntMap (Event t w, v')))
 -> EventWriterT
      t
      w
      m
      (IntMap (Event t w, v'), Event t (PatchIntMap (Event t w, v'))))
-> m (IntMap (Event t w, v'),
      Event t (PatchIntMap (Event t w, v')))
-> EventWriterT
     t
     w
     m
     (IntMap (Event t w, v'), Event t (PatchIntMap (Event t w, v')))
forall a b. (a -> b) -> a -> b
$ (Int -> v -> m (Event t w, v'))
-> IntMap v
-> Event t (PatchIntMap v)
-> m (IntMap (Event t w, v'),
      Event t (PatchIntMap (Event t w, v')))
forall t (m :: * -> *) v v'.
Adjustable t m =>
(Int -> v -> m v')
-> IntMap v
-> Event t (PatchIntMap v)
-> m (IntMap v', Event t (PatchIntMap v'))
traverseIntMapWithKeyWithAdjust Int -> v -> m (Event t w, v')
f IntMap v
dm0 Event t (PatchIntMap v)
dm') Incremental t (PatchIntMap (Event t w))
-> Event t (PatchTarget (PatchIntMap w))
forall k (t :: k) a.
Reflex t =>
Incremental t (PatchIntMap (Event t a)) -> Event t (IntMap a)
mergeIntIncremental Event t (PatchIntMap (Event t w)) -> Event t (PatchIntMap w)
forall k (t :: k) v.
Reflex t =>
Event t (PatchIntMap (Event t v)) -> Event t (PatchIntMap v)
coincidencePatchIntMap
  traverseDMapWithKeyWithAdjust :: (forall a. k a -> v a -> EventWriterT t w m (v' a))
-> DMap k v
-> Event t (PatchDMap k v)
-> EventWriterT t w m (DMap k v', Event t (PatchDMap k v'))
traverseDMapWithKeyWithAdjust = ((forall a. k a -> v a -> m (Compose ((,) (Event t w)) v' a))
 -> DMap k v
 -> Event t (PatchDMap k v)
 -> EventWriterT
      t
      w
      m
      (DMap k (Compose ((,) (Event t w)) v'),
       Event t (PatchDMap k (Compose ((,) (Event t w)) v'))))
-> ((forall a. Compose ((,) (Event t w)) v' a -> v' a)
    -> PatchDMap k (Compose ((,) (Event t w)) v') -> PatchDMap k v')
-> ((forall a. Compose ((,) (Event t w)) v' a -> Event t w)
    -> PatchDMap k (Compose ((,) (Event t w)) v')
    -> PatchMap (Some k) (Event t w))
-> (Incremental t (PatchMap (Some k) (Event t w))
    -> Event t (PatchTarget (PatchMap (Some k) w)))
-> (Event t (PatchMap (Some k) (Event t w))
    -> Event t (PatchMap (Some k) w))
-> (forall a. k a -> v a -> EventWriterT t w m (v' a))
-> DMap k v
-> Event t (PatchDMap k v)
-> EventWriterT t w m (DMap k v', Event t (PatchDMap k v'))
forall t (m :: * -> *) (p :: (* -> *) -> (* -> *) -> *)
       (p' :: * -> * -> *) w (k :: * -> *) (v :: * -> *) (v' :: * -> *).
(Reflex t, MonadHold t m, Semigroup w,
 Patch (p' (Some k) (Event t w)),
 PatchTarget (p' (Some k) (Event t w)) ~ Map (Some k) (Event t w),
 GCompare k, Patch (p' (Some k) w),
 PatchTarget (p' (Some k) w) ~ Map (Some k) w) =>
((forall a. k a -> v a -> m (Compose ((,) (Event t w)) v' a))
 -> DMap k v
 -> Event t (p k v)
 -> EventWriterT
      t
      w
      m
      (DMap k (Compose ((,) (Event t w)) v'),
       Event t (p k (Compose ((,) (Event t w)) v'))))
-> ((forall a. Compose ((,) (Event t w)) v' a -> v' a)
    -> p k (Compose ((,) (Event t w)) v') -> p k v')
-> ((forall a. Compose ((,) (Event t w)) v' a -> Event t w)
    -> p k (Compose ((,) (Event t w)) v') -> p' (Some k) (Event t w))
-> (Incremental t (p' (Some k) (Event t w))
    -> Event t (PatchTarget (p' (Some k) w)))
-> (Event t (p' (Some k) (Event t w)) -> Event t (p' (Some k) w))
-> (forall a. k a -> v a -> EventWriterT t w m (v' a))
-> DMap k v
-> Event t (p k v)
-> EventWriterT t w m (DMap k v', Event t (p k v'))
sequenceDMapWithAdjustEventWriterTWith (\forall a. k a -> v a -> m (Compose ((,) (Event t w)) v' a)
f DMap k v
dm0 Event t (PatchDMap k v)
dm' -> m (DMap k (Compose ((,) (Event t w)) v'),
   Event t (PatchDMap k (Compose ((,) (Event t w)) v')))
-> EventWriterT
     t
     w
     m
     (DMap k (Compose ((,) (Event t w)) v'),
      Event t (PatchDMap k (Compose ((,) (Event t w)) v')))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (DMap k (Compose ((,) (Event t w)) v'),
    Event t (PatchDMap k (Compose ((,) (Event t w)) v')))
 -> EventWriterT
      t
      w
      m
      (DMap k (Compose ((,) (Event t w)) v'),
       Event t (PatchDMap k (Compose ((,) (Event t w)) v'))))
-> m (DMap k (Compose ((,) (Event t w)) v'),
      Event t (PatchDMap k (Compose ((,) (Event t w)) v')))
-> EventWriterT
     t
     w
     m
     (DMap k (Compose ((,) (Event t w)) v'),
      Event t (PatchDMap k (Compose ((,) (Event t w)) v')))
forall a b. (a -> b) -> a -> b
$ (forall a. k a -> v a -> m (Compose ((,) (Event t w)) v' a))
-> DMap k v
-> Event t (PatchDMap k v)
-> m (DMap k (Compose ((,) (Event t w)) v'),
      Event t (PatchDMap k (Compose ((,) (Event t w)) v')))
forall t (m :: * -> *) (k :: * -> *) (v :: * -> *) (v' :: * -> *).
(Adjustable t m, GCompare k) =>
(forall a. k a -> v a -> m (v' a))
-> DMap k v
-> Event t (PatchDMap k v)
-> m (DMap k v', Event t (PatchDMap k v'))
traverseDMapWithKeyWithAdjust forall a. k a -> v a -> m (Compose ((,) (Event t w)) v' a)
f DMap k v
dm0 Event t (PatchDMap k v)
dm') (forall a. Compose ((,) (Event t w)) v' a -> v' a)
-> PatchDMap k (Compose ((,) (Event t w)) v') -> PatchDMap k v'
forall k1 (v :: k1 -> *) (v' :: k1 -> *) (k2 :: k1 -> *).
(forall (a :: k1). v a -> v' a)
-> PatchDMap k2 v -> PatchDMap k2 v'
mapPatchDMap (forall a. Compose ((,) (Event t w)) v' a -> Event t w)
-> PatchDMap k (Compose ((,) (Event t w)) v')
-> PatchMap (Some k) (Event t w)
forall k1 (v :: k1 -> *) v' (k2 :: k1 -> *).
(forall (a :: k1). v a -> v')
-> PatchDMap k2 v -> PatchMap (Some k2) v'
weakenPatchDMapWith Incremental t (PatchMap (Some k) (Event t w))
-> Event t (PatchTarget (PatchMap (Some k) w))
forall k1 (t :: k1) k2 a.
(Reflex t, Ord k2) =>
Incremental t (PatchMap k2 (Event t a)) -> Event t (Map k2 a)
mergeMapIncremental Event t (PatchMap (Some k) (Event t w))
-> Event t (PatchMap (Some k) w)
forall k1 (t :: k1) k2 v.
(Reflex t, Ord k2) =>
Event t (PatchMap k2 (Event t v)) -> Event t (PatchMap k2 v)
coincidencePatchMap
  traverseDMapWithKeyWithAdjustWithMove :: (forall a. k a -> v a -> EventWriterT t w m (v' a))
-> DMap k v
-> Event t (PatchDMapWithMove k v)
-> EventWriterT t w m (DMap k v', Event t (PatchDMapWithMove k v'))
traverseDMapWithKeyWithAdjustWithMove = ((forall a. k a -> v a -> m (Compose ((,) (Event t w)) v' a))
 -> DMap k v
 -> Event t (PatchDMapWithMove k v)
 -> EventWriterT
      t
      w
      m
      (DMap k (Compose ((,) (Event t w)) v'),
       Event t (PatchDMapWithMove k (Compose ((,) (Event t w)) v'))))
-> ((forall a. Compose ((,) (Event t w)) v' a -> v' a)
    -> PatchDMapWithMove k (Compose ((,) (Event t w)) v')
    -> PatchDMapWithMove k v')
-> ((forall a. Compose ((,) (Event t w)) v' a -> Event t w)
    -> PatchDMapWithMove k (Compose ((,) (Event t w)) v')
    -> PatchMapWithMove (Some k) (Event t w))
-> (Incremental t (PatchMapWithMove (Some k) (Event t w))
    -> Event t (PatchTarget (PatchMapWithMove (Some k) w)))
-> (Event t (PatchMapWithMove (Some k) (Event t w))
    -> Event t (PatchMapWithMove (Some k) w))
-> (forall a. k a -> v a -> EventWriterT t w m (v' a))
-> DMap k v
-> Event t (PatchDMapWithMove k v)
-> EventWriterT t w m (DMap k v', Event t (PatchDMapWithMove k v'))
forall t (m :: * -> *) (p :: (* -> *) -> (* -> *) -> *)
       (p' :: * -> * -> *) w (k :: * -> *) (v :: * -> *) (v' :: * -> *).
(Reflex t, MonadHold t m, Semigroup w,
 Patch (p' (Some k) (Event t w)),
 PatchTarget (p' (Some k) (Event t w)) ~ Map (Some k) (Event t w),
 GCompare k, Patch (p' (Some k) w),
 PatchTarget (p' (Some k) w) ~ Map (Some k) w) =>
((forall a. k a -> v a -> m (Compose ((,) (Event t w)) v' a))
 -> DMap k v
 -> Event t (p k v)
 -> EventWriterT
      t
      w
      m
      (DMap k (Compose ((,) (Event t w)) v'),
       Event t (p k (Compose ((,) (Event t w)) v'))))
-> ((forall a. Compose ((,) (Event t w)) v' a -> v' a)
    -> p k (Compose ((,) (Event t w)) v') -> p k v')
-> ((forall a. Compose ((,) (Event t w)) v' a -> Event t w)
    -> p k (Compose ((,) (Event t w)) v') -> p' (Some k) (Event t w))
-> (Incremental t (p' (Some k) (Event t w))
    -> Event t (PatchTarget (p' (Some k) w)))
-> (Event t (p' (Some k) (Event t w)) -> Event t (p' (Some k) w))
-> (forall a. k a -> v a -> EventWriterT t w m (v' a))
-> DMap k v
-> Event t (p k v)
-> EventWriterT t w m (DMap k v', Event t (p k v'))
sequenceDMapWithAdjustEventWriterTWith (\forall a. k a -> v a -> m (Compose ((,) (Event t w)) v' a)
f DMap k v
dm0 Event t (PatchDMapWithMove k v)
dm' -> m (DMap k (Compose ((,) (Event t w)) v'),
   Event t (PatchDMapWithMove k (Compose ((,) (Event t w)) v')))
-> EventWriterT
     t
     w
     m
     (DMap k (Compose ((,) (Event t w)) v'),
      Event t (PatchDMapWithMove k (Compose ((,) (Event t w)) v')))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (DMap k (Compose ((,) (Event t w)) v'),
    Event t (PatchDMapWithMove k (Compose ((,) (Event t w)) v')))
 -> EventWriterT
      t
      w
      m
      (DMap k (Compose ((,) (Event t w)) v'),
       Event t (PatchDMapWithMove k (Compose ((,) (Event t w)) v'))))
-> m (DMap k (Compose ((,) (Event t w)) v'),
      Event t (PatchDMapWithMove k (Compose ((,) (Event t w)) v')))
-> EventWriterT
     t
     w
     m
     (DMap k (Compose ((,) (Event t w)) v'),
      Event t (PatchDMapWithMove k (Compose ((,) (Event t w)) v')))
forall a b. (a -> b) -> a -> b
$ (forall a. k a -> v a -> m (Compose ((,) (Event t w)) v' a))
-> DMap k v
-> Event t (PatchDMapWithMove k v)
-> m (DMap k (Compose ((,) (Event t w)) v'),
      Event t (PatchDMapWithMove k (Compose ((,) (Event t w)) v')))
forall t (m :: * -> *) (k :: * -> *) (v :: * -> *) (v' :: * -> *).
(Adjustable t m, GCompare k) =>
(forall a. k a -> v a -> m (v' a))
-> DMap k v
-> Event t (PatchDMapWithMove k v)
-> m (DMap k v', Event t (PatchDMapWithMove k v'))
traverseDMapWithKeyWithAdjustWithMove forall a. k a -> v a -> m (Compose ((,) (Event t w)) v' a)
f DMap k v
dm0 Event t (PatchDMapWithMove k v)
dm') (forall a. Compose ((,) (Event t w)) v' a -> v' a)
-> PatchDMapWithMove k (Compose ((,) (Event t w)) v')
-> PatchDMapWithMove k v'
forall k1 (k2 :: k1 -> *) (v :: k1 -> *) (v' :: k1 -> *).
(forall (a :: k1). v a -> v' a)
-> PatchDMapWithMove k2 v -> PatchDMapWithMove k2 v'
mapPatchDMapWithMove (forall a. Compose ((,) (Event t w)) v' a -> Event t w)
-> PatchDMapWithMove k (Compose ((,) (Event t w)) v')
-> PatchMapWithMove (Some k) (Event t w)
forall k1 (k2 :: k1 -> *) (v :: k1 -> *) v'.
(forall (a :: k1). v a -> v')
-> PatchDMapWithMove k2 v -> PatchMapWithMove (Some k2) v'
weakenPatchDMapWithMoveWith Incremental t (PatchMapWithMove (Some k) (Event t w))
-> Event t (PatchTarget (PatchMapWithMove (Some k) w))
forall k1 (t :: k1) k2 a.
(Reflex t, Ord k2) =>
Incremental t (PatchMapWithMove k2 (Event t a))
-> Event t (Map k2 a)
mergeMapIncrementalWithMove Event t (PatchMapWithMove (Some k) (Event t w))
-> Event t (PatchMapWithMove (Some k) w)
forall k1 (t :: k1) k2 v.
(Reflex t, Ord k2) =>
Event t (PatchMapWithMove k2 (Event t v))
-> Event t (PatchMapWithMove k2 v)
coincidencePatchMapWithMove

instance Requester t m => Requester t (EventWriterT t w m) where
  type Request (EventWriterT t w m) = Request m
  type Response (EventWriterT t w m) = Response m
  requesting :: Event t (Request (EventWriterT t w m) a)
-> EventWriterT t w m (Event t (Response (EventWriterT t w m) a))
requesting = m (Event t (Response m a))
-> EventWriterT t w m (Event t (Response m a))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Event t (Response m a))
 -> EventWriterT t w m (Event t (Response m a)))
-> (Event t (Request m a) -> m (Event t (Response m a)))
-> Event t (Request m a)
-> EventWriterT t w m (Event t (Response m a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Event t (Request m a) -> m (Event t (Response m a))
forall t (m :: * -> *) a.
Requester t m =>
Event t (Request m a) -> m (Event t (Response m a))
requesting
  requesting_ :: Event t (Request (EventWriterT t w m) a) -> EventWriterT t w m ()
requesting_ = m () -> EventWriterT t w m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> EventWriterT t w m ())
-> (Event t (Request m a) -> m ())
-> Event t (Request m a)
-> EventWriterT t w m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Event t (Request m a) -> m ()
forall t (m :: * -> *) a.
Requester t m =>
Event t (Request m a) -> m ()
requesting_

-- | Given a function like 'runWithReplace' for the underlying monad, implement
-- 'runWithReplace' for 'EventWriterT'.  This is necessary when the underlying
-- monad doesn't have a 'Adjustable' instance or to override the default
-- 'Adjustable' behavior.
runWithReplaceEventWriterTWith :: forall m t w a b. (Reflex t, MonadHold t m, Semigroup w)
                               => (forall a' b'. m a' -> Event t (m b') -> EventWriterT t w m (a', Event t b'))
                               -> EventWriterT t w m a
                               -> Event t (EventWriterT t w m b)
                               -> EventWriterT t w m (a, Event t b)
runWithReplaceEventWriterTWith :: (forall a' b'.
 m a' -> Event t (m b') -> EventWriterT t w m (a', Event t b'))
-> EventWriterT t w m a
-> Event t (EventWriterT t w m b)
-> EventWriterT t w m (a, Event t b)
runWithReplaceEventWriterTWith forall a' b'.
m a' -> Event t (m b') -> EventWriterT t w m (a', Event t b')
f EventWriterT t w m a
a0 Event t (EventWriterT t w m b)
a' = do
  ((a, Event t w)
result0, Event t (b, Event t w)
result') <- m (a, Event t w)
-> Event t (m (b, Event t w))
-> EventWriterT t w m ((a, Event t w), Event t (b, Event t w))
forall a' b'.
m a' -> Event t (m b') -> EventWriterT t w m (a', Event t b')
f (EventWriterT t w m a -> m (a, Event t w)
forall t (m :: * -> *) w a.
(Reflex t, Monad m, Semigroup w) =>
EventWriterT t w m a -> m (a, Event t w)
runEventWriterT EventWriterT t w m a
a0) (Event t (m (b, Event t w))
 -> EventWriterT t w m ((a, Event t w), Event t (b, Event t w)))
-> Event t (m (b, Event t w))
-> EventWriterT t w m ((a, Event t w), Event t (b, Event t w))
forall a b. (a -> b) -> a -> b
$ (EventWriterT t w m b -> m (b, Event t w))
-> Event t (EventWriterT t w m b) -> Event t (m (b, Event t w))
forall k (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap EventWriterT t w m b -> m (b, Event t w)
forall t (m :: * -> *) w a.
(Reflex t, Monad m, Semigroup w) =>
EventWriterT t w m a -> m (a, Event t w)
runEventWriterT Event t (EventWriterT t w m b)
a'
  Event t w -> EventWriterT t w m ()
forall t w (m :: * -> *). EventWriter t w m => Event t w -> m ()
tellEvent (Event t w -> EventWriterT t w m ())
-> EventWriterT t w m (Event t w) -> EventWriterT t w m ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Event t w -> Event t (Event t w) -> EventWriterT t w m (Event t w)
forall k (t :: k) (m :: * -> *) a.
(Reflex t, MonadHold t m) =>
Event t a -> Event t (Event t a) -> m (Event t a)
switchHoldPromptOnly ((a, Event t w) -> Event t w
forall a b. (a, b) -> b
snd (a, Event t w)
result0) (((b, Event t w) -> Event t w)
-> Event t (b, Event t w) -> Event t (Event t w)
forall k (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap (b, Event t w) -> Event t w
forall a b. (a, b) -> b
snd Event t (b, Event t w)
result')
  (a, Event t b) -> EventWriterT t w m (a, Event t b)
forall (m :: * -> *) a. Monad m => a -> m a
return ((a, Event t w) -> a
forall a b. (a, b) -> a
fst (a, Event t w)
result0, ((b, Event t w) -> b) -> Event t (b, Event t w) -> Event t b
forall k (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap (b, Event t w) -> b
forall a b. (a, b) -> a
fst Event t (b, Event t w)
result')

-- | Like 'runWithReplaceEventWriterTWith', but for 'sequenceIntMapWithAdjust'.
sequenceIntMapWithAdjustEventWriterTWith
  :: forall t m p w v v'
  .  ( Reflex t
     , MonadHold t m
     , Semigroup w
     , Functor p
     , Patch (p (Event t w))
     , PatchTarget (p (Event t w)) ~ IntMap (Event t w)
     , Patch (p w)
     , PatchTarget (p w) ~ IntMap w
     )
  => (   (IntMap.Key -> v -> m (Event t w, v'))
      -> IntMap v
      -> Event t (p v)
      -> EventWriterT t w m (IntMap (Event t w, v'), Event t (p (Event t w, v')))
     )
  -> (Incremental t (p (Event t w)) -> Event t (PatchTarget (p w)))
  -> (Event t (p (Event t w)) -> Event t (p w))
  -> (IntMap.Key -> v -> EventWriterT t w m v')
  -> IntMap v
  -> Event t (p v)
  -> EventWriterT t w m (IntMap v', Event t (p v'))
sequenceIntMapWithAdjustEventWriterTWith :: ((Int -> v -> m (Event t w, v'))
 -> IntMap v
 -> Event t (p v)
 -> EventWriterT
      t w m (IntMap (Event t w, v'), Event t (p (Event t w, v'))))
-> (Incremental t (p (Event t w)) -> Event t (PatchTarget (p w)))
-> (Event t (p (Event t w)) -> Event t (p w))
-> (Int -> v -> EventWriterT t w m v')
-> IntMap v
-> Event t (p v)
-> EventWriterT t w m (IntMap v', Event t (p v'))
sequenceIntMapWithAdjustEventWriterTWith (Int -> v -> m (Event t w, v'))
-> IntMap v
-> Event t (p v)
-> EventWriterT
     t w m (IntMap (Event t w, v'), Event t (p (Event t w, v')))
base Incremental t (p (Event t w)) -> Event t (PatchTarget (p w))
mergePatchIncremental Event t (p (Event t w)) -> Event t (p w)
coincidencePatch Int -> v -> EventWriterT t w m v'
f IntMap v
dm0 Event t (p v)
dm' = do
  let f' :: IntMap.Key -> v -> m (Event t w, v')
      f' :: Int -> v -> m (Event t w, v')
f' Int
k v
v = (v', Event t w) -> (Event t w, v')
forall a b. (a, b) -> (b, a)
swap ((v', Event t w) -> (Event t w, v'))
-> m (v', Event t w) -> m (Event t w, v')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> EventWriterT t w m v' -> m (v', Event t w)
forall t (m :: * -> *) w a.
(Reflex t, Monad m, Semigroup w) =>
EventWriterT t w m a -> m (a, Event t w)
runEventWriterT (Int -> v -> EventWriterT t w m v'
f Int
k v
v)
  (IntMap (Event t w, v')
children0, Event t (p (Event t w, v'))
children') <- (Int -> v -> m (Event t w, v'))
-> IntMap v
-> Event t (p v)
-> EventWriterT
     t w m (IntMap (Event t w, v'), Event t (p (Event t w, v')))
base Int -> v -> m (Event t w, v')
f' IntMap v
dm0 Event t (p v)
dm'
  let result0 :: IntMap v'
result0 = ((Event t w, v') -> v') -> IntMap (Event t w, v') -> IntMap v'
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Event t w, v') -> v'
forall a b. (a, b) -> b
snd IntMap (Event t w, v')
children0
      result' :: Event t (p v')
result' = (p (Event t w, v') -> p v')
-> Event t (p (Event t w, v')) -> Event t (p v')
forall k (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap (((Event t w, v') -> v') -> p (Event t w, v') -> p v'
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Event t w, v') -> v'
forall a b. (a, b) -> b
snd) Event t (p (Event t w, v'))
children'
      requests0 :: IntMap (Event t w)
      requests0 :: IntMap (Event t w)
requests0 = ((Event t w, v') -> Event t w)
-> IntMap (Event t w, v') -> IntMap (Event t w)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Event t w, v') -> Event t w
forall a b. (a, b) -> a
fst IntMap (Event t w, v')
children0
      requests' :: Event t (p (Event t w))
      requests' :: Event t (p (Event t w))
requests' = (p (Event t w, v') -> p (Event t w))
-> Event t (p (Event t w, v')) -> Event t (p (Event t w))
forall k (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap (((Event t w, v') -> Event t w)
-> p (Event t w, v') -> p (Event t w)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Event t w, v') -> Event t w
forall a b. (a, b) -> a
fst) Event t (p (Event t w, v'))
children'
  Event t (IntMap w)
e <- (Incremental t (p (Event t w)) -> Event t (IntMap w))
-> (Event t (p (Event t w)) -> Event t (p w))
-> IntMap (Event t w)
-> Event t (p (Event t w))
-> EventWriterT t w m (Event t (IntMap w))
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 (IntMap w)
Incremental t (p (Event t w)) -> Event t (PatchTarget (p w))
mergePatchIncremental Event t (p (Event t w)) -> Event t (p w)
coincidencePatch IntMap (Event t w)
requests0 Event t (p (Event t w))
requests'
  Event t w -> EventWriterT t w m ()
forall t w (m :: * -> *). EventWriter t w m => Event t w -> m ()
tellEvent (Event t w -> EventWriterT t w m ())
-> Event t w -> EventWriterT t w m ()
forall a b. (a -> b) -> a -> b
$ Event t (IntMap w) -> (IntMap w -> Maybe w) -> Event t w
forall k (t :: k) a b.
Reflex t =>
Event t a -> (a -> Maybe b) -> Event t b
fforMaybeCheap Event t (IntMap w)
e ((IntMap w -> Maybe w) -> Event t w)
-> (IntMap w -> Maybe w) -> Event t w
forall a b. (a -> b) -> a -> b
$ \IntMap w
m ->
    case IntMap w -> [w]
forall a. IntMap a -> [a]
IntMap.elems IntMap w
m of
      [] -> Maybe w
forall a. Maybe a
Nothing
      w
h : [w]
t -> w -> Maybe w
forall a. a -> Maybe a
Just (w -> Maybe w) -> w -> Maybe w
forall a b. (a -> b) -> a -> b
$ NonEmpty w -> w
forall a. Semigroup a => NonEmpty a -> a
sconcat (NonEmpty w -> w) -> NonEmpty w -> w
forall a b. (a -> b) -> a -> b
$ w
h w -> [w] -> NonEmpty w
forall a. a -> [a] -> NonEmpty a
:| [w]
t
  (IntMap v', Event t (p v'))
-> EventWriterT t w m (IntMap v', Event t (p v'))
forall (m :: * -> *) a. Monad m => a -> m a
return (IntMap v'
result0, Event t (p v')
result')

-- | Like 'runWithReplaceEventWriterTWith', but for 'sequenceDMapWithAdjust'.
sequenceDMapWithAdjustEventWriterTWith
  :: forall t m p p' w k v v'
  .  ( Reflex t
     , MonadHold t m
     , Semigroup w
     , Patch (p' (Some k) (Event t w))
     , PatchTarget (p' (Some k) (Event t w)) ~ Map (Some k) (Event t w)
     , GCompare k
     , Patch (p' (Some k) w)
     , PatchTarget (p' (Some k) w) ~ Map (Some k) w
     )
  => (   (forall a. k a -> v a -> m (Compose ((,) (Event t w)) v' a))
      -> DMap k v
      -> Event t (p k v)
      -> EventWriterT t w m (DMap k (Compose ((,) (Event t w)) v'), Event t (p k (Compose ((,) (Event t w)) v')))
     )
  -> ((forall a. Compose ((,) (Event t w)) v' a -> v' a) -> p k (Compose ((,) (Event t w)) v') -> p k v')
  -> ((forall a. Compose ((,) (Event t w)) v' a -> Event t w) -> p k (Compose ((,) (Event t w)) v') -> p' (Some k) (Event t w))
  -> (Incremental t (p' (Some k) (Event t w)) -> Event t (PatchTarget (p' (Some k) w)))
  -> (Event t (p' (Some k) (Event t w)) -> Event t (p' (Some k) w))
  -> (forall a. k a -> v a -> EventWriterT t w m (v' a))
  -> DMap k v
  -> Event t (p k v)
  -> EventWriterT t w m (DMap k v', Event t (p k v'))
sequenceDMapWithAdjustEventWriterTWith :: ((forall a. k a -> v a -> m (Compose ((,) (Event t w)) v' a))
 -> DMap k v
 -> Event t (p k v)
 -> EventWriterT
      t
      w
      m
      (DMap k (Compose ((,) (Event t w)) v'),
       Event t (p k (Compose ((,) (Event t w)) v'))))
-> ((forall a. Compose ((,) (Event t w)) v' a -> v' a)
    -> p k (Compose ((,) (Event t w)) v') -> p k v')
-> ((forall a. Compose ((,) (Event t w)) v' a -> Event t w)
    -> p k (Compose ((,) (Event t w)) v') -> p' (Some k) (Event t w))
-> (Incremental t (p' (Some k) (Event t w))
    -> Event t (PatchTarget (p' (Some k) w)))
-> (Event t (p' (Some k) (Event t w)) -> Event t (p' (Some k) w))
-> (forall a. k a -> v a -> EventWriterT t w m (v' a))
-> DMap k v
-> Event t (p k v)
-> EventWriterT t w m (DMap k v', Event t (p k v'))
sequenceDMapWithAdjustEventWriterTWith (forall a. k a -> v a -> m (Compose ((,) (Event t w)) v' a))
-> DMap k v
-> Event t (p k v)
-> EventWriterT
     t
     w
     m
     (DMap k (Compose ((,) (Event t w)) v'),
      Event t (p k (Compose ((,) (Event t w)) v')))
base (forall a. Compose ((,) (Event t w)) v' a -> v' a)
-> p k (Compose ((,) (Event t w)) v') -> p k v'
mapPatch (forall a. Compose ((,) (Event t w)) v' a -> Event t w)
-> p k (Compose ((,) (Event t w)) v') -> p' (Some k) (Event t w)
weakenPatchWith Incremental t (p' (Some k) (Event t w))
-> Event t (PatchTarget (p' (Some k) w))
mergePatchIncremental Event t (p' (Some k) (Event t w)) -> Event t (p' (Some k) w)
coincidencePatch forall a. k a -> v a -> EventWriterT t w m (v' a)
f DMap k v
dm0 Event t (p k v)
dm' = do
  let f' :: forall a. k a -> v a -> m (Compose ((,) (Event t w)) v' a)
      f' :: k a -> v a -> m (Compose ((,) (Event t w)) v' a)
f' k a
k v a
v = (Event t w, v' a) -> Compose ((,) (Event t w)) v' a
forall k k1 (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose ((Event t w, v' a) -> Compose ((,) (Event t w)) v' a)
-> ((v' a, Event t w) -> (Event t w, v' a))
-> (v' a, Event t w)
-> Compose ((,) (Event t w)) v' a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (v' a, Event t w) -> (Event t w, v' a)
forall a b. (a, b) -> (b, a)
swap ((v' a, Event t w) -> Compose ((,) (Event t w)) v' a)
-> m (v' a, Event t w) -> m (Compose ((,) (Event t w)) v' a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> EventWriterT t w m (v' a) -> m (v' a, Event t w)
forall t (m :: * -> *) w a.
(Reflex t, Monad m, Semigroup w) =>
EventWriterT t w m a -> m (a, Event t w)
runEventWriterT (k a -> v a -> EventWriterT t w m (v' a)
forall a. k a -> v a -> EventWriterT t w m (v' a)
f k a
k v a
v)
  (DMap k (Compose ((,) (Event t w)) v')
children0, Event t (p k (Compose ((,) (Event t w)) v'))
children') <- (forall a. k a -> v a -> m (Compose ((,) (Event t w)) v' a))
-> DMap k v
-> Event t (p k v)
-> EventWriterT
     t
     w
     m
     (DMap k (Compose ((,) (Event t w)) v'),
      Event t (p k (Compose ((,) (Event t w)) v')))
base forall a. k a -> v a -> m (Compose ((,) (Event t w)) v' a)
f' DMap k v
dm0 Event t (p k v)
dm'
  let result0 :: DMap k v'
result0 = (forall a. Compose ((,) (Event t w)) v' a -> v' a)
-> DMap k (Compose ((,) (Event t w)) v') -> DMap k 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 w, v' v) -> v' v
forall a b. (a, b) -> b
snd ((Event t w, v' v) -> v' v)
-> (Compose ((,) (Event t w)) v' v -> (Event t w, v' v))
-> Compose ((,) (Event t w)) v' v
-> v' v
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Compose ((,) (Event t w)) v' v -> (Event t w, v' v)
forall k1 (f :: k1 -> *) k2 (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose) DMap k (Compose ((,) (Event t w)) v')
children0
      result' :: Event t (p k v')
result' = Event t (p k (Compose ((,) (Event t w)) v'))
-> (p k (Compose ((,) (Event t w)) v') -> p k v')
-> Event t (p k v')
forall k (t :: k) a b.
Reflex t =>
Event t a -> (a -> b) -> Event t b
fforCheap Event t (p k (Compose ((,) (Event t w)) v'))
children' ((p k (Compose ((,) (Event t w)) v') -> p k v')
 -> Event t (p k v'))
-> (p k (Compose ((,) (Event t w)) v') -> p k v')
-> Event t (p k v')
forall a b. (a -> b) -> a -> b
$ (forall a. Compose ((,) (Event t w)) v' a -> v' a)
-> p k (Compose ((,) (Event t w)) v') -> p k v'
mapPatch ((forall a. Compose ((,) (Event t w)) v' a -> v' a)
 -> p k (Compose ((,) (Event t w)) v') -> p k v')
-> (forall a. Compose ((,) (Event t w)) v' a -> v' a)
-> p k (Compose ((,) (Event t w)) v')
-> p k v'
forall a b. (a -> b) -> a -> b
$ (Event t w, v' a) -> v' a
forall a b. (a, b) -> b
snd ((Event t w, v' a) -> v' a)
-> (Compose ((,) (Event t w)) v' a -> (Event t w, v' a))
-> Compose ((,) (Event t w)) v' a
-> v' a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Compose ((,) (Event t w)) v' a -> (Event t w, v' a)
forall k1 (f :: k1 -> *) k2 (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose
      requests0 :: Map (Some k) (Event t w)
      requests0 :: Map (Some k) (Event t w)
requests0 = (forall a. Compose ((,) (Event t w)) v' a -> Event t w)
-> DMap k (Compose ((,) (Event t w)) v')
-> Map (Some k) (Event t w)
forall k1 (v :: k1 -> *) v' (k2 :: k1 -> *).
(forall (a :: k1). v a -> v') -> DMap k2 v -> Map (Some k2) v'
weakenDMapWith ((Event t w, v' a) -> Event t w
forall a b. (a, b) -> a
fst ((Event t w, v' a) -> Event t w)
-> (Compose ((,) (Event t w)) v' a -> (Event t w, v' a))
-> Compose ((,) (Event t w)) v' a
-> Event t w
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Compose ((,) (Event t w)) v' a -> (Event t w, v' a)
forall k1 (f :: k1 -> *) k2 (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose) DMap k (Compose ((,) (Event t w)) v')
children0
      requests' :: Event t (p' (Some k) (Event t w))
      requests' :: Event t (p' (Some k) (Event t w))
requests' = Event t (p k (Compose ((,) (Event t w)) v'))
-> (p k (Compose ((,) (Event t w)) v') -> p' (Some k) (Event t w))
-> Event t (p' (Some k) (Event t w))
forall k (t :: k) a b.
Reflex t =>
Event t a -> (a -> b) -> Event t b
fforCheap Event t (p k (Compose ((,) (Event t w)) v'))
children' ((p k (Compose ((,) (Event t w)) v') -> p' (Some k) (Event t w))
 -> Event t (p' (Some k) (Event t w)))
-> (p k (Compose ((,) (Event t w)) v') -> p' (Some k) (Event t w))
-> Event t (p' (Some k) (Event t w))
forall a b. (a -> b) -> a -> b
$ (forall a. Compose ((,) (Event t w)) v' a -> Event t w)
-> p k (Compose ((,) (Event t w)) v') -> p' (Some k) (Event t w)
weakenPatchWith ((forall a. Compose ((,) (Event t w)) v' a -> Event t w)
 -> p k (Compose ((,) (Event t w)) v') -> p' (Some k) (Event t w))
-> (forall a. Compose ((,) (Event t w)) v' a -> Event t w)
-> p k (Compose ((,) (Event t w)) v')
-> p' (Some k) (Event t w)
forall a b. (a -> b) -> a -> b
$ (Event t w, v' a) -> Event t w
forall a b. (a, b) -> a
fst ((Event t w, v' a) -> Event t w)
-> (Compose ((,) (Event t w)) v' a -> (Event t w, v' a))
-> Compose ((,) (Event t w)) v' a
-> Event t w
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Compose ((,) (Event t w)) v' a -> (Event t w, v' a)
forall k1 (f :: k1 -> *) k2 (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose
  Event t (Map (Some k) w)
e <- (Incremental t (p' (Some k) (Event t w))
 -> Event t (Map (Some k) w))
-> (Event t (p' (Some k) (Event t w)) -> Event t (p' (Some k) w))
-> Map (Some k) (Event t w)
-> Event t (p' (Some k) (Event t w))
-> EventWriterT t w m (Event t (Map (Some k) w))
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' (Some k) (Event t w)) -> Event t (Map (Some k) w)
Incremental t (p' (Some k) (Event t w))
-> Event t (PatchTarget (p' (Some k) w))
mergePatchIncremental Event t (p' (Some k) (Event t w)) -> Event t (p' (Some k) w)
coincidencePatch Map (Some k) (Event t w)
requests0 Event t (p' (Some k) (Event t w))
requests'
  Event t w -> EventWriterT t w m ()
forall t w (m :: * -> *). EventWriter t w m => Event t w -> m ()
tellEvent (Event t w -> EventWriterT t w m ())
-> Event t w -> EventWriterT t w m ()
forall a b. (a -> b) -> a -> b
$ Event t (Map (Some k) w)
-> (Map (Some k) w -> Maybe w) -> Event t w
forall k (t :: k) a b.
Reflex t =>
Event t a -> (a -> Maybe b) -> Event t b
fforMaybeCheap Event t (Map (Some k) w)
e ((Map (Some k) w -> Maybe w) -> Event t w)
-> (Map (Some k) w -> Maybe w) -> Event t w
forall a b. (a -> b) -> a -> b
$ \Map (Some k) w
m ->
    case Map (Some k) w -> [w]
forall k a. Map k a -> [a]
Map.elems Map (Some k) w
m of
      [] -> Maybe w
forall a. Maybe a
Nothing
      w
h : [w]
t -> w -> Maybe w
forall a. a -> Maybe a
Just (w -> Maybe w) -> w -> Maybe w
forall a b. (a -> b) -> a -> b
$ NonEmpty w -> w
forall a. Semigroup a => NonEmpty a -> a
sconcat (NonEmpty w -> w) -> NonEmpty w -> w
forall a b. (a -> b) -> a -> b
$ w
h w -> [w] -> NonEmpty w
forall a. a -> [a] -> NonEmpty a
:| [w]
t
  (DMap k v', Event t (p k v'))
-> EventWriterT t w m (DMap k v', Event t (p k v'))
forall (m :: * -> *) a. Monad m => a -> m a
return (DMap k v'
result0, Event t (p k v')
result')

instance PerformEvent t m => PerformEvent t (EventWriterT t w m) where
  type Performable (EventWriterT t w m) = Performable m
  performEvent_ :: Event t (Performable (EventWriterT t w m) ())
-> EventWriterT t w m ()
performEvent_ = m () -> EventWriterT t w m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> EventWriterT t w m ())
-> (Event t (Performable m ()) -> m ())
-> Event t (Performable m ())
-> EventWriterT t w m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Event t (Performable m ()) -> m ()
forall t (m :: * -> *).
PerformEvent t m =>
Event t (Performable m ()) -> m ()
performEvent_
  performEvent :: Event t (Performable (EventWriterT t w m) a)
-> EventWriterT t w m (Event t a)
performEvent = m (Event t a) -> EventWriterT t w m (Event t a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Event t a) -> EventWriterT t w m (Event t a))
-> (Event t (Performable m a) -> m (Event t a))
-> Event t (Performable m a)
-> EventWriterT t w m (Event t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Event t (Performable m a) -> m (Event t a)
forall t (m :: * -> *) a.
PerformEvent t m =>
Event t (Performable m a) -> m (Event t a)
performEvent

instance PostBuild t m => PostBuild t (EventWriterT t w m) where
  getPostBuild :: EventWriterT t w m (Event t ())
getPostBuild = m (Event t ()) -> EventWriterT t w m (Event t ())
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m (Event t ())
forall t (m :: * -> *). PostBuild t m => m (Event t ())
getPostBuild

instance TriggerEvent t m => TriggerEvent t (EventWriterT t w m) where
  newTriggerEvent :: EventWriterT t w m (Event t a, a -> IO ())
newTriggerEvent = m (Event t a, a -> IO ())
-> EventWriterT t w m (Event t a, a -> IO ())
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m (Event t a, a -> IO ())
forall t (m :: * -> *) a.
TriggerEvent t m =>
m (Event t a, a -> IO ())
newTriggerEvent
  newTriggerEventWithOnComplete :: EventWriterT t w m (Event t a, a -> IO () -> IO ())
newTriggerEventWithOnComplete = m (Event t a, a -> IO () -> IO ())
-> EventWriterT t w m (Event t a, a -> IO () -> IO ())
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m (Event t a, a -> IO () -> IO ())
forall t (m :: * -> *) a.
TriggerEvent t m =>
m (Event t a, a -> IO () -> IO ())
newTriggerEventWithOnComplete
  newEventWithLazyTriggerWithOnComplete :: ((a -> IO () -> IO ()) -> IO (IO ()))
-> EventWriterT t w m (Event t a)
newEventWithLazyTriggerWithOnComplete = m (Event t a) -> EventWriterT t w m (Event t a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Event t a) -> EventWriterT t w m (Event t a))
-> (((a -> IO () -> IO ()) -> IO (IO ())) -> m (Event t a))
-> ((a -> IO () -> IO ()) -> IO (IO ()))
-> EventWriterT t w m (Event t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((a -> IO () -> IO ()) -> IO (IO ())) -> m (Event t a)
forall t (m :: * -> *) a.
TriggerEvent t m =>
((a -> IO () -> IO ()) -> IO (IO ())) -> m (Event t a)
newEventWithLazyTriggerWithOnComplete

instance MonadReader r m => MonadReader r (EventWriterT t w m) where
  ask :: EventWriterT t w m r
ask = m r -> EventWriterT t w m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m r
forall r (m :: * -> *). MonadReader r m => m r
ask
  local :: (r -> r) -> EventWriterT t w m a -> EventWriterT t w m a
local r -> r
f (EventWriterT StateT (EventWriterState t w) m a
a) = StateT (EventWriterState t w) m a -> EventWriterT t w m a
forall t w (m :: * -> *) a.
StateT (EventWriterState t w) m a -> EventWriterT t w m a
EventWriterT (StateT (EventWriterState t w) m a -> EventWriterT t w m a)
-> StateT (EventWriterState t w) m a -> EventWriterT t w m a
forall a b. (a -> b) -> a -> b
$ (m (a, EventWriterState t w) -> m (a, EventWriterState t w))
-> StateT (EventWriterState t w) m a
-> StateT (EventWriterState t w) m a
forall (m :: * -> *) a s (n :: * -> *) b.
(m (a, s) -> n (b, s)) -> StateT s m a -> StateT s n b
mapStateT ((r -> r)
-> m (a, EventWriterState t w) -> m (a, EventWriterState t w)
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local r -> r
f) StateT (EventWriterState t w) m a
a
  reader :: (r -> a) -> EventWriterT t w m a
reader = m a -> EventWriterT t w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> EventWriterT t w m a)
-> ((r -> a) -> m a) -> (r -> a) -> EventWriterT t w m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (r -> a) -> m a
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
reader

instance MonadRef m => MonadRef (EventWriterT t w m) where
  type Ref (EventWriterT t w m) = Ref m
  newRef :: a -> EventWriterT t w m (Ref (EventWriterT t w m) a)
newRef = m (Ref m a) -> EventWriterT t w m (Ref m a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Ref m a) -> EventWriterT t w m (Ref m a))
-> (a -> m (Ref m a)) -> a -> EventWriterT t w m (Ref m a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> m (Ref m a)
forall (m :: * -> *) a. MonadRef m => a -> m (Ref m a)
newRef
  readRef :: Ref (EventWriterT t w m) a -> EventWriterT t w m a
readRef = m a -> EventWriterT t w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> EventWriterT t w m a)
-> (Ref m a -> m a) -> Ref m a -> EventWriterT t w m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ref m a -> m a
forall (m :: * -> *) a. MonadRef m => Ref m a -> m a
readRef
  writeRef :: Ref (EventWriterT t w m) a -> a -> EventWriterT t w m ()
writeRef Ref (EventWriterT t w m) a
r = m () -> EventWriterT t w m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> EventWriterT t w m ())
-> (a -> m ()) -> a -> EventWriterT t w m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ref m a -> a -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> m ()
writeRef Ref m a
Ref (EventWriterT t w m) a
r

instance MonadAtomicRef m => MonadAtomicRef (EventWriterT t w m) where
  atomicModifyRef :: Ref (EventWriterT t w m) a -> (a -> (a, b)) -> EventWriterT t w m b
atomicModifyRef Ref (EventWriterT t w m) a
r = m b -> EventWriterT t w m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m b -> EventWriterT t w m b)
-> ((a -> (a, b)) -> m b) -> (a -> (a, b)) -> EventWriterT t w m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ref m a -> (a -> (a, b)) -> m b
forall (m :: * -> *) a b.
MonadAtomicRef m =>
Ref m a -> (a -> (a, b)) -> m b
atomicModifyRef Ref m a
Ref (EventWriterT t w m) a
r

instance MonadReflexCreateTrigger t m => MonadReflexCreateTrigger t (EventWriterT t w m) where
  newEventWithTrigger :: (EventTrigger t a -> IO (IO ())) -> EventWriterT t w m (Event t a)
newEventWithTrigger = m (Event t a) -> EventWriterT t w m (Event t a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Event t a) -> EventWriterT t w m (Event t a))
-> ((EventTrigger t a -> IO (IO ())) -> m (Event t a))
-> (EventTrigger t a -> IO (IO ()))
-> EventWriterT t w m (Event t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (EventTrigger t a -> IO (IO ())) -> m (Event t a)
forall t (m :: * -> *) a.
MonadReflexCreateTrigger t m =>
(EventTrigger t a -> IO (IO ())) -> m (Event t a)
newEventWithTrigger
  newFanEventWithTrigger :: (forall a. k a -> EventTrigger t a -> IO (IO ()))
-> EventWriterT t w m (EventSelector t k)
newFanEventWithTrigger forall a. k a -> EventTrigger t a -> IO (IO ())
f = m (EventSelector t k) -> EventWriterT t w m (EventSelector t k)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (EventSelector t k) -> EventWriterT t w m (EventSelector t k))
-> m (EventSelector t k) -> EventWriterT t w m (EventSelector t k)
forall a b. (a -> b) -> a -> b
$ (forall a. k a -> EventTrigger t a -> IO (IO ()))
-> m (EventSelector t k)
forall t (m :: * -> *) (k :: * -> *).
(MonadReflexCreateTrigger t m, GCompare k) =>
(forall a. k a -> EventTrigger t a -> IO (IO ()))
-> m (EventSelector t k)
newFanEventWithTrigger forall a. k a -> EventTrigger t a -> IO (IO ())
f

instance (MonadQuery t q m, Monad m) => MonadQuery t q (EventWriterT t w m) where
  tellQueryIncremental :: Incremental t (AdditivePatch q) -> EventWriterT t w m ()
tellQueryIncremental = m () -> EventWriterT t w m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> EventWriterT t w m ())
-> (Incremental t (AdditivePatch q) -> m ())
-> Incremental t (AdditivePatch q)
-> EventWriterT t w m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Incremental t (AdditivePatch q) -> m ()
forall t q (m :: * -> *).
MonadQuery t q m =>
Incremental t (AdditivePatch q) -> m ()
tellQueryIncremental
  askQueryResult :: EventWriterT t w m (Dynamic t (QueryResult q))
askQueryResult = m (Dynamic t (QueryResult q))
-> EventWriterT t w m (Dynamic t (QueryResult q))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m (Dynamic t (QueryResult q))
forall t q (m :: * -> *).
MonadQuery t q m =>
m (Dynamic t (QueryResult q))
askQueryResult
  queryIncremental :: Incremental t (AdditivePatch q)
-> EventWriterT t w m (Dynamic t (QueryResult q))
queryIncremental = m (Dynamic t (QueryResult q))
-> EventWriterT t w m (Dynamic t (QueryResult q))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Dynamic t (QueryResult q))
 -> EventWriterT t w m (Dynamic t (QueryResult q)))
-> (Incremental t (AdditivePatch q)
    -> m (Dynamic t (QueryResult q)))
-> Incremental t (AdditivePatch q)
-> EventWriterT t w m (Dynamic t (QueryResult q))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Incremental t (AdditivePatch q) -> m (Dynamic t (QueryResult q))
forall t q (m :: * -> *).
MonadQuery t q m =>
Incremental t (AdditivePatch q) -> m (Dynamic t (QueryResult q))
queryIncremental

instance DynamicWriter t w m => DynamicWriter t w (EventWriterT t v m) where
  tellDyn :: Dynamic t w -> EventWriterT t v m ()
tellDyn = m () -> EventWriterT t v m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> EventWriterT t v m ())
-> (Dynamic t w -> m ()) -> Dynamic t w -> EventWriterT t v m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dynamic t w -> m ()
forall t w (m :: * -> *).
DynamicWriter t w m =>
Dynamic t w -> m ()
tellDyn

instance PrimMonad m => PrimMonad (EventWriterT t w m) where
  type PrimState (EventWriterT t w m) = PrimState m
  primitive :: (State# (PrimState (EventWriterT t w m))
 -> (# State# (PrimState (EventWriterT t w m)), a #))
-> EventWriterT t w m a
primitive = m a -> EventWriterT t w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> EventWriterT t w m a)
-> ((State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a)
-> (State# (PrimState m) -> (# State# (PrimState m), a #))
-> EventWriterT t w m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive

-- | Map a function over the output of a 'EventWriterT'.
withEventWriterT :: (Semigroup w, Semigroup w', Reflex t, MonadHold t m)
                 => (w -> w')
                 -> EventWriterT t w m a
                 -> EventWriterT t w' m a
withEventWriterT :: (w -> w') -> EventWriterT t w m a -> EventWriterT t w' m a
withEventWriterT w -> w'
f EventWriterT t w m a
ew = do
  (a
r, Event t w'
e) <- m (a, Event t w') -> EventWriterT t w' m (a, Event t w')
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (a, Event t w') -> EventWriterT t w' m (a, Event t w'))
-> m (a, Event t w') -> EventWriterT t w' m (a, Event t w')
forall a b. (a -> b) -> a -> b
$ do
    (a
r, Event t w
e) <- EventWriterT t w m a -> m (a, Event t w)
forall t (m :: * -> *) w a.
(Reflex t, Monad m, Semigroup w) =>
EventWriterT t w m a -> m (a, Event t w)
runEventWriterT EventWriterT t w m a
ew
    let e' :: Event t w'
e' = (w -> w') -> Event t w -> Event t w'
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap w -> w'
f Event t w
e
    (a, Event t w') -> m (a, Event t w')
forall (m :: * -> *) a. Monad m => a -> m a
return (a
r, Event t w'
e')
  Event t w' -> EventWriterT t w' m ()
forall t w (m :: * -> *). EventWriter t w m => Event t w -> m ()
tellEvent Event t w'
e
  a -> EventWriterT t w' m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
r

-- | Change the monad underlying an EventWriterT
mapEventWriterT
  :: (forall x. m x -> n x)
  -> EventWriterT t w m a
  -> EventWriterT t w n a
mapEventWriterT :: (forall x. m x -> n x)
-> EventWriterT t w m a -> EventWriterT t w n a
mapEventWriterT forall x. m x -> n x
f (EventWriterT StateT (EventWriterState t w) m a
a) = StateT (EventWriterState t w) n a -> EventWriterT t w n a
forall t w (m :: * -> *) a.
StateT (EventWriterState t w) m a -> EventWriterT t w m a
EventWriterT (StateT (EventWriterState t w) n a -> EventWriterT t w n a)
-> StateT (EventWriterState t w) n a -> EventWriterT t w n a
forall a b. (a -> b) -> a -> b
$ (m (a, EventWriterState t w) -> n (a, EventWriterState t w))
-> StateT (EventWriterState t w) m a
-> StateT (EventWriterState t w) n a
forall (m :: * -> *) a s (n :: * -> *) b.
(m (a, s) -> n (b, s)) -> StateT s m a -> StateT s n b
mapStateT m (a, EventWriterState t w) -> n (a, EventWriterState t w)
forall x. m x -> n x
f StateT (EventWriterState t w) m a
a