rio-0.1.18.0: A standard library for Haskell

Safe Haskell | Safe
Language | Haskell2010

RIO.List

Contents

- Basic functions
- List transformations
- Reducing lists (folds)
  - Special folds
- Building lists
  - Scans
  - Accumulating maps
  - Infinite lists
  - Unfolding
- Sublists
  - Extracting sublists
  - Predicates
- Searching lists
  - Searching by equality
  - Searching with a predicate
- Indexing lists
- Zipping and unzipping lists
- Special lists
  - Functions on strings
  - "Set" operations
  - Ordered lists
- Generalized functions
  - The "`By`" operations
    - User-supplied equality (replacing an `Eq` context)
    - User-supplied comparison (replacing an `Ord` context)
  - The "`generic`" operations

Description

`List`. Import as:

    import qualified RIO.List as L

This module does not export any partial functions. For those, see RIO.List.Partial

Synopsis

- (++) :: [a] -> [a] -> [a]
- uncons :: [a] -> Maybe (a, [a])
- null :: Foldable t => t a -> Bool
- length :: Foldable t => t a -> Int
- headMaybe :: [a] -> Maybe a
- lastMaybe :: [a] -> Maybe a
- tailMaybe :: [a] -> Maybe [a]
- initMaybe :: [a] -> Maybe [a]
- map :: (a -> b) -> [a] -> [b]
- reverse :: [a] -> [a]
- intersperse :: a -> [a] -> [a]
- intercalate :: [a] -> [[a]] -> [a]
- transpose :: [[a]] -> [[a]]
- subsequences :: [a] -> [[a]]
- permutations :: [a] -> [[a]]
- foldl :: Foldable t => (b -> a -> b) -> b -> t a -> b
- foldl' :: Foldable t => (b -> a -> b) -> b -> t a -> b
- foldr :: Foldable t => (a -> b -> b) -> b -> t a -> b
- concat :: Foldable t => t [a] -> [a]
- concatMap :: Foldable t => (a -> [b]) -> t a -> [b]
- and :: Foldable t => t Bool -> Bool
- or :: Foldable t => t Bool -> Bool
- any :: Foldable t => (a -> Bool) -> t a -> Bool
- all :: Foldable t => (a -> Bool) -> t a -> Bool
- sum :: (Foldable t, Num a) => t a -> a
- product :: (Foldable t, Num a) => t a -> a
- maximumMaybe :: (Ord a, Foldable t) => t a -> Maybe a
- minimumMaybe :: (Ord a, Foldable t) => t a -> Maybe a
- maximumByMaybe :: Foldable t => (a -> a -> Ordering) -> t a -> Maybe a
- minimumByMaybe :: Foldable t => (a -> a -> Ordering) -> t a -> Maybe a
- scanl :: (b -> a -> b) -> b -> [a] -> [b]
- scanl' :: (b -> a -> b) -> b -> [a] -> [b]
- scanr :: (a -> b -> b) -> b -> [a] -> [b]
- scanl1 :: (a -> a -> a) -> [a] -> [a]
- scanr1 :: (a -> a -> a) -> [a] -> [a]
- mapAccumL :: Traversable t => (a -> b -> (a, c)) -> a -> t b -> (a, t c)
- mapAccumR :: Traversable t => (a -> b -> (a, c)) -> a -> t b -> (a, t c)
- iterate :: (a -> a) -> a -> [a]
- repeat :: a -> [a]
- replicate :: Int -> a -> [a]
- cycle :: [a] -> [a]
- unfoldr :: (b -> Maybe (a, b)) -> b -> [a]
- take :: Int -> [a] -> [a]
- drop :: Int -> [a] -> [a]
- splitAt :: Int -> [a] -> ([a], [a])
- takeWhile :: (a -> Bool) -> [a] -> [a]
- dropWhile :: (a -> Bool) -> [a] -> [a]
- dropWhileEnd :: (a -> Bool) -> [a] -> [a]
- span :: (a -> Bool) -> [a] -> ([a], [a])
- break :: (a -> Bool) -> [a] -> ([a], [a])
- stripPrefix :: Eq a => [a] -> [a] -> Maybe [a]
- stripSuffix :: Eq a => [a] -> [a] -> Maybe [a]
- dropPrefix :: Eq a => [a] -> [a] -> [a]
- dropSuffix :: Eq a => [a] -> [a] -> [a]
- group :: Eq a => [a] -> [[a]]
- inits :: [a] -> [[a]]
- tails :: [a] -> [[a]]
- isPrefixOf :: Eq a => [a] -> [a] -> Bool
- isSuffixOf :: Eq a => [a] -> [a] -> Bool
- isInfixOf :: Eq a => [a] -> [a] -> Bool
- isSubsequenceOf :: Eq a => [a] -> [a] -> Bool
- elem :: (Foldable t, Eq a) => a -> t a -> Bool
- notElem :: (Foldable t, Eq a) => a -> t a -> Bool
- lookup :: Eq a => a -> [(a, b)] -> Maybe b
- find :: Foldable t => (a -> Bool) -> t a -> Maybe a
- filter :: (a -> Bool) -> [a] -> [a]
- partition :: (a -> Bool) -> [a] -> ([a], [a])
- elemIndex :: Eq a => a -> [a] -> Maybe Int
- elemIndices :: Eq a => a -> [a] -> [Int]
- findIndex :: (a -> Bool) -> [a] -> Maybe Int
- findIndices :: (a -> Bool) -> [a] -> [Int]
- zip :: [a] -> [b] -> [(a, b)]
- zip3 :: [a] -> [b] -> [c] -> [(a, b, c)]
- zip4 :: [a] -> [b] -> [c] -> [d] -> [(a, b, c, d)]
- zip5 :: [a] -> [b] -> [c] -> [d] -> [e] -> [(a, b, c, d, e)]
- zip6 :: [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [(a, b, c, d, e, f)]
- zip7 :: [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> [(a, b, c, d, e, f, g)]
- zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
- zipWith3 :: (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]
- zipWith4 :: (a -> b -> c -> d -> e) -> [a] -> [b] -> [c] -> [d] -> [e]
- zipWith5 :: (a -> b -> c -> d -> e -> f) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f]
- zipWith6 :: (a -> b -> c -> d -> e -> f -> g) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g]
- zipWith7 :: (a -> b -> c -> d -> e -> f -> g -> h) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> [h]
- unzip :: [(a, b)] -> ([a], [b])
- unzip3 :: [(a, b, c)] -> ([a], [b], [c])
- unzip4 :: [(a, b, c, d)] -> ([a], [b], [c], [d])
- unzip5 :: [(a, b, c, d, e)] -> ([a], [b], [c], [d], [e])
- unzip6 :: [(a, b, c, d, e, f)] -> ([a], [b], [c], [d], [e], [f])
- unzip7 :: [(a, b, c, d, e, f, g)] -> ([a], [b], [c], [d], [e], [f], [g])
- lines :: String -> [String]
- linesCR :: String -> [String]
- words :: String -> [String]
- unlines :: [String] -> String
- unwords :: [String] -> String
- nub :: Eq a => [a] -> [a]
- delete :: Eq a => a -> [a] -> [a]
- (\\) :: Eq a => [a] -> [a] -> [a]
- union :: Eq a => [a] -> [a] -> [a]
- intersect :: Eq a => [a] -> [a] -> [a]
- sort :: Ord a => [a] -> [a]
- sortOn :: Ord b => (a -> b) -> [a] -> [a]
- insert :: Ord a => a -> [a] -> [a]
- nubBy :: (a -> a -> Bool) -> [a] -> [a]
- deleteBy :: (a -> a -> Bool) -> a -> [a] -> [a]
- deleteFirstsBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]
- unionBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]
- intersectBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]
- groupBy :: (a -> a -> Bool) -> [a] -> [[a]]
- sortBy :: (a -> a -> Ordering) -> [a] -> [a]
- insertBy :: (a -> a -> Ordering) -> a -> [a] -> [a]
- genericLength :: Num i => [a] -> i
- genericTake :: Integral i => i -> [a] -> [a]
- genericDrop :: Integral i => i -> [a] -> [a]
- genericSplitAt :: Integral i => i -> [a] -> ([a], [a])
- genericIndex :: Integral i => [a] -> i -> a
- genericReplicate :: Integral i => i -> a -> [a]

