| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Stream.Filter
Synopsis
- newtype FilterStream (m :: Type -> Type) (f :: Type -> Type) a = FilterStream {
- getFilterStream :: StreamT m (f a)
- constFilter :: forall (m :: Type -> Type) f a. Applicative m => f a -> FilterStream m f a
- filterM :: Functor m => m (f a) -> FilterStream m f a
- filterS :: forall (m :: Type -> Type) (f :: Type -> Type) a. (Monad m, Witherable f, Applicative f) => (a -> Bool) -> FilterStream m f a -> FilterStream m f a
- streamFilter :: forall (f :: Type -> Type) (m :: Type -> Type) a. (Monad f, Traversable f, Monad m) => StreamT (Compose m f) a -> FilterStream m f a
- runListS :: forall (m :: Type -> Type) a. Monad m => StreamT (Compose m []) a -> StreamT m [a]
- liftFilter :: forall (m :: Type -> Type) (f :: Type -> Type) a. (Monad m, Applicative f) => StreamT m a -> FilterStream m f a
Documentation
newtype FilterStream (m :: Type -> Type) (f :: Type -> Type) a Source #
A stream that filters or traverses its output using a type operator f.
When f is Maybe, then can filter in the sense that on a given step there might not be an output.FilterStream Maybe a
f can also be a type that allows multiple positions, such as lists, or NonEmpty.
In this case, FilterStream branches out and can explore multiple outputs at the same time.
(It keeps a single state, though.)
Constructors
| FilterStream | |
Fields
| |
Instances
constFilter :: forall (m :: Type -> Type) f a. Applicative m => f a -> FilterStream m f a Source #
Use a filtered value to create a FilterStream.
filterM :: Functor m => m (f a) -> FilterStream m f a Source #
Use an effectful filtered value to create a FilterStream.
filterS :: forall (m :: Type -> Type) (f :: Type -> Type) a. (Monad m, Witherable f, Applicative f) => (a -> Bool) -> FilterStream m f a -> FilterStream m f a Source #
Filter a stream according to a predicate.
streamFilter :: forall (f :: Type -> Type) (m :: Type -> Type) a. (Monad f, Traversable f, Monad m) => StreamT (Compose m f) a -> FilterStream m f a Source #
Given an f-effect in the step function of a stream, push it into the output type.
This works by internally tracking the f effects in the state, and at the same time joining them in the output.
For example, if f is lists, and stream :: StreamT (Compose m []) a creates a 2-element list at some point,
the internal state of streamFilter stream will split into two, and there are two outputs.
Likewise, if f is Maybe, and a Nothing occurs at some point, then this automaton is deactivated forever.
runListS :: forall (m :: Type -> Type) a. Monad m => StreamT (Compose m []) a -> StreamT m [a] Source #
Given a branching stream, concatenate all branches at every step.
liftFilter :: forall (m :: Type -> Type) (f :: Type -> Type) a. (Monad m, Applicative f) => StreamT m a -> FilterStream m f a Source #
Lift a regular StreamT (which doesn't filter) to a FilterStream.