{-# LANGUAGE ScopedTypeVariables #-}
module Control.Monad.TransLogicState.Class
( TransLogicState(..)
, observe
, observeAll
, observeMany
)
where
import Control.Arrow
import Control.Monad.Identity
import Control.Monad.Trans
class MonadTrans t => TransLogicState s t where
observeT :: (MonadFail m) => s -> t m a -> m a
observeT s
e t m a
m = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. [a] -> a
head forall a b. (a -> b) -> a -> b
$ forall s (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(TransLogicState s t, Monad m) =>
s -> Int -> t m a -> m [a]
observeManyT s
e Int
1 t m a
m
observeAllT :: (Monad m) => s -> t m a -> m [a]
observeAllT s
e = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (a, b) -> a
fst forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(TransLogicState s t, Monad m) =>
s -> t m a -> m ([a], s)
observeStateAllT s
e
observeStateAllT :: (Monad m) => s -> t m a -> m ([a],s)
observeStateAllT s
e = forall s (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(TransLogicState s t, Monad m) =>
s -> Int -> t m a -> m ([a], s)
observeStateManyT s
e forall a. Bounded a => a
maxBound
observeManyT :: forall m a . (Monad m) => s -> Int -> t m a -> m [a]
observeManyT s
e Int
n t m a
m = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ forall s (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(TransLogicState s t, Monad m) =>
s -> Int -> t m a -> m ([a], s)
observeStateManyT s
e Int
n t m a
m
observeStateManyT :: forall m a . (Monad m) => s -> Int -> t m a -> m ([a],s)
observeStateManyT s
e Int
n t m a
m = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first forall a b. (a -> b) -> a -> b
$ forall a. Int -> [a] -> [a]
take Int
n) forall a b. (a -> b) -> a -> b
$ forall s (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(TransLogicState s t, Monad m) =>
s -> t m a -> m ([a], s)
observeStateAllT s
e t m a
m
liftWithState :: Monad m => (s -> m (a,s)) -> t m a
observe :: (TransLogicState s t) => s -> t Maybe a -> Maybe a
observe :: forall s (t :: (* -> *) -> * -> *) a.
TransLogicState s t =>
s -> t Maybe a -> Maybe a
observe s
e = forall s (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(TransLogicState s t, MonadFail m) =>
s -> t m a -> m a
observeT s
e
observeAll :: (TransLogicState s t) => s -> t Identity a -> [a]
observeAll :: forall s (t :: (* -> *) -> * -> *) a.
TransLogicState s t =>
s -> t Identity a -> [a]
observeAll s
e = forall a. Identity a -> a
runIdentity forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(TransLogicState s t, Monad m) =>
s -> t m a -> m [a]
observeAllT s
e
observeMany :: (TransLogicState s t) => s -> Int -> t Identity a -> [a]
observeMany :: forall s (t :: (* -> *) -> * -> *) a.
TransLogicState s t =>
s -> Int -> t Identity a -> [a]
observeMany s
e Int
i = forall a. Identity a -> a
runIdentity forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(TransLogicState s t, Monad m) =>
s -> Int -> t m a -> m [a]
observeManyT s
e Int
i