Copyright | (c) Bradley Hardy 2016 |
---|---|
License | LGPL3 |
Maintainer | bradleyhardy@live.com |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
This is a set of assorted utility functions for streaming
and
streaming-bytestring
which are used in various places in this library, but may
also be of use to others so they are exposed here.
- expectNull :: (MonadThrow m, Exception e) => e -> ByteString m r -> m r
- chunksOfBS :: Monad m => Int64 -> ByteString m r -> Stream (ByteString m) m r
- rememberPrevious :: Monad m => Stream (Of a) m r -> Stream (Of (Maybe a, a)) m r
- mapWithMemory :: forall m a b r. Monad m => (Maybe b -> a -> m b) -> Stream (Of a) m r -> Stream (Of b) m r
- filterMapped :: (Monad m, Functor f, Functor g) => (forall x. f x -> m (Sum Identity g x)) -> Stream f m r -> Stream g m r
- filtered :: (Monad m, Functor f) => (forall x. f x -> m (Maybe x)) -> Stream f m r -> Stream f m r
- buildByteString :: Monad m => (a -> m (Either r (ByteString m (), a))) -> a -> ByteString m r
- bytestringToVector :: ByteString -> Vector Word8
- vectorToBytestring :: Vector Word8 -> ByteString
Documentation
expectNull :: (MonadThrow m, Exception e) => e -> ByteString m r -> m r Source
If the input ByteString
is empty, return its result. Otherwise throw the
provided error value.
chunksOfBS :: Monad m => Int64 -> ByteString m r -> Stream (ByteString m) m r Source
Split a streaming ByteString up into a stream of chunks of the given size.
rememberPrevious :: Monad m => Stream (Of a) m r -> Stream (Of (Maybe a, a)) m r Source
Remember the previous value at each point in a stream of values.
mapWithMemory :: forall m a b r. Monad m => (Maybe b -> a -> m b) -> Stream (Of a) m r -> Stream (Of b) m r Source
Map a function across a stream, but also include in its arguments the
result of applying it to the previous item in the stream (which is Nothing
if the current item is the first in the stream).
filterMapped :: (Monad m, Functor f, Functor g) => (forall x. f x -> m (Sum Identity g x)) -> Stream f m r -> Stream g m r Source
For each functor wrapper f
in the stream, either strip it off or convert it to
some new functor g
. Return the stream of g
's. This can be seen to be
analogous to a list function of type
if we consider what it looks like when Monad
m => (a -> m (Maybe
b)) -> [a]
-> m [b]f
and g
are
and
Of
a
respectively:Of
b
filterMapped :: (forall x. Of a x -> m (Sum Identity (Of b) x)) -> Stream (Of a) m r -> Stream (Of b) m r
Here,
is isomorphic to Sum
Identity
(Of
b) x
.Of
(Maybe
b) x
filtered :: (Monad m, Functor f) => (forall x. f x -> m (Maybe x)) -> Stream f m r -> Stream f m r Source
For each functor wrapper in the stream, optionally strip it off. Those stripped off will be removed from the resulting stream.
buildByteString :: Monad m => (a -> m (Either r (ByteString m (), a))) -> a -> ByteString m r Source
Build a ByteString
monadically from a seed.
bytestringToVector :: ByteString -> Vector Word8 Source
Directly convert a ByteString
into a storable Vector
, in constant
time.
vectorToBytestring :: Vector Word8 -> ByteString Source
Directly convert a storable Vector
of Word8
s into a ByteString
, in
constant time.