# Basic functions

(++) :: [a] -> [a] -> [a] #

uncons :: [a] -> Maybe (a, [a]) #

null :: Foldable t => t a -> Bool #

length :: Foldable t => t a -> Int #

headMaybe :: [a] -> Maybe a Source #

Since: 0.1.3.0

lastMaybe :: [a] -> Maybe a Source #

Since: 0.1.3.0

tailMaybe :: [a] -> Maybe [a] Source #

Since: 0.1.3.0

initMaybe :: [a] -> Maybe [a] Source #

Since: 0.1.3.0

# List transformations

map :: (a -> b) -> [a] -> [b] #

reverse :: [a] -> [a] #

intersperse :: a -> [a] -> [a] #

intercalate :: [a] -> [[a]] -> [a] #

transpose :: [[a]] -> [[a]] #

subsequences :: [a] -> [[a]] #

permutations :: [a] -> [[a]] #

# Reducing lists (folds)

foldl :: Foldable t => (b -> a -> b) -> b -> t a -> b #

foldl' :: Foldable t => (b -> a -> b) -> b -> t a -> b #

foldr :: Foldable t => (a -> b -> b) -> b -> t a -> b #

## Special folds

concat :: Foldable t => t [a] -> [a] #

concatMap :: Foldable t => (a -> [b]) -> t a -> [b] #

