list-t-1.0.5.6: ListT done right
Safe HaskellSafe-Inferred
LanguageHaskell2010

ListT

Synopsis

Documentation

newtype ListT m a Source #

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.

Constructors

ListT (m (Maybe (a, ListT m a))) 

Instances

Instances details
MMonad ListT Source # 
Instance details

Defined in ListT

Methods

embed :: forall (n :: Type -> Type) m b. Monad n => (forall a. m a -> ListT n a) -> ListT m b -> ListT n b #

MonadTrans ListT Source # 
Instance details

Defined in ListT

Methods

lift :: Monad m => m a -> ListT m a #

MFunctor ListT Source # 
Instance details

Defined in ListT

Methods

hoist :: forall m n (b :: k). Monad m => (forall a. m a -> n a) -> ListT m b -> ListT n b #

MonadBaseControl b m => MonadBaseControl b (ListT m) Source # 
Instance details

Defined in ListT

Associated Types

type StM (ListT m) a #

Methods

liftBaseWith :: (RunInBase (ListT m) b -> b a) -> ListT m a #

restoreM :: StM (ListT m) a -> ListT m a #

MonadError e m => MonadError e (ListT m) Source # 
Instance details

Defined in ListT

Methods

throwError :: e -> ListT m a #

catchError :: ListT m a -> (e -> ListT m a) -> ListT m a #

MonadReader e m => MonadReader e (ListT m) Source # 
Instance details

Defined in ListT

Methods

ask :: ListT m e #

local :: (e -> e) -> ListT m a -> ListT m a #

reader :: (e -> a) -> ListT m a #

MonadState e m => MonadState e (ListT m) Source # 
Instance details

Defined in ListT

Methods

get :: ListT m e #

put :: e -> ListT m () #

state :: (e -> (a, e)) -> ListT m a #

MonadBase b m => MonadBase b (ListT m) Source # 
Instance details

Defined in ListT

Methods

liftBase :: b α -> ListT m α #

Monad m => MonadFail (ListT m) Source # 
Instance details

Defined in ListT

Methods

fail :: String -> ListT m a #

MonadIO m => MonadIO (ListT m) Source # 
Instance details

Defined in ListT

Methods

liftIO :: IO a -> ListT m a #

MonadZip m => MonadZip (ListT m) Source # 
Instance details

Defined in ListT

Methods

mzip :: ListT m a -> ListT m b -> ListT m (a, b) #

mzipWith :: (a -> b -> c) -> ListT m a -> ListT m b -> ListT m c #

munzip :: ListT m (a, b) -> (ListT m a, ListT m b) #

Foldable m => Foldable (ListT m) Source # 
Instance details

Defined in ListT

Methods

fold :: Monoid m0 => ListT m m0 -> m0 #

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

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

foldr :: (a -> b -> b) -> b -> ListT m a -> b #

foldr' :: (a -> b -> b) -> b -> ListT m a -> b #

foldl :: (b -> a -> b) -> b -> ListT m a -> b #

foldl' :: (b -> a -> b) -> b -> ListT m a -> b #

foldr1 :: (a -> a -> a) -> ListT m a -> a #

foldl1 :: (a -> a -> a) -> ListT m a -> a #

toList :: ListT m a -> [a] #

null :: ListT m a -> Bool #

length :: ListT m a -> Int #

elem :: Eq a => a -> ListT m a -> Bool #

maximum :: Ord a => ListT m a -> a #

minimum :: Ord a => ListT m a -> a #

sum :: Num a => ListT m a -> a #

product :: Num a => ListT m a -> a #

Eq1 m => Eq1 (ListT m) Source # 
Instance details

Defined in ListT

Methods

liftEq :: (a -> b -> Bool) -> ListT m a -> ListT m b -> Bool #

Ord1 m => Ord1 (ListT m) Source # 
Instance details

Defined in ListT

Methods

liftCompare :: (a -> b -> Ordering) -> ListT m a -> ListT m b -> Ordering #

Show1 m => Show1 (ListT m) Source # 
Instance details

Defined in ListT

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> ListT m a -> ShowS #

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [ListT m a] -> ShowS #

Traversable m => Traversable (ListT m) Source # 
Instance details

Defined in ListT

Methods

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

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

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

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

(Monad m, Functor m) => Alternative (ListT m) Source # 
Instance details

Defined in ListT

Methods

empty :: ListT m a #

(<|>) :: ListT m a -> ListT m a -> ListT m a #

some :: ListT m a -> ListT m [a] #

many :: ListT m a -> ListT m [a] #

(Monad m, Functor m) => Applicative (ListT m) Source # 
Instance details

Defined in ListT

Methods

pure :: a -> ListT m a #

(<*>) :: ListT m (a -> b) -> ListT m a -> ListT m b #

liftA2 :: (a -> b -> c) -> ListT m a -> ListT m b -> ListT m c #

(*>) :: ListT m a -> ListT m b -> ListT m b #

(<*) :: ListT m a -> ListT m b -> ListT m a #

Functor m => Functor (ListT m) Source # 
Instance details

Defined in ListT

Methods

fmap :: (a -> b) -> ListT m a -> ListT m b #

(<$) :: a -> ListT m b -> ListT m a #

Monad m => Monad (ListT m) Source # 
Instance details

