Add explicit `{-# LANGUAGE CPP, PackageImports #-}` pragmas
[packages/haskell2010.git] / Data / List.hs
1 {-# LANGUAGE CPP, PackageImports #-}
2 #if __GLASGOW_HASKELL__ >= 701
3 {-# LANGUAGE Safe #-}
4 #endif
5
6 module Data.List (
7 -- * Basic functions
8
9 (++) -- :: [a] -> [a] -> [a]
10 , head -- :: [a] -> a
11 , last -- :: [a] -> a
12 , tail -- :: [a] -> [a]
13 , init -- :: [a] -> [a]
14 , null -- :: [a] -> Bool
15 , length -- :: [a] -> Int
16
17 -- * List transformations
18 , map -- :: (a -> b) -> [a] -> [b]
19 , reverse -- :: [a] -> [a]
20
21 , intersperse -- :: a -> [a] -> [a]
22 , intercalate -- :: [a] -> [[a]] -> [a]
23 , transpose -- :: [[a]] -> [[a]]
24
25 , subsequences -- :: [a] -> [[a]]
26 , permutations -- :: [a] -> [[a]]
27
28 -- * Reducing lists (folds)
29
30 , foldl -- :: (a -> b -> a) -> a -> [b] -> a
31 , foldl' -- :: (a -> b -> a) -> a -> [b] -> a
32 , foldl1 -- :: (a -> a -> a) -> [a] -> a
33 , foldl1' -- :: (a -> a -> a) -> [a] -> a
34 , foldr -- :: (a -> b -> b) -> b -> [a] -> b
35 , foldr1 -- :: (a -> a -> a) -> [a] -> a
36
37 -- ** Special folds
38
39 , concat -- :: [[a]] -> [a]
40 , concatMap -- :: (a -> [b]) -> [a] -> [b]
41 , and -- :: [Bool] -> Bool
42 , or -- :: [Bool] -> Bool
43 , any -- :: (a -> Bool) -> [a] -> Bool
44 , all -- :: (a -> Bool) -> [a] -> Bool
45 , sum -- :: (Num a) => [a] -> a
46 , product -- :: (Num a) => [a] -> a
47 , maximum -- :: (Ord a) => [a] -> a
48 , minimum -- :: (Ord a) => [a] -> a
49
50 -- * Building lists
51
52 -- ** Scans
53 , scanl -- :: (a -> b -> a) -> a -> [b] -> [a]
54 , scanl1 -- :: (a -> a -> a) -> [a] -> [a]
55 , scanr -- :: (a -> b -> b) -> b -> [a] -> [b]
56 , scanr1 -- :: (a -> a -> a) -> [a] -> [a]
57
58 -- ** Accumulating maps
59 , mapAccumL -- :: (a -> b -> (a,c)) -> a -> [b] -> (a,[c])
60 , mapAccumR -- :: (a -> b -> (a,c)) -> a -> [b] -> (a,[c])
61
62 -- ** Infinite lists
63 , iterate -- :: (a -> a) -> a -> [a]
64 , repeat -- :: a -> [a]
65 , replicate -- :: Int -> a -> [a]
66 , cycle -- :: [a] -> [a]
67
68 -- ** Unfolding
69 , unfoldr -- :: (b -> Maybe (a, b)) -> b -> [a]
70
71 -- * Sublists
72
73 -- ** Extracting sublists
74 , take -- :: Int -> [a] -> [a]
75 , drop -- :: Int -> [a] -> [a]
76 , splitAt -- :: Int -> [a] -> ([a], [a])
77
78 , takeWhile -- :: (a -> Bool) -> [a] -> [a]
79 , dropWhile -- :: (a -> Bool) -> [a] -> [a]
80 , span -- :: (a -> Bool) -> [a] -> ([a], [a])
81 , break -- :: (a -> Bool) -> [a] -> ([a], [a])
82
83 , stripPrefix -- :: Eq a => [a] -> [a] -> Maybe [a]
84
85 , group -- :: Eq a => [a] -> [[a]]
86
87 , inits -- :: [a] -> [[a]]
88 , tails -- :: [a] -> [[a]]
89
90 -- ** Predicates
91 , isPrefixOf -- :: (Eq a) => [a] -> [a] -> Bool
92 , isSuffixOf -- :: (Eq a) => [a] -> [a] -> Bool
93 , isInfixOf -- :: (Eq a) => [a] -> [a] -> Bool
94
95 -- * Searching lists
96
97 -- ** Searching by equality
98 , elem -- :: a -> [a] -> Bool
99 , notElem -- :: a -> [a] -> Bool
100 , lookup -- :: (Eq a) => a -> [(a,b)] -> Maybe b
101
102 -- ** Searching with a predicate
103 , find -- :: (a -> Bool) -> [a] -> Maybe a
104 , filter -- :: (a -> Bool) -> [a] -> [a]
105 , partition -- :: (a -> Bool) -> [a] -> ([a], [a])
106
107 -- * Indexing lists
108 -- | These functions treat a list @xs@ as a indexed collection,
109 -- with indices ranging from 0 to @'length' xs - 1@.
110
111 , (!!) -- :: [a] -> Int -> a
112
113 , elemIndex -- :: (Eq a) => a -> [a] -> Maybe Int
114 , elemIndices -- :: (Eq a) => a -> [a] -> [Int]
115
116 , findIndex -- :: (a -> Bool) -> [a] -> Maybe Int
117 , findIndices -- :: (a -> Bool) -> [a] -> [Int]
118
119 -- * Zipping and unzipping lists
120
121 , zip -- :: [a] -> [b] -> [(a,b)]
122 , zip3
123 , zip4, zip5, zip6, zip7
124
125 , zipWith -- :: (a -> b -> c) -> [a] -> [b] -> [c]
126 , zipWith3
127 , zipWith4, zipWith5, zipWith6, zipWith7
128
129 , unzip -- :: [(a,b)] -> ([a],[b])
130 , unzip3
131 , unzip4, unzip5, unzip6, unzip7
132
133 -- * Special lists
134
135 -- ** Functions on strings
136 , lines -- :: String -> [String]
137 , words -- :: String -> [String]
138 , unlines -- :: [String] -> String
139 , unwords -- :: [String] -> String
140
141 -- ** \"Set\" operations
142
143 , nub -- :: (Eq a) => [a] -> [a]
144
145 , delete -- :: (Eq a) => a -> [a] -> [a]
146 , (\\) -- :: (Eq a) => [a] -> [a] -> [a]
147
148 , union -- :: (Eq a) => [a] -> [a] -> [a]
149 , intersect -- :: (Eq a) => [a] -> [a] -> [a]
150
151 -- ** Ordered lists
152 , sort -- :: (Ord a) => [a] -> [a]
153 , insert -- :: (Ord a) => a -> [a] -> [a]
154
155 -- * Generalized functions
156
157 -- ** The \"@By@\" operations
158 -- | By convention, overloaded functions have a non-overloaded
159 -- counterpart whose name is suffixed with \`@By@\'.
160
161 -- *** User-supplied equality (replacing an @Eq@ context)
162 -- | The predicate is assumed to define an equivalence.
163 , nubBy -- :: (a -> a -> Bool) -> [a] -> [a]
164 , deleteBy -- :: (a -> a -> Bool) -> a -> [a] -> [a]
165 , deleteFirstsBy -- :: (a -> a -> Bool) -> [a] -> [a] -> [a]
166 , unionBy -- :: (a -> a -> Bool) -> [a] -> [a] -> [a]
167 , intersectBy -- :: (a -> a -> Bool) -> [a] -> [a] -> [a]
168 , groupBy -- :: (a -> a -> Bool) -> [a] -> [[a]]
169
170 -- *** User-supplied comparison (replacing an @Ord@ context)
171 -- | The function is assumed to define a total ordering.
172 , sortBy -- :: (a -> a -> Ordering) -> [a] -> [a]
173 , insertBy -- :: (a -> a -> Ordering) -> a -> [a] -> [a]
174 , maximumBy -- :: (a -> a -> Ordering) -> [a] -> a
175 , minimumBy -- :: (a -> a -> Ordering) -> [a] -> a
176
177 -- ** The \"@generic@\" operations
178 -- | The prefix \`@generic@\' indicates an overloaded function that
179 -- is a generalized version of a "Prelude" function.
180
181 , genericLength -- :: (Integral a) => [b] -> a
182 , genericTake -- :: (Integral a) => a -> [b] -> [b]
183 , genericDrop -- :: (Integral a) => a -> [b] -> [b]
184 , genericSplitAt -- :: (Integral a) => a -> [b] -> ([b], [b])
185 , genericIndex -- :: (Integral a) => [b] -> a -> b
186 , genericReplicate -- :: (Integral a) => a -> b -> [b]
187
188 ) where
189 import "base" Data.List hiding ( splitAt )