and :: Foldable t => t Bool -> Bool #

or :: Foldable t => t Bool -> Bool #

any :: Foldable t => (a -> Bool) -> t a -> Bool #

all :: Foldable t => (a -> Bool) -> t a -> Bool #

sum :: (Foldable t, Num a) => t a -> a #

product :: (Foldable t, Num a) => t a -> a #

maximumMaybe :: (Ord a, Foldable t) => t a -> Maybe a Source #

Since: 0.1.3.0

minimumMaybe :: (Ord a, Foldable t) => t a -> Maybe a Source #

Since: 0.1.3.0

maximumByMaybe :: Foldable t => (a -> a -> Ordering) -> t a -> Maybe a Source #

Since: 0.1.3.0

minimumByMaybe :: Foldable t => (a -> a -> Ordering) -> t a -> Maybe a Source #

Since: 0.1.3.0

# Building lists

## Scans

scanl :: (b -> a -> b) -> b -> [a] -> [b] #

scanl' :: (b -> a -> b) -> b -> [a] -> [b] #

scanr :: (a -> b -> b) -> b -> [a] -> [b] #

scanl1 :: (a -> a -> a) -> [a] -> [a] #

scanr1 :: (a -> a -> a) -> [a] -> [a] #

## Accumulating maps

mapAccumL :: Traversable t => (a -> b -> (a, c)) -> a -> t b -> (a, t c) #

mapAccumR :: Traversable t => (a -> b -> (a, c)) -> a -> t b -> (a, t c) #

## Infinite lists

iterate :: (a -> a) -> a -> [a] #

repeat :: a -> [a] #

replicate :: Int -> a -> [a] #

cycle :: [a] -> [a] #

## Unfolding

unfoldr :: (b -> Maybe (a, b)) -> b -> [a] #

# Sublists

## Extracting sublists

take :: Int -> [a] -> [a] #

drop :: Int -> [a] -> [a] #

splitAt :: Int -> [a] -> ([a], [a]) #

takeWhile :: (a -> Bool) -> [a] -> [a] #

dropWhile :: (a -> Bool) -> [a] -> [a] #

dropWhileEnd :: (a -> Bool) -> [a] -> [a] #

span :: (a -> Bool) -> [a] -> ([a], [a]) #

break :: (a -> Bool) -> [a] -> ([a], [a]) #

stripPrefix :: Eq a => [a] -> [a] -> Maybe [a] #

stripSuffix Source #

Arguments

:: Eq a |
=> [a] | suffix
-> [a] |
-> Maybe [a] |

Remove the suffix from the given list, if present

Since: 0.0.0

dropPrefix Source #

Arguments

:: Eq a |
=> [a] | prefix
-> [a] |
-> [a] |

Drop prefix if present, otherwise return original list.

Since: 0.0.0.0

dropSuffix Source #

Arguments

:: Eq a |
=> [a] | suffix
-> [a] |
-> [a] |

Drop prefix if present, otherwise return original list.

Since: 0.0.0.0

group :: Eq a => [a] -> [[a]] #

inits :: [a] -> [[a]] #

tails :: [a] -> [[a]] #

## Predicates

isPrefixOf :: Eq a => [a] -> [a] -> Bool #

isSuffixOf :: Eq a => [a] -> [a] -> Bool #

isInfixOf :: Eq a => [a] -> [a] -> Bool #

isSubsequenceOf :: Eq a => [a] -> [a] -> Bool #

# Searching lists

## Searching by equality

elem :: (Foldable t, Eq a) => a -> t a -> Bool #

notElem :: (Foldable t, Eq a) => a -> t a -> Bool #

lookup :: Eq a => a -> [(a, b)] -> Maybe b #

## Searching with a predicate

find :: Foldable t => (a -> Bool) -> t a -> Maybe a #

filter :: (a -> Bool) -> [a] -> [a] #