Defined in ListT

Methods

(>>=) :: ListT m a -> (a -> ListT m b) -> ListT m b #

(>>) :: ListT m a -> ListT m b -> ListT m b #

return :: a -> ListT m a #

Monad m => MonadPlus (ListT m) Source # 
Instance details

Defined in ListT

Methods

mzero :: ListT m a #

mplus :: ListT m a -> ListT m a -> ListT m a #

Monad m => MonadLogic (ListT m) Source # 
Instance details

Defined in ListT

Methods

msplit :: ListT m a -> ListT m (Maybe (a, ListT m a)) #

interleave :: ListT m a -> ListT m a -> ListT m a #

(>>-) :: ListT m a -> (a -> ListT m b) -> ListT m b #

once :: ListT m a -> ListT m a #

lnot :: ListT m a -> ListT m () #

ifte :: ListT m a -> (a -> ListT m b) -> ListT m b -> ListT m b #

(Typeable m, Typeable a, Data (m (Maybe (a, ListT m a)))) => Data (ListT m a) Source # 
Instance details

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) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (ListT m a) #

toConstr :: ListT m a -> Constr #

dataTypeOf :: ListT m a -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (ListT m a)) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (ListT m a)) #

gmapT :: (forall b. Data b => b -> b) -> ListT m a -> ListT m a #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ListT m a -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ListT m a -> r #

gmapQ :: (forall d. Data d => d -> u) -> ListT m a -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> ListT m a -> u #

gmapM :: Monad m0 => (forall d. Data d => d -> m0 d) -> ListT m a -> m0 (ListT m a) #

gmapMp :: MonadPlus m0 => (forall d. Data d => d -> m0 d) -> ListT m a -> m0 (ListT m a) #

gmapMo :: MonadPlus m0 => (forall d. Data d => d -> m0 d) -> ListT m a -> m0 (ListT m a) #

Monad m => Monoid (ListT m a) Source # 
Instance details

Defined in ListT

Methods

mempty :: ListT m a #

mappend :: ListT m a -> ListT m a -> ListT m a #

mconcat :: [ListT m a] -> ListT m a #

Monad m => Semigroup (ListT m a) Source # 
Instance details

Defined in ListT

Methods

(<>) :: ListT m a -> ListT m a -> ListT m a #

sconcat :: NonEmpty (ListT m a) -> ListT m a #

stimes :: Integral b => b -> ListT m a -> ListT m a #

Generic (ListT m a) Source # 
Instance details

Defined in ListT

Associated Types

type Rep (ListT m a) :: Type -> Type #

Methods

from :: ListT m a -> Rep (ListT m a) x #

to :: Rep (ListT m a) x -> ListT m a #

Read (m (Maybe (a, ListT m a))) => Read (ListT m a) Source # 
Instance details

Defined in ListT

Show (m (Maybe (a, ListT m a))) => Show (ListT m a) Source # 
Instance details

Defined in ListT

Methods

showsPrec :: Int -> ListT m a -> ShowS #

show :: ListT m a -> String #

showList :: [ListT m a] -> ShowS #

Eq (m (Maybe (a, ListT m a))) => Eq (ListT m a) Source # 
Instance details

Defined in ListT

Methods

(==) :: ListT m a -> ListT m a -> Bool #

(/=) :: ListT m a -> ListT m a -> Bool #

Ord (m (Maybe (a, ListT m a))) => Ord (ListT m a) Source # 
Instance details

Defined in ListT

Methods

compare :: ListT m a -> ListT m a -> Ordering #

(<) :: ListT m a -> ListT m a -> Bool #

(<=) :: ListT m a -> ListT m a -> Bool #

(>) :: ListT m a -> ListT m a -> Bool #

(>=) :: ListT m a -> ListT m a -> Bool #

max :: ListT m a -> ListT m a -> ListT m a #

min :: ListT m a -> ListT m a -> ListT m a #

type StM (ListT m) a Source # 
Instance details

Defined in ListT

type StM (ListT m) a = StM m (Maybe (a, ListT m a))
type Rep (ListT m a) Source # 
Instance details

Defined in ListT

type Rep (ListT m a) = D1 ('MetaData "ListT" "ListT" "list-t-1.0.5.6-3W9r7IByJvs6hZM41sJEKx" 'True) (C1 ('MetaCons "ListT" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (m (Maybe (a, ListT m a))))))

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.

null :: Monad m => ListT m a -> m Bool Source #

Execute, checking whether 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 #

Use a monad morphism to convert a ListT to a similar monad, such as '[]'.

A more efficient alternative to alternate . hoist f.

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.

toList :: Monad m => ListT m a -> m [a] Source #

Execute, folding to a list.

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

cons :: Monad m => a -> ListT m a -> ListT m a Source #

Prepend an element.

fromFoldable :: (Monad m, Foldable f) => f a -> ListT m a Source #

Construct from any foldable.

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.

repeat :: Monad m => a -> ListT m a Source #

Produce an infinite stream.

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.

drop :: Monad m => Int -> ListT m a -> ListT m a Source #

A transformation, reproducing the behaviour of Data.List.drop.

slice :: Monad m => Int -> ListT m a -> ListT m [a] Source #

A transformation, which slices a list into chunks of the specified length.