Safe Haskell | None |
---|---|
Language | Haskell2010 |
ListT
Synopsis
- newtype ListT m a = ListT (m ( Maybe (a, ListT m a)))
- uncons :: ListT m a -> m ( Maybe (a, ListT m a))
- head :: Monad m => ListT m a -> m ( Maybe a)
- tail :: Monad m => ListT m a -> m ( Maybe ( ListT m a))
- null :: Monad m => ListT m a -> m Bool
- alternate :: ( Alternative m, Monad m) => ListT m a -> m a
- alternateHoisting :: ( Monad n, Alternative n) => ( forall a. m a -> n a) -> ListT m a -> n a
- fold :: Monad m => (b -> a -> m b) -> b -> ListT m a -> m b
- foldMaybe :: Monad m => (b -> a -> m ( Maybe b)) -> b -> ListT m a -> m b
- applyFoldM :: Monad m => FoldM m i o -> ListT m i -> m o
- toList :: Monad m => ListT m a -> m [a]
- toReverseList :: Monad m => ListT m a -> m [a]
- traverse_ :: Monad m => (a -> m ()) -> ListT m a -> m ()
- splitAt :: Monad m => Int -> ListT m a -> m ([a], ListT m a)
- cons :: Monad m => a -> ListT m a -> ListT m a
- fromFoldable :: ( Monad m, Foldable f) => f a -> ListT m a
- fromMVar :: MonadIO m => MVar ( Maybe a) -> ListT m a
- unfold :: Monad m => (b -> Maybe (a, b)) -> b -> ListT m a
- unfoldM :: Monad m => (b -> m ( Maybe (a, b))) -> b -> ListT m a
- repeat :: Monad m => a -> ListT m a
- traverse :: Monad m => (a -> m b) -> ListT m a -> ListT m b
- take :: Monad m => Int -> ListT m a -> ListT m a
- drop :: Monad m => Int -> ListT m a -> ListT m a
- slice :: Monad m => Int -> ListT m a -> ListT m [a]
Documentation
A proper implementation of the list monad-transformer. Useful for streaming of monadic data structures.
Since it has instances of
MonadPlus
and
Alternative
,
you can use general utilities packages like
"monadplus"
with it.
Instances
MMonad ListT Source # | |
MonadTrans ListT Source # | |
MonadBase b m => MonadBase b ( ListT m) Source # | |
MonadBaseControl b m => MonadBaseControl b ( ListT m) Source # | |
MonadState e m => MonadState e ( ListT m) Source # | |
MonadReader e m => MonadReader e ( ListT m) Source # | |
MonadError e m => MonadError e ( ListT m) Source # | |
Monad m => Monad ( ListT m) Source # | |
Functor m => Functor ( ListT m) Source # | |
Monad m => MonadFail ( ListT m) Source # | |
( Monad m, Functor m) => Applicative ( ListT m) Source # | |
Foldable m => Foldable ( ListT m) Source # | |
Defined in ListT Methods fold :: Monoid m0 => ListT m m0 -> m0 Source # foldMap :: Monoid m0 => (a -> m0) -> ListT m a -> m0 Source # foldMap' :: Monoid m0 => (a -> m0) -> ListT m a -> m0 Source # foldr :: (a -> b -> b) -> b -> ListT m a -> b Source # foldr' :: (a -> b -> b) -> b -> ListT m a -> b Source # foldl :: (b -> a -> b) -> b -> ListT m a -> b Source # foldl' :: (b -> a -> b) -> b -> ListT m a -> b Source # foldr1 :: (a -> a -> a) -> ListT m a -> a Source # foldl1 :: (a -> a -> a) -> ListT m a -> a Source # toList :: ListT m a -> [a] Source # null :: ListT m a -> Bool Source # length :: ListT m a -> Int Source # elem :: Eq a => a -> ListT m a -> Bool Source # maximum :: Ord a => ListT m a -> a Source # minimum :: Ord a => ListT m a -> a Source # |
|
Traversable m => Traversable ( ListT m) Source # | |
Defined in ListT |
|
Eq1 m => Eq1 ( ListT m) Source # | |
Ord1 m => Ord1 ( ListT m) Source # | |
Show1 m => Show1 ( ListT m) Source # | |
MonadZip m => MonadZip ( ListT m) Source # | |
MonadIO m => MonadIO ( ListT m) Source # | |
( Monad m, Functor m) => Alternative ( ListT m) Source # | |
Monad m => MonadPlus ( ListT m) Source # | |
Monad m => MonadLogic ( ListT m) Source # | |
Defined in ListT Methods msplit :: ListT m a -> ListT m ( Maybe (a, ListT m a)) Source # interleave :: ListT m a -> ListT m a -> ListT m a Source # (>>-) :: ListT m a -> (a -> ListT m b) -> ListT m b Source # once :: ListT m a -> ListT m a Source # lnot :: ListT m a -> ListT m () Source # ifte :: ListT m a -> (a -> ListT m b) -> ListT m b -> ListT m b Source # |
|
MFunctor ListT Source # | |
Eq (m ( Maybe (a, ListT m a))) => Eq ( ListT m a) Source # | |
( Typeable m, Typeable a, Data (m ( Maybe (a, ListT m a)))) => Data ( ListT m a) Source # | |
Defined in ListT Methods gfoldl :: ( forall d b. Data d => c (d -> b) -> d -> c b) -> ( forall g. g -> c g) -> ListT m a -> c ( ListT m a) Source # gunfold :: ( forall b r. Data b => c (b -> r) -> c r) -> ( forall r. r -> c r) -> Constr -> c ( ListT m a) Source # toConstr :: ListT m a -> Constr Source # dataTypeOf :: ListT m a -> DataType Source # dataCast1 :: Typeable t => ( forall d. Data d => c (t d)) -> Maybe (c ( ListT m a)) Source # dataCast2 :: Typeable t => ( forall d e. ( Data d, Data e) => c (t d e)) -> Maybe (c ( ListT m a)) Source # gmapT :: ( forall b. Data b => b -> b) -> ListT m a -> ListT m a Source # gmapQl :: (r -> r' -> r) -> r -> ( forall d. Data d => d -> r') -> ListT m a -> r Source # gmapQr :: forall r r'. (r' -> r -> r) -> r -> ( forall d. Data d => d -> r') -> ListT m a -> r Source # gmapQ :: ( forall d. Data d => d -> u) -> ListT m a -> [u] Source # gmapQi :: Int -> ( forall d. Data d => d -> u) -> ListT m a -> u Source # gmapM :: Monad m0 => ( forall d. Data d => d -> m0 d) -> ListT m a -> m0 ( ListT m a) Source # gmapMp :: MonadPlus m0 => ( forall d. Data d => d -> m0 d) -> ListT m a -> m0 ( ListT m a) Source # gmapMo :: MonadPlus m0 => ( forall d. Data d => d -> m0 d) -> ListT m a -> m0 ( ListT m a) Source # |
|
Ord (m ( Maybe (a, ListT m a))) => Ord ( ListT m a) Source # | |
Defined in ListT Methods compare :: ListT m a -> ListT m a -> Ordering Source # (<) :: ListT m a -> ListT m a -> Bool Source # (<=) :: ListT m a -> ListT m a -> Bool Source # (>) :: ListT m a -> ListT m a -> Bool Source # (>=) :: ListT m a -> ListT m a -> Bool Source # |
|
Read (m ( Maybe (a, ListT m a))) => Read ( ListT m a) Source # | |
Show (m ( Maybe (a, ListT m a))) => Show ( ListT m a) Source # | |
Generic ( ListT m a) Source # | |
Monad m => Semigroup ( ListT m a) Source # | |
Monad m => Monoid ( ListT m a) Source # | |
type StM ( ListT m) a Source # | |
type Rep ( ListT m a) Source # | |
Defined in ListT |
Execution utilities
uncons :: ListT m a -> m ( Maybe (a, ListT m a)) Source #
Execute in the inner monad, getting the head and the tail. Returns nothing if it's empty.
head :: Monad m => ListT m a -> m ( Maybe a) Source #
Execute, getting the head. Returns nothing if it's empty.
tail :: Monad m => ListT m a -> m ( Maybe ( ListT m a)) Source #
Execute, getting the tail. Returns nothing if it's empty.
alternate :: ( Alternative m, Monad m) => ListT m a -> m a Source #
Execute in the inner monad,
using its
(<|>)
function on each entry.
alternateHoisting :: ( Monad n, Alternative n) => ( forall a. m a -> n a) -> ListT m a -> n a Source #
fold :: Monad m => (b -> a -> m b) -> b -> ListT m a -> m b Source #
Execute, applying a strict left fold.
foldMaybe :: Monad m => (b -> a -> m ( Maybe b)) -> b -> ListT m a -> m b Source #
A version of
fold
, which allows early termination.
applyFoldM :: Monad m => FoldM m i o -> ListT m i -> m o Source #
Apply the left fold abstraction from the "foldl" package.
toReverseList :: Monad m => ListT m a -> m [a] Source #
Execute, folding to a list in the reverse order.
Performs more efficiently than
toList
.
traverse_ :: Monad m => (a -> m ()) -> ListT m a -> m () Source #
Execute, traversing the stream with a side effect in the inner monad.
splitAt :: Monad m => Int -> ListT m a -> m ([a], ListT m a) Source #
Execute, consuming a list of the specified length and returning the remainder stream.
Construction utilities
fromMVar :: MonadIO m => MVar ( Maybe a) -> ListT m a Source #
Construct from an MVar, interpreting the value of Nothing as the end.
unfold :: Monad m => (b -> Maybe (a, b)) -> b -> ListT m a Source #
Construct by unfolding a pure data structure.
unfoldM :: Monad m => (b -> m ( Maybe (a, b))) -> b -> ListT m a Source #
Construct by unfolding a monadic data structure
This is the most memory-efficient way to construct ListT where the length depends on the inner monad.
Transformation utilities
These utilities only accumulate the transformations without actually traversing the stream. They only get applied in a single traversal, which only happens at the execution.
traverse :: Monad m => (a -> m b) -> ListT m a -> ListT m b Source #
A transformation, which traverses the stream with an action in the inner monad.
take :: Monad m => Int -> ListT m a -> ListT m a Source #
A transformation,
reproducing the behaviour of
Data.List.
.
take