The `List`

class and actions for lists

- class (MonadPlus l, Monad (ItemM l)) => List l where
- cons :: MonadPlus m => a -> m a -> m a
- fromList :: MonadPlus m => [a] -> m a
- filter :: MonadPlus m => (a -> Bool) -> m a -> m a
- repeat :: MonadPlus m => a -> m a
- takeWhile :: List l => (a -> Bool) -> l a -> l a
- genericTake :: (Integral i, List l) => i -> l a -> l a
- scanl :: List l => (a -> b -> a) -> a -> l b -> l a
- transpose :: List l => l (l a) -> l (l a)
- zip :: List l => l a -> l b -> l (a, b)
- zipWith :: List l => (a -> b -> c) -> l a -> l b -> l c
- foldlL :: List l => (a -> b -> a) -> a -> l b -> ItemM l a
- toList :: List l => l a -> ItemM l [a]
- lengthL :: (Integral i, List l) => l a -> ItemM l i
- lastL :: List l => l a -> ItemM l a
- merge2On :: (Ord b, List l) => (a -> b) -> l a -> l a -> l a
- mergeOn :: (Ord b, List l) => (a -> b) -> l (l a) -> l a
- execute :: List l => l a -> ItemM l ()
- joinM :: List l => l (ItemM l a) -> l a
- convList :: (ItemM l ~ ItemM k, List l, List k) => l a -> k a
- transformListMonad :: (List l, List k) => (forall x. ItemM l x -> ItemM k x) -> l a -> k a
- liftListMonad :: (MonadTrans t, Monad (t (ItemM l)), List l) => l a -> ListT (t (ItemM l)) a

# Documentation

The List typeclass

class (MonadPlus l, Monad (ItemM l)) => List l whereSource

A class for list types. Every list has an underlying monad.

joinL :: ItemM l (l b) -> l bSource

Transform an action returning a list to the returned list

> joinL $ Identity "hello" "hello"

foldrL :: (a -> ItemM l b -> ItemM l b) -> ItemM l b -> l a -> ItemM l bSource

foldr for `List`

s.
the result and 'right side' values are monadic actions.

toListT :: l a -> ListT (ItemM l) aSource

Convert to a `ListT`

.

Can be done with a foldrL but included in type-class for efficiency.

fromListT :: ListT (ItemM l) a -> l aSource

Convert from a `ListT`

.

Can be done with a foldrL but included in type-class for efficiency.

List operations for MonadPlus

fromList :: MonadPlus m => [a] -> m aSource

Convert a list to a `MonadPlus`

> fromList [] :: Maybe Int Nothing > fromList [5] :: Maybe Int Just 5

filter :: MonadPlus m => (a -> Bool) -> m a -> m aSource

filter for any MonadPlus

> filter (> 5) (Just 3) Nothing

Standard list operations

genericTake :: (Integral i, List l) => i -> l a -> l aSource

Non standard List operations

toList :: List l => l a -> ItemM l [a]Source

An action to transform a `List`

to a list

> runIdentity $ toList "hello!" "hello!"

lengthL :: (Integral i, List l) => l a -> ItemM l iSource

Consume a list (execute its actions) and return its length

> runIdentity $ lengthL [1,2,3] 3

lastL :: List l => l a -> ItemM l aSource

Consume all items and return the last one

> runIdentity $ lastL "hello" 'o'

merge2On :: (Ord b, List l) => (a -> b) -> l a -> l a -> l aSource

Merge two lists sorted by a criteria given the criteria

> merge2On id "01568" "239" "01235689"

mergeOn :: (Ord b, List l) => (a -> b) -> l (l a) -> l aSource

Merge many lists sorted by a criteria given the criteria

> mergeOn length [["hi", "hey", "hello"], ["cat", "falcon"], ["banana", "cucumber"]] ["hi","cat","hey","hello","banana","falcon","cucumber"]

Operations useful for monadic lists

joinM :: List l => l (ItemM l a) -> l aSource

Transform a list of actions to a list of their results

> joinM [Identity 4, Identity 7] [4,7]

Convert between List types

convList :: (ItemM l ~ ItemM k, List l, List k) => l a -> k aSource

Convert between lists with the same underlying monad

transformListMonad :: (List l, List k) => (forall x. ItemM l x -> ItemM k x) -> l a -> k aSource

Transform the underlying monad of a list given a way to transform the monad

> import Data.List.Tree (bfs) > bfs (transformListMonad (\(Identity x) -> [x, x]) "hey" :: ListT [] Char) "hheeeeyyyyyyyy"

liftListMonad :: (MonadTrans t, Monad (t (ItemM l)), List l) => l a -> ListT (t (ItemM l)) aSource

Lift the underlying monad of a list and transform it to a ListT.

Doing plain 'transformListMonad lift' instead doesn't give the compiler the same knowledge about the types.