Module

Control.Monad.List.Trans

Package
purescript-transformers
Repository
purescript/purescript-transformers

This module defines the list monad transformer, ListT.

#ListT Source

newtype ListT :: (Type -> Type) -> Type -> Typenewtype 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 f a. Functor f => ListT f (Maybe a) -> ListT f a

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

#cons Source

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

Attach an element to the front of a list.

#drop Source

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

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

#dropWhile Source

dropWhile :: forall f a. 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 f a. 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 f a b. 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 f a b. 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 f a b. 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 f a b. 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 f a. Applicative f => f a -> ListT f a

Lift a computation from the base functor.

#head Source

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

Extract the first element of a list.

#iterate Source

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

Generate an infinite list by iterating a function.

#mapMaybe Source

mapMaybe :: forall f a b. 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 f a. Applicative f => ListT f a

The empty list.

#prepend Source

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

Prepend an element to a list.

#prepend' Source

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

Prepend an element to a lazily-evaluated list.

#repeat Source

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

Generate an infinite list by repeating a value.

#runListT Source

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

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

#runListTRec Source

runListTRec :: forall f a. 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 f a b. 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 f a. Applicative f => a -> ListT f a

Create a list with one element.

#tail Source

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

Extract all but the first element of a list.

#take Source

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

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

#takeWhile Source

takeWhile :: forall f a. 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 f a. 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 f a z. Monad f => (z -> f (Maybe (Tuple z a))) -> z -> ListT f a

Unfold a list using an effectful generator function.

#wrapEffect Source

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

Lift a computation from the base monad.

#wrapLazy Source

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

Defer evaluation of a list.

#zipWith Source

zipWith :: forall f a b c. 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 f a b c. 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 :: ((Type -> Type) -> Type -> Type) -> Constraintclass 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