automaton-1.6: Effectful streams and automata in coalgebraic encoding
Safe HaskellNone
LanguageHaskell2010

Data.Stream.Filter

Synopsis

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 FilterStream Maybe a can filter in the sense that on a given step there might not be an output.

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

Instances details
(Foldable m, Foldable f) => Foldable (FilterStream m f) Source # 
Instance details

Defined in Data.Stream.Filter

Methods

fold :: Monoid m0 => FilterStream m f m0 -> m0 #

foldMap :: Monoid m0 => (a -> m0) -> FilterStream m f a -> m0 #

foldMap' :: Monoid m0 => (a -> m0) -> FilterStream m f a -> m0 #

foldr :: (a -> b -> b) -> b -> FilterStream m f a -> b #

foldr' :: (a -> b -> b) -> b -> FilterStream m f a -> b #

foldl :: (b -> a -> b) -> b -> FilterStream m f a -> b #

foldl' :: (b -> a -> b) -> b -> FilterStream m f a -> b #

foldr1 :: (a -> a -> a) -> FilterStream m f a -> a #

foldl1 :: (a -> a -> a) -> FilterStream m f a -> a #

toList :: FilterStream m f a -> [a] #

null :: FilterStream m f a -> Bool #

length :: FilterStream m f a -> Int #

elem :: Eq a => a -> FilterStream m f a -> Bool #

maximum :: Ord a => FilterStream m f a -> a #

minimum :: Ord a => FilterStream m f a -> a #

sum :: Num a => FilterStream m f a -> a #

product :: Num a => FilterStream m f a -> a #

(Traversable m, Traversable f) => Traversable (FilterStream m f) Source # 
Instance details

Defined in Data.Stream.Filter

Methods

traverse :: Applicative f0 => (a -> f0 b) -> FilterStream m f a -> f0 (FilterStream m f b) #

sequenceA :: Applicative f0 => FilterStream m f (f0 a) -> f0 (FilterStream m f a) #

mapM :: Monad m0 => (a -> m0 b) -> FilterStream m f a -> m0 (FilterStream m f b) #

sequence :: Monad m0 => FilterStream m f (m0 a) -> m0 (FilterStream m f a) #

(Alternative m, Applicative f) => Alternative (FilterStream m f) Source # 
Instance details

Defined in Data.Stream.Filter

Methods

empty :: FilterStream m f a #

(<|>) :: FilterStream m f a -> FilterStream m f a -> FilterStream m f a #

some :: FilterStream m f a -> FilterStream m f [a] #

many :: FilterStream m f a -> FilterStream m f [a] #

(Applicative m, Applicative f) => Applicative (FilterStream m f) Source # 
Instance details

Defined in Data.Stream.Filter

Methods

pure :: a -> FilterStream m f a #

(<*>) :: FilterStream m f (a -> b) -> FilterStream m f a -> FilterStream m f b #

liftA2 :: (a -> b -> c) -> FilterStream m f a -> FilterStream m f b -> FilterStream m f c #

(*>) :: FilterStream m f a -> FilterStream m f b -> FilterStream m f b #

(<*) :: FilterStream m f a -> FilterStream m f b -> FilterStream m f a #

(Functor m, Functor f) => Functor (FilterStream m f) Source # 
Instance details

Defined in Data.Stream.Filter

Methods

fmap :: (a -> b) -> FilterStream m f a -> FilterStream m f b #

(<$) :: a -> FilterStream m f b -> FilterStream m f a #

(Align f, Applicative m) => Align (FilterStream m f) Source # 
Instance details

Defined in Data.Stream.Filter

Methods

nil :: FilterStream m f a #

(Semialign f, Applicative m) => Semialign (FilterStream m f) Source #

Run two streams in parallel and align their outputs.

Instance details

Defined in Data.Stream.Filter

Methods

align :: FilterStream m f a -> FilterStream m f b -> FilterStream m f (These a b) #

alignWith :: (These a b -> c) -> FilterStream m f a -> FilterStream m f b -> FilterStream m f c #

(Functor m, Filterable f) => Filterable (FilterStream m f) Source # 
Instance details

Defined in Data.Stream.Filter

Methods

mapMaybe :: (a -> Maybe b) -> FilterStream m f a -> FilterStream m f b #

catMaybes :: FilterStream m f (Maybe a) -> FilterStream m f a #

filter :: (a -> Bool) -> FilterStream m f a -> FilterStream m f a #

drain :: FilterStream m f a -> FilterStream m f b #

(Functor m, Traversable m, Filterable f, Traversable f) => Witherable (FilterStream m f) Source # 
Instance details

Defined in Data.Stream.Filter

Methods

wither :: Applicative f0 => (a -> f0 (Maybe b)) -> FilterStream m f a -> f0 (FilterStream m f b) #

witherM :: Monad m0 => (a -> m0 (Maybe b)) -> FilterStream m f a -> m0 (FilterStream m f b) #

filterA :: Applicative f0 => (a -> f0 Bool) -> FilterStream m f a -> f0 (FilterStream m f a) #

witherMap :: Applicative m0 => (FilterStream m f b -> r) -> (a -> m0 (Maybe b)) -> FilterStream m f a -> m0 r #

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.