partition :: (a -> Bool) -> [a] -> ([a], [a]) #

# Indexing lists

These functions treat a list `xs` as a indexed collection, with indices ranging from 0 to ``length` xs - 1`.

elemIndex :: Eq a => a -> [a] -> Maybe Int #

elemIndices :: Eq a => a -> [a] -> [Int] #

findIndex :: (a -> Bool) -> [a] -> Maybe Int #

findIndices :: (a -> Bool) -> [a] -> [Int] #

# Zipping and unzipping lists

zip :: [a] -> [b] -> [(a, b)] #

zip3 :: [a] -> [b] -> [c] -> [(a, b, c)] #

zip4 :: [a] -> [b] -> [c] -> [d] -> [(a, b, c, d)] #

zip5 :: [a] -> [b] -> [c] -> [d] -> [e] -> [(a, b, c, d, e)] #

zip6 :: [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [(a, b, c, d, e, f)] #

zip7 :: [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> [(a, b, c, d, e, f, g)] #

zipWith :: (a -> b -> c) -> [a] -> [b] -> [c] #

zipWith3 :: (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d] #

zipWith4 :: (a -> b -> c -> d -> e) -> [a] -> [b] -> [c] -> [d] -> [e] #

zipWith5 :: (a -> b -> c -> d -> e -> f) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f] #

zipWith6 :: (a -> b -> c -> d -> e -> f -> g) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] #

zipWith7 :: (a -> b -> c -> d -> e -> f -> g -> h) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> [h] #

unzip :: [(a, b)] -> ([a], [b]) #

unzip3 :: [(a, b, c)] -> ([a], [b], [c]) #

unzip4 :: [(a, b, c, d)] -> ([a], [b], [c], [d]) #

unzip5 :: [(a, b, c, d, e)] -> ([a], [b], [c], [d], [e]) #

unzip6 :: [(a, b, c, d, e, f)] -> ([a], [b], [c], [d], [e], [f]) #

unzip7 :: [(a, b, c, d, e, f, g)] -> ([a], [b], [c], [d], [e], [f], [g]) #

# Special lists

## Functions on strings

lines :: String -> [String] #

linesCR :: String -> [String] Source #

`linesCR` breaks a `String` up into a list of `String`s at newline `Char`s. It is very similar to `lines`, but it also removes any trailing `'r'` `Char`s. The resulting `String` values do not contain newlines or trailing `'r'` characters.

Since: 0.1.0.0

words :: String -> [String] #

unlines :: [String] -> String #

unwords :: [String] -> String #

## "Set" operations

nub :: Eq a => [a] -> [a] #

delete :: Eq a => a -> [a] -> [a] #

(\\) :: Eq a => [a] -> [a] -> [a] #

union :: Eq a => [a] -> [a] -> [a] #

intersect :: Eq a => [a] -> [a] -> [a] #

## Ordered lists

sort :: Ord a => [a] -> [a] #

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

insert :: Ord a => a -> [a] -> [a] #

# Generalized functions

## The "`By`" operations

By convention, overloaded functions have a non-overloaded counterpart whose name is suffixed with ``By`'.

It is often convenient to use these functions together with `on`, for instance ``sortBy` (`compare` `on` `fst`)`.

### User-supplied equality (replacing an `Eq` context)

The predicate is assumed to define an equivalence.

nubBy :: (a -> a -> Bool) -> [a] -> [a] #

deleteBy :: (a -> a -> Bool) -> a -> [a] -> [a] #

deleteFirstsBy :: (a -> a -> Bool) -> [a] -> [a] -> [a] #

unionBy :: (a -> a -> Bool) -> [a] -> [a] -> [a] #

intersectBy :: (a -> a -> Bool) -> [a] -> [a] -> [a] #

groupBy :: (a -> a -> Bool) -> [a] -> [[a]] #

### User-supplied comparison (replacing an `Ord` context)

The function is assumed to define a total ordering.

sortBy :: (a -> a -> Ordering) -> [a] -> [a] #

insertBy :: (a -> a -> Ordering) -> a -> [a] -> [a] #

## The "`generic`" operations

The prefix ``generic`' indicates an overloaded function that is a generalized version of a Prelude function.

genericLength :: Num i => [a] -> i #

genericTake :: Integral i => i -> [a] -> [a] #

genericDrop :: Integral i => i -> [a] -> [a] #

genericSplitAt :: Integral i => i -> [a] -> ([a], [a]) #

genericIndex :: Integral i => [a] -> i -> a #

genericReplicate :: Integral i => i -> a -> [a] #