-- | This module defines 'PostBuildT', the standard implementation of
-- 'PostBuild'.
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecursiveDo #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
#ifdef USE_REFLEX_OPTIMIZER
{-# OPTIONS_GHC -fplugin=Reflex.Optimizer #-}
#endif
module Reflex.PostBuild.Base
  ( PostBuildT (..)
  , runPostBuildT
  -- * Internal
  , mapIntMapWithAdjustImpl
  , mapDMapWithAdjustImpl
  ) where

import Reflex.Class
import Reflex.Adjustable.Class
import Reflex.Host.Class
import Reflex.PerformEvent.Class
import Reflex.PostBuild.Class
import Reflex.TriggerEvent.Class

import Control.Applicative (liftA2)
import Control.Monad.Exception
import Control.Monad.Identity
import Control.Monad.Primitive
import Control.Monad.Reader
import Control.Monad.Ref
import qualified Control.Monad.Trans.Control as TransControl
import Data.Dependent.Map (DMap)
import qualified Data.Dependent.Map as DMap
import Data.Functor.Compose
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Semigroup as S

-- | Provides a basic implementation of 'PostBuild'.
newtype PostBuildT t m a = PostBuildT { forall t (m :: * -> *) a.
PostBuildT t m a -> ReaderT (Event t ()) m a
unPostBuildT :: ReaderT (Event t ()) m a } deriving ((forall a b. (a -> b) -> PostBuildT t m a -> PostBuildT t m b)
-> (forall a b. a -> PostBuildT t m b -> PostBuildT t m a)
-> Functor (PostBuildT t m)
forall a b. a -> PostBuildT t m b -> PostBuildT t m a
forall a b. (a -> b) -> PostBuildT t m a -> PostBuildT t m b
forall t (m :: * -> *) a b.
Functor m =>
a -> PostBuildT t m b -> PostBuildT t m a
forall t (m :: * -> *) a b.
Functor m =>
(a -> b) -> PostBuildT t m a -> PostBuildT t m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall t (m :: * -> *) a b.
Functor m =>
(a -> b) -> PostBuildT t m a -> PostBuildT t m b
fmap :: forall a b. (a -> b) -> PostBuildT t m a -> PostBuildT t m b
$c<$ :: forall t (m :: * -> *) a b.
Functor m =>
a -> PostBuildT t m b -> PostBuildT t m a
<$ :: forall a b. a -> PostBuildT t m b -> PostBuildT t m a
Functor, Functor (PostBuildT t m)
Functor (PostBuildT t m)
-> (forall a. a -> PostBuildT t m a)
-> (forall a b.
    PostBuildT t m (a -> b) -> PostBuildT t m a -> PostBuildT t m b)
-> (forall a b c.
    (a -> b -> c)
    -> PostBuildT t m a -> PostBuildT t m b -> PostBuildT t m c)
-> (forall a b.
    PostBuildT t m a -> PostBuildT t m b -> PostBuildT t m b)
-> (forall a b.
    PostBuildT t m a -> PostBuildT t m b -> PostBuildT t m a)
-> Applicative (PostBuildT t m)
forall a. a -> PostBuildT t m a
forall a b.
PostBuildT t m a -> PostBuildT t m b -> PostBuildT t m a
forall a b.
PostBuildT t m a -> PostBuildT t m b -> PostBuildT t m b
forall a b.
PostBuildT t m (a -> b) -> PostBuildT t m a -> PostBuildT t m b
forall a b c.
(a -> b -> c)
-> PostBuildT t m a -> PostBuildT t m b -> PostBuildT t m c
forall {t} {m :: * -> *}. Applicative m => Functor (PostBuildT t m)
forall t (m :: * -> *) a. Applicative m => a -> PostBuildT t m a
forall t (m :: * -> *) a b.
Applicative m =>
PostBuildT t m a -> PostBuildT t m b -> PostBuildT t m a
forall t (m :: * -> *) a b.
Applicative m =>
PostBuildT t m a -> PostBuildT t m b -> PostBuildT t m b
forall t (m :: * -> *) a b.
Applicative m =>
PostBuildT t m (a -> b) -> PostBuildT t m a -> PostBuildT t m b
forall t (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> PostBuildT t m a -> PostBuildT t m b -> PostBuildT t 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
$cpure :: forall t (m :: * -> *) a. Applicative m => a -> PostBuildT t m a
pure :: forall a. a -> PostBuildT t m a
$c<*> :: forall t (m :: * -> *) a b.
Applicative m =>
PostBuildT t m (a -> b) -> PostBuildT t m a -> PostBuildT t m b
<*> :: forall a b.
PostBuildT t m (a -> b) -> PostBuildT t m a -> PostBuildT t m b
$cliftA2 :: forall t (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> PostBuildT t m a -> PostBuildT t m b -> PostBuildT t m c
liftA2 :: forall a b c.
(a -> b -> c)
-> PostBuildT t m a -> PostBuildT t m b -> PostBuildT t m c
$c*> :: forall t (m :: * -> *) a b.
Applicative m =>
PostBuildT t m a -> PostBuildT t m b -> PostBuildT t m b
*> :: forall a b.
PostBuildT t m a -> PostBuildT t m b -> PostBuildT t m b
$c<* :: forall t (m :: * -> *) a b.
Applicative m =>
PostBuildT t m a -> PostBuildT t m b -> PostBuildT t m a
<* :: forall a b.
PostBuildT t m a -> PostBuildT t m b -> PostBuildT t m a
Applicative, Applicative (PostBuildT t m)
Applicative (PostBuildT t m)
-> (forall a b.
    PostBuildT t m a -> (a -> PostBuildT t m b) -> PostBuildT t m b)
-> (forall a b.
    PostBuildT t m a -> PostBuildT t m b -> PostBuildT t m b)
-> (forall a. a -> PostBuildT t m a)
-> Monad (PostBuildT t m)
forall a. a -> PostBuildT t m a
forall a b.
PostBuildT t m a -> PostBuildT t m b -> PostBuildT t m b
forall a b.
PostBuildT t m a -> (a -> PostBuildT t m b) -> PostBuildT t m b
forall {t} {m :: * -> *}. Monad m => Applicative (PostBuildT t m)
forall t (m :: * -> *) a. Monad m => a -> PostBuildT t m a
forall t (m :: * -> *) a b.
Monad m =>
PostBuildT t m a -> PostBuildT t m b -> PostBuildT t m b
forall t (m :: * -> *) a b.
Monad m =>
PostBuildT t m a -> (a -> PostBuildT t m b) -> PostBuildT t 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
$c>>= :: forall t (m :: * -> *) a b.
Monad m =>
PostBuildT t m a -> (a -> PostBuildT t m b) -> PostBuildT t m b
>>= :: forall a b.
PostBuildT t m a -> (a -> PostBuildT t m b) -> PostBuildT t m b
$c>> :: forall t (m :: * -> *) a b.
Monad m =>
PostBuildT t m a -> PostBuildT t m b -> PostBuildT t m b
>> :: forall a b.
PostBuildT t m a -> PostBuildT t m b -> PostBuildT t m b
$creturn :: forall t (m :: * -> *) a. Monad m => a -> PostBuildT t m a
return :: forall a. a -> PostBuildT t m a
Monad, Monad (PostBuildT t m)
Monad (PostBuildT t m)
-> (forall a. (a -> PostBuildT t m a) -> PostBuildT t m a)
-> MonadFix (PostBuildT t m)
forall a. (a -> PostBuildT t m a) -> PostBuildT t m a
forall {t} {m :: * -> *}. MonadFix m => Monad (PostBuildT t m)
forall t (m :: * -> *) a.
MonadFix m =>
(a -> PostBuildT t m a) -> PostBuildT t m a
forall (m :: * -> *).
Monad m -> (forall a. (a -> m a) -> m a) -> MonadFix m
$cmfix :: forall t (m :: * -> *) a.
MonadFix m =>
(a -> PostBuildT t m a) -> PostBuildT t m a
mfix :: forall a. (a -> PostBuildT t m a) -> PostBuildT t m a
MonadFix, Monad (PostBuildT t m)
Monad (PostBuildT t m)
-> (forall a. IO a -> PostBuildT t m a) -> MonadIO (PostBuildT t m)
forall a. IO a -> PostBuildT t m a
forall {t} {m :: * -> *}. MonadIO m => Monad (PostBuildT t m)
forall t (m :: * -> *) a. MonadIO m => IO a -> PostBuildT t m a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
$cliftIO :: forall t (m :: * -> *) a. MonadIO m => IO a -> PostBuildT t m a
liftIO :: forall a. IO a -> PostBuildT t m a
MonadIO, (forall (m :: * -> *) a. Monad m => m a -> PostBuildT t m a)
-> MonadTrans (PostBuildT t)
forall t (m :: * -> *) a. Monad m => m a -> PostBuildT t m a
forall (m :: * -> *) a. Monad m => m a -> PostBuildT t m a
forall (t :: (* -> *) -> * -> *).
(forall (m :: * -> *) a. Monad m => m a -> t m a) -> MonadTrans t
$clift :: forall t (m :: * -> *) a. Monad m => m a -> PostBuildT t m a
lift :: forall (m :: * -> *) a. Monad m => m a -> PostBuildT t m a
MonadTrans, Monad (PostBuildT t m)
Monad (PostBuildT t m)
-> (forall e a. Exception e => e -> PostBuildT t m a)
-> (forall e a.
    Exception e =>
    PostBuildT t m a -> (e -> PostBuildT t m a) -> PostBuildT t m a)
-> (forall a b.
    PostBuildT t m a -> PostBuildT t m b -> PostBuildT t m a)
-> MonadException (PostBuildT t m)
forall e a. Exception e => e -> PostBuildT t m a
forall e a.
Exception e =>
PostBuildT t m a -> (e -> PostBuildT t m a) -> PostBuildT t m a
forall a b.
PostBuildT t m a -> PostBuildT t m b -> PostBuildT t m a
forall {t} {m :: * -> *}.
MonadException m =>
Monad (PostBuildT t m)
forall t (m :: * -> *) e a.
(MonadException m, Exception e) =>
e -> PostBuildT t m a
forall t (m :: * -> *) e a.
(MonadException m, Exception e) =>
PostBuildT t m a -> (e -> PostBuildT t m a) -> PostBuildT t m a
forall t (m :: * -> *) a b.
MonadException m =>
PostBuildT t m a -> PostBuildT t m b -> PostBuildT t 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
$cthrow :: forall t (m :: * -> *) e a.
(MonadException m, Exception e) =>
e -> PostBuildT t m a
throw :: forall e a. Exception e => e -> PostBuildT t m a
$ccatch :: forall t (m :: * -> *) e a.
(MonadException m, Exception e) =>
PostBuildT t m a -> (e -> PostBuildT t m a) -> PostBuildT t m a
catch :: forall e a.
Exception e =>
PostBuildT t m a -> (e -> PostBuildT t m a) -> PostBuildT t m a
$cfinally :: forall t (m :: * -> *) a b.
MonadException m =>
PostBuildT t m a -> PostBuildT t m b -> PostBuildT t m a
finally :: forall a b.
PostBuildT t m a -> PostBuildT t m b -> PostBuildT t m a
MonadException, MonadIO (PostBuildT t m)
MonadException (PostBuildT t m)
MonadIO (PostBuildT t m)
-> MonadException (PostBuildT t m)
-> (forall b.
    ((forall a. PostBuildT t m a -> PostBuildT t m a)
     -> PostBuildT t m b)
    -> PostBuildT t m b)
-> MonadAsyncException (PostBuildT t m)
forall b.
((forall a. PostBuildT t m a -> PostBuildT t m a)
 -> PostBuildT t m b)
-> PostBuildT t m b
forall {t} {m :: * -> *}.
MonadAsyncException m =>
MonadIO (PostBuildT t m)
forall {t} {m :: * -> *}.
MonadAsyncException m =>
MonadException (PostBuildT t m)
forall t (m :: * -> *) b.
MonadAsyncException m =>
((forall a. PostBuildT t m a -> PostBuildT t m a)
 -> PostBuildT t m b)
-> PostBuildT t m b
forall (m :: * -> *).
MonadIO m
-> MonadException m
-> (forall b. ((forall a. m a -> m a) -> m b) -> m b)
-> MonadAsyncException m
$cmask :: forall t (m :: * -> *) b.
MonadAsyncException m =>
((forall a. PostBuildT t m a -> PostBuildT t m a)
 -> PostBuildT t m b)
-> PostBuildT t m b
mask :: forall b.
((forall a. PostBuildT t m a -> PostBuildT t m a)
 -> PostBuildT t m b)
-> PostBuildT t m b
MonadAsyncException)

-- | Run a 'PostBuildT' action.  An 'Event' should be provided that fires
-- immediately after the action is finished running; no other 'Event's should
-- fire first.
{-# INLINABLE runPostBuildT #-}
runPostBuildT :: PostBuildT t m a -> Event t () -> m a
runPostBuildT :: forall t (m :: * -> *) a. PostBuildT t m a -> Event t () -> m a
runPostBuildT (PostBuildT ReaderT (Event t ()) m a
a) = ReaderT (Event t ()) m a -> Event t () -> m a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT ReaderT (Event t ()) m a
a

-- TODO: Monoid and Semigroup can likely be derived once ReaderT has them.
instance (Monoid a, Applicative m) => Monoid (PostBuildT t m a) where
  mempty :: PostBuildT t m a
mempty = a -> PostBuildT t m a
forall a. a -> PostBuildT t m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
forall a. Monoid a => a
mempty
  mappend :: PostBuildT t m a -> PostBuildT t m a -> PostBuildT t m a
mappend = (a -> a -> a)
-> PostBuildT t m a -> PostBuildT t m a -> PostBuildT t m a
forall a b c.
(a -> b -> c)
-> PostBuildT t m a -> PostBuildT t m b -> PostBuildT t m c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 a -> a -> a
forall a. Monoid a => a -> a -> a
mappend

instance (S.Semigroup a, Applicative m) => S.Semigroup (PostBuildT t m a) where
  <> :: PostBuildT t m a -> PostBuildT t m a -> PostBuildT t m a
(<>) = (a -> a -> a)
-> PostBuildT t m a -> PostBuildT t m a -> PostBuildT t m a
forall a b c.
(a -> b -> c)
-> PostBuildT t m a -> PostBuildT t m b -> PostBuildT t m c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 a -> a -> a
forall a. Semigroup a => a -> a -> a
(S.<>)

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

instance (Reflex t, Monad m) => PostBuild t (PostBuildT t m) where
  {-# INLINABLE getPostBuild #-}
  getPostBuild :: PostBuildT t m (Event t ())
getPostBuild = ReaderT (Event t ()) m (Event t ()) -> PostBuildT t m (Event t ())
forall t (m :: * -> *) a.
ReaderT (Event t ()) m a -> PostBuildT t m a
PostBuildT ReaderT (Event t ()) m (Event t ())
forall r (m :: * -> *). MonadReader r m => m r
ask

instance MonadSample t m => MonadSample t (PostBuildT t m) where
  {-# INLINABLE sample #-}
  sample :: forall a. Behavior t a -> PostBuildT t m a
sample = m a -> PostBuildT t m a
forall (m :: * -> *) a. Monad m => m a -> PostBuildT t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> PostBuildT t m a)
-> (Behavior t a -> m a) -> Behavior t a -> PostBuildT t 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 (PostBuildT t m) where
  {-# INLINABLE hold #-}
  hold :: forall a. a -> Event t a -> PostBuildT t m (Behavior t a)
hold a
v0 = m (Behavior t a) -> PostBuildT t m (Behavior t a)
forall (m :: * -> *) a. Monad m => m a -> PostBuildT t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Behavior t a) -> PostBuildT t m (Behavior t a))
-> (Event t a -> m (Behavior t a))
-> Event t a
-> PostBuildT t 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
  {-# INLINABLE holdDyn #-}
  holdDyn :: forall a. a -> Event t a -> PostBuildT t m (Dynamic t a)
holdDyn a
v0 = m (Dynamic t a) -> PostBuildT t m (Dynamic t a)
forall (m :: * -> *) a. Monad m => m a -> PostBuildT t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Dynamic t a) -> PostBuildT t m (Dynamic t a))
-> (Event t a -> m (Dynamic t a))
-> Event t a
-> PostBuildT t 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
  {-# INLINABLE holdIncremental #-}
  holdIncremental :: forall p.
Patch p =>
PatchTarget p -> Event t p -> PostBuildT t m (Incremental t p)
holdIncremental PatchTarget p
v0 = m (Incremental t p) -> PostBuildT t m (Incremental t p)
forall (m :: * -> *) a. Monad m => m a -> PostBuildT t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Incremental t p) -> PostBuildT t m (Incremental t p))
-> (Event t p -> m (Incremental t p))
-> Event t p
-> PostBuildT t 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
  {-# INLINABLE buildDynamic #-}
  buildDynamic :: forall a. PushM t a -> Event t a -> PostBuildT t m (Dynamic t a)
buildDynamic PushM t a
a0 = m (Dynamic t a) -> PostBuildT t m (Dynamic t a)
forall (m :: * -> *) a. Monad m => m a -> PostBuildT t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Dynamic t a) -> PostBuildT t m (Dynamic t a))
-> (Event t a -> m (Dynamic t a))
-> Event t a
-> PostBuildT t 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
  {-# INLINABLE headE #-}
  headE :: forall a. Event t a -> PostBuildT t m (Event t a)
headE = m (Event t a) -> PostBuildT t m (Event t a)
forall (m :: * -> *) a. Monad m => m a -> PostBuildT t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Event t a) -> PostBuildT t m (Event t a))
-> (Event t a -> m (Event t a))
-> Event t a
-> PostBuildT t 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
  {-# INLINABLE now #-}
  now :: PostBuildT t m (Event t ())
now = m (Event t ()) -> PostBuildT t m (Event t ())
forall (m :: * -> *) a. Monad m => m a -> PostBuildT t 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 PerformEvent t m => PerformEvent t (PostBuildT t m) where
  type Performable (PostBuildT t m) = Performable m
  {-# INLINABLE performEvent_ #-}
  performEvent_ :: Event t (Performable (PostBuildT t m) ()) -> PostBuildT t m ()
performEvent_ = m () -> PostBuildT t m ()
forall (m :: * -> *) a. Monad m => m a -> PostBuildT t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> PostBuildT t m ())
-> (Event t (Performable m ()) -> m ())
-> Event t (Performable m ())
-> PostBuildT t 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_
  {-# INLINABLE performEvent #-}
  performEvent :: forall a.
Event t (Performable (PostBuildT t m) a)
-> PostBuildT t m (Event t a)
performEvent = m (Event t a) -> PostBuildT t m (Event t a)
forall (m :: * -> *) a. Monad m => m a -> PostBuildT t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Event t a) -> PostBuildT t m (Event t a))
-> (Event t (Performable m a) -> m (Event t a))
-> Event t (Performable m a)
-> PostBuildT t m (Event t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Event t (Performable m a) -> m (Event t a)
forall a. 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 (ReflexHost t, MonadReflexCreateTrigger t m) => MonadReflexCreateTrigger t (PostBuildT t m) where
  {-# INLINABLE newEventWithTrigger #-}
  newEventWithTrigger :: forall a.
(EventTrigger t a -> IO (IO ())) -> PostBuildT t m (Event t a)
newEventWithTrigger = ReaderT (Event t ()) m (Event t a) -> PostBuildT t m (Event t a)
forall t (m :: * -> *) a.
ReaderT (Event t ()) m a -> PostBuildT t m a
PostBuildT (ReaderT (Event t ()) m (Event t a) -> PostBuildT t m (Event t a))
-> ((EventTrigger t a -> IO (IO ()))
    -> ReaderT (Event t ()) m (Event t a))
-> (EventTrigger t a -> IO (IO ()))
-> PostBuildT t m (Event t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (Event t a) -> ReaderT (Event t ()) m (Event t a)
forall (m :: * -> *) a. Monad m => m a -> ReaderT (Event t ()) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Event t a) -> ReaderT (Event t ()) m (Event t a))
-> ((EventTrigger t a -> IO (IO ())) -> m (Event t a))
-> (EventTrigger t a -> IO (IO ()))
-> ReaderT (Event t ()) m (Event t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (EventTrigger t a -> IO (IO ())) -> m (Event t a)
forall a. (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
  {-# INLINABLE newFanEventWithTrigger #-}
  newFanEventWithTrigger :: forall (k :: * -> *).
GCompare k =>
(forall a. k a -> EventTrigger t a -> IO (IO ()))
-> PostBuildT t m (EventSelector t k)
newFanEventWithTrigger forall a. k a -> EventTrigger t a -> IO (IO ())
f = ReaderT (Event t ()) m (EventSelector t k)
-> PostBuildT t m (EventSelector t k)
forall t (m :: * -> *) a.
ReaderT (Event t ()) m a -> PostBuildT t m a
PostBuildT (ReaderT (Event t ()) m (EventSelector t k)
 -> PostBuildT t m (EventSelector t k))
-> ReaderT (Event t ()) m (EventSelector t k)
-> PostBuildT t m (EventSelector t k)
forall a b. (a -> b) -> a -> b
$ m (EventSelector t k) -> ReaderT (Event t ()) m (EventSelector t k)
forall (m :: * -> *) a. Monad m => m a -> ReaderT (Event t ()) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (EventSelector t k)
 -> ReaderT (Event t ()) m (EventSelector t k))
-> m (EventSelector t k)
-> ReaderT (Event t ()) 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)
forall (k :: * -> *).
GCompare k =>
(forall a. k a -> EventTrigger t a -> IO (IO ()))
-> m (EventSelector t k)
newFanEventWithTrigger k a -> EventTrigger t a -> IO (IO ())
forall a. k a -> EventTrigger t a -> IO (IO ())
f

instance TriggerEvent t m => TriggerEvent t (PostBuildT t m) where
  {-# INLINABLE newTriggerEvent #-}
  newTriggerEvent :: forall a. PostBuildT t m (Event t a, a -> IO ())
newTriggerEvent = m (Event t a, a -> IO ()) -> PostBuildT t m (Event t a, a -> IO ())
forall (m :: * -> *) a. Monad m => m a -> PostBuildT t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m (Event t a, a -> IO ())
forall a. m (Event t a, a -> IO ())
forall t (m :: * -> *) a.
TriggerEvent t m =>
m (Event t a, a -> IO ())
newTriggerEvent
  {-# INLINABLE newTriggerEventWithOnComplete #-}
  newTriggerEventWithOnComplete :: forall a. PostBuildT t m (Event t a, a -> IO () -> IO ())
newTriggerEventWithOnComplete = m (Event t a, a -> IO () -> IO ())
-> PostBuildT t m (Event t a, a -> IO () -> IO ())
forall (m :: * -> *) a. Monad m => m a -> PostBuildT t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m (Event t a, a -> IO () -> IO ())
forall a. m (Event t a, a -> IO () -> IO ())
forall t (m :: * -> *) a.
TriggerEvent t m =>
m (Event t a, a -> IO () -> IO ())
newTriggerEventWithOnComplete
  newEventWithLazyTriggerWithOnComplete :: forall a.
((a -> IO () -> IO ()) -> IO (IO ())) -> PostBuildT t m (Event t a)
newEventWithLazyTriggerWithOnComplete = m (Event t a) -> PostBuildT t m (Event t a)
forall (m :: * -> *) a. Monad m => m a -> PostBuildT t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Event t a) -> PostBuildT t m (Event t a))
-> (((a -> IO () -> IO ()) -> IO (IO ())) -> m (Event t a))
-> ((a -> IO () -> IO ()) -> IO (IO ()))
-> PostBuildT t m (Event t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((a -> IO () -> IO ()) -> IO (IO ())) -> m (Event t a)
forall a. ((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 MonadRef m => MonadRef (PostBuildT t m) where
  type Ref (PostBuildT t m) = Ref m
  {-# INLINABLE newRef #-}
  newRef :: forall a. a -> PostBuildT t m (Ref (PostBuildT t m) a)
newRef = m (Ref m a) -> PostBuildT t m (Ref m a)
forall (m :: * -> *) a. Monad m => m a -> PostBuildT t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Ref m a) -> PostBuildT t m (Ref m a))
-> (a -> m (Ref m a)) -> a -> PostBuildT t m (Ref m a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> m (Ref m a)
forall a. a -> m (Ref m a)
forall (m :: * -> *) a. MonadRef m => a -> m (Ref m a)
newRef
  {-# INLINABLE readRef #-}
  readRef :: forall a. Ref (PostBuildT t m) a -> PostBuildT t m a
readRef = m a -> PostBuildT t m a
forall (m :: * -> *) a. Monad m => m a -> PostBuildT t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> PostBuildT t m a)
-> (Ref m a -> m a) -> Ref m a -> PostBuildT t m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ref m a -> m a
forall a. Ref m a -> m a
forall (m :: * -> *) a. MonadRef m => Ref m a -> m a
readRef
  {-# INLINABLE writeRef #-}
  writeRef :: forall a. Ref (PostBuildT t m) a -> a -> PostBuildT t m ()
writeRef Ref (PostBuildT t m) a
r = m () -> PostBuildT t m ()
forall (m :: * -> *) a. Monad m => m a -> PostBuildT t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> PostBuildT t m ())
-> (a -> m ()) -> a -> PostBuildT t m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ref m a -> a -> m ()
forall a. Ref m a -> a -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> m ()
writeRef Ref m a
Ref (PostBuildT t m) a
r

instance MonadAtomicRef m => MonadAtomicRef (PostBuildT t m) where
  {-# INLINABLE atomicModifyRef #-}
  atomicModifyRef :: forall a b.
Ref (PostBuildT t m) a -> (a -> (a, b)) -> PostBuildT t m b
atomicModifyRef Ref (PostBuildT t m) a
r = m b -> PostBuildT t m b
forall (m :: * -> *) a. Monad m => m a -> PostBuildT t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m b -> PostBuildT t m b)
-> ((a -> (a, b)) -> m b) -> (a -> (a, b)) -> PostBuildT t m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ref m a -> (a -> (a, b)) -> m b
forall a b. 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 (PostBuildT t m) a
r

instance (Reflex t, MonadHold t m, MonadFix m, Adjustable t m, PerformEvent t m) => Adjustable t (PostBuildT t m) where
  runWithReplace :: forall a b.
PostBuildT t m a
-> Event t (PostBuildT t m b) -> PostBuildT t m (a, Event t b)
runWithReplace PostBuildT t m a
a0 Event t (PostBuildT t m b)
a' = do
    Event t ()
postBuild <- PostBuildT t m (Event t ())
forall t (m :: * -> *). PostBuild t m => m (Event t ())
getPostBuild
    m (a, Event t b) -> PostBuildT t m (a, Event t b)
forall (m :: * -> *) a. Monad m => m a -> PostBuildT t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (a, Event t b) -> PostBuildT t m (a, Event t b))
-> m (a, Event t b) -> PostBuildT t m (a, Event t b)
forall a b. (a -> b) -> a -> b
$ do
      rec result :: (a, Event t b)
result@(a
_, Event t b
result') <- m a -> Event t (m b) -> m (a, Event t b)
forall 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 (PostBuildT t m a -> Event t () -> m a
forall t (m :: * -> *) a. PostBuildT t m a -> Event t () -> m a
runPostBuildT PostBuildT t m a
a0 Event t ()
postBuild) (Event t (m b) -> m (a, Event t b))
-> Event t (m b) -> m (a, Event t b)
forall a b. (a -> b) -> a -> b
$ (PostBuildT t m b -> m b)
-> Event t (PostBuildT t m b) -> Event t (m 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 (\PostBuildT t m b
v -> PostBuildT t m b -> Event t () -> m b
forall t (m :: * -> *) a. PostBuildT t m a -> Event t () -> m a
runPostBuildT PostBuildT t m b
v (Event t () -> m b) -> m (Event t ()) -> m b
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< 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 ()
voidResult') Event t (PostBuildT t m b)
a'
          let voidResult' :: Event t ()
voidResult' = (b -> ()) -> Event t b -> Event t ()
forall {k} (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap (\b
_ -> ()) Event t b
result'
      (a, Event t b) -> m (a, Event t b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a, Event t b)
result
  {-# INLINABLE traverseIntMapWithKeyWithAdjust #-}
  traverseIntMapWithKeyWithAdjust :: forall v v'.
(Key -> v -> PostBuildT t m v')
-> IntMap v
-> Event t (PatchIntMap v)
-> PostBuildT t m (IntMap v', Event t (PatchIntMap v'))
traverseIntMapWithKeyWithAdjust = ((Key -> (Event t (), v) -> m v')
 -> IntMap (Event t (), v)
 -> Event t (PatchIntMap (Event t (), v))
 -> m (IntMap v', Event t (PatchIntMap v')))
-> (Key -> v -> PostBuildT t m v')
-> IntMap v
-> Event t (PatchIntMap v)
-> PostBuildT t m (IntMap v', Event t (PatchIntMap v'))
forall t (m :: * -> *) v v' (p :: * -> *).
(Reflex t, MonadFix m, MonadHold t m, Functor p) =>
((Key -> (Event t (), v) -> m v')
 -> IntMap (Event t (), v)
 -> Event t (p (Event t (), v))
 -> m (IntMap v', Event t (p v')))
-> (Key -> v -> PostBuildT t m v')
-> IntMap v
-> Event t (p v)
-> PostBuildT t m (IntMap v', Event t (p v'))
mapIntMapWithAdjustImpl (Key -> (Event t (), v) -> m v')
-> IntMap (Event t (), v)
-> Event t (PatchIntMap (Event t (), v))
-> m (IntMap v', Event t (PatchIntMap v'))
forall v v'.
(Key -> v -> m v')
-> IntMap v
-> Event t (PatchIntMap v)
-> m (IntMap v', Event t (PatchIntMap v'))
forall t (m :: * -> *) v v'.
Adjustable t m =>
(Key -> v -> m v')
-> IntMap v
-> Event t (PatchIntMap v)
-> m (IntMap v', Event t (PatchIntMap v'))
traverseIntMapWithKeyWithAdjust
  {-# INLINABLE traverseDMapWithKeyWithAdjust #-}
  traverseDMapWithKeyWithAdjust :: forall (k :: * -> *) (v :: * -> *) (v' :: * -> *).
GCompare k =>
(forall a. k a -> v a -> PostBuildT t m (v' a))
-> DMap k v
-> Event t (PatchDMap k v)
-> PostBuildT t m (DMap k v', Event t (PatchDMap k v'))
traverseDMapWithKeyWithAdjust = ((forall a.
  k a -> Compose ((,) (Bool, Event t ())) v a -> m (v' a))
 -> DMap k (Compose ((,) (Bool, Event t ())) v)
 -> Event t (PatchDMap k (Compose ((,) (Bool, Event t ())) v))
 -> m (DMap k v', Event t (PatchDMap k v')))
-> ((forall a. v a -> Compose ((,) (Bool, Event t ())) v a)
    -> PatchDMap k v
    -> PatchDMap k (Compose ((,) (Bool, Event t ())) v))
-> (forall a. k a -> v a -> PostBuildT t m (v' a))
-> DMap k v
-> Event t (PatchDMap k v)
-> PostBuildT t m (DMap k v', Event t (PatchDMap k v'))
forall t (m :: * -> *) (k :: * -> *) (v :: * -> *) (v' :: * -> *)
       (p :: (* -> *) -> (* -> *) -> *).
(Reflex t, MonadFix m, MonadHold t m) =>
((forall a.
  k a -> Compose ((,) (Bool, Event t ())) v a -> m (v' a))
 -> DMap k (Compose ((,) (Bool, Event t ())) v)
 -> Event t (p k (Compose ((,) (Bool, Event t ())) v))
 -> m (DMap k v', Event t (p k v')))
-> ((forall a. v a -> Compose ((,) (Bool, Event t ())) v a)
    -> p k v -> p k (Compose ((,) (Bool, Event t ())) v))
-> (forall a. k a -> v a -> PostBuildT t m (v' a))
-> DMap k v
-> Event t (p k v)
-> PostBuildT t m (DMap k v', Event t (p k v'))
mapDMapWithAdjustImpl (forall a. k a -> Compose ((,) (Bool, Event t ())) v a -> m (v' a))
-> DMap k (Compose ((,) (Bool, Event t ())) v)
-> Event t (PatchDMap k (Compose ((,) (Bool, Event t ())) v))
-> m (DMap k v', Event t (PatchDMap k 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'))
forall (k :: * -> *) (v :: * -> *) (v' :: * -> *).
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. v a -> Compose ((,) (Bool, Event t ())) v a)
-> PatchDMap k v
-> PatchDMap k (Compose ((,) (Bool, Event t ())) v)
forall {k1} (v :: k1 -> *) (v' :: k1 -> *) (k2 :: k1 -> *).
(forall (a :: k1). v a -> v' a)
-> PatchDMap k2 v -> PatchDMap k2 v'
mapPatchDMap
  traverseDMapWithKeyWithAdjustWithMove :: forall (k :: * -> *) (v :: * -> *) (v' :: * -> *).
GCompare k =>
(forall a. k a -> v a -> PostBuildT t m (v' a))
-> DMap k v
-> Event t (PatchDMapWithMove k v)
-> PostBuildT t m (DMap k v', Event t (PatchDMapWithMove k v'))
traverseDMapWithKeyWithAdjustWithMove = ((forall a.
  k a -> Compose ((,) (Bool, Event t ())) v a -> m (v' a))
 -> DMap k (Compose ((,) (Bool, Event t ())) v)
 -> Event
      t (PatchDMapWithMove k (Compose ((,) (Bool, Event t ())) v))
 -> m (DMap k v', Event t (PatchDMapWithMove k v')))
-> ((forall a. v a -> Compose ((,) (Bool, Event t ())) v a)
    -> PatchDMapWithMove k v
    -> PatchDMapWithMove k (Compose ((,) (Bool, Event t ())) v))
-> (forall a. k a -> v a -> PostBuildT t m (v' a))
-> DMap k v
-> Event t (PatchDMapWithMove k v)
-> PostBuildT t m (DMap k v', Event t (PatchDMapWithMove k v'))
forall t (m :: * -> *) (k :: * -> *) (v :: * -> *) (v' :: * -> *)
       (p :: (* -> *) -> (* -> *) -> *).
(Reflex t, MonadFix m, MonadHold t m) =>
((forall a.
  k a -> Compose ((,) (Bool, Event t ())) v a -> m (v' a))
 -> DMap k (Compose ((,) (Bool, Event t ())) v)
 -> Event t (p k (Compose ((,) (Bool, Event t ())) v))
 -> m (DMap k v', Event t (p k v')))
-> ((forall a. v a -> Compose ((,) (Bool, Event t ())) v a)
    -> p k v -> p k (Compose ((,) (Bool, Event t ())) v))
-> (forall a. k a -> v a -> PostBuildT t m (v' a))
-> DMap k v
-> Event t (p k v)
-> PostBuildT t m (DMap k v', Event t (p k v'))
mapDMapWithAdjustImpl (forall a. k a -> Compose ((,) (Bool, Event t ())) v a -> m (v' a))
-> DMap k (Compose ((,) (Bool, Event t ())) v)
-> Event
     t (PatchDMapWithMove k (Compose ((,) (Bool, Event t ())) v))
-> m (DMap k v', Event t (PatchDMapWithMove k 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'))
forall (k :: * -> *) (v :: * -> *) (v' :: * -> *).
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. v a -> Compose ((,) (Bool, Event t ())) v a)
-> PatchDMapWithMove k v
-> PatchDMapWithMove k (Compose ((,) (Bool, Event t ())) v)
forall {k1} (k2 :: k1 -> *) (v :: k1 -> *) (v' :: k1 -> *).
(forall (a :: k1). v a -> v' a)
-> PatchDMapWithMove k2 v -> PatchDMapWithMove k2 v'
mapPatchDMapWithMove

{-# INLINABLE mapIntMapWithAdjustImpl #-}
mapIntMapWithAdjustImpl :: forall t m v v' p. (Reflex t, MonadFix m, MonadHold t m, Functor p)
  => (   (IntMap.Key -> (Event t (), v) -> m v')
      -> IntMap (Event t (), v)
      -> Event t (p (Event t (), v))
      -> m (IntMap v', Event t (p v'))
     )
  -> (IntMap.Key -> v -> PostBuildT t m v')
  -> IntMap v
  -> Event t (p v)
  -> PostBuildT t m (IntMap v', Event t (p v'))
mapIntMapWithAdjustImpl :: forall t (m :: * -> *) v v' (p :: * -> *).
(Reflex t, MonadFix m, MonadHold t m, Functor p) =>
((Key -> (Event t (), v) -> m v')
 -> IntMap (Event t (), v)
 -> Event t (p (Event t (), v))
 -> m (IntMap v', Event t (p v')))
-> (Key -> v -> PostBuildT t m v')
-> IntMap v
-> Event t (p v)
-> PostBuildT t m (IntMap v', Event t (p v'))
mapIntMapWithAdjustImpl (Key -> (Event t (), v) -> m v')
-> IntMap (Event t (), v)
-> Event t (p (Event t (), v))
-> m (IntMap v', Event t (p v'))
base Key -> v -> PostBuildT t m v'
f IntMap v
dm0 Event t (p v)
dm' = do
  Event t ()
postBuild <- PostBuildT t m (Event t ())
forall t (m :: * -> *). PostBuild t m => m (Event t ())
getPostBuild
  let loweredDm0 :: IntMap (Event t (), v)
loweredDm0 = (v -> (Event t (), v)) -> IntMap v -> IntMap (Event t (), v)
forall a b. (a -> b) -> IntMap a -> IntMap b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((,) Event t ()
postBuild) IntMap v
dm0
      f' :: IntMap.Key -> (Event t (), v) -> m v'
      f' :: Key -> (Event t (), v) -> m v'
f' Key
k (Event t ()
e, v
v) = do
        PostBuildT t m v' -> Event t () -> m v'
forall t (m :: * -> *) a. PostBuildT t m a -> Event t () -> m a
runPostBuildT (Key -> v -> PostBuildT t m v'
f Key
k v
v) Event t ()
e
  m (IntMap v', Event t (p v'))
-> PostBuildT t m (IntMap v', Event t (p v'))
forall (m :: * -> *) a. Monad m => m a -> PostBuildT t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (IntMap v', Event t (p v'))
 -> PostBuildT t m (IntMap v', Event t (p v')))
-> m (IntMap v', Event t (p v'))
-> PostBuildT t m (IntMap v', Event t (p v'))
forall a b. (a -> b) -> a -> b
$ do
    rec (IntMap v'
result0, Event t (p v')
result') <- (Key -> (Event t (), v) -> m v')
-> IntMap (Event t (), v)
-> Event t (p (Event t (), v))
-> m (IntMap v', Event t (p v'))
base Key -> (Event t (), v) -> m v'
f' IntMap (Event t (), v)
loweredDm0 Event t (p (Event t (), v))
loweredDm'
        Event t Key
cohortDone <- Key -> Event t (p v') -> m (Event t Key)
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_ Key
1 Event t (p v')
result'
        Event t (Key, p v)
numberedDm' <- Key -> Event t (p v) -> m (Event t (Key, p v))
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 Key
1 Event t (p v)
dm'
        let postBuild' :: EventSelectorInt t ()
postBuild' = Event t (IntMap ()) -> EventSelectorInt t ()
forall a. Event t (IntMap a) -> EventSelectorInt t a
forall {k} (t :: k) a.
Reflex t =>
Event t (IntMap a) -> EventSelectorInt t a
fanInt (Event t (IntMap ()) -> EventSelectorInt t ())
-> Event t (IntMap ()) -> EventSelectorInt t ()
forall a b. (a -> b) -> a -> b
$ (Key -> IntMap ()) -> Event t Key -> Event t (IntMap ())
forall {k} (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap (Key -> () -> IntMap ()
forall a. Key -> a -> IntMap a
`IntMap.singleton` ()) Event t Key
cohortDone
            loweredDm' :: Event t (p (Event t (), v))
loweredDm' = (((Key, p v) -> PushM t (p (Event t (), v)))
 -> Event t (Key, p v) -> Event t (p (Event t (), v)))
-> Event t (Key, p v)
-> ((Key, p v) -> PushM t (p (Event t (), v)))
-> Event t (p (Event t (), v))
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((Key, p v) -> PushM t (p (Event t (), v)))
-> Event t (Key, p v) -> Event t (p (Event t (), v))
forall {k} (t :: k) a b.
Reflex t =>
(a -> PushM t b) -> Event t a -> Event t b
pushAlways Event t (Key, p v)
numberedDm' (((Key, p v) -> PushM t (p (Event t (), v)))
 -> Event t (p (Event t (), v)))
-> ((Key, p v) -> PushM t (p (Event t (), v)))
-> Event t (p (Event t (), v))
forall a b. (a -> b) -> a -> b
$ \(Key
n, p v
p) -> do
              p (Event t (), v) -> PushM t (p (Event t (), v))
forall a. a -> PushM t a
forall (m :: * -> *) a. Monad m => a -> m a
return (p (Event t (), v) -> PushM t (p (Event t (), v)))
-> p (Event t (), v) -> PushM t (p (Event t (), v))
forall a b. (a -> b) -> a -> b
$ (v -> (Event t (), v)) -> p v -> p (Event t (), v)
forall a b. (a -> b) -> p a -> p b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((,) (EventSelectorInt t () -> Key -> Event t ()
forall {k} (t :: k) a. EventSelectorInt t a -> Key -> Event t a
selectInt EventSelectorInt t ()
postBuild' Key
n)) p v
p
    (IntMap v', Event t (p v')) -> m (IntMap v', Event t (p v'))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (IntMap v'
result0, Event t (p v')
result')

{-# INLINABLE mapDMapWithAdjustImpl #-}
mapDMapWithAdjustImpl :: forall t m k v v' p. (Reflex t, MonadFix m, MonadHold t m)
  => (   (forall a. k a -> Compose ((,) (Bool, Event t ())) v a -> m (v' a))
      -> DMap k (Compose ((,) (Bool, Event t ())) v)
      -> Event t (p k (Compose ((,) (Bool, Event t ())) v))
      -> m (DMap k v', Event t (p k v'))
     )
  -> ((forall a. v a -> Compose ((,) (Bool, Event t ())) v a) -> p k v -> p k (Compose ((,) (Bool, Event t ())) v))
  -> (forall a. k a -> v a -> PostBuildT t m (v' a))
  -> DMap k v
  -> Event t (p k v)
  -> PostBuildT t m (DMap k v', Event t (p k v'))
mapDMapWithAdjustImpl :: forall t (m :: * -> *) (k :: * -> *) (v :: * -> *) (v' :: * -> *)
       (p :: (* -> *) -> (* -> *) -> *).
(Reflex t, MonadFix m, MonadHold t m) =>
((forall a.
  k a -> Compose ((,) (Bool, Event t ())) v a -> m (v' a))
 -> DMap k (Compose ((,) (Bool, Event t ())) v)
 -> Event t (p k (Compose ((,) (Bool, Event t ())) v))
 -> m (DMap k v', Event t (p k v')))
-> ((forall a. v a -> Compose ((,) (Bool, Event t ())) v a)
    -> p k v -> p k (Compose ((,) (Bool, Event t ())) v))
-> (forall a. k a -> v a -> PostBuildT t m (v' a))
-> DMap k v
-> Event t (p k v)
-> PostBuildT t m (DMap k v', Event t (p k v'))
mapDMapWithAdjustImpl (forall a. k a -> Compose ((,) (Bool, Event t ())) v a -> m (v' a))
-> DMap k (Compose ((,) (Bool, Event t ())) v)
-> Event t (p k (Compose ((,) (Bool, Event t ())) v))
-> m (DMap k v', Event t (p k v'))
base (forall a. v a -> Compose ((,) (Bool, Event t ())) v a)
-> p k v -> p k (Compose ((,) (Bool, Event t ())) v)
mapPatch forall a. k a -> v a -> PostBuildT t m (v' a)
f DMap k v
dm0 Event t (p k v)
dm' = do
  Event t ()
postBuild <- PostBuildT t m (Event t ())
forall t (m :: * -> *). PostBuild t m => m (Event t ())
getPostBuild
  let loweredDm0 :: DMap k (Compose ((,) (Bool, Event t ())) v)
loweredDm0 = (forall a. v a -> Compose ((,) (Bool, Event t ())) v a)
-> DMap k v -> DMap k (Compose ((,) (Bool, 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 (((Bool, Event t ()), v v) -> Compose ((,) (Bool, Event t ())) v v
forall {k} {k1} (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose (((Bool, Event t ()), v v) -> Compose ((,) (Bool, Event t ())) v v)
-> (v v -> ((Bool, Event t ()), v v))
-> v v
-> Compose ((,) (Bool, Event t ())) v v
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (,) (Bool
False, Event t ()
postBuild)) DMap k v
dm0
      f' :: forall a. k a -> Compose ((,) (Bool, Event t ())) v a -> m (v' a)
      f' :: forall a. k a -> Compose ((,) (Bool, Event t ())) v a -> m (v' a)
f' k a
k (Compose ((Bool
shouldHeadE, Event t ()
e), v a
v)) = do
        Event t ()
eOnce <- if Bool
shouldHeadE
          then 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 ()
e --TODO: Avoid doing this headE so many times; once per loweredDm' firing ought to be OK, but it's not totally trivial to do because result' might be firing at the same time, and we don't want *that* to be the postBuild occurrence
          else Event t () -> m (Event t ())
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Event t ()
e
        PostBuildT t m (v' a) -> Event t () -> m (v' a)
forall t (m :: * -> *) a. PostBuildT t m a -> Event t () -> m a
runPostBuildT (k a -> v a -> PostBuildT t m (v' a)
forall a. k a -> v a -> PostBuildT t m (v' a)
f k a
k v a
v) Event t ()
eOnce
  m (DMap k v', Event t (p k v'))
-> PostBuildT t m (DMap k v', Event t (p k v'))
forall (m :: * -> *) a. Monad m => m a -> PostBuildT t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (DMap k v', Event t (p k v'))
 -> PostBuildT t m (DMap k v', Event t (p k v')))
-> m (DMap k v', Event t (p k v'))
-> PostBuildT t m (DMap k v', Event t (p k v'))
forall a b. (a -> b) -> a -> b
$ do
    rec (DMap k v'
result0, Event t (p k v')
result') <- (forall a. k a -> Compose ((,) (Bool, Event t ())) v a -> m (v' a))
-> DMap k (Compose ((,) (Bool, Event t ())) v)
-> Event t (p k (Compose ((,) (Bool, Event t ())) v))
-> m (DMap k v', Event t (p k v'))
base k a -> Compose ((,) (Bool, Event t ())) v a -> m (v' a)
forall a. k a -> Compose ((,) (Bool, Event t ())) v a -> m (v' a)
f' DMap k (Compose ((,) (Bool, Event t ())) v)
loweredDm0 Event t (p k (Compose ((,) (Bool, Event t ())) v))
loweredDm'
        let voidResult' :: Event t ()
voidResult' = (p k v' -> ()) -> Event t (p k v') -> Event t ()
forall {k} (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap (\p k v'
_ -> ()) Event t (p k v')
result'
        let loweredDm' :: Event t (p k (Compose ((,) (Bool, Event t ())) v))
loweredDm' = Event t (p k v)
-> (p k v -> p k (Compose ((,) (Bool, Event t ())) v))
-> Event t (p k (Compose ((,) (Bool, Event t ())) v))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
ffor Event t (p k v)
dm' ((p k v -> p k (Compose ((,) (Bool, Event t ())) v))
 -> Event t (p k (Compose ((,) (Bool, Event t ())) v)))
-> (p k v -> p k (Compose ((,) (Bool, Event t ())) v))
-> Event t (p k (Compose ((,) (Bool, Event t ())) v))
forall a b. (a -> b) -> a -> b
$ (forall a. v a -> Compose ((,) (Bool, Event t ())) v a)
-> p k v -> p k (Compose ((,) (Bool, Event t ())) v)
mapPatch (((Bool, Event t ()), v a) -> Compose ((,) (Bool, Event t ())) v a
forall {k} {k1} (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose (((Bool, Event t ()), v a) -> Compose ((,) (Bool, Event t ())) v a)
-> (v a -> ((Bool, Event t ()), v a))
-> v a
-> Compose ((,) (Bool, Event t ())) v a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (,) (Bool
True, Event t ()
voidResult'))
    (DMap k v', Event t (p k v')) -> m (DMap k v', Event t (p k v'))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (DMap k v'
result0, Event t (p k v')
result')

--------------------------------------------------------------------------------
-- Deprecated functionality
--------------------------------------------------------------------------------

-- | Deprecated
instance TransControl.MonadTransControl (PostBuildT t) where
  type StT (PostBuildT t) a = TransControl.StT (ReaderT (Event t ())) a
  {-# INLINABLE liftWith #-}
  liftWith :: forall (m :: * -> *) a.
Monad m =>
(Run (PostBuildT t) -> m a) -> PostBuildT t m a
liftWith = (forall b. ReaderT (Event t ()) m b -> PostBuildT t m b)
-> (forall (o :: * -> *) b.
    PostBuildT t o b -> ReaderT (Event t ()) o b)
-> (RunDefault (PostBuildT t) (ReaderT (Event t ())) -> m a)
-> PostBuildT t m a
forall (m :: * -> *) (n :: (* -> *) -> * -> *)
       (t :: (* -> *) -> * -> *) a.
(Monad m, MonadTransControl n) =>
(forall b. n m b -> t m b)
-> (forall (o :: * -> *) b. t o b -> n o b)
-> (RunDefault t n -> m a)
-> t m a
TransControl.defaultLiftWith ReaderT (Event t ()) m b -> PostBuildT t m b
forall b. ReaderT (Event t ()) m b -> PostBuildT t m b
forall t (m :: * -> *) a.
ReaderT (Event t ()) m a -> PostBuildT t m a
PostBuildT PostBuildT t o b -> ReaderT (Event t ()) o b
forall t (m :: * -> *) a.
PostBuildT t m a -> ReaderT (Event t ()) m a
forall (o :: * -> *) b.
PostBuildT t o b -> ReaderT (Event t ()) o b
unPostBuildT
  {-# INLINABLE restoreT #-}
  restoreT :: forall (m :: * -> *) a.
Monad m =>
m (StT (PostBuildT t) a) -> PostBuildT t m a
restoreT = (ReaderT (Event t ()) m a -> PostBuildT t m a)
-> m (StT (ReaderT (Event t ())) a) -> PostBuildT t m a
forall (m :: * -> *) (n :: (* -> *) -> * -> *) a
       (t :: (* -> *) -> * -> *).
(Monad m, MonadTransControl n) =>
(n m a -> t m a) -> m (StT n a) -> t m a
TransControl.defaultRestoreT ReaderT (Event t ()) m a -> PostBuildT t m a
forall t (m :: * -> *) a.
ReaderT (Event t ()) m a -> PostBuildT t m a
PostBuildT