-- | This module provides 'RequesterT', the standard implementation of
-- 'Requester'.
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE RecursiveDo #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
#ifdef USE_REFLEX_OPTIMIZER
{-# OPTIONS_GHC -fplugin=Reflex.Optimizer #-}
#endif
module Reflex.Requester.Base
  ( RequesterT (..)
  , runRequesterT
  , withRequesterT
  , runWithReplaceRequesterTWith
  , traverseIntMapWithKeyWithAdjustRequesterTWith
  , traverseDMapWithKeyWithAdjustRequesterTWith
  , RequesterData
  , RequesterDataKey
  , traverseRequesterData
  , forRequesterData
  , requesterDataToList
  , singletonRequesterData
  , matchResponsesWithRequests
  , multiEntry
  , unMultiEntry
  , requesting'
  ) where

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

import Control.Applicative (liftA2)
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.Bits
import Data.Coerce
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.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IntMap
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Monoid ((<>))
import Data.Proxy
import qualified Data.Semigroup as S
import Data.Some (Some(Some))
import Data.Type.Equality
import Data.Unique.Tag

import GHC.Exts (Any)
import Unsafe.Coerce

--TODO: Make this module type-safe

newtype TagMap (f :: * -> *) = TagMap (IntMap Any)

newtype RequesterData f = RequesterData (TagMap (Entry f))

data RequesterDataKey a where
  RequesterDataKey_Single :: {-# UNPACK #-} !(MyTag (Single a)) -> RequesterDataKey a
  RequesterDataKey_Multi :: {-# UNPACK #-} !(MyTag Multi) -> {-# UNPACK #-} !Int -> !(RequesterDataKey a) -> RequesterDataKey a --TODO: Don't put a second Int here (or in the other Multis); use a single Int instead
  RequesterDataKey_Multi2 :: {-# UNPACK #-} !(MyTag (Multi2 k)) -> !(Some k) -> {-# UNPACK #-} !Int -> !(RequesterDataKey a) -> RequesterDataKey a
  RequesterDataKey_Multi3 :: {-# UNPACK #-} !(MyTag Multi3) -> {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> !(RequesterDataKey a) -> RequesterDataKey a

singletonRequesterData :: RequesterDataKey a -> f a -> RequesterData f
singletonRequesterData :: RequesterDataKey a -> f a -> RequesterData f
singletonRequesterData RequesterDataKey a
rdk f a
v = case RequesterDataKey a
rdk of
  RequesterDataKey_Single MyTag (Single a)
k -> TagMap (Entry f) -> RequesterData f
forall (f :: * -> *). TagMap (Entry f) -> RequesterData f
RequesterData (TagMap (Entry f) -> RequesterData f)
-> TagMap (Entry f) -> RequesterData f
forall a b. (a -> b) -> a -> b
$ MyTag (Single a) -> Entry f (Single a) -> TagMap (Entry f)
forall (f :: * -> *) a. MyTag a -> f a -> TagMap f
singletonTagMap MyTag (Single a)
k (Entry f (Single a) -> TagMap (Entry f))
-> Entry f (Single a) -> TagMap (Entry f)
forall a b. (a -> b) -> a -> b
$ EntryContents f (Single a) -> Entry f (Single a)
forall (request :: * -> *) x.
EntryContents request x -> Entry request x
Entry f a
EntryContents f (Single a)
v
  RequesterDataKey_Multi MyTag Multi
k Int
k' RequesterDataKey a
k'' -> TagMap (Entry f) -> RequesterData f
forall (f :: * -> *). TagMap (Entry f) -> RequesterData f
RequesterData (TagMap (Entry f) -> RequesterData f)
-> TagMap (Entry f) -> RequesterData f
forall a b. (a -> b) -> a -> b
$ MyTag Multi -> Entry f Multi -> TagMap (Entry f)
forall (f :: * -> *) a. MyTag a -> f a -> TagMap f
singletonTagMap MyTag Multi
k (Entry f Multi -> TagMap (Entry f))
-> Entry f Multi -> TagMap (Entry f)
forall a b. (a -> b) -> a -> b
$ EntryContents f Multi -> Entry f Multi
forall (request :: * -> *) x.
EntryContents request x -> Entry request x
Entry (EntryContents f Multi -> Entry f Multi)
-> EntryContents f Multi -> Entry f Multi
forall a b. (a -> b) -> a -> b
$ Int -> RequesterData f -> IntMap (RequesterData f)
forall a. Int -> a -> IntMap a
IntMap.singleton Int
k' (RequesterData f -> IntMap (RequesterData f))
-> RequesterData f -> IntMap (RequesterData f)
forall a b. (a -> b) -> a -> b
$ RequesterDataKey a -> f a -> RequesterData f
forall a (f :: * -> *).
RequesterDataKey a -> f a -> RequesterData f
singletonRequesterData RequesterDataKey a
k'' f a
v
  RequesterDataKey_Multi2 MyTag (Multi2 k)
k Some k
k' Int
k'' RequesterDataKey a
k''' -> TagMap (Entry f) -> RequesterData f
forall (f :: * -> *). TagMap (Entry f) -> RequesterData f
RequesterData (TagMap (Entry f) -> RequesterData f)
-> TagMap (Entry f) -> RequesterData f
forall a b. (a -> b) -> a -> b
$ MyTag (Multi2 k) -> Entry f (Multi2 k) -> TagMap (Entry f)
forall (f :: * -> *) a. MyTag a -> f a -> TagMap f
singletonTagMap MyTag (Multi2 k)
k (Entry f (Multi2 k) -> TagMap (Entry f))
-> Entry f (Multi2 k) -> TagMap (Entry f)
forall a b. (a -> b) -> a -> b
$ EntryContents f (Multi2 k) -> Entry f (Multi2 k)
forall (request :: * -> *) x.
EntryContents request x -> Entry request x
Entry (EntryContents f (Multi2 k) -> Entry f (Multi2 k))
-> EntryContents f (Multi2 k) -> Entry f (Multi2 k)
forall a b. (a -> b) -> a -> b
$ Some k
-> IntMap (RequesterData f)
-> Map (Some k) (IntMap (RequesterData f))
forall k a. k -> a -> Map k a
Map.singleton Some k
k' (IntMap (RequesterData f)
 -> Map (Some k) (IntMap (RequesterData f)))
-> IntMap (RequesterData f)
-> Map (Some k) (IntMap (RequesterData f))
forall a b. (a -> b) -> a -> b
$ Int -> RequesterData f -> IntMap (RequesterData f)
forall a. Int -> a -> IntMap a
IntMap.singleton Int
k'' (RequesterData f -> IntMap (RequesterData f))
-> RequesterData f -> IntMap (RequesterData f)
forall a b. (a -> b) -> a -> b
$ RequesterDataKey a -> f a -> RequesterData f
forall a (f :: * -> *).
RequesterDataKey a -> f a -> RequesterData f
singletonRequesterData RequesterDataKey a
k''' f a
v
  RequesterDataKey_Multi3 MyTag Multi3
k Int
k' Int
k'' RequesterDataKey a
k''' -> TagMap (Entry f) -> RequesterData f
forall (f :: * -> *). TagMap (Entry f) -> RequesterData f
RequesterData (TagMap (Entry f) -> RequesterData f)
-> TagMap (Entry f) -> RequesterData f
forall a b. (a -> b) -> a -> b
$ MyTag Multi3 -> Entry f Multi3 -> TagMap (Entry f)
forall (f :: * -> *) a. MyTag a -> f a -> TagMap f
singletonTagMap MyTag Multi3
k (Entry f Multi3 -> TagMap (Entry f))
-> Entry f Multi3 -> TagMap (Entry f)
forall a b. (a -> b) -> a -> b
$ EntryContents f Multi3 -> Entry f Multi3
forall (request :: * -> *) x.
EntryContents request x -> Entry request x
Entry (EntryContents f Multi3 -> Entry f Multi3)
-> EntryContents f Multi3 -> Entry f Multi3
forall a b. (a -> b) -> a -> b
$ Int
-> IntMap (RequesterData f) -> IntMap (IntMap (RequesterData f))
forall a. Int -> a -> IntMap a
IntMap.singleton Int
k' (IntMap (RequesterData f) -> IntMap (IntMap (RequesterData f)))
-> IntMap (RequesterData f) -> IntMap (IntMap (RequesterData f))
forall a b. (a -> b) -> a -> b
$ Int -> RequesterData f -> IntMap (RequesterData f)
forall a. Int -> a -> IntMap a
IntMap.singleton Int
k'' (RequesterData f -> IntMap (RequesterData f))
-> RequesterData f -> IntMap (RequesterData f)
forall a b. (a -> b) -> a -> b
$ RequesterDataKey a -> f a -> RequesterData f
forall a (f :: * -> *).
RequesterDataKey a -> f a -> RequesterData f
singletonRequesterData RequesterDataKey a
k''' f a
v

requesterDataToList :: RequesterData f -> [DSum RequesterDataKey f]
requesterDataToList :: RequesterData f -> [DSum RequesterDataKey f]
requesterDataToList (RequesterData TagMap (Entry f)
m) = do
  MyTag a
k :=> Entry EntryContents f a
e <- TagMap (Entry f) -> [DSum MyTag (Entry f)]
forall (f :: * -> *). TagMap f -> [DSum MyTag f]
tagMapToList TagMap (Entry f)
m
  case MyTag a -> MyTagType a
forall x. MyTag x -> MyTagType x
myKeyType MyTag a
k of
    MyTagType a
MyTagType_Single -> DSum RequesterDataKey f -> [DSum RequesterDataKey f]
forall (m :: * -> *) a. Monad m => a -> m a
return (DSum RequesterDataKey f -> [DSum RequesterDataKey f])
-> DSum RequesterDataKey f -> [DSum RequesterDataKey f]
forall a b. (a -> b) -> a -> b
$ MyTag (Single a) -> RequesterDataKey a
forall a. MyTag (Single a) -> RequesterDataKey a
RequesterDataKey_Single MyTag a
MyTag (Single a)
k RequesterDataKey a -> f a -> DSum RequesterDataKey f
forall k (tag :: k -> *) (f :: k -> *) (a :: k).
tag a -> f a -> DSum tag f
:=> f a
EntryContents f a
e
    MyTagType a
MyTagType_Multi -> do
      (Int
k', RequesterData f
e') <- IntMap (RequesterData f) -> [(Int, RequesterData f)]
forall a. IntMap a -> [(Int, a)]
IntMap.toList IntMap (RequesterData f)
EntryContents f a
e
      RequesterDataKey a
k'' :=> f a
e'' <- RequesterData f -> [DSum RequesterDataKey f]
forall (f :: * -> *). RequesterData f -> [DSum RequesterDataKey f]
requesterDataToList RequesterData f
e'
      DSum RequesterDataKey f -> [DSum RequesterDataKey f]
forall (m :: * -> *) a. Monad m => a -> m a
return (DSum RequesterDataKey f -> [DSum RequesterDataKey f])
-> DSum RequesterDataKey f -> [DSum RequesterDataKey f]
forall a b. (a -> b) -> a -> b
$ MyTag Multi -> Int -> RequesterDataKey a -> RequesterDataKey a
forall a.
MyTag Multi -> Int -> RequesterDataKey a -> RequesterDataKey a
RequesterDataKey_Multi MyTag a
MyTag Multi
k Int
k' RequesterDataKey a
k'' RequesterDataKey a -> f a -> DSum RequesterDataKey f
forall k (tag :: k -> *) (f :: k -> *) (a :: k).
tag a -> f a -> DSum tag f
:=> f a
e''
    MyTagType a
MyTagType_Multi2 -> do
      (Some k
k', IntMap (RequesterData f)
e') <- Map (Some k) (IntMap (RequesterData f))
-> [(Some k, IntMap (RequesterData f))]
forall k a. Map k a -> [(k, a)]
Map.toList Map (Some k) (IntMap (RequesterData f))
EntryContents f a
e
      (Int
k'', RequesterData f
e'') <- IntMap (RequesterData f) -> [(Int, RequesterData f)]
forall a. IntMap a -> [(Int, a)]
IntMap.toList IntMap (RequesterData f)
e'
      RequesterDataKey a
k''' :=> f a
e''' <- RequesterData f -> [DSum RequesterDataKey f]
forall (f :: * -> *). RequesterData f -> [DSum RequesterDataKey f]
requesterDataToList RequesterData f
e''
      DSum RequesterDataKey f -> [DSum RequesterDataKey f]
forall (m :: * -> *) a. Monad m => a -> m a
return (DSum RequesterDataKey f -> [DSum RequesterDataKey f])
-> DSum RequesterDataKey f -> [DSum RequesterDataKey f]
forall a b. (a -> b) -> a -> b
$ MyTag (Multi2 k)
-> Some k -> Int -> RequesterDataKey a -> RequesterDataKey a
forall (k :: * -> *) a.
MyTag (Multi2 k)
-> Some k -> Int -> RequesterDataKey a -> RequesterDataKey a
RequesterDataKey_Multi2 MyTag a
MyTag (Multi2 k)
k Some k
k' Int
k'' RequesterDataKey a
k''' RequesterDataKey a -> f a -> DSum RequesterDataKey f
forall k (tag :: k -> *) (f :: k -> *) (a :: k).
tag a -> f a -> DSum tag f
:=> f a
e'''
    MyTagType a
MyTagType_Multi3 -> do
      (Int
k', IntMap (RequesterData f)
e') <- IntMap (IntMap (RequesterData f))
-> [(Int, IntMap (RequesterData f))]
forall a. IntMap a -> [(Int, a)]
IntMap.toList IntMap (IntMap (RequesterData f))
EntryContents f a
e
      (Int
k'', RequesterData f
e'') <- IntMap (RequesterData f) -> [(Int, RequesterData f)]
forall a. IntMap a -> [(Int, a)]
IntMap.toList IntMap (RequesterData f)
e'
      RequesterDataKey a
k''' :=> f a
e''' <- RequesterData f -> [DSum RequesterDataKey f]
forall (f :: * -> *). RequesterData f -> [DSum RequesterDataKey f]
requesterDataToList RequesterData f
e''
      DSum RequesterDataKey f -> [DSum RequesterDataKey f]
forall (m :: * -> *) a. Monad m => a -> m a
return (DSum RequesterDataKey f -> [DSum RequesterDataKey f])
-> DSum RequesterDataKey f -> [DSum RequesterDataKey f]
forall a b. (a -> b) -> a -> b
$ MyTag Multi3
-> Int -> Int -> RequesterDataKey a -> RequesterDataKey a
forall a.
MyTag Multi3
-> Int -> Int -> RequesterDataKey a -> RequesterDataKey a
RequesterDataKey_Multi3 MyTag a
MyTag Multi3
k Int
k' Int
k'' RequesterDataKey a
k''' RequesterDataKey a -> f a -> DSum RequesterDataKey f
forall k (tag :: k -> *) (f :: k -> *) (a :: k).
tag a -> f a -> DSum tag f
:=> f a
e'''

singletonTagMap :: forall f a. MyTag a -> f a -> TagMap f
singletonTagMap :: MyTag a -> f a -> TagMap f
singletonTagMap (MyTag Int
k) f a
v = IntMap Any -> TagMap f
forall (f :: * -> *). IntMap Any -> TagMap f
TagMap (IntMap Any -> TagMap f) -> IntMap Any -> TagMap f
forall a b. (a -> b) -> a -> b
$ Int -> Any -> IntMap Any
forall a. Int -> a -> IntMap a
IntMap.singleton Int
k (Any -> IntMap Any) -> Any -> IntMap Any
forall a b. (a -> b) -> a -> b
$ (f a -> Any
forall a b. a -> b
unsafeCoerce :: f a -> Any) f a
v

tagMapToList :: forall f. TagMap f -> [DSum MyTag f]
tagMapToList :: TagMap f -> [DSum MyTag f]
tagMapToList (TagMap IntMap Any
m) = (Int, Any) -> DSum MyTag f
f ((Int, Any) -> DSum MyTag f) -> [(Int, Any)] -> [DSum MyTag f]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IntMap Any -> [(Int, Any)]
forall a. IntMap a -> [(Int, a)]
IntMap.toList IntMap Any
m
  where f :: (Int, Any) -> DSum MyTag f
        f :: (Int, Any) -> DSum MyTag f
f (Int
k, Any
v) = Int -> MyTag Any
forall x. Int -> MyTag x
MyTag Int
k MyTag Any -> f Any -> DSum MyTag f
forall k (tag :: k -> *) (f :: k -> *) (a :: k).
tag a -> f a -> DSum tag f
:=> (forall a. Any -> f a
forall a b. a -> b
unsafeCoerce :: Any -> f a) Any
v

traverseTagMapWithKey :: forall t f g. Applicative t => (forall a. MyTag a -> f a -> t (g a)) -> TagMap f -> t (TagMap g)
traverseTagMapWithKey :: (forall a. MyTag a -> f a -> t (g a)) -> TagMap f -> t (TagMap g)
traverseTagMapWithKey forall a. MyTag a -> f a -> t (g a)
f (TagMap IntMap Any
m) = IntMap Any -> TagMap g
forall (f :: * -> *). IntMap Any -> TagMap f
TagMap (IntMap Any -> TagMap g) -> t (IntMap Any) -> t (TagMap g)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int -> Any -> t Any) -> IntMap Any -> t (IntMap Any)
forall (t :: * -> *) a b.
Applicative t =>
(Int -> a -> t b) -> IntMap a -> t (IntMap b)
IntMap.traverseWithKey Int -> Any -> t Any
g IntMap Any
m
  where
    g :: Int -> Any -> t Any
    g :: Int -> Any -> t Any
g Int
k Any
v = (forall a. g a -> Any
forall a b. a -> b
unsafeCoerce :: g a -> Any) (g Any -> Any) -> t (g Any) -> t Any
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MyTag Any -> f Any -> t (g Any)
forall a. MyTag a -> f a -> t (g a)
f (Int -> MyTag Any
forall x. Int -> MyTag x
MyTag Int
k) ((forall a. Any -> f a
forall a b. a -> b
unsafeCoerce :: Any -> f a) Any
v)

-- | Runs in reverse to accommodate for the fact that we accumulate it in reverse
traverseRequesterData :: forall m request response. Applicative m => (forall a. request a -> m (response a)) -> RequesterData request -> m (RequesterData response)
traverseRequesterData :: (forall a. request a -> m (response a))
-> RequesterData request -> m (RequesterData response)
traverseRequesterData forall a. request a -> m (response a)
f (RequesterData TagMap (Entry request)
m) = TagMap (Entry response) -> RequesterData response
forall (f :: * -> *). TagMap (Entry f) -> RequesterData f
RequesterData (TagMap (Entry response) -> RequesterData response)
-> m (TagMap (Entry response)) -> m (RequesterData response)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall a. MyTag a -> Entry request a -> m (Entry response a))
-> TagMap (Entry request) -> m (TagMap (Entry response))
forall (t :: * -> *) (f :: * -> *) (g :: * -> *).
Applicative t =>
(forall a. MyTag a -> f a -> t (g a)) -> TagMap f -> t (TagMap g)
traverseTagMapWithKey forall a. MyTag a -> Entry request a -> m (Entry response a)
go TagMap (Entry request)
m --TODO: reverse this, since our tags are in reverse order
  where go :: forall x. MyTag x -> Entry request x -> m (Entry response x)
        go :: MyTag x -> Entry request x -> m (Entry response x)
go MyTag x
k (Entry EntryContents request x
request) = EntryContents response x -> Entry response x
forall (request :: * -> *) x.
EntryContents request x -> Entry request x
Entry (EntryContents response x -> Entry response x)
-> m (EntryContents response x) -> m (Entry response x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> case MyTag x -> MyTagType x
forall x. MyTag x -> MyTagType x
myKeyType MyTag x
k of
          MyTagType x
MyTagType_Single -> request a -> m (response a)
forall a. request a -> m (response a)
f request a
EntryContents request x
request
          MyTagType x
MyTagType_Multi -> (RequesterData request -> m (RequesterData response))
-> IntMap (RequesterData request)
-> m (IntMap (RequesterData response))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((forall a. request a -> m (response a))
-> RequesterData request -> m (RequesterData response)
forall (m :: * -> *) (request :: * -> *) (response :: * -> *).
Applicative m =>
(forall a. request a -> m (response a))
-> RequesterData request -> m (RequesterData response)
traverseRequesterData forall a. request a -> m (response a)
f) IntMap (RequesterData request)
EntryContents request x
request
          MyTagType x
MyTagType_Multi2 -> (IntMap (RequesterData request)
 -> m (IntMap (RequesterData response)))
-> Map (Some k) (IntMap (RequesterData request))
-> m (Map (Some k) (IntMap (RequesterData response)))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((RequesterData request -> m (RequesterData response))
-> IntMap (RequesterData request)
-> m (IntMap (RequesterData response))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((forall a. request a -> m (response a))
-> RequesterData request -> m (RequesterData response)
forall (m :: * -> *) (request :: * -> *) (response :: * -> *).
Applicative m =>
(forall a. request a -> m (response a))
-> RequesterData request -> m (RequesterData response)
traverseRequesterData forall a. request a -> m (response a)
f)) Map (Some k) (IntMap (RequesterData request))
EntryContents request x
request
          MyTagType x
MyTagType_Multi3 -> (IntMap (RequesterData request)
 -> m (IntMap (RequesterData response)))
-> IntMap (IntMap (RequesterData request))
-> m (IntMap (IntMap (RequesterData response)))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((RequesterData request -> m (RequesterData response))
-> IntMap (RequesterData request)
-> m (IntMap (RequesterData response))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((forall a. request a -> m (response a))
-> RequesterData request -> m (RequesterData response)
forall (m :: * -> *) (request :: * -> *) (response :: * -> *).
Applicative m =>
(forall a. request a -> m (response a))
-> RequesterData request -> m (RequesterData response)
traverseRequesterData forall a. request a -> m (response a)
f)) IntMap (IntMap (RequesterData request))
EntryContents request x
request

-- | 'traverseRequesterData' with its arguments flipped
forRequesterData :: forall request response m. Applicative m => RequesterData request -> (forall a. request a -> m (response a)) -> m (RequesterData response)
forRequesterData :: RequesterData request
-> (forall a. request a -> m (response a))
-> m (RequesterData response)
forRequesterData RequesterData request
r forall a. request a -> m (response a)
f = (forall a. request a -> m (response a))
-> RequesterData request -> m (RequesterData response)
forall (m :: * -> *) (request :: * -> *) (response :: * -> *).
Applicative m =>
(forall a. request a -> m (response a))
-> RequesterData request -> m (RequesterData response)
traverseRequesterData forall a. request a -> m (response a)
f RequesterData request
r

data MyTagType :: * -> * where
  MyTagType_Single :: MyTagType (Single a)
  MyTagType_Multi :: MyTagType Multi
  MyTagType_Multi2 :: MyTagType (Multi2 k)
  MyTagType_Multi3 :: MyTagType Multi3

myKeyType :: MyTag x -> MyTagType x
myKeyType :: MyTag x -> MyTagType x
myKeyType (MyTag Int
k) = case Int
k Int -> Int -> Int
forall a. Bits a => a -> a -> a
.&. Int
0x3 of
  Int
0x0 -> MyTagType (Single Any) -> MyTagType x
forall a b. a -> b
unsafeCoerce MyTagType (Single Any)
forall a. MyTagType (Single a)
MyTagType_Single
  Int
0x1 -> MyTagType Multi -> MyTagType x
forall a b. a -> b
unsafeCoerce MyTagType Multi
MyTagType_Multi
  Int
0x2 -> MyTagType (Multi2 Any) -> MyTagType x
forall a b. a -> b
unsafeCoerce MyTagType (Multi2 Any)
forall (k :: * -> *). MyTagType (Multi2 k)
MyTagType_Multi2
  Int
0x3 -> MyTagType Multi3 -> MyTagType x
forall a b. a -> b
unsafeCoerce MyTagType Multi3
MyTagType_Multi3
  Int
t -> [Char] -> MyTagType x
forall a. HasCallStack => [Char] -> a
error ([Char] -> MyTagType x) -> [Char] -> MyTagType x
forall a b. (a -> b) -> a -> b
$ [Char]
"Reflex.Requester.Base.myKeyType: no such key type" [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> Int -> [Char]
forall a. Show a => a -> [Char]
show Int
t

data Single a
data Multi
data Multi2 (k :: * -> *)
data Multi3

class MyTagTypeOffset x where
  myTagTypeOffset :: proxy x -> Int

instance MyTagTypeOffset (Single a) where
  myTagTypeOffset :: proxy (Single a) -> Int
myTagTypeOffset proxy (Single a)
_ = Int
0x0

instance MyTagTypeOffset Multi where
  myTagTypeOffset :: proxy Multi -> Int
myTagTypeOffset proxy Multi
_ = Int
0x1

instance MyTagTypeOffset (Multi2 k) where
  myTagTypeOffset :: proxy (Multi2 k) -> Int
myTagTypeOffset proxy (Multi2 k)
_ = Int
0x2

instance MyTagTypeOffset Multi3 where
  myTagTypeOffset :: proxy Multi3 -> Int
myTagTypeOffset proxy Multi3
_ = Int
0x3

type family EntryContents request a where
  EntryContents request (Single a) = request a
  EntryContents request Multi = IntMap (RequesterData request)
  EntryContents request (Multi2 k) = Map (Some k) (IntMap (RequesterData request))
  EntryContents request Multi3 = IntMap (IntMap (RequesterData request))

newtype Entry request x = Entry { Entry request x -> EntryContents request x
unEntry :: EntryContents request x }

{-# INLINE singleEntry #-}
singleEntry :: f a -> Entry f (Single a)
singleEntry :: f a -> Entry f (Single a)
singleEntry = f a -> Entry f (Single a)
forall (request :: * -> *) x.
EntryContents request x -> Entry request x
Entry

{-# INLINE multiEntry #-}
multiEntry :: IntMap (RequesterData f) -> Entry f Multi
multiEntry :: IntMap (RequesterData f) -> Entry f Multi
multiEntry = IntMap (RequesterData f) -> Entry f Multi
forall (request :: * -> *) x.
EntryContents request x -> Entry request x
Entry

{-# INLINE unMultiEntry #-}
unMultiEntry :: Entry f Multi -> IntMap (RequesterData f)
unMultiEntry :: Entry f Multi -> IntMap (RequesterData f)
unMultiEntry = Entry f Multi -> IntMap (RequesterData f)
forall (request :: * -> *) x.
Entry request x -> EntryContents request x
unEntry

-- | We use a hack here to pretend we have x ~ request a; we don't want to use a GADT, because GADTs (even with zero-size existential contexts) can't be newtypes
-- WARNING: This type should never be exposed.  In particular, this is extremely unsound if a MyTag from one run of runRequesterT is ever compared against a MyTag from another
newtype MyTag x = MyTag Int deriving (Int -> MyTag x -> [Char] -> [Char]
[MyTag x] -> [Char] -> [Char]
MyTag x -> [Char]
(Int -> MyTag x -> [Char] -> [Char])
-> (MyTag x -> [Char])
-> ([MyTag x] -> [Char] -> [Char])
-> Show (MyTag x)
forall x. Int -> MyTag x -> [Char] -> [Char]
forall x. [MyTag x] -> [Char] -> [Char]
forall x. MyTag x -> [Char]
forall a.
(Int -> a -> [Char] -> [Char])
-> (a -> [Char]) -> ([a] -> [Char] -> [Char]) -> Show a
showList :: [MyTag x] -> [Char] -> [Char]
$cshowList :: forall x. [MyTag x] -> [Char] -> [Char]
show :: MyTag x -> [Char]
$cshow :: forall x. MyTag x -> [Char]
showsPrec :: Int -> MyTag x -> [Char] -> [Char]
$cshowsPrec :: forall x. Int -> MyTag x -> [Char] -> [Char]
Show, MyTag x -> MyTag x -> Bool
(MyTag x -> MyTag x -> Bool)
-> (MyTag x -> MyTag x -> Bool) -> Eq (MyTag x)
forall x. MyTag x -> MyTag x -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MyTag x -> MyTag x -> Bool
$c/= :: forall x. MyTag x -> MyTag x -> Bool
== :: MyTag x -> MyTag x -> Bool
$c== :: forall x. MyTag x -> MyTag x -> Bool
Eq, Eq (MyTag x)
Eq (MyTag x)
-> (MyTag x -> MyTag x -> Ordering)
-> (MyTag x -> MyTag x -> Bool)
-> (MyTag x -> MyTag x -> Bool)
-> (MyTag x -> MyTag x -> Bool)
-> (MyTag x -> MyTag x -> Bool)
-> (MyTag x -> MyTag x -> MyTag x)
-> (MyTag x -> MyTag x -> MyTag x)
-> Ord (MyTag x)
MyTag x -> MyTag x -> Bool
MyTag x -> MyTag x -> Ordering
MyTag x -> MyTag x -> MyTag x
forall x. Eq (MyTag 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 x. MyTag x -> MyTag x -> Bool
forall x. MyTag x -> MyTag x -> Ordering
forall x. MyTag x -> MyTag x -> MyTag x
min :: MyTag x -> MyTag x -> MyTag x
$cmin :: forall x. MyTag x -> MyTag x -> MyTag x
max :: MyTag x -> MyTag x -> MyTag x
$cmax :: forall x. MyTag x -> MyTag x -> MyTag x
>= :: MyTag x -> MyTag x -> Bool
$c>= :: forall x. MyTag x -> MyTag x -> Bool
> :: MyTag x -> MyTag x -> Bool
$c> :: forall x. MyTag x -> MyTag x -> Bool
<= :: MyTag x -> MyTag x -> Bool
$c<= :: forall x. MyTag x -> MyTag x -> Bool
< :: MyTag x -> MyTag x -> Bool
$c< :: forall x. MyTag x -> MyTag x -> Bool
compare :: MyTag x -> MyTag x -> Ordering
$ccompare :: forall x. MyTag x -> MyTag x -> Ordering
$cp1Ord :: forall x. Eq (MyTag x)
Ord, Int -> MyTag x
MyTag x -> Int
MyTag x -> [MyTag x]
MyTag x -> MyTag x
MyTag x -> MyTag x -> [MyTag x]
MyTag x -> MyTag x -> MyTag x -> [MyTag x]
(MyTag x -> MyTag x)
-> (MyTag x -> MyTag x)
-> (Int -> MyTag x)
-> (MyTag x -> Int)
-> (MyTag x -> [MyTag x])
-> (MyTag x -> MyTag x -> [MyTag x])
-> (MyTag x -> MyTag x -> [MyTag x])
-> (MyTag x -> MyTag x -> MyTag x -> [MyTag x])
-> Enum (MyTag x)
forall x. Int -> MyTag x
forall x. MyTag x -> Int
forall x. MyTag x -> [MyTag x]
forall x. MyTag x -> MyTag x
forall x. MyTag x -> MyTag x -> [MyTag x]
forall x. MyTag x -> MyTag x -> MyTag x -> [MyTag 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
enumFromThenTo :: MyTag x -> MyTag x -> MyTag x -> [MyTag x]
$cenumFromThenTo :: forall x. MyTag x -> MyTag x -> MyTag x -> [MyTag x]
enumFromTo :: MyTag x -> MyTag x -> [MyTag x]
$cenumFromTo :: forall x. MyTag x -> MyTag x -> [MyTag x]
enumFromThen :: MyTag x -> MyTag x -> [MyTag x]
$cenumFromThen :: forall x. MyTag x -> MyTag x -> [MyTag x]
enumFrom :: MyTag x -> [MyTag x]
$cenumFrom :: forall x. MyTag x -> [MyTag x]
fromEnum :: MyTag x -> Int
$cfromEnum :: forall x. MyTag x -> Int
toEnum :: Int -> MyTag x
$ctoEnum :: forall x. Int -> MyTag x
pred :: MyTag x -> MyTag x
$cpred :: forall x. MyTag x -> MyTag x
succ :: MyTag x -> MyTag x
$csucc :: forall x. MyTag x -> MyTag x
Enum)

newtype MyTagWrap (f :: * -> *) x = MyTagWrap Int deriving (Int -> MyTagWrap f x -> [Char] -> [Char]
[MyTagWrap f x] -> [Char] -> [Char]
MyTagWrap f x -> [Char]
(Int -> MyTagWrap f x -> [Char] -> [Char])
-> (MyTagWrap f x -> [Char])
-> ([MyTagWrap f x] -> [Char] -> [Char])
-> Show (MyTagWrap f x)
forall a.
(Int -> a -> [Char] -> [Char])
-> (a -> [Char]) -> ([a] -> [Char] -> [Char]) -> Show a
forall (f :: * -> *) x. Int -> MyTagWrap f x -> [Char] -> [Char]
forall (f :: * -> *) x. [MyTagWrap f x] -> [Char] -> [Char]
forall (f :: * -> *) x. MyTagWrap f x -> [Char]
showList :: [MyTagWrap f x] -> [Char] -> [Char]
$cshowList :: forall (f :: * -> *) x. [MyTagWrap f x] -> [Char] -> [Char]
show :: MyTagWrap f x -> [Char]
$cshow :: forall (f :: * -> *) x. MyTagWrap f x -> [Char]
showsPrec :: Int -> MyTagWrap f x -> [Char] -> [Char]
$cshowsPrec :: forall (f :: * -> *) x. Int -> MyTagWrap f x -> [Char] -> [Char]
Show, MyTagWrap f x -> MyTagWrap f x -> Bool
(MyTagWrap f x -> MyTagWrap f x -> Bool)
-> (MyTagWrap f x -> MyTagWrap f x -> Bool) -> Eq (MyTagWrap f x)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall (f :: * -> *) x. MyTagWrap f x -> MyTagWrap f x -> Bool
/= :: MyTagWrap f x -> MyTagWrap f x -> Bool
$c/= :: forall (f :: * -> *) x. MyTagWrap f x -> MyTagWrap f x -> Bool
== :: MyTagWrap f x -> MyTagWrap f x -> Bool
$c== :: forall (f :: * -> *) x. MyTagWrap f x -> MyTagWrap f x -> Bool
Eq, Eq (MyTagWrap f x)
Eq (MyTagWrap f x)
-> (MyTagWrap f x -> MyTagWrap f x -> Ordering)
-> (MyTagWrap f x -> MyTagWrap f x -> Bool)
-> (MyTagWrap f x -> MyTagWrap f x -> Bool)
-> (MyTagWrap f x -> MyTagWrap f x -> Bool)
-> (MyTagWrap f x -> MyTagWrap f x -> Bool)
-> (MyTagWrap f x -> MyTagWrap f x -> MyTagWrap f x)
-> (MyTagWrap f x -> MyTagWrap f x -> MyTagWrap f x)
-> Ord (MyTagWrap f x)
MyTagWrap f x -> MyTagWrap f x -> Bool
MyTagWrap f x -> MyTagWrap f x -> Ordering
MyTagWrap f x -> MyTagWrap f x -> MyTagWrap f 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 (f :: * -> *) x. Eq (MyTagWrap f x)
forall (f :: * -> *) x. MyTagWrap f x -> MyTagWrap f x -> Bool
forall (f :: * -> *) x. MyTagWrap f x -> MyTagWrap f x -> Ordering
forall (f :: * -> *) x.
MyTagWrap f x -> MyTagWrap f x -> MyTagWrap f x
min :: MyTagWrap f x -> MyTagWrap f x -> MyTagWrap f x
$cmin :: forall (f :: * -> *) x.
MyTagWrap f x -> MyTagWrap f x -> MyTagWrap f x
max :: MyTagWrap f x -> MyTagWrap f x -> MyTagWrap f x
$cmax :: forall (f :: * -> *) x.
MyTagWrap f x -> MyTagWrap f x -> MyTagWrap f x
>= :: MyTagWrap f x -> MyTagWrap f x -> Bool
$c>= :: forall (f :: * -> *) x. MyTagWrap f x -> MyTagWrap f x -> Bool
> :: MyTagWrap f x -> MyTagWrap f x -> Bool
$c> :: forall (f :: * -> *) x. MyTagWrap f x -> MyTagWrap f x -> Bool
<= :: MyTagWrap f x -> MyTagWrap f x -> Bool
$c<= :: forall (f :: * -> *) x. MyTagWrap f x -> MyTagWrap f x -> Bool
< :: MyTagWrap f x -> MyTagWrap f x -> Bool
$c< :: forall (f :: * -> *) x. MyTagWrap f x -> MyTagWrap f x -> Bool
compare :: MyTagWrap f x -> MyTagWrap f x -> Ordering
$ccompare :: forall (f :: * -> *) x. MyTagWrap f x -> MyTagWrap f x -> Ordering
$cp1Ord :: forall (f :: * -> *) x. Eq (MyTagWrap f x)
Ord, Int -> MyTagWrap f x
MyTagWrap f x -> Int
MyTagWrap f x -> [MyTagWrap f x]
MyTagWrap f x -> MyTagWrap f x
MyTagWrap f x -> MyTagWrap f x -> [MyTagWrap f x]
MyTagWrap f x -> MyTagWrap f x -> MyTagWrap f x -> [MyTagWrap f x]
(MyTagWrap f x -> MyTagWrap f x)
-> (MyTagWrap f x -> MyTagWrap f x)
-> (Int -> MyTagWrap f x)
-> (MyTagWrap f x -> Int)
-> (MyTagWrap f x -> [MyTagWrap f x])
-> (MyTagWrap f x -> MyTagWrap f x -> [MyTagWrap f x])
-> (MyTagWrap f x -> MyTagWrap f x -> [MyTagWrap f x])
-> (MyTagWrap f x
    -> MyTagWrap f x -> MyTagWrap f x -> [MyTagWrap f x])
-> Enum (MyTagWrap f 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 (f :: * -> *) x. Int -> MyTagWrap f x
forall (f :: * -> *) x. MyTagWrap f x -> Int
forall (f :: * -> *) x. MyTagWrap f x -> [MyTagWrap f x]
forall (f :: * -> *) x. MyTagWrap f x -> MyTagWrap f x
forall (f :: * -> *) x.
MyTagWrap f x -> MyTagWrap f x -> [MyTagWrap f x]
forall (f :: * -> *) x.
MyTagWrap f x -> MyTagWrap f x -> MyTagWrap f x -> [MyTagWrap f x]
enumFromThenTo :: MyTagWrap f x -> MyTagWrap f x -> MyTagWrap f x -> [MyTagWrap f x]
$cenumFromThenTo :: forall (f :: * -> *) x.
MyTagWrap f x -> MyTagWrap f x -> MyTagWrap f x -> [MyTagWrap f x]
enumFromTo :: MyTagWrap f x -> MyTagWrap f x -> [MyTagWrap f x]
$cenumFromTo :: forall (f :: * -> *) x.
MyTagWrap f x -> MyTagWrap f x -> [MyTagWrap f x]
enumFromThen :: MyTagWrap f x -> MyTagWrap f x -> [MyTagWrap f x]
$cenumFromThen :: forall (f :: * -> *) x.
MyTagWrap f x -> MyTagWrap f x -> [MyTagWrap f x]
enumFrom :: MyTagWrap f x -> [MyTagWrap f x]
$cenumFrom :: forall (f :: * -> *) x. MyTagWrap f x -> [MyTagWrap f x]
fromEnum :: MyTagWrap f x -> Int
$cfromEnum :: forall (f :: * -> *) x. MyTagWrap f x -> Int
toEnum :: Int -> MyTagWrap f x
$ctoEnum :: forall (f :: * -> *) x. Int -> MyTagWrap f x
pred :: MyTagWrap f x -> MyTagWrap f x
$cpred :: forall (f :: * -> *) x. MyTagWrap f x -> MyTagWrap f x
succ :: MyTagWrap f x -> MyTagWrap f x
$csucc :: forall (f :: * -> *) x. MyTagWrap f x -> MyTagWrap f x
Enum)

{-# INLINE castMyTagWrap #-}
castMyTagWrap :: MyTagWrap f (Entry f x) -> MyTagWrap g (Entry g x)
castMyTagWrap :: MyTagWrap f (Entry f x) -> MyTagWrap g (Entry g x)
castMyTagWrap = MyTagWrap f (Entry f x) -> MyTagWrap g (Entry g x)
coerce

instance GEq MyTag where
  (MyTag Int
a) geq :: MyTag a -> MyTag b -> Maybe (a :~: b)
`geq` (MyTag Int
b) =
    if Int
a Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
b
    then (a :~: b) -> Maybe (a :~: b)
forall a. a -> Maybe a
Just ((a :~: b) -> Maybe (a :~: b)) -> (a :~: b) -> Maybe (a :~: b)
forall a b. (a -> b) -> a -> b
$ (Any :~: Any) -> a :~: b
forall a b. a -> b
unsafeCoerce Any :~: Any
forall k (a :: k). a :~: a
Refl
    else Maybe (a :~: b)
forall a. Maybe a
Nothing

instance GCompare MyTag where
  (MyTag Int
a) gcompare :: MyTag a -> MyTag b -> GOrdering a b
`gcompare` (MyTag Int
b) =
    case Int
a Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Int
b of
      Ordering
LT -> GOrdering a b
forall k (a :: k) (b :: k). GOrdering a b
GLT
      Ordering
EQ -> GOrdering Any Any -> GOrdering a b
forall a b. a -> b
unsafeCoerce GOrdering Any Any
forall k (a :: k). GOrdering a a
GEQ
      Ordering
GT -> GOrdering a b
forall k (a :: k) (b :: k). GOrdering a b
GGT

instance GEq (MyTagWrap f) where
  (MyTagWrap Int
a) geq :: MyTagWrap f a -> MyTagWrap f b -> Maybe (a :~: b)
`geq` (MyTagWrap Int
b) =
    if Int
a Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
b
    then (a :~: b) -> Maybe (a :~: b)
forall a. a -> Maybe a
Just ((a :~: b) -> Maybe (a :~: b)) -> (a :~: b) -> Maybe (a :~: b)
forall a b. (a -> b) -> a -> b
$ (Any :~: Any) -> a :~: b
forall a b. a -> b
unsafeCoerce Any :~: Any
forall k (a :: k). a :~: a
Refl
    else Maybe (a :~: b)
forall a. Maybe a
Nothing

instance GCompare (MyTagWrap f) where
  (MyTagWrap Int
a) gcompare :: MyTagWrap f a -> MyTagWrap f b -> GOrdering a b
`gcompare` (MyTagWrap Int
b) =
    case Int
a Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Int
b of
      Ordering
LT -> GOrdering a b
forall k (a :: k) (b :: k). GOrdering a b
GLT
      Ordering
EQ -> GOrdering Any Any -> GOrdering a b
forall a b. a -> b
unsafeCoerce GOrdering Any Any
forall k (a :: k). GOrdering a a
GEQ
      Ordering
GT -> GOrdering a b
forall k (a :: k) (b :: k). GOrdering a b
GGT

data RequesterState t (request :: * -> *) = RequesterState
  { RequesterState t request -> Int
_requesterState_nextMyTag :: {-# UNPACK #-} !Int -- Starts at -4 and goes down by 4 each time, to accommodate two 'type' bits at the bottom
  , RequesterState t request -> [(Int, Event t Any)]
_requesterState_requests :: ![(Int, Event t Any)]
  }

-- | A basic implementation of 'Requester'.
newtype RequesterT t request (response :: * -> *) m a = RequesterT { RequesterT t request response m a
-> StateT
     (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) a
unRequesterT :: StateT (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) a }
  deriving (a
-> RequesterT t request response m b
-> RequesterT t request response m a
(a -> b)
-> RequesterT t request response m a
-> RequesterT t request response m b
(forall a b.
 (a -> b)
 -> RequesterT t request response m a
 -> RequesterT t request response m b)
-> (forall a b.
    a
    -> RequesterT t request response m b
    -> RequesterT t request response m a)
-> Functor (RequesterT t request response m)
forall a b.
a
-> RequesterT t request response m b
-> RequesterT t request response m a
forall a b.
(a -> b)
-> RequesterT t request response m a
-> RequesterT t request response m b
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a
       b.
Functor m =>
a
-> RequesterT t request response m b
-> RequesterT t request response m a
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a
       b.
Functor m =>
(a -> b)
-> RequesterT t request response m a
-> RequesterT t request response m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a
-> RequesterT t request response m b
-> RequesterT t request response m a
$c<$ :: forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a
       b.
Functor m =>
a
-> RequesterT t request response m b
-> RequesterT t request response m a
fmap :: (a -> b)
-> RequesterT t request response m a
-> RequesterT t request response m b
$cfmap :: forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a
       b.
Functor m =>
(a -> b)
-> RequesterT t request response m a
-> RequesterT t request response m b
Functor, Functor (RequesterT t request response m)
a -> RequesterT t request response m a
Functor (RequesterT t request response m)
-> (forall a. a -> RequesterT t request response m a)
-> (forall a b.
    RequesterT t request response m (a -> b)
    -> RequesterT t request response m a
    -> RequesterT t request response m b)
-> (forall a b c.
    (a -> b -> c)
    -> RequesterT t request response m a
    -> RequesterT t request response m b
    -> RequesterT t request response m c)
-> (forall a b.
    RequesterT t request response m a
    -> RequesterT t request response m b
    -> RequesterT t request response m b)
-> (forall a b.
    RequesterT t request response m a
    -> RequesterT t request response m b
    -> RequesterT t request response m a)
-> Applicative (RequesterT t request response m)
RequesterT t request response m a
-> RequesterT t request response m b
-> RequesterT t request response m b
RequesterT t request response m a
-> RequesterT t request response m b
-> RequesterT t request response m a
RequesterT t request response m (a -> b)
-> RequesterT t request response m a
-> RequesterT t request response m b
(a -> b -> c)
-> RequesterT t request response m a
-> RequesterT t request response m b
-> RequesterT t request response m c
forall a. a -> RequesterT t request response m a
forall a b.
RequesterT t request response m a
-> RequesterT t request response m b
-> RequesterT t request response m a
forall a b.
RequesterT t request response m a
-> RequesterT t request response m b
-> RequesterT t request response m b
forall a b.
RequesterT t request response m (a -> b)
-> RequesterT t request response m a
-> RequesterT t request response m b
forall a b c.
(a -> b -> c)
-> RequesterT t request response m a
-> RequesterT t request response m b
-> RequesterT t request response m c
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *).
Monad m =>
Functor (RequesterT t request response m)
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a.
Monad m =>
a -> RequesterT t request response m a
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a
       b.
Monad m =>
RequesterT t request response m a
-> RequesterT t request response m b
-> RequesterT t request response m a
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a
       b.
Monad m =>
RequesterT t request response m a
-> RequesterT t request response m b
-> RequesterT t request response m b
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a
       b.
Monad m =>
RequesterT t request response m (a -> b)
-> RequesterT t request response m a
-> RequesterT t request response m b
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a b
       c.
Monad m =>
(a -> b -> c)
-> RequesterT t request response m a
-> RequesterT t request response m b
-> RequesterT t request response 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
<* :: RequesterT t request response m a
-> RequesterT t request response m b
-> RequesterT t request response m a
$c<* :: forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a
       b.
Monad m =>
RequesterT t request response m a
-> RequesterT t request response m b
-> RequesterT t request response m a
*> :: RequesterT t request response m a
-> RequesterT t request response m b
-> RequesterT t request response m b
$c*> :: forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a
       b.
Monad m =>
RequesterT t request response m a
-> RequesterT t request response m b
-> RequesterT t request response m b
liftA2 :: (a -> b -> c)
-> RequesterT t request response m a
-> RequesterT t request response m b
-> RequesterT t request response m c
$cliftA2 :: forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a b
       c.
Monad m =>
(a -> b -> c)
-> RequesterT t request response m a
-> RequesterT t request response m b
-> RequesterT t request response m c
<*> :: RequesterT t request response m (a -> b)
-> RequesterT t request response m a
-> RequesterT t request response m b
$c<*> :: forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a
       b.
Monad m =>
RequesterT t request response m (a -> b)
-> RequesterT t request response m a
-> RequesterT t request response m b
pure :: a -> RequesterT t request response m a
$cpure :: forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a.
Monad m =>
a -> RequesterT t request response m a
$cp1Applicative :: forall t (request :: * -> *) (response :: * -> *) (m :: * -> *).
Monad m =>
Functor (RequesterT t request response m)
Applicative, Applicative (RequesterT t request response m)
a -> RequesterT t request response m a
Applicative (RequesterT t request response m)
-> (forall a b.
    RequesterT t request response m a
    -> (a -> RequesterT t request response m b)
    -> RequesterT t request response m b)
-> (forall a b.
    RequesterT t request response m a
    -> RequesterT t request response m b
    -> RequesterT t request response m b)
-> (forall a. a -> RequesterT t request response m a)
-> Monad (RequesterT t request response m)
RequesterT t request response m a
-> (a -> RequesterT t request response m b)
-> RequesterT t request response m b
RequesterT t request response m a
-> RequesterT t request response m b
-> RequesterT t request response m b
forall a. a -> RequesterT t request response m a
forall a b.
RequesterT t request response m a
-> RequesterT t request response m b
-> RequesterT t request response m b
forall a b.
RequesterT t request response m a
-> (a -> RequesterT t request response m b)
-> RequesterT t request response m b
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *).
Monad m =>
Applicative (RequesterT t request response m)
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a.
Monad m =>
a -> RequesterT t request response m a
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a
       b.
Monad m =>
RequesterT t request response m a
-> RequesterT t request response m b
-> RequesterT t request response m b
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a
       b.
Monad m =>
RequesterT t request response m a
-> (a -> RequesterT t request response m b)
-> RequesterT t request response 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 -> RequesterT t request response m a
$creturn :: forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a.
Monad m =>
a -> RequesterT t request response m a
>> :: RequesterT t request response m a
-> RequesterT t request response m b
-> RequesterT t request response m b
$c>> :: forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a
       b.
Monad m =>
RequesterT t request response m a
-> RequesterT t request response m b
-> RequesterT t request response m b
>>= :: RequesterT t request response m a
-> (a -> RequesterT t request response m b)
-> RequesterT t request response m b
$c>>= :: forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a
       b.
Monad m =>
RequesterT t request response m a
-> (a -> RequesterT t request response m b)
-> RequesterT t request response m b
$cp1Monad :: forall t (request :: * -> *) (response :: * -> *) (m :: * -> *).
Monad m =>
Applicative (RequesterT t request response m)
Monad, Monad (RequesterT t request response m)
Monad (RequesterT t request response m)
-> (forall a.
    (a -> RequesterT t request response m a)
    -> RequesterT t request response m a)
-> MonadFix (RequesterT t request response m)
(a -> RequesterT t request response m a)
-> RequesterT t request response m a
forall a.
(a -> RequesterT t request response m a)
-> RequesterT t request response m a
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *).
MonadFix m =>
Monad (RequesterT t request response m)
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a.
MonadFix m =>
(a -> RequesterT t request response m a)
-> RequesterT t request response m a
forall (m :: * -> *).
Monad m -> (forall a. (a -> m a) -> m a) -> MonadFix m
mfix :: (a -> RequesterT t request response m a)
-> RequesterT t request response m a
$cmfix :: forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a.
MonadFix m =>
(a -> RequesterT t request response m a)
-> RequesterT t request response m a
$cp1MonadFix :: forall t (request :: * -> *) (response :: * -> *) (m :: * -> *).
MonadFix m =>
Monad (RequesterT t request response m)
MonadFix, Monad (RequesterT t request response m)
Monad (RequesterT t request response m)
-> (forall a. IO a -> RequesterT t request response m a)
-> MonadIO (RequesterT t request response m)
IO a -> RequesterT t request response m a
forall a. IO a -> RequesterT t request response m a
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *).
MonadIO m =>
Monad (RequesterT t request response m)
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a.
MonadIO m =>
IO a -> RequesterT t request response m a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
liftIO :: IO a -> RequesterT t request response m a
$cliftIO :: forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a.
MonadIO m =>
IO a -> RequesterT t request response m a
$cp1MonadIO :: forall t (request :: * -> *) (response :: * -> *) (m :: * -> *).
MonadIO m =>
Monad (RequesterT t request response m)
MonadIO, Monad (RequesterT t request response m)
e -> RequesterT t request response m a
Monad (RequesterT t request response m)
-> (forall e a.
    Exception e =>
    e -> RequesterT t request response m a)
-> (forall e a.
    Exception e =>
    RequesterT t request response m a
    -> (e -> RequesterT t request response m a)
    -> RequesterT t request response m a)
-> (forall a b.
    RequesterT t request response m a
    -> RequesterT t request response m b
    -> RequesterT t request response m a)
-> MonadException (RequesterT t request response m)
RequesterT t request response m a
-> (e -> RequesterT t request response m a)
-> RequesterT t request response m a
RequesterT t request response m a
-> RequesterT t request response m b
-> RequesterT t request response m a
forall e a. Exception e => e -> RequesterT t request response m a
forall e a.
Exception e =>
RequesterT t request response m a
-> (e -> RequesterT t request response m a)
-> RequesterT t request response m a
forall a b.
RequesterT t request response m a
-> RequesterT t request response m b
-> RequesterT t request response m a
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *).
MonadException m =>
Monad (RequesterT t request response m)
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) e
       a.
(MonadException m, Exception e) =>
e -> RequesterT t request response m a
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) e
       a.
(MonadException m, Exception e) =>
RequesterT t request response m a
-> (e -> RequesterT t request response m a)
-> RequesterT t request response m a
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a
       b.
MonadException m =>
RequesterT t request response m a
-> RequesterT t request response m b
-> RequesterT t request response 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 :: RequesterT t request response m a
-> RequesterT t request response m b
-> RequesterT t request response m a
$cfinally :: forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a
       b.
MonadException m =>
RequesterT t request response m a
-> RequesterT t request response m b
-> RequesterT t request response m a
catch :: RequesterT t request response m a
-> (e -> RequesterT t request response m a)
-> RequesterT t request response m a
$ccatch :: forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) e
       a.
(MonadException m, Exception e) =>
RequesterT t request response m a
-> (e -> RequesterT t request response m a)
-> RequesterT t request response m a
throw :: e -> RequesterT t request response m a
$cthrow :: forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) e
       a.
(MonadException m, Exception e) =>
e -> RequesterT t request response m a
$cp1MonadException :: forall t (request :: * -> *) (response :: * -> *) (m :: * -> *).
MonadException m =>
Monad (RequesterT t request response m)
MonadException
-- MonadAsyncException can't be derived on ghc-8.0.1; we use base-4.9.1 as a proxy for ghc-8.0.2
#if MIN_VERSION_base(4,9,1)
           , MonadIO (RequesterT t request response m)
MonadException (RequesterT t request response m)
MonadIO (RequesterT t request response m)
-> MonadException (RequesterT t request response m)
-> (forall b.
    ((forall a.
      RequesterT t request response m a
      -> RequesterT t request response m a)
     -> RequesterT t request response m b)
    -> RequesterT t request response m b)
-> MonadAsyncException (RequesterT t request response m)
((forall a.
  RequesterT t request response m a
  -> RequesterT t request response m a)
 -> RequesterT t request response m b)
-> RequesterT t request response m b
forall b.
((forall a.
  RequesterT t request response m a
  -> RequesterT t request response m a)
 -> RequesterT t request response m b)
-> RequesterT t request response m b
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *).
MonadAsyncException m =>
MonadIO (RequesterT t request response m)
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *).
MonadAsyncException m =>
MonadException (RequesterT t request response m)
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) b.
MonadAsyncException m =>
((forall a.
  RequesterT t request response m a
  -> RequesterT t request response m a)
 -> RequesterT t request response m b)
-> RequesterT t request response 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.
  RequesterT t request response m a
  -> RequesterT t request response m a)
 -> RequesterT t request response m b)
-> RequesterT t request response m b
$cmask :: forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) b.
MonadAsyncException m =>
((forall a.
  RequesterT t request response m a
  -> RequesterT t request response m a)
 -> RequesterT t request response m b)
-> RequesterT t request response m b
$cp2MonadAsyncException :: forall t (request :: * -> *) (response :: * -> *) (m :: * -> *).
MonadAsyncException m =>
MonadException (RequesterT t request response m)
$cp1MonadAsyncException :: forall t (request :: * -> *) (response :: * -> *) (m :: * -> *).
MonadAsyncException m =>
MonadIO (RequesterT t request response m)
MonadAsyncException
#endif
           )

deriving instance MonadSample t m => MonadSample t (RequesterT t request response m)
deriving instance MonadHold t m => MonadHold t (RequesterT t request response m)
deriving instance PostBuild t m => PostBuild t (RequesterT t request response m)
deriving instance TriggerEvent t m => TriggerEvent t (RequesterT t request response m)

instance PrimMonad m => PrimMonad (RequesterT t request response m) where
  type PrimState (RequesterT t request response m) = PrimState m
  primitive :: (State# (PrimState (RequesterT t request response m))
 -> (# State# (PrimState (RequesterT t request response m)), a #))
-> RequesterT t request response m a
primitive = m a -> RequesterT t request response m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> RequesterT t request response m a)
-> ((State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a)
-> (State# (PrimState m) -> (# State# (PrimState m), a #))
-> RequesterT t request response 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

-- TODO: Monoid and Semigroup can likely be derived once StateT has them.
instance (Monoid a, Monad m) => Monoid (RequesterT t request response m a) where
  mempty :: RequesterT t request response m a
mempty = a -> RequesterT t request response m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
forall a. Monoid a => a
mempty
  mappend :: RequesterT t request response m a
-> RequesterT t request response m a
-> RequesterT t request response m a
mappend = (a -> a -> a)
-> RequesterT t request response m a
-> RequesterT t request response m a
-> RequesterT t request response m a
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, Monad m) => S.Semigroup (RequesterT t request response m a) where
  <> :: RequesterT t request response m a
-> RequesterT t request response m a
-> RequesterT t request response m a
(<>) = (a -> a -> a)
-> RequesterT t request response m a
-> RequesterT t request response m a
-> RequesterT t request response m a
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.<>)


-- | Run a 'RequesterT' action.  The resulting 'Event' will fire whenever
-- requests are made, and responses should be provided in the input 'Event'.
-- The 'Tag' keys will be used to return the responses to the same place the
-- requests were issued.
runRequesterT :: (Reflex t, Monad m)
              => RequesterT t request response m a
              -> Event t (RequesterData response) --TODO: This DMap will be in reverse order, so we need to make sure the caller traverses it in reverse
              -> m (a, Event t (RequesterData request)) --TODO: we need to hide these 'MyTag's here, because they're unsafe to mix in the wild
runRequesterT :: RequesterT t request response m a
-> Event t (RequesterData response)
-> m (a, Event t (RequesterData request))
runRequesterT (RequesterT StateT
  (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) a
a) Event t (RequesterData response)
responses = do
  (a
result, RequesterState t request
s) <- ReaderT (EventSelectorInt t Any) m (a, RequesterState t request)
-> EventSelectorInt t Any -> m (a, RequesterState t request)
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT (StateT
  (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) a
-> RequesterState t request
-> ReaderT (EventSelectorInt t Any) m (a, RequesterState t request)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
runStateT StateT
  (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) a
a (RequesterState t request
 -> ReaderT
      (EventSelectorInt t Any) m (a, RequesterState t request))
-> RequesterState t request
-> ReaderT (EventSelectorInt t Any) m (a, RequesterState t request)
forall a b. (a -> b) -> a -> b
$ Int -> [(Int, Event t Any)] -> RequesterState t request
forall t (request :: * -> *).
Int -> [(Int, Event t Any)] -> RequesterState t request
RequesterState (-Int
4) []) (EventSelectorInt t Any -> m (a, RequesterState t request))
-> EventSelectorInt t Any -> m (a, RequesterState t request)
forall a b. (a -> b) -> a -> b
$ Event t (IntMap Any) -> EventSelectorInt t Any
forall k (t :: k) a.
Reflex t =>
Event t (IntMap a) -> EventSelectorInt t a
fanInt (Event t (IntMap Any) -> EventSelectorInt t Any)
-> Event t (IntMap Any) -> EventSelectorInt t Any
forall a b. (a -> b) -> a -> b
$
    Event t (RequesterData response) -> Event t (IntMap Any)
forall k (t :: k) a b.
(Reflex t, Coercible a b) =>
Event t a -> Event t b
coerceEvent Event t (RequesterData response)
responses
  (a, Event t (RequesterData request))
-> m (a, Event t (RequesterData request))
forall (m :: * -> *) a. Monad m => a -> m a
return (a
result, (IntMap Any -> RequesterData request)
-> Event t (IntMap Any) -> Event t (RequesterData request)
forall k (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap (TagMap (Entry request) -> RequesterData request
forall (f :: * -> *). TagMap (Entry f) -> RequesterData f
RequesterData (TagMap (Entry request) -> RequesterData request)
-> (IntMap Any -> TagMap (Entry request))
-> IntMap Any
-> RequesterData request
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IntMap Any -> TagMap (Entry request)
forall (f :: * -> *). IntMap Any -> TagMap f
TagMap) (Event t (IntMap Any) -> Event t (RequesterData request))
-> Event t (IntMap Any) -> Event t (RequesterData request)
forall a b. (a -> b) -> a -> b
$ IntMap (Event t Any) -> Event t (IntMap Any)
forall k (t :: k) a.
Reflex t =>
IntMap (Event t a) -> Event t (IntMap a)
mergeInt (IntMap (Event t Any) -> Event t (IntMap Any))
-> IntMap (Event t Any) -> Event t (IntMap Any)
forall a b. (a -> b) -> a -> b
$ [(Int, Event t Any)] -> IntMap (Event t Any)
forall a. [(Int, a)] -> IntMap a
IntMap.fromDistinctAscList ([(Int, Event t Any)] -> IntMap (Event t Any))
-> [(Int, Event t Any)] -> IntMap (Event t Any)
forall a b. (a -> b) -> a -> b
$ RequesterState t request -> [(Int, Event t Any)]
forall t (request :: * -> *).
RequesterState t request -> [(Int, Event t Any)]
_requesterState_requests RequesterState t request
s)

-- | Map a function over the request and response of a 'RequesterT'
withRequesterT
  :: (Reflex t, MonadFix m)
  => (forall x. req x -> req' x) -- ^ The function to map over the request
  -> (forall x. rsp' x -> rsp x) -- ^ The function to map over the response
  -> RequesterT t req rsp m a -- ^ The internal 'RequesterT' whose input and output will be transformed
  -> RequesterT t req' rsp' m a -- ^ The resulting 'RequesterT'
withRequesterT :: (forall x. req x -> req' x)
-> (forall x. rsp' x -> rsp x)
-> RequesterT t req rsp m a
-> RequesterT t req' rsp' m a
withRequesterT forall x. req x -> req' x
freq forall x. rsp' x -> rsp x
frsp RequesterT t req rsp m a
child = do
  rec let rsp :: Event t (RequesterData rsp)
rsp = (RequesterData rsp' -> RequesterData rsp)
-> Event t (RequesterData rsp') -> Event t (RequesterData rsp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Identity (RequesterData rsp) -> RequesterData rsp
forall a. Identity a -> a
runIdentity (Identity (RequesterData rsp) -> RequesterData rsp)
-> (RequesterData rsp' -> Identity (RequesterData rsp))
-> RequesterData rsp'
-> RequesterData rsp
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. rsp' a -> Identity (rsp a))
-> RequesterData rsp' -> Identity (RequesterData rsp)
forall (m :: * -> *) (request :: * -> *) (response :: * -> *).
Applicative m =>
(forall a. request a -> m (response a))
-> RequesterData request -> m (RequesterData response)
traverseRequesterData (rsp a -> Identity (rsp a)
forall a. a -> Identity a
Identity (rsp a -> Identity (rsp a))
-> (rsp' a -> rsp a) -> rsp' a -> Identity (rsp a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. rsp' a -> rsp a
forall x. rsp' x -> rsp x
frsp)) Event t (RequesterData rsp')
rsp'
      (a
a, Event t (RequesterData req)
req) <- m (a, Event t (RequesterData req))
-> RequesterT t req' rsp' m (a, Event t (RequesterData req))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (a, Event t (RequesterData req))
 -> RequesterT t req' rsp' m (a, Event t (RequesterData req)))
-> m (a, Event t (RequesterData req))
-> RequesterT t req' rsp' m (a, Event t (RequesterData req))
forall a b. (a -> b) -> a -> b
$ RequesterT t req rsp m a
-> Event t (RequesterData rsp)
-> m (a, Event t (RequesterData req))
forall t (m :: * -> *) (request :: * -> *) (response :: * -> *) a.
(Reflex t, Monad m) =>
RequesterT t request response m a
-> Event t (RequesterData response)
-> m (a, Event t (RequesterData request))
runRequesterT RequesterT t req rsp m a
child Event t (RequesterData rsp)
rsp
      Event t (RequesterData rsp')
rsp' <- (Event t (Entry rsp' Multi) -> Event t (RequesterData rsp'))
-> RequesterT t req' rsp' m (Event t (Entry rsp' Multi))
-> RequesterT t req' rsp' m (Event t (RequesterData rsp'))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((EventSelectorInt t (RequesterData rsp')
 -> Int -> Event t (RequesterData rsp'))
-> Int
-> EventSelectorInt t (RequesterData rsp')
-> Event t (RequesterData rsp')
forall a b c. (a -> b -> c) -> b -> a -> c
flip EventSelectorInt t (RequesterData rsp')
-> Int -> Event t (RequesterData rsp')
forall k (t :: k) a. EventSelectorInt t a -> Int -> Event t a
selectInt Int
0 (EventSelectorInt t (RequesterData rsp')
 -> Event t (RequesterData rsp'))
-> (Event t (Entry rsp' Multi)
    -> EventSelectorInt t (RequesterData rsp'))
-> Event t (Entry rsp' Multi)
-> Event t (RequesterData rsp')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Event t (IntMap (RequesterData rsp'))
-> EventSelectorInt t (RequesterData rsp')
forall k (t :: k) a.
Reflex t =>
Event t (IntMap a) -> EventSelectorInt t a
fanInt (Event t (IntMap (RequesterData rsp'))
 -> EventSelectorInt t (RequesterData rsp'))
-> (Event t (Entry rsp' Multi)
    -> Event t (IntMap (RequesterData rsp')))
-> Event t (Entry rsp' Multi)
-> EventSelectorInt t (RequesterData rsp')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Entry rsp' Multi -> IntMap (RequesterData rsp'))
-> Event t (Entry rsp' Multi)
-> Event t (IntMap (RequesterData rsp'))
forall k (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap Entry rsp' Multi -> IntMap (RequesterData rsp')
forall (f :: * -> *). Entry f Multi -> IntMap (RequesterData f)
unMultiEntry) (RequesterT t req' rsp' m (Event t (Entry rsp' Multi))
 -> RequesterT t req' rsp' m (Event t (RequesterData rsp')))
-> RequesterT t req' rsp' m (Event t (Entry rsp' Multi))
-> RequesterT t req' rsp' m (Event t (RequesterData rsp'))
forall a b. (a -> b) -> a -> b
$ Event t (Entry req' Multi)
-> RequesterT t req' rsp' m (Event t (Entry rsp' Multi))
forall x (m :: * -> *) t (request :: * -> *) (response :: * -> *).
(MyTagTypeOffset x, Monad m) =>
Event t (Entry request x)
-> RequesterT t request response m (Event t (Entry response x))
requesting' (Event t (Entry req' Multi)
 -> RequesterT t req' rsp' m (Event t (Entry rsp' Multi)))
-> Event t (Entry req' Multi)
-> RequesterT t req' rsp' m (Event t (Entry rsp' Multi))
forall a b. (a -> b) -> a -> b
$
        (RequesterData req' -> Entry req' Multi)
-> Event t (RequesterData req') -> Event t (Entry req' Multi)
forall k (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap (IntMap (RequesterData req') -> Entry req' Multi
forall (f :: * -> *). IntMap (RequesterData f) -> Entry f Multi
multiEntry (IntMap (RequesterData req') -> Entry req' Multi)
-> (RequesterData req' -> IntMap (RequesterData req'))
-> RequesterData req'
-> Entry req' Multi
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> RequesterData req' -> IntMap (RequesterData req')
forall a. Int -> a -> IntMap a
IntMap.singleton Int
0) (Event t (RequesterData req') -> Event t (Entry req' Multi))
-> Event t (RequesterData req') -> Event t (Entry req' Multi)
forall a b. (a -> b) -> a -> b
$ (RequesterData req -> RequesterData req')
-> Event t (RequesterData req) -> Event t (RequesterData req')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Identity (RequesterData req') -> RequesterData req'
forall a. Identity a -> a
runIdentity (Identity (RequesterData req') -> RequesterData req')
-> (RequesterData req -> Identity (RequesterData req'))
-> RequesterData req
-> RequesterData req'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. req a -> Identity (req' a))
-> RequesterData req -> Identity (RequesterData req')
forall (m :: * -> *) (request :: * -> *) (response :: * -> *).
Applicative m =>
(forall a. request a -> m (response a))
-> RequesterData request -> m (RequesterData response)
traverseRequesterData (req' a -> Identity (req' a)
forall a. a -> Identity a
Identity (req' a -> Identity (req' a))
-> (req a -> req' a) -> req a -> Identity (req' a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. req a -> req' a
forall x. req x -> req' x
freq)) Event t (RequesterData req)
req
  a -> RequesterT t req' rsp' m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a

instance (Reflex t, Monad m) => Requester t (RequesterT t request response m) where
  type Request (RequesterT t request response m) = request
  type Response (RequesterT t request response m) = response
  requesting :: Event t (Request (RequesterT t request response m) a)
-> RequesterT
     t
     request
     response
     m
     (Event t (Response (RequesterT t request response m) a))
requesting = (Event t (Entry response (Single a)) -> Event t (response a))
-> RequesterT
     t request response m (Event t (Entry response (Single a)))
-> RequesterT t request response m (Event t (response a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Event t (Entry response (Single a)) -> Event t (response a)
forall k (t :: k) a b.
(Reflex t, Coercible a b) =>
Event t a -> Event t b
coerceEvent (RequesterT
   t request response m (Event t (Entry response (Single a)))
 -> RequesterT t request response m (Event t (response a)))
-> (MyTagWrap request (Entry request (Single a))
    -> RequesterT
         t request response m (Event t (Entry response (Single a))))
-> MyTagWrap request (Entry request (Single a))
-> RequesterT t request response m (Event t (response a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MyTagWrap response (Entry response (Single a))
-> RequesterT
     t request response m (Event t (Entry response (Single a)))
forall (m :: * -> *) (response :: * -> *) x t (request :: * -> *).
Monad m =>
MyTagWrap response (Entry response x)
-> RequesterT t request response m (Event t (Entry response x))
responseFromTag (MyTagWrap response (Entry response (Single a))
 -> RequesterT
      t request response m (Event t (Entry response (Single a))))
-> (MyTagWrap request (Entry request (Single a))
    -> MyTagWrap response (Entry response (Single a)))
-> MyTagWrap request (Entry request (Single a))
-> RequesterT
     t request response m (Event t (Entry response (Single a)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MyTagWrap request (Entry request (Single a))
-> MyTagWrap response (Entry response (Single a))
forall (f :: * -> *) x (g :: * -> *).
MyTagWrap f (Entry f x) -> MyTagWrap g (Entry g x)
castMyTagWrap (MyTagWrap request (Entry request (Single a))
 -> RequesterT t request response m (Event t (response a)))
-> (Event t (request a)
    -> RequesterT
         t
         request
         response
         m
         (MyTagWrap request (Entry request (Single a))))
-> Event t (request a)
-> RequesterT t request response m (Event t (response a))
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Event t (Entry request (Single a))
-> RequesterT
     t request response m (MyTagWrap request (Entry request (Single a)))
forall (m :: * -> *) x t (request :: * -> *) (response :: * -> *).
(Monad m, MyTagTypeOffset x) =>
Event t (Entry request x)
-> RequesterT
     t request response m (MyTagWrap request (Entry request x))
tagRequest (Event t (Entry request (Single a))
 -> RequesterT
      t
      request
      response
      m
      (MyTagWrap request (Entry request (Single a))))
-> (Event t (request a) -> Event t (Entry request (Single a)))
-> Event t (request a)
-> RequesterT
     t request response m (MyTagWrap request (Entry request (Single a)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. Event t (request a) -> Event t (Entry request (Single a))
forall k (t :: k) a b.
(Reflex t, Coercible a b) =>
Event t a -> Event t b
coerceEvent :: Event t (request a) -> Event t (Entry request (Single a)))
  requesting_ :: Event t (Request (RequesterT t request response m) a)
-> RequesterT t request response m ()
requesting_ = RequesterT
  t request response m (MyTagWrap request (Entry request (Single a)))
-> RequesterT t request response m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (RequesterT
   t request response m (MyTagWrap request (Entry request (Single a)))
 -> RequesterT t request response m ())
-> (Event t (request a)
    -> RequesterT
         t
         request
         response
         m
         (MyTagWrap request (Entry request (Single a))))
-> Event t (request a)
-> RequesterT t request response m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Event t (Entry request (Single a))
-> RequesterT
     t request response m (MyTagWrap request (Entry request (Single a)))
forall (m :: * -> *) x t (request :: * -> *) (response :: * -> *).
(Monad m, MyTagTypeOffset x) =>
Event t (Entry request x)
-> RequesterT
     t request response m (MyTagWrap request (Entry request x))
tagRequest (Event t (Entry request (Single a))
 -> RequesterT
      t
      request
      response
      m
      (MyTagWrap request (Entry request (Single a))))
-> (Event t (request a) -> Event t (Entry request (Single a)))
-> Event t (request a)
-> RequesterT
     t request response m (MyTagWrap request (Entry request (Single a)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (request a -> Entry request (Single a))
-> Event t (request a) -> Event t (Entry request (Single a))
forall k (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap request a -> Entry request (Single a)
forall (f :: * -> *) a. f a -> Entry f (Single a)
singleEntry

{-# INLINE tagRequest #-}
tagRequest :: forall m x t request response. (Monad m, MyTagTypeOffset x) => Event t (Entry request x) -> RequesterT t request response m (MyTagWrap request (Entry request x))
tagRequest :: Event t (Entry request x)
-> RequesterT
     t request response m (MyTagWrap request (Entry request x))
tagRequest Event t (Entry request x)
req = do
  RequesterState t request
old <- StateT
  (RequesterState t request)
  (ReaderT (EventSelectorInt t Any) m)
  (RequesterState t request)
-> RequesterT t request response m (RequesterState t request)
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a.
StateT
  (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) a
-> RequesterT t request response m a
RequesterT StateT
  (RequesterState t request)
  (ReaderT (EventSelectorInt t Any) m)
  (RequesterState t request)
forall s (m :: * -> *). MonadState s m => m s
get
  let n :: Int
n = RequesterState t request -> Int
forall t (request :: * -> *). RequesterState t request -> Int
_requesterState_nextMyTag RequesterState t request
old Int -> Int -> Int
forall a. Bits a => a -> a -> a
.|. Proxy x -> Int
forall x (proxy :: * -> *). MyTagTypeOffset x => proxy x -> Int
myTagTypeOffset (Proxy x
forall k (t :: k). Proxy t
Proxy :: Proxy x)
      t :: MyTagWrap request (Entry request x)
t = Int -> MyTagWrap request (Entry request x)
forall (f :: * -> *) x. Int -> MyTagWrap f x
MyTagWrap Int
n
  StateT
  (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) ()
-> RequesterT t request response m ()
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a.
StateT
  (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) a
-> RequesterT t request response m a
RequesterT (StateT
   (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) ()
 -> RequesterT t request response m ())
-> StateT
     (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) ()
-> RequesterT t request response m ()
forall a b. (a -> b) -> a -> b
$ RequesterState t request
-> StateT
     (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put (RequesterState t request
 -> StateT
      (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) ())
-> RequesterState t request
-> StateT
     (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) ()
forall a b. (a -> b) -> a -> b
$ RequesterState :: forall t (request :: * -> *).
Int -> [(Int, Event t Any)] -> RequesterState t request
RequesterState
    { _requesterState_nextMyTag :: Int
_requesterState_nextMyTag = RequesterState t request -> Int
forall t (request :: * -> *). RequesterState t request -> Int
_requesterState_nextMyTag RequesterState t request
old Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
0x4
    , _requesterState_requests :: [(Int, Event t Any)]
_requesterState_requests = (Int
n, (Event t (Entry request x) -> Event t Any
forall a b. a -> b
unsafeCoerce :: Event t (Entry request x) -> Event t Any) Event t (Entry request x)
req) (Int, Event t Any) -> [(Int, Event t Any)] -> [(Int, Event t Any)]
forall a. a -> [a] -> [a]
: RequesterState t request -> [(Int, Event t Any)]
forall t (request :: * -> *).
RequesterState t request -> [(Int, Event t Any)]
_requesterState_requests RequesterState t request
old
    }
  MyTagWrap request (Entry request x)
-> RequesterT
     t request response m (MyTagWrap request (Entry request x))
forall (m :: * -> *) a. Monad m => a -> m a
return MyTagWrap request (Entry request x)
t

{-# INLINE responseFromTag #-}
responseFromTag :: Monad m => MyTagWrap response (Entry response x) -> RequesterT t request response m (Event t (Entry response x))
responseFromTag :: MyTagWrap response (Entry response x)
-> RequesterT t request response m (Event t (Entry response x))
responseFromTag (MyTagWrap Int
t) = do
  responses :: EventSelectorInt t Any <- StateT
  (RequesterState t request)
  (ReaderT (EventSelectorInt t Any) m)
  (EventSelectorInt t Any)
-> RequesterT t request response m (EventSelectorInt t Any)
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a.
StateT
  (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) a
-> RequesterT t request response m a
RequesterT StateT
  (RequesterState t request)
  (ReaderT (EventSelectorInt t Any) m)
  (EventSelectorInt t Any)
forall r (m :: * -> *). MonadReader r m => m r
ask
  Event t (Entry response x)
-> RequesterT t request response m (Event t (Entry response x))
forall (m :: * -> *) a. Monad m => a -> m a
return (Event t (Entry response x)
 -> RequesterT t request response m (Event t (Entry response x)))
-> Event t (Entry response x)
-> RequesterT t request response m (Event t (Entry response x))
forall a b. (a -> b) -> a -> b
$ (forall a b. a -> b
forall (response :: * -> *) x.
Event t Any -> Event t (Entry response x)
unsafeCoerce :: Event t Any -> Event t (Entry response x)) (Event t Any -> Event t (Entry response x))
-> Event t Any -> Event t (Entry response x)
forall a b. (a -> b) -> a -> b
$ EventSelectorInt t Any -> Int -> Event t Any
forall k (t :: k) a. EventSelectorInt t a -> Int -> Event t a
selectInt EventSelectorInt t Any
responses Int
t

instance MonadTrans (RequesterT t request response) where
  lift :: m a -> RequesterT t request response m a
lift = StateT
  (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) a
-> RequesterT t request response m a
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a.
StateT
  (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) a
-> RequesterT t request response m a
RequesterT (StateT
   (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) a
 -> RequesterT t request response m a)
-> (m a
    -> StateT
         (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) a)
-> m a
-> RequesterT t request response m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ReaderT (EventSelectorInt t Any) m a
-> StateT
     (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT (EventSelectorInt t Any) m a
 -> StateT
      (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) a)
-> (m a -> ReaderT (EventSelectorInt t Any) m a)
-> m a
-> StateT
     (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m a -> ReaderT (EventSelectorInt t Any) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift

instance MFunctor (RequesterT t request response) where
  hoist :: (forall a. m a -> n a)
-> RequesterT t request response m b
-> RequesterT t request response n b
hoist forall a. m a -> n a
f = StateT
  (RequesterState t request) (ReaderT (EventSelectorInt t Any) n) b
-> RequesterT t request response n b
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a.
StateT
  (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) a
-> RequesterT t request response m a
RequesterT (StateT
   (RequesterState t request) (ReaderT (EventSelectorInt t Any) n) b
 -> RequesterT t request response n b)
-> (RequesterT t request response m b
    -> StateT
         (RequesterState t request) (ReaderT (EventSelectorInt t Any) n) b)
-> RequesterT t request response m b
-> RequesterT t request response n b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a.
 ReaderT (EventSelectorInt t Any) m a
 -> ReaderT (EventSelectorInt t Any) n a)
-> StateT
     (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) b
-> StateT
     (RequesterState t request) (ReaderT (EventSelectorInt t Any) n) b
forall k (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
       (b :: k).
(MFunctor t, Monad m) =>
(forall a. m a -> n a) -> t m b -> t n b
hoist ((forall a. m a -> n a)
-> ReaderT (EventSelectorInt t Any) m a
-> ReaderT (EventSelectorInt t Any) n a
forall k (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
       (b :: k).
(MFunctor t, Monad m) =>
(forall a. m a -> n a) -> t m b -> t n b
hoist forall a. m a -> n a
f) (StateT
   (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) b
 -> StateT
      (RequesterState t request) (ReaderT (EventSelectorInt t Any) n) b)
-> (RequesterT t request response m b
    -> StateT
         (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) b)
-> RequesterT t request response m b
-> StateT
     (RequesterState t request) (ReaderT (EventSelectorInt t Any) n) b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RequesterT t request response m b
-> StateT
     (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) b
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a.
RequesterT t request response m a
-> StateT
     (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) a
unRequesterT

instance PerformEvent t m => PerformEvent t (RequesterT t request response m) where
  type Performable (RequesterT t request response m) = Performable m
  performEvent_ :: Event t (Performable (RequesterT t request response m) ())
-> RequesterT t request response m ()
performEvent_ = m () -> RequesterT t request response m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> RequesterT t request response m ())
-> (Event t (Performable m ()) -> m ())
-> Event t (Performable m ())
-> RequesterT t request response 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 (RequesterT t request response m) a)
-> RequesterT t request response m (Event t a)
performEvent = m (Event t a) -> RequesterT t request response m (Event t a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Event t a) -> RequesterT t request response m (Event t a))
-> (Event t (Performable m a) -> m (Event t a))
-> Event t (Performable m a)
-> RequesterT t request response 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 MonadRef m => MonadRef (RequesterT t request response m) where
  type Ref (RequesterT t request response m) = Ref m
  newRef :: a
-> RequesterT
     t request response m (Ref (RequesterT t request response m) a)
newRef = m (Ref m a) -> RequesterT t request response m (Ref m a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Ref m a) -> RequesterT t request response m (Ref m a))
-> (a -> m (Ref m a))
-> a
-> RequesterT t request response 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 (RequesterT t request response m) a
-> RequesterT t request response m a
readRef = m a -> RequesterT t request response m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> RequesterT t request response m a)
-> (Ref m a -> m a) -> Ref m a -> RequesterT t request response 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 (RequesterT t request response m) a
-> a -> RequesterT t request response m ()
writeRef Ref (RequesterT t request response m) a
r = m () -> RequesterT t request response m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> RequesterT t request response m ())
-> (a -> m ()) -> a -> RequesterT t request response 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 (RequesterT t request response m) a
r

instance MonadReflexCreateTrigger t m => MonadReflexCreateTrigger t (RequesterT t request response m) where
  newEventWithTrigger :: (EventTrigger t a -> IO (IO ()))
-> RequesterT t request response m (Event t a)
newEventWithTrigger = m (Event t a) -> RequesterT t request response m (Event t a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Event t a) -> RequesterT t request response m (Event t a))
-> ((EventTrigger t a -> IO (IO ())) -> m (Event t a))
-> (EventTrigger t a -> IO (IO ()))
-> RequesterT t request response 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 ()))
-> RequesterT t request response m (EventSelector t k)
newFanEventWithTrigger forall a. k a -> EventTrigger t a -> IO (IO ())
f = m (EventSelector t k)
-> RequesterT t request response m (EventSelector t k)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (EventSelector t k)
 -> RequesterT t request response m (EventSelector t k))
-> m (EventSelector t k)
-> RequesterT t request response 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 MonadReader r m => MonadReader r (RequesterT t request response m) where
  ask :: RequesterT t request response m r
ask = m r -> RequesterT t request response 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)
-> RequesterT t request response m a
-> RequesterT t request response m a
local r -> r
f (RequesterT StateT
  (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) a
a) = StateT
  (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) a
-> RequesterT t request response m a
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) a.
StateT
  (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) a
-> RequesterT t request response m a
RequesterT (StateT
   (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) a
 -> RequesterT t request response m a)
-> StateT
     (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) a
-> RequesterT t request response m a
forall a b. (a -> b) -> a -> b
$ (ReaderT (EventSelectorInt t Any) m (a, RequesterState t request)
 -> ReaderT
      (EventSelectorInt t Any) m (a, RequesterState t request))
-> StateT
     (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) a
-> StateT
     (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) a
forall (m :: * -> *) a s (n :: * -> *) b.
(m (a, s) -> n (b, s)) -> StateT s m a -> StateT s n b
mapStateT ((m (a, RequesterState t request)
 -> m (a, RequesterState t request))
-> ReaderT (EventSelectorInt t Any) m (a, RequesterState t request)
-> ReaderT (EventSelectorInt t Any) m (a, RequesterState t request)
forall (m :: * -> *) a (n :: * -> *) b r.
(m a -> n b) -> ReaderT r m a -> ReaderT r n b
mapReaderT ((m (a, RequesterState t request)
  -> m (a, RequesterState t request))
 -> ReaderT (EventSelectorInt t Any) m (a, RequesterState t request)
 -> ReaderT
      (EventSelectorInt t Any) m (a, RequesterState t request))
-> (m (a, RequesterState t request)
    -> m (a, RequesterState t request))
-> ReaderT (EventSelectorInt t Any) m (a, RequesterState t request)
-> ReaderT (EventSelectorInt t Any) m (a, RequesterState t request)
forall a b. (a -> b) -> a -> b
$ (r -> r)
-> m (a, RequesterState t request)
-> m (a, RequesterState t request)
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local r -> r
f) StateT
  (RequesterState t request) (ReaderT (EventSelectorInt t Any) m) a
a
  reader :: (r -> a) -> RequesterT t request response m a
reader = m a -> RequesterT t request response m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> RequesterT t request response m a)
-> ((r -> a) -> m a)
-> (r -> a)
-> RequesterT t request response 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 (Reflex t, Adjustable t m, MonadHold t m, MonadFix m) => Adjustable t (RequesterT t request response m) where
  runWithReplace :: RequesterT t request response m a
-> Event t (RequesterT t request response m b)
-> RequesterT t request response m (a, Event t b)
runWithReplace = (forall a' b'.
 m a'
 -> Event t (m b')
 -> RequesterT t request response m (a', Event t b'))
-> RequesterT t request response m a
-> Event t (RequesterT t request response m b)
-> RequesterT t request response m (a, Event t b)
forall (m :: * -> *) t (request :: * -> *) (response :: * -> *) a
       b.
(Reflex t, MonadHold t m, MonadFix m) =>
(forall a' b'.
 m a'
 -> Event t (m b')
 -> RequesterT t request response m (a', Event t b'))
-> RequesterT t request response m a
-> Event t (RequesterT t request response m b)
-> RequesterT t request response m (a, Event t b)
runWithReplaceRequesterTWith ((forall a' b'.
  m a'
  -> Event t (m b')
  -> RequesterT t request response m (a', Event t b'))
 -> RequesterT t request response m a
 -> Event t (RequesterT t request response m b)
 -> RequesterT t request response m (a, Event t b))
-> (forall a' b'.
    m a'
    -> Event t (m b')
    -> RequesterT t request response m (a', Event t b'))
-> RequesterT t request response m a
-> Event t (RequesterT t request response m b)
-> RequesterT t request response 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')
-> RequesterT t request response m (a', Event t b')
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (a', Event t b')
 -> RequesterT t request response m (a', Event t b'))
-> m (a', Event t b')
-> RequesterT t request response 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 -> RequesterT t request response m v')
-> IntMap v
-> Event t (PatchIntMap v)
-> RequesterT
     t request response m (IntMap v', Event t (PatchIntMap v'))
traverseIntMapWithKeyWithAdjust = ((Int
  -> (Int, v) -> m (Event t (IntMap (RequesterData request)), v'))
 -> IntMap (Int, v)
 -> Event t (PatchIntMap (Int, v))
 -> RequesterT
      t
      request
      response
      m
      (IntMap (Event t (IntMap (RequesterData request)), v'),
       Event
         t (PatchIntMap (Event t (IntMap (RequesterData request)), v'))))
-> (PatchIntMap (Event t (IntMap (RequesterData request)))
    -> IntMap (Event t (IntMap (RequesterData request))))
-> (Incremental
      t (PatchIntMap (Event t (IntMap (RequesterData request))))
    -> Event t (IntMap (IntMap (RequesterData request))))
-> (Int -> v -> RequesterT t request response m v')
-> IntMap v
-> Event t (PatchIntMap v)
-> RequesterT
     t request response m (IntMap v', Event t (PatchIntMap v'))
forall t (request :: * -> *) (response :: * -> *) (m :: * -> *) v
       v' (p :: * -> *).
(Reflex t, MonadHold t m,
 PatchTarget (p (Event t (IntMap (RequesterData request))))
 ~ IntMap (Event t (IntMap (RequesterData request))),
 Patch (p (Event t (IntMap (RequesterData request)))), Functor p,
 MonadFix m) =>
((Int
  -> (Int, v) -> m (Event t (IntMap (RequesterData request)), v'))
 -> IntMap (Int, v)
 -> Event t (p (Int, v))
 -> RequesterT
      t
      request
      response
      m
      (IntMap (Event t (IntMap (RequesterData request)), v'),
       Event t (p (Event t (IntMap (RequesterData request)), v'))))
-> (p (Event t (IntMap (RequesterData request)))
    -> IntMap (Event t (IntMap (RequesterData request))))
-> (Incremental t (p (Event t (IntMap (RequesterData request))))
    -> Event t (IntMap (IntMap (RequesterData request))))
-> (Int -> v -> RequesterT t request response m v')
-> IntMap v
-> Event t (p v)
-> RequesterT t request response m (IntMap v', Event t (p v'))
traverseIntMapWithKeyWithAdjustRequesterTWith (\Int -> (Int, v) -> m (Event t (IntMap (RequesterData request)), v')
f IntMap (Int, v)
dm0 Event t (PatchIntMap (Int, v))
dm' -> m (IntMap (Event t (IntMap (RequesterData request)), v'),
   Event
     t (PatchIntMap (Event t (IntMap (RequesterData request)), v')))
-> RequesterT
     t
     request
     response
     m
     (IntMap (Event t (IntMap (RequesterData request)), v'),
      Event
        t (PatchIntMap (Event t (IntMap (RequesterData request)), v')))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (IntMap (Event t (IntMap (RequesterData request)), v'),
    Event
      t (PatchIntMap (Event t (IntMap (RequesterData request)), v')))
 -> RequesterT
      t
      request
      response
      m
      (IntMap (Event t (IntMap (RequesterData request)), v'),
       Event
         t (PatchIntMap (Event t (IntMap (RequesterData request)), v'))))
-> m (IntMap (Event t (IntMap (RequesterData request)), v'),
      Event
        t (PatchIntMap (Event t (IntMap (RequesterData request)), v')))
-> RequesterT
     t
     request
     response
     m
     (IntMap (Event t (IntMap (RequesterData request)), v'),
      Event
        t (PatchIntMap (Event t (IntMap (RequesterData request)), v')))
forall a b. (a -> b) -> a -> b
$ (Int
 -> (Int, v) -> m (Event t (IntMap (RequesterData request)), v'))
-> IntMap (Int, v)
-> Event t (PatchIntMap (Int, v))
-> m (IntMap (Event t (IntMap (RequesterData request)), v'),
      Event
        t (PatchIntMap (Event t (IntMap (RequesterData request)), 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 -> (Int, v) -> m (Event t (IntMap (RequesterData request)), v')
f IntMap (Int, v)
dm0 Event t (PatchIntMap (Int, v))
dm') PatchIntMap (Event t (IntMap (RequesterData request)))
-> IntMap (Event t (IntMap (RequesterData request)))
forall a. PatchIntMap a -> IntMap a
patchIntMapNewElementsMap Incremental
  t (PatchIntMap (Event t (IntMap (RequesterData request))))
-> Event t (IntMap (IntMap (RequesterData request)))
forall k (t :: k) a.
Reflex t =>
Incremental t (PatchIntMap (Event t a)) -> Event t (IntMap a)
mergeIntIncremental
  {-# INLINABLE traverseDMapWithKeyWithAdjust #-}
  traverseDMapWithKeyWithAdjust :: (forall a. k a -> v a -> RequesterT t request response m (v' a))
-> DMap k v
-> Event t (PatchDMap k v)
-> RequesterT
     t request response m (DMap k v', Event t (PatchDMap k v'))
traverseDMapWithKeyWithAdjust = (forall (k' :: * -> *) (v1 :: * -> *) (v2 :: * -> *).
 GCompare k' =>
 (forall a. k' a -> v1 a -> m (v2 a))
 -> DMap k' v1
 -> Event t (PatchDMap k' v1)
 -> RequesterT
      t request response m (DMap k' v2, Event t (PatchDMap k' v2)))
-> (forall (v1 :: * -> *) (v2 :: * -> *).
    (forall a. v1 a -> v2 a) -> PatchDMap k v1 -> PatchDMap k v2)
-> (forall (v1 :: * -> *) v2.
    (forall a. v1 a -> v2) -> PatchDMap k v1 -> PatchMap (Some k) v2)
-> (forall v2. PatchMap (Some k) v2 -> Map (Some k) v2)
-> (forall a.
    Incremental t (PatchMap (Some k) (Event t a))
    -> Event t (Map (Some k) a))
-> (forall a. k a -> v a -> RequesterT t request response m (v' a))
-> DMap k v
-> Event t (PatchDMap k v)
-> RequesterT
     t request response m (DMap k v', Event t (PatchDMap k v'))
forall (k :: * -> *) t (request :: * -> *) (response :: * -> *)
       (m :: * -> *) (v :: * -> *) (v' :: * -> *)
       (p :: (* -> *) -> (* -> *) -> *) (p' :: * -> * -> *).
(GCompare k, Reflex t, MonadHold t m,
 PatchTarget
   (p' (Some k) (Event t (IntMap (RequesterData request))))
 ~ Map (Some k) (Event t (IntMap (RequesterData request))),
 Patch (p' (Some k) (Event t (IntMap (RequesterData request)))),
 MonadFix m) =>
(forall (k' :: * -> *) (v1 :: * -> *) (v2 :: * -> *).
 GCompare k' =>
 (forall a. k' a -> v1 a -> m (v2 a))
 -> DMap k' v1
 -> Event t (p k' v1)
 -> RequesterT t request response m (DMap k' v2, Event t (p k' v2)))
-> (forall (v1 :: * -> *) (v2 :: * -> *).
    (forall a. v1 a -> v2 a) -> p k v1 -> p k v2)
-> (forall (v1 :: * -> *) v2.
    (forall a. v1 a -> v2) -> p k v1 -> p' (Some k) v2)
-> (forall v2. p' (Some k) v2 -> Map (Some k) v2)
-> (forall a.
    Incremental t (p' (Some k) (Event t a))
    -> Event t (Map (Some k) a))
-> (forall a. k a -> v a -> RequesterT t request response m (v' a))
-> DMap k v
-> Event t (p k v)
-> RequesterT t request response m (DMap k v', Event t (p k v'))
traverseDMapWithKeyWithAdjustRequesterTWith (\forall a. k' a -> v1 a -> m (v2 a)
f DMap k' v1
dm0 Event t (PatchDMap k' v1)
dm' -> m (DMap k' v2, Event t (PatchDMap k' v2))
-> RequesterT
     t request response m (DMap k' v2, Event t (PatchDMap k' v2))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (DMap k' v2, Event t (PatchDMap k' v2))
 -> RequesterT
      t request response m (DMap k' v2, Event t (PatchDMap k' v2)))
-> m (DMap k' v2, Event t (PatchDMap k' v2))
-> RequesterT
     t request response m (DMap k' v2, Event t (PatchDMap k' v2))
forall a b. (a -> b) -> a -> b
$ (forall a. k' a -> v1 a -> m (v2 a))
-> DMap k' v1
-> Event t (PatchDMap k' v1)
-> m (DMap k' v2, Event t (PatchDMap k' v2))
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 -> v1 a -> m (v2 a)
f DMap k' v1
dm0 Event t (PatchDMap k' v1)
dm') forall k1 (v :: k1 -> *) (v' :: k1 -> *) (k2 :: k1 -> *).
(forall (a :: k1). v a -> v' a)
-> PatchDMap k2 v -> PatchDMap k2 v'
forall (v1 :: * -> *) (v2 :: * -> *).
(forall a. v1 a -> v2 a) -> PatchDMap k v1 -> PatchDMap k v2
mapPatchDMap forall k1 (v :: k1 -> *) v' (k2 :: k1 -> *).
(forall (a :: k1). v a -> v')
-> PatchDMap k2 v -> PatchMap (Some k2) v'
forall (v1 :: * -> *) v2.
(forall a. v1 a -> v2) -> PatchDMap k v1 -> PatchMap (Some k) v2
weakenPatchDMapWith forall v2. PatchMap (Some k) v2 -> Map (Some k) v2
forall k v. PatchMap k v -> Map k v
patchMapNewElementsMap forall a.
Incremental t (PatchMap (Some k) (Event t a))
-> Event t (Map (Some k) a)
forall k1 (t :: k1) k2 a.
(Reflex t, Ord k2) =>
Incremental t (PatchMap k2 (Event t a)) -> Event t (Map k2 a)
mergeMapIncremental
  traverseDMapWithKeyWithAdjustWithMove :: (forall a. k a -> v a -> RequesterT t request response m (v' a))
-> DMap k v
-> Event t (PatchDMapWithMove k v)
-> RequesterT
     t request response m (DMap k v', Event t (PatchDMapWithMove k v'))
traverseDMapWithKeyWithAdjustWithMove = (forall (k' :: * -> *) (v1 :: * -> *) (v2 :: * -> *).
 GCompare k' =>
 (forall a. k' a -> v1 a -> m (v2 a))
 -> DMap k' v1
 -> Event t (PatchDMapWithMove k' v1)
 -> RequesterT
      t
      request
      response
      m
      (DMap k' v2, Event t (PatchDMapWithMove k' v2)))
-> (forall (v1 :: * -> *) (v2 :: * -> *).
    (forall a. v1 a -> v2 a)
    -> PatchDMapWithMove k v1 -> PatchDMapWithMove k v2)
-> (forall (v1 :: * -> *) v2.
    (forall a. v1 a -> v2)
    -> PatchDMapWithMove k v1 -> PatchMapWithMove (Some k) v2)
-> (forall v2. PatchMapWithMove (Some k) v2 -> Map (Some k) v2)
-> (forall a.
    Incremental t (PatchMapWithMove (Some k) (Event t a))
    -> Event t (Map (Some k) a))
-> (forall a. k a -> v a -> RequesterT t request response m (v' a))
-> DMap k v
-> Event t (PatchDMapWithMove k v)
-> RequesterT
     t request response m (DMap k v', Event t (PatchDMapWithMove k v'))
forall (k :: * -> *) t (request :: * -> *) (response :: * -> *)
       (m :: * -> *) (v :: * -> *) (v' :: * -> *)
       (p :: (* -> *) -> (* -> *) -> *) (p' :: * -> * -> *).
(GCompare k, Reflex t, MonadHold t m,
 PatchTarget
   (p' (Some k) (Event t (IntMap (RequesterData request))))
 ~ Map (Some k) (Event t (IntMap (RequesterData request))),
 Patch (p' (Some k) (Event t (IntMap (RequesterData request)))),
 MonadFix m) =>
(forall (k' :: * -> *) (v1 :: * -> *) (v2 :: * -> *).
 GCompare k' =>
 (forall a. k' a -> v1 a -> m (v2 a))
 -> DMap k' v1
 -> Event t (p k' v1)
 -> RequesterT t request response m (DMap k' v2, Event t (p k' v2)))
-> (forall (v1 :: * -> *) (v2 :: * -> *).
    (forall a. v1 a -> v2 a) -> p k v1 -> p k v2)
-> (forall (v1 :: * -> *) v2.
    (forall a. v1 a -> v2) -> p k v1 -> p' (Some k) v2)
-> (forall v2. p' (Some k) v2 -> Map (Some k) v2)
-> (forall a.
    Incremental t (p' (Some k) (Event t a))
    -> Event t (Map (Some k) a))
-> (forall a. k a -> v a -> RequesterT t request response m (v' a))
-> DMap k v
-> Event t (p k v)
-> RequesterT t request response m (DMap k v', Event t (p k v'))
traverseDMapWithKeyWithAdjustRequesterTWith (\forall a. k' a -> v1 a -> m (v2 a)
f DMap k' v1
dm0 Event t (PatchDMapWithMove k' v1)
dm' -> m (DMap k' v2, Event t (PatchDMapWithMove k' v2))
-> RequesterT
     t
     request
     response
     m
     (DMap k' v2, Event t (PatchDMapWithMove k' v2))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (DMap k' v2, Event t (PatchDMapWithMove k' v2))
 -> RequesterT
      t
      request
      response
      m
      (DMap k' v2, Event t (PatchDMapWithMove k' v2)))
-> m (DMap k' v2, Event t (PatchDMapWithMove k' v2))
-> RequesterT
     t
     request
     response
     m
     (DMap k' v2, Event t (PatchDMapWithMove k' v2))
forall a b. (a -> b) -> a -> b
$ (forall a. k' a -> v1 a -> m (v2 a))
-> DMap k' v1
-> Event t (PatchDMapWithMove k' v1)
-> m (DMap k' v2, Event t (PatchDMapWithMove k' v2))
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 -> v1 a -> m (v2 a)
f DMap k' v1
dm0 Event t (PatchDMapWithMove k' v1)
dm') forall k1 (k2 :: k1 -> *) (v :: k1 -> *) (v' :: k1 -> *).
(forall (a :: k1). v a -> v' a)
-> PatchDMapWithMove k2 v -> PatchDMapWithMove k2 v'
forall (v1 :: * -> *) (v2 :: * -> *).
(forall a. v1 a -> v2 a)
-> PatchDMapWithMove k v1 -> PatchDMapWithMove k v2
mapPatchDMapWithMove forall k1 (k2 :: k1 -> *) (v :: k1 -> *) v'.
(forall (a :: k1). v a -> v')
-> PatchDMapWithMove k2 v -> PatchMapWithMove (Some k2) v'
forall (v1 :: * -> *) v2.
(forall a. v1 a -> v2)
-> PatchDMapWithMove k v1 -> PatchMapWithMove (Some k) v2
weakenPatchDMapWithMoveWith forall v2. PatchMapWithMove (Some k) v2 -> Map (Some k) v2
forall k v. PatchMapWithMove k v -> Map k v
patchMapWithMoveNewElementsMap forall a.
Incremental t (PatchMapWithMove (Some k) (Event t a))
-> Event t (Map (Some k) a)
forall k1 (t :: k1) k2 a.
(Reflex t, Ord k2) =>
Incremental t (PatchMapWithMove k2 (Event t a))
-> Event t (Map k2 a)
mergeMapIncrementalWithMove

requesting' :: (MyTagTypeOffset x, Monad m) => Event t (Entry request x) -> RequesterT t request response m (Event t (Entry response x))
requesting' :: Event t (Entry request x)
-> RequesterT t request response m (Event t (Entry response x))
requesting' = MyTagWrap response (Entry response x)
-> RequesterT t request response m (Event t (Entry response x))
forall (m :: * -> *) (response :: * -> *) x t (request :: * -> *).
Monad m =>
MyTagWrap response (Entry response x)
-> RequesterT t request response m (Event t (Entry response x))
responseFromTag (MyTagWrap response (Entry response x)
 -> RequesterT t request response m (Event t (Entry response x)))
-> (MyTagWrap request (Entry request x)
    -> MyTagWrap response (Entry response x))
-> MyTagWrap request (Entry request x)
-> RequesterT t request response m (Event t (Entry response x))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MyTagWrap request (Entry request x)
-> MyTagWrap response (Entry response x)
forall (f :: * -> *) x (g :: * -> *).
MyTagWrap f (Entry f x) -> MyTagWrap g (Entry g x)
castMyTagWrap (MyTagWrap request (Entry request x)
 -> RequesterT t request response m (Event t (Entry response x)))
-> (Event t (Entry request x)
    -> RequesterT
         t request response m (MyTagWrap request (Entry request x)))
-> Event t (Entry request x)
-> RequesterT t request response m (Event t (Entry response x))
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Event t (Entry request x)
-> RequesterT
     t request response m (MyTagWrap request (Entry request x))
forall (m :: * -> *) x t (request :: * -> *) (response :: * -> *).
(Monad m, MyTagTypeOffset x) =>
Event t (Entry request x)
-> RequesterT
     t request response m (MyTagWrap request (Entry request x))
tagRequest

{-# INLINABLE runWithReplaceRequesterTWith #-}
runWithReplaceRequesterTWith :: forall m t request response a b. (Reflex t, MonadHold t m
                                                                 , MonadFix m
                                                                 )
                             => (forall a' b'. m a' -> Event t (m b') -> RequesterT t request response m (a', Event t b'))
                             -> RequesterT t request response m a
                             -> Event t (RequesterT t request response m b)
                             -> RequesterT t request response m (a, Event t b)
runWithReplaceRequesterTWith :: (forall a' b'.
 m a'
 -> Event t (m b')
 -> RequesterT t request response m (a', Event t b'))
-> RequesterT t request response m a
-> Event t (RequesterT t request response m b)
-> RequesterT t request response m (a, Event t b)
runWithReplaceRequesterTWith forall a' b'.
m a'
-> Event t (m b')
-> RequesterT t request response m (a', Event t b')
f RequesterT t request response m a
a0 Event t (RequesterT t request response m b)
a' = do
  rec Event t (Int, RequesterT t request response m b)
na' <- Int
-> Event t (RequesterT t request response m b)
-> RequesterT
     t
     request
     response
     m
     (Event t (Int, RequesterT t request response m b))
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 Int
1 Event t (RequesterT t request response m b)
a'
      Event t (IntMap (RequesterData response))
responses <- (Event t (Entry response Multi)
 -> Event t (IntMap (RequesterData response)))
-> RequesterT t request response m (Event t (Entry response Multi))
-> RequesterT
     t request response m (Event t (IntMap (RequesterData response)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Entry response Multi -> IntMap (RequesterData response))
-> Event t (Entry response Multi)
-> Event t (IntMap (RequesterData response))
forall k (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap Entry response Multi -> IntMap (RequesterData response)
forall (f :: * -> *). Entry f Multi -> IntMap (RequesterData f)
unMultiEntry) (RequesterT t request response m (Event t (Entry response Multi))
 -> RequesterT
      t request response m (Event t (IntMap (RequesterData response))))
-> RequesterT t request response m (Event t (Entry response Multi))
-> RequesterT
     t request response m (Event t (IntMap (RequesterData response)))
forall a b. (a -> b) -> a -> b
$ Event t (Entry request Multi)
-> RequesterT t request response m (Event t (Entry response Multi))
forall x (m :: * -> *) t (request :: * -> *) (response :: * -> *).
(MyTagTypeOffset x, Monad m) =>
Event t (Entry request x)
-> RequesterT t request response m (Event t (Entry response x))
requesting' (Event t (Entry request Multi)
 -> RequesterT
      t request response m (Event t (Entry response Multi)))
-> Event t (Entry request Multi)
-> RequesterT t request response m (Event t (Entry response Multi))
forall a b. (a -> b) -> a -> b
$ (IntMap (RequesterData request) -> Entry request Multi)
-> Event t (IntMap (RequesterData request))
-> Event t (Entry request Multi)
forall k (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap IntMap (RequesterData request) -> Entry request Multi
forall (f :: * -> *). IntMap (RequesterData f) -> Entry f Multi
multiEntry (Event t (IntMap (RequesterData request))
 -> Event t (Entry request Multi))
-> Event t (IntMap (RequesterData request))
-> Event t (Entry request Multi)
forall a b. (a -> b) -> a -> b
$ Dynamic t (Event t (IntMap (RequesterData request)))
-> Event t (IntMap (RequesterData request))
forall k (t :: k) a. Reflex t => Dynamic t (Event t a) -> Event t a
switchPromptlyDyn Dynamic t (Event t (IntMap (RequesterData request)))
requests --TODO: Investigate whether we can really get rid of the prompt stuff here
      let responses' :: EventSelectorInt t (RequesterData response)
responses' = Event t (IntMap (RequesterData response))
-> EventSelectorInt t (RequesterData response)
forall k (t :: k) a.
Reflex t =>
Event t (IntMap a) -> EventSelectorInt t a
fanInt Event t (IntMap (RequesterData response))
responses
      ((a
result0, Event t (RequesterData request)
requests0), Event t (Int, (b, Event t (RequesterData request)))
v') <- m (a, Event t (RequesterData request))
-> Event t (m (Int, (b, Event t (RequesterData request))))
-> RequesterT
     t
     request
     response
     m
     ((a, Event t (RequesterData request)),
      Event t (Int, (b, Event t (RequesterData request))))
forall a' b'.
m a'
-> Event t (m b')
-> RequesterT t request response m (a', Event t b')
f (RequesterT t request response m a
-> Event t (RequesterData response)
-> m (a, Event t (RequesterData request))
forall t (m :: * -> *) (request :: * -> *) (response :: * -> *) a.
(Reflex t, Monad m) =>
RequesterT t request response m a
-> Event t (RequesterData response)
-> m (a, Event t (RequesterData request))
runRequesterT RequesterT t request response m a
a0 (EventSelectorInt t (RequesterData response)
-> Int -> Event t (RequesterData response)
forall k (t :: k) a. EventSelectorInt t a -> Int -> Event t a
selectInt EventSelectorInt t (RequesterData response)
responses' Int
0)) (Event t (m (Int, (b, Event t (RequesterData request))))
 -> RequesterT
      t
      request
      response
      m
      ((a, Event t (RequesterData request)),
       Event t (Int, (b, Event t (RequesterData request)))))
-> Event t (m (Int, (b, Event t (RequesterData request))))
-> RequesterT
     t
     request
     response
     m
     ((a, Event t (RequesterData request)),
      Event t (Int, (b, Event t (RequesterData request))))
forall a b. (a -> b) -> a -> b
$ ((Int, RequesterT t request response m b)
 -> m (Int, (b, Event t (RequesterData request))))
-> Event t (Int, RequesterT t request response m b)
-> Event t (m (Int, (b, Event t (RequesterData request))))
forall k (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap (\(Int
n, RequesterT t request response m b
a) -> ((b, Event t (RequesterData request))
 -> (Int, (b, Event t (RequesterData request))))
-> m (b, Event t (RequesterData request))
-> m (Int, (b, Event t (RequesterData request)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((,) Int
n) (m (b, Event t (RequesterData request))
 -> m (Int, (b, Event t (RequesterData request))))
-> m (b, Event t (RequesterData request))
-> m (Int, (b, Event t (RequesterData request)))
forall a b. (a -> b) -> a -> b
$ RequesterT t request response m b
-> Event t (RequesterData response)
-> m (b, Event t (RequesterData request))
forall t (m :: * -> *) (request :: * -> *) (response :: * -> *) a.
(Reflex t, Monad m) =>
RequesterT t request response m a
-> Event t (RequesterData response)
-> m (a, Event t (RequesterData request))
runRequesterT RequesterT t request response m b
a (Event t (RequesterData response)
 -> m (b, Event t (RequesterData request)))
-> Event t (RequesterData response)
-> m (b, Event t (RequesterData request))
forall a b. (a -> b) -> a -> b
$ EventSelectorInt t (RequesterData response)
-> Int -> Event t (RequesterData response)
forall k (t :: k) a. EventSelectorInt t a -> Int -> Event t a
selectInt EventSelectorInt t (RequesterData response)
responses' Int
n) Event t (Int, RequesterT t request response m b)
na'
      Dynamic t (Event t (IntMap (RequesterData request)))
requests <- Event t (IntMap (RequesterData request))
-> Event t (Event t (IntMap (RequesterData request)))
-> RequesterT
     t
     request
     response
     m
     (Dynamic t (Event t (IntMap (RequesterData request))))
forall k (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Dynamic t a)
holdDyn ((RequesterData request -> IntMap (RequesterData request))
-> Event t (RequesterData request)
-> Event t (IntMap (RequesterData request))
forall k (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap (Int -> RequesterData request -> IntMap (RequesterData request)
forall a. Int -> a -> IntMap a
IntMap.singleton Int
0) Event t (RequesterData request)
requests0) (Event t (Event t (IntMap (RequesterData request)))
 -> RequesterT
      t
      request
      response
      m
      (Dynamic t (Event t (IntMap (RequesterData request)))))
-> Event t (Event t (IntMap (RequesterData request)))
-> RequesterT
     t
     request
     response
     m
     (Dynamic t (Event t (IntMap (RequesterData request))))
forall a b. (a -> b) -> a -> b
$ ((Int, (b, Event t (RequesterData request)))
 -> Event t (IntMap (RequesterData request)))
-> Event t (Int, (b, Event t (RequesterData request)))
-> Event t (Event t (IntMap (RequesterData request)))
forall k (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap (\(Int
n, (b
_, Event t (RequesterData request)
reqs)) -> (RequesterData request -> IntMap (RequesterData request))
-> Event t (RequesterData request)
-> Event t (IntMap (RequesterData request))
forall k (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap (Int -> RequesterData request -> IntMap (RequesterData request)
forall a. Int -> a -> IntMap a
IntMap.singleton Int
n) Event t (RequesterData request)
reqs) Event t (Int, (b, Event t (RequesterData request)))
v'
  (a, Event t b) -> RequesterT t request response m (a, Event t b)
forall (m :: * -> *) a. Monad m => a -> m a
return (a
result0, ((Int, (b, Event t (RequesterData request))) -> b)
-> Event t (Int, (b, Event t (RequesterData request))) -> Event t b
forall k (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap ((b, Event t (RequesterData request)) -> b
forall a b. (a, b) -> a
fst ((b, Event t (RequesterData request)) -> b)
-> ((Int, (b, Event t (RequesterData request)))
    -> (b, Event t (RequesterData request)))
-> (Int, (b, Event t (RequesterData request)))
-> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int, (b, Event t (RequesterData request)))
-> (b, Event t (RequesterData request))
forall a b. (a, b) -> b
snd) Event t (Int, (b, Event t (RequesterData request)))
v')

{-# INLINE traverseIntMapWithKeyWithAdjustRequesterTWith #-}
traverseIntMapWithKeyWithAdjustRequesterTWith :: forall t request response m v v' p.
                                        ( Reflex t
                                        , MonadHold t m
                                        , PatchTarget (p (Event t (IntMap (RequesterData request)))) ~ IntMap (Event t (IntMap (RequesterData request)))
                                        , Patch (p (Event t (IntMap (RequesterData request))))
                                        , Functor p
                                        , MonadFix m
                                        )
                                     => (   (IntMap.Key -> (IntMap.Key, v) -> m (Event t (IntMap (RequesterData request)), v'))
                                         -> IntMap (IntMap.Key, v)
                                         -> Event t (p (IntMap.Key, v))
                                         -> RequesterT t request response m (IntMap (Event t (IntMap (RequesterData request)), v'), Event t (p (Event t (IntMap (RequesterData request)), v')))
                                        )
                                     -> (p (Event t (IntMap (RequesterData request))) -> IntMap (Event t (IntMap (RequesterData request))))
                                     -> (Incremental t (p (Event t (IntMap (RequesterData request)))) -> Event t (IntMap (IntMap (RequesterData request))))
                                     -> (IntMap.Key -> v -> RequesterT t request response m v')
                                     -> IntMap v
                                     -> Event t (p v)
                                     -> RequesterT t request response m (IntMap v', Event t (p v'))
traverseIntMapWithKeyWithAdjustRequesterTWith :: ((Int
  -> (Int, v) -> m (Event t (IntMap (RequesterData request)), v'))
 -> IntMap (Int, v)
 -> Event t (p (Int, v))
 -> RequesterT
      t
      request
      response
      m
      (IntMap (Event t (IntMap (RequesterData request)), v'),
       Event t (p (Event t (IntMap (RequesterData request)), v'))))
-> (p (Event t (IntMap (RequesterData request)))
    -> IntMap (Event t (IntMap (RequesterData request))))
-> (Incremental t (p (Event t (IntMap (RequesterData request))))
    -> Event t (IntMap (IntMap (RequesterData request))))
-> (Int -> v -> RequesterT t request response m v')
-> IntMap v
-> Event t (p v)
-> RequesterT t request response m (IntMap v', Event t (p v'))
traverseIntMapWithKeyWithAdjustRequesterTWith (Int
 -> (Int, v) -> m (Event t (IntMap (RequesterData request)), v'))
-> IntMap (Int, v)
-> Event t (p (Int, v))
-> RequesterT
     t
     request
     response
     m
     (IntMap (Event t (IntMap (RequesterData request)), v'),
      Event t (p (Event t (IntMap (RequesterData request)), v')))
base p (Event t (IntMap (RequesterData request)))
-> IntMap (Event t (IntMap (RequesterData request)))
patchNewElements Incremental t (p (Event t (IntMap (RequesterData request))))
-> Event t (IntMap (IntMap (RequesterData request)))
mergePatchIncremental Int -> v -> RequesterT t request response m v'
f IntMap v
dm0 Event t (p v)
dm' = do
  rec Event t (Entry response Multi3)
response <- Event t (Entry request Multi3)
-> RequesterT
     t request response m (Event t (Entry response Multi3))
forall x (m :: * -> *) t (request :: * -> *) (response :: * -> *).
(MyTagTypeOffset x, Monad m) =>
Event t (Entry request x)
-> RequesterT t request response m (Event t (Entry response x))
requesting' (Event t (Entry request Multi3)
 -> RequesterT
      t request response m (Event t (Entry response Multi3)))
-> Event t (Entry request Multi3)
-> RequesterT
     t request response m (Event t (Entry response Multi3))
forall a b. (a -> b) -> a -> b
$ (IntMap (IntMap (RequesterData request)) -> Entry request Multi3)
-> Event t (IntMap (IntMap (RequesterData request)))
-> Event t (Entry request Multi3)
forall k (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap IntMap (IntMap (RequesterData request)) -> Entry request Multi3
pack (Event t (IntMap (IntMap (RequesterData request)))
 -> Event t (Entry request Multi3))
-> Event t (IntMap (IntMap (RequesterData request)))
-> Event t (Entry request Multi3)
forall a b. (a -> b) -> a -> b
$ Event t (IntMap (IntMap (RequesterData request)))
promptRequests Event t (IntMap (IntMap (RequesterData request)))
-> Event t (IntMap (IntMap (RequesterData request)))
-> Event t (IntMap (IntMap (RequesterData request)))
forall a. Monoid a => a -> a -> a
`mappend` Incremental t (p (Event t (IntMap (RequesterData request))))
-> Event t (IntMap (IntMap (RequesterData request)))
mergePatchIncremental Incremental t (p (Event t (IntMap (RequesterData request))))
requests --TODO: Investigate whether we can really get rid of the prompt stuff here
      let responses :: EventSelectorInt t (IntMap (RequesterData response))
          responses :: EventSelectorInt t (IntMap (RequesterData response))
responses = Event t (IntMap (IntMap (RequesterData response)))
-> EventSelectorInt t (IntMap (RequesterData response))
forall k (t :: k) a.
Reflex t =>
Event t (IntMap a) -> EventSelectorInt t a
fanInt (Event t (IntMap (IntMap (RequesterData response)))
 -> EventSelectorInt t (IntMap (RequesterData response)))
-> Event t (IntMap (IntMap (RequesterData response)))
-> EventSelectorInt t (IntMap (RequesterData response))
forall a b. (a -> b) -> a -> b
$ (Entry response Multi3 -> IntMap (IntMap (RequesterData response)))
-> Event t (Entry response Multi3)
-> Event t (IntMap (IntMap (RequesterData response)))
forall k (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap Entry response Multi3 -> IntMap (IntMap (RequesterData response))
unpack Event t (Entry response Multi3)
response
          unpack :: Entry response Multi3 -> IntMap (IntMap (RequesterData response))
          unpack :: Entry response Multi3 -> IntMap (IntMap (RequesterData response))
unpack = Entry response Multi3 -> IntMap (IntMap (RequesterData response))
forall (request :: * -> *) x.
Entry request x -> EntryContents request x
unEntry
          pack :: IntMap (IntMap (RequesterData request)) -> Entry request Multi3
          pack :: IntMap (IntMap (RequesterData request)) -> Entry request Multi3
pack = IntMap (IntMap (RequesterData request)) -> Entry request Multi3
forall (request :: * -> *) x.
EntryContents request x -> Entry request x
Entry
          f' :: IntMap.Key -> (Int, v) -> m (Event t (IntMap (RequesterData request)), v')
          f' :: Int -> (Int, v) -> m (Event t (IntMap (RequesterData request)), v')
f' Int
k (Int
n, v
v) = do
            (v'
result, Event t (RequesterData request)
myRequests) <- RequesterT t request response m v'
-> Event t (RequesterData response)
-> m (v', Event t (RequesterData request))
forall t (m :: * -> *) (request :: * -> *) (response :: * -> *) a.
(Reflex t, Monad m) =>
RequesterT t request response m a
-> Event t (RequesterData response)
-> m (a, Event t (RequesterData request))
runRequesterT (Int -> v -> RequesterT t request response m v'
f Int
k v
v) (Event t (RequesterData response)
 -> m (v', Event t (RequesterData request)))
-> Event t (RequesterData response)
-> m (v', Event t (RequesterData request))
forall a b. (a -> b) -> a -> b
$ (IntMap (RequesterData response) -> Maybe (RequesterData response))
-> Event t (IntMap (RequesterData response))
-> Event t (RequesterData response)
forall k (t :: k) a b.
Reflex t =>
(a -> Maybe b) -> Event t a -> Event t b
mapMaybeCheap (Int
-> IntMap (RequesterData response)
-> Maybe (RequesterData response)
forall a. Int -> IntMap a -> Maybe a
IntMap.lookup Int
n) (Event t (IntMap (RequesterData response))
 -> Event t (RequesterData response))
-> Event t (IntMap (RequesterData response))
-> Event t (RequesterData response)
forall a b. (a -> b) -> a -> b
$ EventSelectorInt t (IntMap (RequesterData response))
-> Int -> Event t (IntMap (RequesterData response))
forall k (t :: k) a. EventSelectorInt t a -> Int -> Event t a
selectInt EventSelectorInt t (IntMap (RequesterData response))
responses Int
k --TODO: Instead of doing mapMaybeCheap, can we share a fanInt across all instances of a given key, or at least the ones that are adjacent in time?
            (Event t (IntMap (RequesterData request)), v')
-> m (Event t (IntMap (RequesterData request)), v')
forall (m :: * -> *) a. Monad m => a -> m a
return ((RequesterData request -> IntMap (RequesterData request))
-> Event t (RequesterData request)
-> Event t (IntMap (RequesterData request))
forall k (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap (Int -> RequesterData request -> IntMap (RequesterData request)
forall a. Int -> a -> IntMap a
IntMap.singleton Int
n) Event t (RequesterData request)
myRequests, v'
result)
      Event t (Int, p v)
ndm' <- Int
-> Event t (p v)
-> RequesterT t request response m (Event t (Int, 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 Int
1 Event t (p v)
dm'
      (IntMap (Event t (IntMap (RequesterData request)), v')
children0, Event t (p (Event t (IntMap (RequesterData request)), v'))
children') <- (Int
 -> (Int, v) -> m (Event t (IntMap (RequesterData request)), v'))
-> IntMap (Int, v)
-> Event t (p (Int, v))
-> RequesterT
     t
     request
     response
     m
     (IntMap (Event t (IntMap (RequesterData request)), v'),
      Event t (p (Event t (IntMap (RequesterData request)), v')))
base Int -> (Int, v) -> m (Event t (IntMap (RequesterData request)), v')
f' ((v -> (Int, v)) -> IntMap v -> IntMap (Int, v)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((,) Int
0) IntMap v
dm0) (Event t (p (Int, v))
 -> RequesterT
      t
      request
      response
      m
      (IntMap (Event t (IntMap (RequesterData request)), v'),
       Event t (p (Event t (IntMap (RequesterData request)), v'))))
-> Event t (p (Int, v))
-> RequesterT
     t
     request
     response
     m
     (IntMap (Event t (IntMap (RequesterData request)), v'),
      Event t (p (Event t (IntMap (RequesterData request)), v')))
forall a b. (a -> b) -> a -> b
$ ((Int, p v) -> p (Int, v))
-> Event t (Int, p v) -> Event t (p (Int, v))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(Int
n, p v
dm) -> (v -> (Int, v)) -> p v -> p (Int, v)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((,) Int
n) p v
dm) Event t (Int, p v)
ndm' --TODO: Avoid this somehow, probably by adding some sort of per-cohort information passing to Adjustable
      let result0 :: IntMap v'
result0 = ((Event t (IntMap (RequesterData request)), v') -> v')
-> IntMap (Event t (IntMap (RequesterData request)), v')
-> IntMap v'
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Event t (IntMap (RequesterData request)), v') -> v'
forall a b. (a, b) -> b
snd IntMap (Event t (IntMap (RequesterData request)), v')
children0
          result' :: Event t (p v')
result' = Event t (p (Event t (IntMap (RequesterData request)), v'))
-> (p (Event t (IntMap (RequesterData request)), v') -> p v')
-> Event t (p v')
forall k (t :: k) a b.
Reflex t =>
Event t a -> (a -> b) -> Event t b
fforCheap Event t (p (Event t (IntMap (RequesterData request)), v'))
children' ((p (Event t (IntMap (RequesterData request)), v') -> p v')
 -> Event t (p v'))
-> (p (Event t (IntMap (RequesterData request)), v') -> p v')
-> Event t (p v')
forall a b. (a -> b) -> a -> b
$ ((Event t (IntMap (RequesterData request)), v') -> v')
-> p (Event t (IntMap (RequesterData request)), v') -> p v'
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Event t (IntMap (RequesterData request)), v') -> v'
forall a b. (a, b) -> b
snd
          requests0 :: IntMap (Event t (IntMap (RequesterData request)))
          requests0 :: IntMap (Event t (IntMap (RequesterData request)))
requests0 = ((Event t (IntMap (RequesterData request)), v')
 -> Event t (IntMap (RequesterData request)))
-> IntMap (Event t (IntMap (RequesterData request)), v')
-> IntMap (Event t (IntMap (RequesterData request)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Event t (IntMap (RequesterData request)), v')
-> Event t (IntMap (RequesterData request))
forall a b. (a, b) -> a
fst IntMap (Event t (IntMap (RequesterData request)), v')
children0
          requests' :: Event t (p (Event t (IntMap (RequesterData request))))
          requests' :: Event t (p (Event t (IntMap (RequesterData request))))
requests' = Event t (p (Event t (IntMap (RequesterData request)), v'))
-> (p (Event t (IntMap (RequesterData request)), v')
    -> p (Event t (IntMap (RequesterData request))))
-> Event t (p (Event t (IntMap (RequesterData request))))
forall k (t :: k) a b.
Reflex t =>
Event t a -> (a -> b) -> Event t b
fforCheap Event t (p (Event t (IntMap (RequesterData request)), v'))
children' ((p (Event t (IntMap (RequesterData request)), v')
  -> p (Event t (IntMap (RequesterData request))))
 -> Event t (p (Event t (IntMap (RequesterData request)))))
-> (p (Event t (IntMap (RequesterData request)), v')
    -> p (Event t (IntMap (RequesterData request))))
-> Event t (p (Event t (IntMap (RequesterData request))))
forall a b. (a -> b) -> a -> b
$ ((Event t (IntMap (RequesterData request)), v')
 -> Event t (IntMap (RequesterData request)))
-> p (Event t (IntMap (RequesterData request)), v')
-> p (Event t (IntMap (RequesterData request)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Event t (IntMap (RequesterData request)), v')
-> Event t (IntMap (RequesterData request))
forall a b. (a, b) -> a
fst
          promptRequests :: Event t (IntMap (IntMap (RequesterData request)))
          promptRequests :: Event t (IntMap (IntMap (RequesterData request)))
promptRequests = Event t (Event t (IntMap (IntMap (RequesterData request))))
-> Event t (IntMap (IntMap (RequesterData request)))
forall k (t :: k) a. Reflex t => Event t (Event t a) -> Event t a
coincidence (Event t (Event t (IntMap (IntMap (RequesterData request))))
 -> Event t (IntMap (IntMap (RequesterData request))))
-> Event t (Event t (IntMap (IntMap (RequesterData request))))
-> Event t (IntMap (IntMap (RequesterData request)))
forall a b. (a -> b) -> a -> b
$ (p (Event t (IntMap (RequesterData request)))
 -> Event t (IntMap (IntMap (RequesterData request))))
-> Event t (p (Event t (IntMap (RequesterData request))))
-> Event t (Event t (IntMap (IntMap (RequesterData request))))
forall k (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap (IntMap (Event t (IntMap (RequesterData request)))
-> Event t (IntMap (IntMap (RequesterData request)))
forall k (t :: k) a.
Reflex t =>
IntMap (Event t a) -> Event t (IntMap a)
mergeInt (IntMap (Event t (IntMap (RequesterData request)))
 -> Event t (IntMap (IntMap (RequesterData request))))
-> (p (Event t (IntMap (RequesterData request)))
    -> IntMap (Event t (IntMap (RequesterData request))))
-> p (Event t (IntMap (RequesterData request)))
-> Event t (IntMap (IntMap (RequesterData request)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p (Event t (IntMap (RequesterData request)))
-> IntMap (Event t (IntMap (RequesterData request)))
patchNewElements) Event t (p (Event t (IntMap (RequesterData request))))
requests' --TODO: Create a mergeIncrementalPromptly, and use that to eliminate this 'coincidence'
      Incremental t (p (Event t (IntMap (RequesterData request))))
requests <- PatchTarget (p (Event t (IntMap (RequesterData request))))
-> Event t (p (Event t (IntMap (RequesterData request))))
-> RequesterT
     t
     request
     response
     m
     (Incremental t (p (Event t (IntMap (RequesterData request)))))
forall k (t :: k) (m :: * -> *) p.
(MonadHold t m, Patch p) =>
PatchTarget p -> Event t p -> m (Incremental t p)
holdIncremental IntMap (Event t (IntMap (RequesterData request)))
PatchTarget (p (Event t (IntMap (RequesterData request))))
requests0 Event t (p (Event t (IntMap (RequesterData request))))
requests'
  (IntMap v', Event t (p v'))
-> RequesterT t request response m (IntMap v', Event t (p v'))
forall (m :: * -> *) a. Monad m => a -> m a
return (IntMap v'
result0, Event t (p v')
result')

{-# INLINE traverseDMapWithKeyWithAdjustRequesterTWith #-}
traverseDMapWithKeyWithAdjustRequesterTWith :: forall k t request response m v v' p p'.
                                        ( GCompare k
                                        , Reflex t
                                        , MonadHold t m
                                        , PatchTarget (p' (Some k) (Event t (IntMap (RequesterData request)))) ~ Map (Some k) (Event t (IntMap (RequesterData request)))
                                        , Patch (p' (Some k) (Event t (IntMap (RequesterData request))))
                                        , MonadFix m
                                        )
                                     => (forall k' v1 v2. GCompare k'
                                         => (forall a. k' a -> v1 a -> m (v2 a))
                                         -> DMap k' v1
                                         -> Event t (p k' v1)
                                         -> RequesterT t request response m (DMap k' v2, Event t (p k' v2))
                                        )
                                     -> (forall v1 v2. (forall a. v1 a -> v2 a) -> p k v1 -> p k v2)
                                     -> (forall v1 v2. (forall a. v1 a -> v2) -> p k v1 -> p' (Some k) v2)
                                     -> (forall v2. p' (Some k) v2 -> Map (Some k) v2)
                                     -> (forall a. Incremental t (p' (Some k) (Event t a)) -> Event t (Map (Some k) a))
                                     -> (forall a. k a -> v a -> RequesterT t request response m (v' a))
                                     -> DMap k v
                                     -> Event t (p k v)
                                     -> RequesterT t request response m (DMap k v', Event t (p k v'))
traverseDMapWithKeyWithAdjustRequesterTWith :: (forall (k' :: * -> *) (v1 :: * -> *) (v2 :: * -> *).
 GCompare k' =>
 (forall a. k' a -> v1 a -> m (v2 a))
 -> DMap k' v1
 -> Event t (p k' v1)
 -> RequesterT t request response m (DMap k' v2, Event t (p k' v2)))
-> (forall (v1 :: * -> *) (v2 :: * -> *).
    (forall a. v1 a -> v2 a) -> p k v1 -> p k v2)
-> (forall (v1 :: * -> *) v2.
    (forall a. v1 a -> v2) -> p k v1 -> p' (Some k) v2)
-> (forall v2. p' (Some k) v2 -> Map (Some k) v2)
-> (forall a.
    Incremental t (p' (Some k) (Event t a))
    -> Event t (Map (Some k) a))
-> (forall a. k a -> v a -> RequesterT t request response m (v' a))
-> DMap k v
-> Event t (p k v)
-> RequesterT t request response m (DMap k v', Event t (p k v'))
traverseDMapWithKeyWithAdjustRequesterTWith forall (k' :: * -> *) (v1 :: * -> *) (v2 :: * -> *).
GCompare k' =>
(forall a. k' a -> v1 a -> m (v2 a))
-> DMap k' v1
-> Event t (p k' v1)
-> RequesterT t request response m (DMap k' v2, Event t (p k' v2))
base forall (v1 :: * -> *) (v2 :: * -> *).
(forall a. v1 a -> v2 a) -> p k v1 -> p k v2
mapPatch forall (v1 :: * -> *) v2.
(forall a. v1 a -> v2) -> p k v1 -> p' (Some k) v2
weakenPatchWith forall v2. p' (Some k) v2 -> Map (Some k) v2
patchNewElements forall a.
Incremental t (p' (Some k) (Event t a)) -> Event t (Map (Some k) a)
mergePatchIncremental forall a. k a -> v a -> RequesterT t request response m (v' a)
f DMap k v
dm0 Event t (p k v)
dm' = do
  rec Event t (Entry response (Multi2 k))
response <- Event t (Entry request (Multi2 k))
-> RequesterT
     t request response m (Event t (Entry response (Multi2 k)))
forall x (m :: * -> *) t (request :: * -> *) (response :: * -> *).
(MyTagTypeOffset x, Monad m) =>
Event t (Entry request x)
-> RequesterT t request response m (Event t (Entry response x))
requesting' (Event t (Entry request (Multi2 k))
 -> RequesterT
      t request response m (Event t (Entry response (Multi2 k))))
-> Event t (Entry request (Multi2 k))
-> RequesterT
     t request response m (Event t (Entry response (Multi2 k)))
forall a b. (a -> b) -> a -> b
$ (Map (Some k) (IntMap (RequesterData request))
 -> Entry request (Multi2 k))
-> Event t (Map (Some k) (IntMap (RequesterData request)))
-> Event t (Entry request (Multi2 k))
forall k (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap Map (Some k) (IntMap (RequesterData request))
-> Entry request (Multi2 k)
pack (Event t (Map (Some k) (IntMap (RequesterData request)))
 -> Event t (Entry request (Multi2 k)))
-> Event t (Map (Some k) (IntMap (RequesterData request)))
-> Event t (Entry request (Multi2 k))
forall a b. (a -> b) -> a -> b
$ Event t (Map (Some k) (IntMap (RequesterData request)))
promptRequests Event t (Map (Some k) (IntMap (RequesterData request)))
-> Event t (Map (Some k) (IntMap (RequesterData request)))
-> Event t (Map (Some k) (IntMap (RequesterData request)))
forall a. Monoid a => a -> a -> a
`mappend` Incremental
  t (p' (Some k) (Event t (IntMap (RequesterData request))))
-> Event t (Map (Some k) (IntMap (RequesterData request)))
forall a.
Incremental t (p' (Some k) (Event t a)) -> Event t (Map (Some k) a)
mergePatchIncremental Incremental
  t (p' (Some k) (Event t (IntMap (RequesterData request))))
requests --TODO: Investigate whether we can really get rid of the prompt stuff here
      let responses :: EventSelector t (Const2 (Some k) (IntMap (RequesterData response)))
          responses :: EventSelector t (Const2 (Some k) (IntMap (RequesterData response)))
responses = Event t (Map (Some k) (IntMap (RequesterData response)))
-> EventSelector
     t (Const2 (Some k) (IntMap (RequesterData response)))
forall k1 (t :: k1) k2 a.
(Reflex t, Ord k2) =>
Event t (Map k2 a) -> EventSelector t (Const2 k2 a)
fanMap (Event t (Map (Some k) (IntMap (RequesterData response)))
 -> EventSelector
      t (Const2 (Some k) (IntMap (RequesterData response))))
-> Event t (Map (Some k) (IntMap (RequesterData response)))
-> EventSelector
     t (Const2 (Some k) (IntMap (RequesterData response)))
forall a b. (a -> b) -> a -> b
$ (Entry response (Multi2 k)
 -> Map (Some k) (IntMap (RequesterData response)))
-> Event t (Entry response (Multi2 k))
-> Event t (Map (Some k) (IntMap (RequesterData response)))
forall k (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap Entry response (Multi2 k)
-> Map (Some k) (IntMap (RequesterData response))
unpack Event t (Entry response (Multi2 k))
response
          unpack :: Entry response (Multi2 k) -> Map (Some k) (IntMap (RequesterData response))
          unpack :: Entry response (Multi2 k)
-> Map (Some k) (IntMap (RequesterData response))
unpack = Entry response (Multi2 k)
-> Map (Some k) (IntMap (RequesterData response))
forall (request :: * -> *) x.
Entry request x -> EntryContents request x
unEntry
          pack :: Map (Some k) (IntMap (RequesterData request)) -> Entry request (Multi2 k)
          pack :: Map (Some k) (IntMap (RequesterData request))
-> Entry request (Multi2 k)
pack = Map (Some k) (IntMap (RequesterData request))
-> Entry request (Multi2 k)
forall (request :: * -> *) x.
EntryContents request x -> Entry request x
Entry
          f' :: forall a. k a -> Compose ((,) Int) v a -> m (Compose ((,) (Event t (IntMap (RequesterData request)))) v' a)
          f' :: k a
-> Compose ((,) Int) v a
-> m (Compose
        ((,) (Event t (IntMap (RequesterData request)))) v' a)
f' k a
k (Compose (Int
n, v a
v)) = do
            (v' a
result, Event t (RequesterData request)
myRequests) <- RequesterT t request response m (v' a)
-> Event t (RequesterData response)
-> m (v' a, Event t (RequesterData request))
forall t (m :: * -> *) (request :: * -> *) (response :: * -> *) a.
(Reflex t, Monad m) =>
RequesterT t request response m a
-> Event t (RequesterData response)
-> m (a, Event t (RequesterData request))
runRequesterT (k a -> v a -> RequesterT t request response m (v' a)
forall a. k a -> v a -> RequesterT t request response m (v' a)
f k a
k v a
v) (Event t (RequesterData response)
 -> m (v' a, Event t (RequesterData request)))
-> Event t (RequesterData response)
-> m (v' a, Event t (RequesterData request))
forall a b. (a -> b) -> a -> b
$ (IntMap (RequesterData response) -> Maybe (RequesterData response))
-> Event t (IntMap (RequesterData response))
-> Event t (RequesterData response)
forall k (t :: k) a b.
Reflex t =>
(a -> Maybe b) -> Event t a -> Event t b
mapMaybeCheap (Int
-> IntMap (RequesterData response)
-> Maybe (RequesterData response)
forall a. Int -> IntMap a -> Maybe a
IntMap.lookup Int
n) (Event t (IntMap (RequesterData response))
 -> Event t (RequesterData response))
-> Event t (IntMap (RequesterData response))
-> Event t (RequesterData response)
forall a b. (a -> b) -> a -> b
$ EventSelector t (Const2 (Some k) (IntMap (RequesterData response)))
-> Const2
     (Some k)
     (IntMap (RequesterData response))
     (IntMap (RequesterData response))
-> Event t (IntMap (RequesterData response))
forall k1 (t :: k1) (k2 :: * -> *).
EventSelector t k2 -> forall a. k2 a -> Event t a
select EventSelector t (Const2 (Some k) (IntMap (RequesterData response)))
responses (Some k
-> Const2
     (Some k)
     (IntMap (RequesterData response))
     (IntMap (RequesterData response))
forall x a (b :: x). a -> Const2 a b b
Const2 (k a -> Some k
forall k (tag :: k -> *) (a :: k). tag a -> Some tag
Some k a
k))
            Compose ((,) (Event t (IntMap (RequesterData request)))) v' a
-> m (Compose
        ((,) (Event t (IntMap (RequesterData request)))) v' a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Compose ((,) (Event t (IntMap (RequesterData request)))) v' a
 -> m (Compose
         ((,) (Event t (IntMap (RequesterData request)))) v' a))
-> Compose ((,) (Event t (IntMap (RequesterData request)))) v' a
-> m (Compose
        ((,) (Event t (IntMap (RequesterData request)))) v' a)
forall a b. (a -> b) -> a -> b
$ (Event t (IntMap (RequesterData request)), v' a)
-> Compose ((,) (Event t (IntMap (RequesterData request)))) v' a
forall k k1 (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose ((RequesterData request -> IntMap (RequesterData request))
-> Event t (RequesterData request)
-> Event t (IntMap (RequesterData request))
forall k (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap (Int -> RequesterData request -> IntMap (RequesterData request)
forall a. Int -> a -> IntMap a
IntMap.singleton Int
n) Event t (RequesterData request)
myRequests, v' a
result)
      Event t (Int, p k v)
ndm' <- Int
-> Event t (p k v)
-> RequesterT t request response m (Event t (Int, p k 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 Int
1 Event t (p k v)
dm'
      (DMap
  k (Compose ((,) (Event t (IntMap (RequesterData request)))) v')
children0, Event
  t
  (p k (Compose ((,) (Event t (IntMap (RequesterData request)))) v'))
children') <- (forall a.
 k a
 -> Compose ((,) Int) v a
 -> m (Compose
         ((,) (Event t (IntMap (RequesterData request)))) v' a))
-> DMap k (Compose ((,) Int) v)
-> Event t (p k (Compose ((,) Int) v))
-> RequesterT
     t
     request
     response
     m
     (DMap
        k (Compose ((,) (Event t (IntMap (RequesterData request)))) v'),
      Event
        t
        (p k
           (Compose ((,) (Event t (IntMap (RequesterData request)))) v')))
forall (k' :: * -> *) (v1 :: * -> *) (v2 :: * -> *).
GCompare k' =>
(forall a. k' a -> v1 a -> m (v2 a))
-> DMap k' v1
-> Event t (p k' v1)
-> RequesterT t request response m (DMap k' v2, Event t (p k' v2))
base forall a.
k a
-> Compose ((,) Int) v a
-> m (Compose
        ((,) (Event t (IntMap (RequesterData request)))) v' a)
f' ((forall v. v v -> Compose ((,) Int) v v)
-> DMap k v -> DMap k (Compose ((,) Int) v)
forall k1 (f :: k1 -> *) (g :: k1 -> *) (k2 :: k1 -> *).
(forall (v :: k1). f v -> g v) -> DMap k2 f -> DMap k2 g
DMap.map (\v v
v -> (Int, v v) -> Compose ((,) Int) v v
forall k k1 (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose (Int
0, v v
v)) DMap k v
dm0) (Event t (p k (Compose ((,) Int) v))
 -> RequesterT
      t
      request
      response
      m
      (DMap
         k (Compose ((,) (Event t (IntMap (RequesterData request)))) v'),
       Event
         t
         (p k
            (Compose ((,) (Event t (IntMap (RequesterData request)))) v'))))
-> Event t (p k (Compose ((,) Int) v))
-> RequesterT
     t
     request
     response
     m
     (DMap
        k (Compose ((,) (Event t (IntMap (RequesterData request)))) v'),
      Event
        t
        (p k
           (Compose ((,) (Event t (IntMap (RequesterData request)))) v')))
forall a b. (a -> b) -> a -> b
$ ((Int, p k v) -> p k (Compose ((,) Int) v))
-> Event t (Int, p k v) -> Event t (p k (Compose ((,) Int) v))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(Int
n, p k v
dm) -> (forall v. v v -> Compose ((,) Int) v v)
-> p k v -> p k (Compose ((,) Int) v)
forall (v1 :: * -> *) (v2 :: * -> *).
(forall a. v1 a -> v2 a) -> p k v1 -> p k v2
mapPatch (\v a
v -> (Int, v a) -> Compose ((,) Int) v a
forall k k1 (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose (Int
n, v a
v)) p k v
dm) Event t (Int, p k v)
ndm'
      let result0 :: DMap k v'
result0 = (forall v.
 Compose ((,) (Event t (IntMap (RequesterData request)))) v' v
 -> v' v)
-> DMap
     k (Compose ((,) (Event t (IntMap (RequesterData request)))) 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 (IntMap (RequesterData request)), v' v) -> v' v
forall a b. (a, b) -> b
snd ((Event t (IntMap (RequesterData request)), v' v) -> v' v)
-> (Compose ((,) (Event t (IntMap (RequesterData request)))) v' v
    -> (Event t (IntMap (RequesterData request)), v' v))
-> Compose ((,) (Event t (IntMap (RequesterData request)))) v' v
-> v' v
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Compose ((,) (Event t (IntMap (RequesterData request)))) v' v
-> (Event t (IntMap (RequesterData request)), 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 (IntMap (RequesterData request)))) v')
children0
          result' :: Event t (p k v')
result' = Event
  t
  (p k (Compose ((,) (Event t (IntMap (RequesterData request)))) v'))
-> (p k
      (Compose ((,) (Event t (IntMap (RequesterData request)))) 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 (IntMap (RequesterData request)))) v'))
children' ((p k (Compose ((,) (Event t (IntMap (RequesterData request)))) v')
  -> p k v')
 -> Event t (p k v'))
-> (p k
      (Compose ((,) (Event t (IntMap (RequesterData request)))) v')
    -> p k v')
-> Event t (p k v')
forall a b. (a -> b) -> a -> b
$ (forall v.
 Compose ((,) (Event t (IntMap (RequesterData request)))) v' v
 -> v' v)
-> p k
     (Compose ((,) (Event t (IntMap (RequesterData request)))) v')
-> p k v'
forall (v1 :: * -> *) (v2 :: * -> *).
(forall a. v1 a -> v2 a) -> p k v1 -> p k v2
mapPatch ((forall v.
  Compose ((,) (Event t (IntMap (RequesterData request)))) v' v
  -> v' v)
 -> p k
      (Compose ((,) (Event t (IntMap (RequesterData request)))) v')
 -> p k v')
-> (forall v.
    Compose ((,) (Event t (IntMap (RequesterData request)))) v' v
    -> v' v)
-> p k
     (Compose ((,) (Event t (IntMap (RequesterData request)))) v')
-> p k v'
forall a b. (a -> b) -> a -> b
$ (Event t (IntMap (RequesterData request)), v' a) -> v' a
forall a b. (a, b) -> b
snd ((Event t (IntMap (RequesterData request)), v' a) -> v' a)
-> (Compose ((,) (Event t (IntMap (RequesterData request)))) v' a
    -> (Event t (IntMap (RequesterData request)), v' a))
-> Compose ((,) (Event t (IntMap (RequesterData request)))) v' a
-> v' a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Compose ((,) (Event t (IntMap (RequesterData request)))) v' a
-> (Event t (IntMap (RequesterData request)), 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 (IntMap (RequesterData request)))
          requests0 :: Map (Some k) (Event t (IntMap (RequesterData request)))
requests0 = (forall a.
 Compose ((,) (Event t (IntMap (RequesterData request)))) v' a
 -> Event t (IntMap (RequesterData request)))
-> DMap
     k (Compose ((,) (Event t (IntMap (RequesterData request)))) v')
-> Map (Some k) (Event t (IntMap (RequesterData request)))
forall k1 (v :: k1 -> *) v' (k2 :: k1 -> *).
(forall (a :: k1). v a -> v') -> DMap k2 v -> Map (Some k2) v'
weakenDMapWith ((Event t (IntMap (RequesterData request)), v' a)
-> Event t (IntMap (RequesterData request))
forall a b. (a, b) -> a
fst ((Event t (IntMap (RequesterData request)), v' a)
 -> Event t (IntMap (RequesterData request)))
-> (Compose ((,) (Event t (IntMap (RequesterData request)))) v' a
    -> (Event t (IntMap (RequesterData request)), v' a))
-> Compose ((,) (Event t (IntMap (RequesterData request)))) v' a
-> Event t (IntMap (RequesterData request))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Compose ((,) (Event t (IntMap (RequesterData request)))) v' a
-> (Event t (IntMap (RequesterData request)), 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 (IntMap (RequesterData request)))) v')
children0
          requests' :: Event t (p' (Some k) (Event t (IntMap (RequesterData request))))
          requests' :: Event t (p' (Some k) (Event t (IntMap (RequesterData request))))
requests' = Event
  t
  (p k (Compose ((,) (Event t (IntMap (RequesterData request)))) v'))
-> (p k
      (Compose ((,) (Event t (IntMap (RequesterData request)))) v')
    -> p' (Some k) (Event t (IntMap (RequesterData request))))
-> Event t (p' (Some k) (Event t (IntMap (RequesterData request))))
forall k (t :: k) a b.
Reflex t =>
Event t a -> (a -> b) -> Event t b
fforCheap Event
  t
  (p k (Compose ((,) (Event t (IntMap (RequesterData request)))) v'))
children' ((p k (Compose ((,) (Event t (IntMap (RequesterData request)))) v')
  -> p' (Some k) (Event t (IntMap (RequesterData request))))
 -> Event
      t (p' (Some k) (Event t (IntMap (RequesterData request)))))
-> (p k
      (Compose ((,) (Event t (IntMap (RequesterData request)))) v')
    -> p' (Some k) (Event t (IntMap (RequesterData request))))
-> Event t (p' (Some k) (Event t (IntMap (RequesterData request))))
forall a b. (a -> b) -> a -> b
$ (forall a.
 Compose ((,) (Event t (IntMap (RequesterData request)))) v' a
 -> Event t (IntMap (RequesterData request)))
-> p k
     (Compose ((,) (Event t (IntMap (RequesterData request)))) v')
-> p' (Some k) (Event t (IntMap (RequesterData request)))
forall (v1 :: * -> *) v2.
(forall a. v1 a -> v2) -> p k v1 -> p' (Some k) v2
weakenPatchWith ((forall a.
  Compose ((,) (Event t (IntMap (RequesterData request)))) v' a
  -> Event t (IntMap (RequesterData request)))
 -> p k
      (Compose ((,) (Event t (IntMap (RequesterData request)))) v')
 -> p' (Some k) (Event t (IntMap (RequesterData request))))
-> (forall a.
    Compose ((,) (Event t (IntMap (RequesterData request)))) v' a
    -> Event t (IntMap (RequesterData request)))
-> p k
     (Compose ((,) (Event t (IntMap (RequesterData request)))) v')
-> p' (Some k) (Event t (IntMap (RequesterData request)))
forall a b. (a -> b) -> a -> b
$ (Event t (IntMap (RequesterData request)), v' a)
-> Event t (IntMap (RequesterData request))
forall a b. (a, b) -> a
fst ((Event t (IntMap (RequesterData request)), v' a)
 -> Event t (IntMap (RequesterData request)))
-> (Compose ((,) (Event t (IntMap (RequesterData request)))) v' a
    -> (Event t (IntMap (RequesterData request)), v' a))
-> Compose ((,) (Event t (IntMap (RequesterData request)))) v' a
-> Event t (IntMap (RequesterData request))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Compose ((,) (Event t (IntMap (RequesterData request)))) v' a
-> (Event t (IntMap (RequesterData request)), v' a)
forall k1 (f :: k1 -> *) k2 (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose
          promptRequests :: Event t (Map (Some k) (IntMap (RequesterData request)))
          promptRequests :: Event t (Map (Some k) (IntMap (RequesterData request)))
promptRequests = Event t (Event t (Map (Some k) (IntMap (RequesterData request))))
-> Event t (Map (Some k) (IntMap (RequesterData request)))
forall k (t :: k) a. Reflex t => Event t (Event t a) -> Event t a
coincidence (Event t (Event t (Map (Some k) (IntMap (RequesterData request))))
 -> Event t (Map (Some k) (IntMap (RequesterData request))))
-> Event
     t (Event t (Map (Some k) (IntMap (RequesterData request))))
-> Event t (Map (Some k) (IntMap (RequesterData request)))
forall a b. (a -> b) -> a -> b
$ (p' (Some k) (Event t (IntMap (RequesterData request)))
 -> Event t (Map (Some k) (IntMap (RequesterData request))))
-> Event t (p' (Some k) (Event t (IntMap (RequesterData request))))
-> Event
     t (Event t (Map (Some k) (IntMap (RequesterData request))))
forall k (t :: k) a b.
Reflex t =>
(a -> b) -> Event t a -> Event t b
fmapCheap (Map (Some k) (Event t (IntMap (RequesterData request)))
-> Event t (Map (Some k) (IntMap (RequesterData request)))
forall k1 (t :: k1) k2 a.
(Reflex t, Ord k2) =>
Map k2 (Event t a) -> Event t (Map k2 a)
mergeMap (Map (Some k) (Event t (IntMap (RequesterData request)))
 -> Event t (Map (Some k) (IntMap (RequesterData request))))
-> (p' (Some k) (Event t (IntMap (RequesterData request)))
    -> Map (Some k) (Event t (IntMap (RequesterData request))))
-> p' (Some k) (Event t (IntMap (RequesterData request)))
-> Event t (Map (Some k) (IntMap (RequesterData request)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p' (Some k) (Event t (IntMap (RequesterData request)))
-> Map (Some k) (Event t (IntMap (RequesterData request)))
forall v2. p' (Some k) v2 -> Map (Some k) v2
patchNewElements) Event t (p' (Some k) (Event t (IntMap (RequesterData request))))
requests' --TODO: Create a mergeIncrementalPromptly, and use that to eliminate this 'coincidence'
      Incremental
  t (p' (Some k) (Event t (IntMap (RequesterData request))))
requests <- PatchTarget
  (p' (Some k) (Event t (IntMap (RequesterData request))))
-> Event t (p' (Some k) (Event t (IntMap (RequesterData request))))
-> RequesterT
     t
     request
     response
     m
     (Incremental
        t (p' (Some k) (Event t (IntMap (RequesterData request)))))
forall k (t :: k) (m :: * -> *) p.
(MonadHold t m, Patch p) =>
PatchTarget p -> Event t p -> m (Incremental t p)
holdIncremental Map (Some k) (Event t (IntMap (RequesterData request)))
PatchTarget
  (p' (Some k) (Event t (IntMap (RequesterData request))))
requests0 Event t (p' (Some k) (Event t (IntMap (RequesterData request))))
requests'
  (DMap k v', Event t (p k v'))
-> RequesterT t request response 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')

data Decoder rawResponse response =
  forall a. Decoder (RequesterDataKey a) (rawResponse -> response a)

-- | Matches incoming responses with previously-sent requests
-- and uses the provided request "decoder" function to process
-- incoming responses.
matchResponsesWithRequests
  :: forall t rawRequest rawResponse request response m.
     ( MonadFix m
     , MonadHold t m
     , Reflex t
     )
  => (forall a. request a -> (rawRequest, rawResponse -> response a))
  -- ^ Given a request (from 'Requester'), produces the wire format of the
  -- request and a function used to process the associated response
  -> Event t (RequesterData request)
  -- ^ The outgoing requests
  -> Event t (Int, rawResponse)
  -- ^ The incoming responses, tagged by an identifying key
  -> m ( Event t (Map Int rawRequest)
       , Event t (RequesterData response)
       )
  -- ^ A map of outgoing wire-format requests and an event of responses keyed
  -- by the 'RequesterData' key of the associated outgoing request
matchResponsesWithRequests :: (forall a. request a -> (rawRequest, rawResponse -> response a))
-> Event t (RequesterData request)
-> Event t (Int, rawResponse)
-> m (Event t (Map Int rawRequest),
      Event t (RequesterData response))
matchResponsesWithRequests forall a. request a -> (rawRequest, rawResponse -> response a)
f Event t (RequesterData request)
send Event t (Int, rawResponse)
recv = do
  rec Behavior t Int
nextId <- Int -> Event t Int -> m (Behavior t Int)
forall k (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Behavior t a)
hold Int
1 (Event t Int -> m (Behavior t Int))
-> Event t Int -> m (Behavior t Int)
forall a b. (a -> b) -> a -> b
$ ((Int, PatchMap Int (Decoder rawResponse response),
  Map Int rawRequest)
 -> Int)
-> Event
     t
     (Int, PatchMap Int (Decoder rawResponse response),
      Map Int rawRequest)
-> Event t Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(Int
next, PatchMap Int (Decoder rawResponse response)
_, Map Int rawRequest
_) -> Int
next) Event
  t
  (Int, PatchMap Int (Decoder rawResponse response),
   Map Int rawRequest)
outgoing
      Incremental t (PatchMap Int (Decoder rawResponse response))
waitingFor :: Incremental t (PatchMap Int (Decoder rawResponse response)) <-
        PatchTarget (PatchMap Int (Decoder rawResponse response))
-> Event t (PatchMap Int (Decoder rawResponse response))
-> m (Incremental t (PatchMap Int (Decoder rawResponse response)))
forall k (t :: k) (m :: * -> *) p.
(MonadHold t m, Patch p) =>
PatchTarget p -> Event t p -> m (Incremental t p)
holdIncremental PatchTarget (PatchMap Int (Decoder rawResponse response))
forall a. Monoid a => a
mempty (Event t (PatchMap Int (Decoder rawResponse response))
 -> m (Incremental t (PatchMap Int (Decoder rawResponse response))))
-> Event t (PatchMap Int (Decoder rawResponse response))
-> m (Incremental t (PatchMap Int (Decoder rawResponse response)))
forall a b. (a -> b) -> a -> b
$ [Event t (PatchMap Int (Decoder rawResponse response))]
-> Event t (PatchMap Int (Decoder rawResponse response))
forall k (t :: k) a. Reflex t => [Event t a] -> Event t a
leftmost
          [ ((Int, PatchMap Int (Decoder rawResponse response),
  Map Int rawRequest)
 -> PatchMap Int (Decoder rawResponse response))
-> Event
     t
     (Int, PatchMap Int (Decoder rawResponse response),
      Map Int rawRequest)
-> Event t (PatchMap Int (Decoder rawResponse response))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(Int
_, PatchMap Int (Decoder rawResponse response)
outstanding, Map Int rawRequest
_) -> PatchMap Int (Decoder rawResponse response)
outstanding) Event
  t
  (Int, PatchMap Int (Decoder rawResponse response),
   Map Int rawRequest)
outgoing
          , (RequesterData response,
 PatchMap Int (Decoder rawResponse response))
-> PatchMap Int (Decoder rawResponse response)
forall a b. (a, b) -> b
snd ((RequesterData response,
  PatchMap Int (Decoder rawResponse response))
 -> PatchMap Int (Decoder rawResponse response))
-> Event
     t
     (RequesterData response,
      PatchMap Int (Decoder rawResponse response))
-> Event t (PatchMap Int (Decoder rawResponse response))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Event
  t
  (RequesterData response,
   PatchMap Int (Decoder rawResponse response))
incoming
          ]
      let outgoing :: Event
  t
  (Int, PatchMap Int (Decoder rawResponse response),
   Map Int rawRequest)
outgoing = Behavior t Int
-> Event t (RequesterData request)
-> Event
     t
     (Int, PatchMap Int (Decoder rawResponse response),
      Map Int rawRequest)
processOutgoing Behavior t Int
nextId Event t (RequesterData request)
send
          incoming :: Event
  t
  (RequesterData response,
   PatchMap Int (Decoder rawResponse response))
incoming = Incremental t (PatchMap Int (Decoder rawResponse response))
-> Event t (Int, rawResponse)
-> Event
     t
     (RequesterData response,
      PatchMap Int (Decoder rawResponse response))
forall v.
Incremental t (PatchMap Int (Decoder rawResponse response))
-> Event t (Int, rawResponse)
-> Event t (RequesterData response, PatchMap Int v)
processIncoming Incremental t (PatchMap Int (Decoder rawResponse response))
waitingFor Event t (Int, rawResponse)
recv
  (Event t (Map Int rawRequest), Event t (RequesterData response))
-> m (Event t (Map Int rawRequest),
      Event t (RequesterData response))
forall (m :: * -> *) a. Monad m => a -> m a
return (((Int, PatchMap Int (Decoder rawResponse response),
  Map Int rawRequest)
 -> Map Int rawRequest)
-> Event
     t
     (Int, PatchMap Int (Decoder rawResponse response),
      Map Int rawRequest)
-> Event t (Map Int rawRequest)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(Int
_, PatchMap Int (Decoder rawResponse response)
_, Map Int rawRequest
rawReqs) -> Map Int rawRequest
rawReqs) Event
  t
  (Int, PatchMap Int (Decoder rawResponse response),
   Map Int rawRequest)
outgoing, (RequesterData response,
 PatchMap Int (Decoder rawResponse response))
-> RequesterData response
forall a b. (a, b) -> a
fst ((RequesterData response,
  PatchMap Int (Decoder rawResponse response))
 -> RequesterData response)
-> Event
     t
     (RequesterData response,
      PatchMap Int (Decoder rawResponse response))
-> Event t (RequesterData response)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Event
  t
  (RequesterData response,
   PatchMap Int (Decoder rawResponse response))
incoming)
  where
    -- Tags each outgoing request with an identifying integer key
    -- and returns the next available key, a map of response decoders
    -- for requests for which there are outstanding responses, and the
    -- raw requests to be sent out.
    processOutgoing
      :: Behavior t Int
      -- The next available key
      -> Event t (RequesterData request)
      -- The outgoing request
      -> Event t ( Int
                 , PatchMap Int (Decoder rawResponse response)
                 , Map Int rawRequest )
      -- The new next-available-key, a map of requests expecting responses, and the tagged raw requests
    processOutgoing :: Behavior t Int
-> Event t (RequesterData request)
-> Event
     t
     (Int, PatchMap Int (Decoder rawResponse response),
      Map Int rawRequest)
processOutgoing Behavior t Int
nextId Event t (RequesterData request)
out = ((RequesterData request
  -> PushM
       t
       (Int, PatchMap Int (Decoder rawResponse response),
        Map Int rawRequest))
 -> Event t (RequesterData request)
 -> Event
      t
      (Int, PatchMap Int (Decoder rawResponse response),
       Map Int rawRequest))
-> Event t (RequesterData request)
-> (RequesterData request
    -> PushM
         t
         (Int, PatchMap Int (Decoder rawResponse response),
          Map Int rawRequest))
-> Event
     t
     (Int, PatchMap Int (Decoder rawResponse response),
      Map Int rawRequest)
forall a b c. (a -> b -> c) -> b -> a -> c
flip (RequesterData request
 -> PushM
      t
      (Int, PatchMap Int (Decoder rawResponse response),
       Map Int rawRequest))
-> Event t (RequesterData request)
-> Event
     t
     (Int, PatchMap Int (Decoder rawResponse response),
      Map Int rawRequest)
forall k (t :: k) a b.
Reflex t =>
(a -> PushM t b) -> Event t a -> Event t b
pushAlways Event t (RequesterData request)
out ((RequesterData request
  -> PushM
       t
       (Int, PatchMap Int (Decoder rawResponse response),
        Map Int rawRequest))
 -> Event
      t
      (Int, PatchMap Int (Decoder rawResponse response),
       Map Int rawRequest))
-> (RequesterData request
    -> PushM
         t
         (Int, PatchMap Int (Decoder rawResponse response),
          Map Int rawRequest))
-> Event
     t
     (Int, PatchMap Int (Decoder rawResponse response),
      Map Int rawRequest)
forall a b. (a -> b) -> a -> b
$ \RequesterData request
dm -> do
      Int
oldNextId <- Behavior t Int -> PushM t Int
forall k (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample Behavior t Int
nextId
      let ([(Int, rawRequest, Decoder rawResponse response)]
result, Int
newNextId) = (State Int [(Int, rawRequest, Decoder rawResponse response)]
 -> Int -> ([(Int, rawRequest, Decoder rawResponse response)], Int))
-> Int
-> State Int [(Int, rawRequest, Decoder rawResponse response)]
-> ([(Int, rawRequest, Decoder rawResponse response)], Int)
forall a b c. (a -> b -> c) -> b -> a -> c
flip State Int [(Int, rawRequest, Decoder rawResponse response)]
-> Int -> ([(Int, rawRequest, Decoder rawResponse response)], Int)
forall s a. State s a -> s -> (a, s)
runState Int
oldNextId (State Int [(Int, rawRequest, Decoder rawResponse response)]
 -> ([(Int, rawRequest, Decoder rawResponse response)], Int))
-> State Int [(Int, rawRequest, Decoder rawResponse response)]
-> ([(Int, rawRequest, Decoder rawResponse response)], Int)
forall a b. (a -> b) -> a -> b
$ [DSum RequesterDataKey request]
-> (DSum RequesterDataKey request
    -> StateT
         Int Identity (Int, rawRequest, Decoder rawResponse response))
-> State Int [(Int, rawRequest, Decoder rawResponse response)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM (RequesterData request -> [DSum RequesterDataKey request]
forall (f :: * -> *). RequesterData f -> [DSum RequesterDataKey f]
requesterDataToList RequesterData request
dm) ((DSum RequesterDataKey request
  -> StateT
       Int Identity (Int, rawRequest, Decoder rawResponse response))
 -> State Int [(Int, rawRequest, Decoder rawResponse response)])
-> (DSum RequesterDataKey request
    -> StateT
         Int Identity (Int, rawRequest, Decoder rawResponse response))
-> State Int [(Int, rawRequest, Decoder rawResponse response)]
forall a b. (a -> b) -> a -> b
$ \(RequesterDataKey a
k :=> request a
v) -> do
            Int
n <- StateT Int Identity Int
forall s (m :: * -> *). MonadState s m => m s
get
            Int -> StateT Int Identity ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put (Int -> StateT Int Identity ()) -> Int -> StateT Int Identity ()
forall a b. (a -> b) -> a -> b
$ Int -> Int
forall a. Enum a => a -> a
succ Int
n
            let (rawRequest
rawReq, rawResponse -> response a
rspF) = request a -> (rawRequest, rawResponse -> response a)
forall a. request a -> (rawRequest, rawResponse -> response a)
f request a
v
            (Int, rawRequest, Decoder rawResponse response)
-> StateT
     Int Identity (Int, rawRequest, Decoder rawResponse response)
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
n, rawRequest
rawReq, RequesterDataKey a
-> (rawResponse -> response a) -> Decoder rawResponse response
forall rawResponse (response :: * -> *) a.
RequesterDataKey a
-> (rawResponse -> response a) -> Decoder rawResponse response
Decoder RequesterDataKey a
k rawResponse -> response a
rspF)
          patchWaitingFor :: PatchMap Int (Decoder rawResponse response)
patchWaitingFor = Map Int (Maybe (Decoder rawResponse response))
-> PatchMap Int (Decoder rawResponse response)
forall k v. Map k (Maybe v) -> PatchMap k v
PatchMap (Map Int (Maybe (Decoder rawResponse response))
 -> PatchMap Int (Decoder rawResponse response))
-> Map Int (Maybe (Decoder rawResponse response))
-> PatchMap Int (Decoder rawResponse response)
forall a b. (a -> b) -> a -> b
$ [(Int, Maybe (Decoder rawResponse response))]
-> Map Int (Maybe (Decoder rawResponse response))
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(Int, Maybe (Decoder rawResponse response))]
 -> Map Int (Maybe (Decoder rawResponse response)))
-> [(Int, Maybe (Decoder rawResponse response))]
-> Map Int (Maybe (Decoder rawResponse response))
forall a b. (a -> b) -> a -> b
$
            (\(Int
n, rawRequest
_, Decoder rawResponse response
dec) -> (Int
n, Decoder rawResponse response
-> Maybe (Decoder rawResponse response)
forall a. a -> Maybe a
Just Decoder rawResponse response
dec)) ((Int, rawRequest, Decoder rawResponse response)
 -> (Int, Maybe (Decoder rawResponse response)))
-> [(Int, rawRequest, Decoder rawResponse response)]
-> [(Int, Maybe (Decoder rawResponse response))]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(Int, rawRequest, Decoder rawResponse response)]
result
          toSend :: Map Int rawRequest
toSend = [(Int, rawRequest)] -> Map Int rawRequest
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(Int, rawRequest)] -> Map Int rawRequest)
-> [(Int, rawRequest)] -> Map Int rawRequest
forall a b. (a -> b) -> a -> b
$ (\(Int
n, rawRequest
rawReq, Decoder rawResponse response
_) -> (Int
n, rawRequest
rawReq)) ((Int, rawRequest, Decoder rawResponse response)
 -> (Int, rawRequest))
-> [(Int, rawRequest, Decoder rawResponse response)]
-> [(Int, rawRequest)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(Int, rawRequest, Decoder rawResponse response)]
result
      (Int, PatchMap Int (Decoder rawResponse response),
 Map Int rawRequest)
-> PushM
     t
     (Int, PatchMap Int (Decoder rawResponse response),
      Map Int rawRequest)
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
newNextId, PatchMap Int (Decoder rawResponse response)
patchWaitingFor, Map Int rawRequest
toSend)
    -- Looks up the each incoming raw response in a map of response
    -- decoders and returns the decoded response and a patch that can
    -- be used to clear the ID of the consumed response out of the queue
    -- of expected responses.
    processIncoming
      :: Incremental t (PatchMap Int (Decoder rawResponse response))
      -- A map of outstanding expected responses
      -> Event t (Int, rawResponse)
      -- A incoming response paired with its identifying key
      -> Event t (RequesterData response, PatchMap Int v)
      -- The decoded response and a patch that clears the outstanding responses queue
    processIncoming :: Incremental t (PatchMap Int (Decoder rawResponse response))
-> Event t (Int, rawResponse)
-> Event t (RequesterData response, PatchMap Int v)
processIncoming Incremental t (PatchMap Int (Decoder rawResponse response))
waitingFor Event t (Int, rawResponse)
inc = (((Int, rawResponse)
  -> PushM t (Maybe (RequesterData response, PatchMap Int v)))
 -> Event t (Int, rawResponse)
 -> Event t (RequesterData response, PatchMap Int v))
-> Event t (Int, rawResponse)
-> ((Int, rawResponse)
    -> PushM t (Maybe (RequesterData response, PatchMap Int v)))
-> Event t (RequesterData response, PatchMap Int v)
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((Int, rawResponse)
 -> PushM t (Maybe (RequesterData response, PatchMap Int v)))
-> Event t (Int, rawResponse)
-> Event t (RequesterData response, PatchMap Int v)
forall k (t :: k) a b.
Reflex t =>
(a -> PushM t (Maybe b)) -> Event t a -> Event t b
push Event t (Int, rawResponse)
inc (((Int, rawResponse)
  -> PushM t (Maybe (RequesterData response, PatchMap Int v)))
 -> Event t (RequesterData response, PatchMap Int v))
-> ((Int, rawResponse)
    -> PushM t (Maybe (RequesterData response, PatchMap Int v)))
-> Event t (RequesterData response, PatchMap Int v)
forall a b. (a -> b) -> a -> b
$ \(Int
n, rawResponse
rawRsp) -> do
      Map Int (Decoder rawResponse response)
wf <- Behavior t (Map Int (Decoder rawResponse response))
-> PushM t (Map Int (Decoder rawResponse response))
forall k (t :: k) (m :: * -> *) a.
MonadSample t m =>
Behavior t a -> m a
sample (Behavior t (Map Int (Decoder rawResponse response))
 -> PushM t (Map Int (Decoder rawResponse response)))
-> Behavior t (Map Int (Decoder rawResponse response))
-> PushM t (Map Int (Decoder rawResponse response))
forall a b. (a -> b) -> a -> b
$ Incremental t (PatchMap Int (Decoder rawResponse response))
-> Behavior
     t (PatchTarget (PatchMap Int (Decoder rawResponse response)))
forall k (t :: k) p.
(Reflex t, Patch p) =>
Incremental t p -> Behavior t (PatchTarget p)
currentIncremental Incremental t (PatchMap Int (Decoder rawResponse response))
waitingFor
      case Int
-> Map Int (Decoder rawResponse response)
-> Maybe (Decoder rawResponse response)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Int
n Map Int (Decoder rawResponse response)
wf of
        Maybe (Decoder rawResponse response)
Nothing -> Maybe (RequesterData response, PatchMap Int v)
-> PushM t (Maybe (RequesterData response, PatchMap Int v))
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (RequesterData response, PatchMap Int v)
forall a. Maybe a
Nothing -- TODO How should lookup failures be handled here? They shouldn't ever happen..
        Just (Decoder RequesterDataKey a
k rawResponse -> response a
rspF) -> do
          let rsp :: response a
rsp = rawResponse -> response a
rspF rawResponse
rawRsp
          Maybe (RequesterData response, PatchMap Int v)
-> PushM t (Maybe (RequesterData response, PatchMap Int v))
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (RequesterData response, PatchMap Int v)
 -> PushM t (Maybe (RequesterData response, PatchMap Int v)))
-> Maybe (RequesterData response, PatchMap Int v)
-> PushM t (Maybe (RequesterData response, PatchMap Int v))
forall a b. (a -> b) -> a -> b
$ (RequesterData response, PatchMap Int v)
-> Maybe (RequesterData response, PatchMap Int v)
forall a. a -> Maybe a
Just
            ( RequesterDataKey a -> response a -> RequesterData response
forall a (f :: * -> *).
RequesterDataKey a -> f a -> RequesterData f
singletonRequesterData RequesterDataKey a
k response a
rsp
            , Map Int (Maybe v) -> PatchMap Int v
forall k v. Map k (Maybe v) -> PatchMap k v
PatchMap (Map Int (Maybe v) -> PatchMap Int v)
-> Map Int (Maybe v) -> PatchMap Int v
forall a b. (a -> b) -> a -> b
$ Int -> Maybe v -> Map Int (Maybe v)
forall k a. k -> a -> Map k a
Map.singleton Int
n Maybe v
forall a. Maybe a
Nothing
            )