List-0.4.3: List monad transformer and class

Data.List.Class

Description

The `List` class and actions for lists

Synopsis

# Documentation

The List typeclass

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

Associated Types

type ItemM l :: * -> *Source

Methods

runList :: l a -> ItemM l (ListItem l a)Source

joinL :: ItemM l (l a) -> l aSource

Transform an action returning a list to the returned list

``` > joinL \$ Identity "hello"
"hello"
```

cons :: a -> l a -> l aSource

cons. Can be derived from MonadPlus but is part of class for performance.

Instances

 List [] Monad m => List (ListT m)

data ListItem l a Source

Constructors

 Nil Cons FieldsheadL :: a tailL :: l a

Instances

 Functor m => Functor (ListItem m) (Eq a, Eq (l a)) => Eq (ListItem l a) (Ord a, Ord (l a)) => Ord (ListItem l a) (Read a, Read (l a)) => Read (ListItem l a) (Show a, Show (l a)) => Show (ListItem l a)

fromList :: List l => [a] -> l aSource

Convert a list to a `MonadPlus`

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

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

``` > filter (> 5) (Just 3)
Nothing
```

Standard list operations

repeat :: List l => a -> l aSource

take :: List l => Int -> l a -> l aSource

takeWhile :: List l => (a -> Bool) -> l a -> l aSource

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

scanl :: List l => (a -> b -> a) -> a -> l b -> l aSource

scanl1 :: List l => (a -> a -> a) -> l a -> l aSource

transpose :: List l => l (l a) -> l (l a)Source

zip :: List l => l a -> l b -> l (a, b)Source

zipWith :: List l => (a -> b -> c) -> l a -> l b -> l cSource

concat :: List l => l [a] -> l aSource

Generalized `concat`

For `List l => l (l a) -> l a` use `join`

concatMap :: List l => (a -> [b]) -> l a -> l bSource

Genereralized `concatMap`

For `List l => (a -> l b) -> l a -> l b` use `=<<` (monadic bind)

tail :: List l => l a -> l aSource

enumFrom :: (List l, Enum a) => a -> l aSource

enumFromTo :: (List l, Enum a) => a -> a -> l aSource

catMaybes :: List l => l (Maybe a) -> l aSource

mapMaybe :: List l => (a -> Maybe b) -> l a -> l bSource

Non standard List operations

foldrL :: List l => (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.

foldlL :: List l => (a -> b -> a) -> a -> l b -> ItemM l aSource

An action to do foldl for `List`s

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

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"]
```

execute :: List l => l a -> ItemM l ()Source

Execute the monadic actions in a `List`

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]
```

mapL :: List l => (a -> ItemM l b) -> l a -> l bSource

filterL :: List l => (a -> ItemM l Bool) -> l a -> l aSource

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

Monadic version of iterate. Can be used to produce trees given a children of node function.

``` import Data.List.Tree (bfsLayers)
take 3 \$ bfsLayers (iterateM (\i -> [i*2, i*2+1])  :: ListT [] Int)
[,[2,3],[4,5,6,7]]
```

takeWhileM :: List l => (a -> ItemM l Bool) -> l a -> l aSource

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

splitAtM :: List l => Int -> l a -> ItemM l ([a], l a)Source

Monadic variant of splitAt. Consumes x items from the list and return them with the remaining monadic list.

sortOn :: Ord b => (a -> b) -> [a] -> [a]Source

Convert between List types

transformListMonad :: (List l, List k) => (ItemM l (k a) -> ItemM k (k a)) -> 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"
```

listStateJoin :: (List l, List k, ItemM l ~ StateT s (ItemM k)) => l a -> ItemM l (k a)Source

listStateJoin can transform a `ListT (StateT s m) a` to a `StateT s m (ListT m a)`.

When iterating a list, a state is already maintained and passed along in the form of the location along the list. This joins the inner `StateT s` into the list. The list will fork the state given to it and won't share its changes.
{"ft_lang_label":"__label__en","ft_lang_prob":0.6607517,"math_prob":0.84835863,"size":5336,"snap":"2019-51-2020-05","text_gpt3_token_len":1815,"char_repetition_ratio":0.2891973,"word_repetition_ratio":0.42532468,"special_character_ratio":0.40592203,"punctuation_ratio":0.1619965,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97939295,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-12-16T06:13:15Z\",\"WARC-Record-ID\":\"<urn:uuid:129ca71f-3664-477b-bc81-15c0b978031c>\",\"Content-Length\":\"31996\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:194ee389-2c95-43e3-9270-3ee61d4f09cf>\",\"WARC-Concurrent-To\":\"<urn:uuid:936efbda-faed-4e19-84e9-c0156c15c8c2>\",\"WARC-IP-Address\":\"151.101.248.68\",\"WARC-Target-URI\":\"https://hackage.haskell.org/package/List-0.4.3/docs/Data-List-Class.html\",\"WARC-Payload-Digest\":\"sha1:XZPYJCTBN6NIFDD6MCM3ECDUUQ4HCT4V\",\"WARC-Block-Digest\":\"sha1:VAWWCWINLSEO2YAT2ZUSRBPND7CBSJPP\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-51/CC-MAIN-2019-51_segments_1575541317967.94_warc_CC-MAIN-20191216041840-20191216065840-00316.warc.gz\"}"}