Safe Haskell | None |
---|---|
Language | Haskell2010 |
Network.GRPC.Common.StreamElem
Contents
Description
Positioned elements
Intended for qualified import.
import Network.GRPC.Common.StreamElem qualified as StreamElem
Network.GRPC.Common (intended for unqualified import) exports
StreamElem(..)
, but none of the operations on StreamElem
.
Synopsis
- data StreamElem b a
- = StreamElem !a
- | FinalElem !a !b
- | NoMoreElems !b
- value :: StreamElem b a -> Maybe a
- mapM_ :: forall m a b. Monad m => (StreamElem b a -> m ()) -> [a] -> b -> m ()
- forM_ :: Monad m => [a] -> b -> (StreamElem b a -> m ()) -> m ()
- whileNext_ :: forall m a b. Monad m => m (StreamElem b a) -> (a -> m ()) -> m b
- collect :: Monad m => m (StreamElem b a) -> m ([a], b)
- whenDefinitelyFinal :: Applicative m => StreamElem b a -> (b -> m ()) -> m ()
Documentation
data StreamElem b a Source #
An element positioned in a stream
Constructors
StreamElem !a | Element in the stream The final element in a stream may or may not be marked as final; if it is not, we will only discover after receiving the final element that it was in fact final. Moreover, we do not know ahead of time whether or not the final element will be marked. When we receive an element and it is not marked final, this might therefore mean one of two things, without being able to tell which:
In this case, the element may or may not be the final element; if it
is, the next value will be
In this case, this element is not final (and the final element, when
we receive it, will be tagged as |
FinalElem !a !b | We received the final element The final element is annotated with some additional information. |
NoMoreElems !b | There are no more elements This is used in two situations:
|
Instances
Conversion
value :: StreamElem b a -> Maybe a Source #
Value of the element, if one is present
Returns Nothing
in case of NoMoreElems
Using this function loses the information whether the item was the final
item; this information can be recovered using whenDefinitelyFinal
.
Iteration
Iteration
mapM_ :: forall m a b. Monad m => (StreamElem b a -> m ()) -> [a] -> b -> m () Source #
Invoke the callback for each element
The final element is marked using FinalElem
; the callback is only invoked
on NoMoreElems
if the list is empty.
mapM_ f ([1,2,3], b) == do f (StreamElem 1) f (StreamElem 2) f (FinalElem 3 b) mapM_ f ([], b) == do f (NoMoreElems b)
forM_ :: Monad m => [a] -> b -> (StreamElem b a -> m ()) -> m () Source #
Like mapM_
, but with the arguments in opposite order
whileNext_ :: forall m a b. Monad m => m (StreamElem b a) -> (a -> m ()) -> m b Source #
Invoke a function on each NextElem
, until FinalElem
or NoMoreElems
collect :: Monad m => m (StreamElem b a) -> m ([a], b) Source #
Invoke the callback until FinalElem
or NoMoreElems
, collecting results
whenDefinitelyFinal :: Applicative m => StreamElem b a -> (b -> m ()) -> m () Source #
Do we have evidence that this element is the final one?
The callback is not called on StreamElem
; this does not mean that the
element was not final; see StreamElem
for detailed discussion.