Safe Haskell | None |
---|---|
Language | Haskell2010 |
Capability.Stream
Contents
Description
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)
- 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.
Methods
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. |
HasState tag [a] m => HasStream (tag :: k) a (StreamStack m) Source # | |
Defined in Capability.Stream Methods yield_ :: Proxy# tag -> a -> StreamStack m () Source # | |
HasWriter tag (DList a) m => HasStream (tag :: k) a (StreamDList m) Source # | |
Defined in Capability.Stream Methods yield_ :: Proxy# tag -> a -> StreamDList 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.
Constructors
StreamStack (m a) |
Instances
newtype StreamDList m (a :: *) Source #
Accumulate streamed values in forward order in a difference list.
Constructors
StreamDList (m a) |
Instances
Modifiers
module Capability.Accessors