Module

Control.Monad.List.Trans

Package
purescript-transformers
Repository
purescript/purescript-transformers

This module defines the list monad transformer, ListT.

#ListT Source

newtype ListT f a

The list monad transformer.

This monad transformer extends the base monad with non-determinism. That is, the transformed monad supports the same effects as the base monad but with multiple return values.

Constructors

Instances

#Step Source

data Step a s

The result of a single step in a ListT computation. Either:

  • Computation has finished (Done), or
  • A result has been returned, along with the next part of the computation (Yield).

The Skip constructor allows us to avoid traversing lists during certain operations.

Constructors

#catMaybes Source

catMaybes :: forall a f. Functor f => ListT f (Maybe a) -> ListT f a

Remove elements from a list which do not contain a value.

#cons Source

cons :: forall a f. Applicative f => Lazy a -> Lazy (ListT f a) -> ListT f a

Attach an element to the front of a list.

#drop Source

drop :: forall a f. Applicative f => Int -> ListT f a -> ListT f a

Drop a number of elements from the front of a list.

#dropWhile Source

dropWhile :: forall a f. Applicative f => (a -> Boolean) -> ListT f a -> ListT f a

Drop elements from the front of a list while a predicate holds.

#filter Source

filter :: forall a f. Functor f => (a -> Boolean) -> ListT f a -> ListT f a

Remove elements from a list for which a predicate fails to hold.

#foldl Source

foldl :: forall b a f. Monad f => (b -> a -> b) -> b -> ListT f a -> f b

Fold a list from the left, accumulating the result using the specified function.

#foldlRec Source

foldlRec :: forall b a f. MonadRec f => (b -> a -> b) -> b -> ListT f a -> f b

Fold a list from the left, accumulating the result using the specified function. Uses tail call optimization.

#foldl' Source

foldl' :: forall b a f. Monad f => (b -> a -> f b) -> b -> ListT f a -> f b

Fold a list from the left, accumulating the result (effectfully) using the specified function.

#foldlRec' Source

foldlRec' :: forall b a f. MonadRec f => (b -> a -> f b) -> b -> ListT f a -> f b

Fold a list from the left, accumulating the result (effectfully) using the specified function. Uses tail call optimization.

#fromEffect Source

fromEffect :: forall a f. Applicative f => f a -> ListT f a

Lift a computation from the base functor.

#head Source

head :: forall a f. Monad f => ListT f a -> f (Maybe a)

Extract the first element of a list.

#iterate Source

iterate :: forall a f. Monad f => (a -> a) -> a -> ListT f a

Generate an infinite list by iterating a function.

#mapMaybe Source

mapMaybe :: forall b a f. Functor f => (a -> Maybe b) -> ListT f a -> ListT f b

Apply a function to the elements of a list, keeping only those return values which contain a result.

#nil Source

nil :: forall a f. Applicative f => ListT f a

The empty list.

#prepend Source

prepend :: forall a f. Applicative f => a -> ListT f a -> ListT f a

Prepend an element to a list.

#prepend' Source

prepend' :: forall a f. Applicative f => a -> Lazy (ListT f a) -> ListT f a

Prepend an element to a lazily-evaluated list.

#repeat Source

repeat :: forall a f. Monad f => a -> ListT f a

Generate an infinite list by repeating a value.

#runListT Source

runListT :: forall a f. Monad f => ListT f a -> f Unit

Drain a ListT, running it to completion and discarding all values.

#runListTRec Source

runListTRec :: forall a f. MonadRec f => ListT f a -> f Unit

Drain a ListT, running it to completion and discarding all values. Stack safe: Uses tail call optimization.

#scanl Source

scanl :: forall b a f. Monad f => (b -> a -> b) -> b -> ListT f a -> ListT f b

Fold a list from the left, accumulating the list of results using the specified function.

#singleton Source

singleton :: forall a f. Applicative f => a -> ListT f a

Create a list with one element.

#tail Source

tail :: forall a f. Monad f => ListT f a -> f (Maybe (ListT f a))

Extract all but the first element of a list.

#take Source

take :: forall a f. Applicative f => Int -> ListT f a -> ListT f a

Take a number of elements from the front of a list.

#takeWhile Source

takeWhile :: forall a f. Applicative f => (a -> Boolean) -> ListT f a -> ListT f a

Take elements from the front of a list while a predicate holds.

#uncons Source

uncons :: forall a f. Monad f => ListT f a -> f (Maybe (Tuple a (ListT f a)))

Perform the first step of a computation in the ListT monad.

#unfold Source

unfold :: forall z a f. Monad f => (z -> f (Maybe (Tuple z a))) -> z -> ListT f a

Unfold a list using an effectful generator function.

#wrapEffect Source

wrapEffect :: forall a f. Functor f => f (ListT f a) -> ListT f a

Lift a computation from the base monad.

#wrapLazy Source

wrapLazy :: forall a f. Applicative f => Lazy (ListT f a) -> ListT f a

Defer evaluation of a list.

#zipWith Source

zipWith :: forall c b a f. Monad f => (a -> b -> c) -> ListT f a -> ListT f b -> ListT f c

Zip the elements of two lists, combining elements at the same position from each list.

#zipWith' Source

zipWith' :: forall c b a f. Monad f => (a -> b -> f c) -> ListT f a -> ListT f b -> ListT f c

Zip the elements of two lists, combining elements at the same position from each list.

Re-exports from Control.Monad.Trans.Class

#MonadTrans Source

class MonadTrans t  where

The MonadTrans type class represents monad transformers.

A monad transformer is a type constructor of kind (* -> *) -> * -> *, which takes a Monad as its first argument, and returns another Monad.

This allows us to add additional effects to an existing monad. By iterating this process, we create monad transformer stacks, which contain all of the effects required for a particular computation.

The laws state that lift is a Monad morphism.

Laws:

  • lift (pure a) = pure a
  • lift (do { x <- m ; y }) = do { x <- lift m ; lift y }

Members