Safe Haskell | None |
---|---|
Language | Haskell2010 |
Defines a capability for computations that produce a stream of values as part of their execution.
Programs producing streams of data are common. Examples: emitting events on input, or emitting events whenever certain conditions are observed. Streams are similar to Python generators.
The HasStream
capability enables separating the logic responsible for
emitting events from that responsible for collecting or handling them.
This can be thought of as a writer capability of a list of values HasWriter
tag [v]
with \x -> tell @tag [x]
as a primitive operation. However, that
implementation would be inefficient.
For example using the Stream
instance, a producer defined
using this capability can be consumed efficiently in a streaming fashion.
Synopsis
- class Monad m => HasStream (tag :: k) (a :: *) (m :: * -> *) | tag m -> a where
- yield :: forall tag a m. HasStream tag a m => a -> m ()
- newtype StreamStack m (a :: *) = StreamStack (m a)
- newtype StreamDList m (a :: *) = StreamDList (m a)
- newtype StreamLog m (a :: *) = StreamLog (m a)
- module Capability.Accessors
Interface
class Monad m => HasStream (tag :: k) (a :: *) (m :: * -> *) | tag m -> a where Source #
Streaming capability.
An instance does not need to fulfill any additional laws besides the monad laws.
Instances
(HasStream tag a m, MonadTrans t, Monad (t m)) => HasStream (tag :: k) a (Lift (t m)) Source # | Lift one layer in a monad transformer stack. Note, that if the deriving (HasStream tag w) via StreamLog (Lift (SomeTrans (MonadState SomeStateMonad))) over deriving (HasStream tag w) via Lift (SomeTrans (StreamLog (MonadState SomeStateMonad))) |
HasState tag [a] m => HasStream (tag :: k) a (StreamStack m) Source # | |
Defined in Capability.Stream yield_ :: Proxy# tag -> a -> StreamStack m () Source # | |
HasStream tag (DList a) m => HasStream (tag :: k) a (StreamDList m) Source # | This instance may seem a bit odd at first. All it does is wrap each
deriving (HasStream tag w) via StreamDList (StreamLog (MonadState SomeStateMonad)) |
Defined in Capability.Stream yield_ :: Proxy# tag -> a -> StreamDList m () Source # | |
(Monoid w, HasState tag w m) => HasStream (tag :: k) w (StreamLog m) Source # | |
Monad m => HasStream (tag :: k) a (Stream (Of a) m) Source # | |
(forall x. Coercible (m x) (t2 (t1 m) x), Monad m, HasStream tag a (t2 (t1 m))) => HasStream (tag :: k) a ((t2 :.: t1) m) Source # | Compose two accessors. |
yield :: forall tag a m. HasStream tag a m => a -> m () Source #
yield @tag a
emits a
in the stream capability tag
.
Strategies
newtype StreamStack m (a :: *) Source #
Accumulate streamed values in a reverse order list.
StreamStack (m a) |
Instances
newtype StreamDList m (a :: *) Source #
Accumulate streamed values in forward order in a difference list.
StreamDList (m a) |
Instances
HasStream tag (DList a) m => HasStream (tag :: k) a (StreamDList m) Source # | This instance may seem a bit odd at first. All it does is wrap each
deriving (HasStream tag w) via StreamDList (StreamLog (MonadState SomeStateMonad)) |
Defined in Capability.Stream yield_ :: Proxy# tag -> a -> StreamDList m () Source # | |
Monad m => Monad (StreamDList m) Source # | |
Defined in Capability.Stream (>>=) :: StreamDList m a -> (a -> StreamDList m b) -> StreamDList m b # (>>) :: StreamDList m a -> StreamDList m b -> StreamDList m b # return :: a -> StreamDList m a # fail :: String -> StreamDList m a # | |
Functor m => Functor (StreamDList m) Source # | |
Defined in Capability.Stream fmap :: (a -> b) -> StreamDList m a -> StreamDList m b # (<$) :: a -> StreamDList m b -> StreamDList m a # | |
Applicative m => Applicative (StreamDList m) Source # | |
Defined in Capability.Stream pure :: a -> StreamDList m a # (<*>) :: StreamDList m (a -> b) -> StreamDList m a -> StreamDList m b # liftA2 :: (a -> b -> c) -> StreamDList m a -> StreamDList m b -> StreamDList m c # (*>) :: StreamDList m a -> StreamDList m b -> StreamDList m b # (<*) :: StreamDList m a -> StreamDList m b -> StreamDList m a # | |
MonadIO m => MonadIO (StreamDList m) Source # | |
Defined in Capability.Stream liftIO :: IO a -> StreamDList m a # | |
PrimMonad m => PrimMonad (StreamDList m) Source # | |
Defined in Capability.Stream type PrimState (StreamDList m) :: Type # primitive :: (State# (PrimState (StreamDList m)) -> (#State# (PrimState (StreamDList m)), a#)) -> StreamDList m a # | |
type PrimState (StreamDList m) Source # | |
Defined in Capability.Stream |
newtype StreamLog m (a :: *) Source #
Accumulate streamed values with their own monoid.
StreamLog (m a) |
Instances
(Monoid w, HasState tag w m) => HasStream (tag :: k) w (StreamLog m) Source # | |
(Monoid w, HasState tag w m) => HasWriter (tag :: k) w (WriterLog m) Source # | |
Monad m => Monad (StreamLog m) Source # | |
Functor m => Functor (StreamLog m) Source # | |
Applicative m => Applicative (StreamLog m) Source # | |
Defined in Capability.Stream | |
MonadIO m => MonadIO (StreamLog m) Source # | |
Defined in Capability.Stream | |
PrimMonad m => PrimMonad (StreamLog m) Source # | |
type PrimState (StreamLog m) Source # | |
Defined in Capability.Stream |
Modifiers
module Capability.Accessors