Ticket #1611: Map.patch

File Map.patch, 43.8 KB (added by Andriy, 8 years ago)

The same patch against the trunk

Line 
1
2New patches:
3
4[Improved, fixed documentation, some minor issues for Data.Map, Data.IntMap. Added examples.
5[email protected]**20080204184756] {
6hunk ./Data/IntMap.hs 6
7+--                (c) Andriy Palamarchuk 2008
8hunk ./Data/IntMap.hs 34
9+-- Operation comments contain the operation time complexity in
10+-- the Big-O notation <http://en.wikipedia.org/wiki/Big_O_notation>.
11hunk ./Data/IntMap.hs 223
12+--
13+-- > fromList [(5,'a'), (3,'b')] ! 1    Error: element not in the map
14+-- > fromList [(5,'a'), (3,'b')] ! 5 == 'a'
15hunk ./Data/IntMap.hs 230
16--- | /O(n+m)/. See 'difference'.
17+-- | Same as 'difference'.
18hunk ./Data/IntMap.hs 278
19+--
20+-- > Data.IntMap.null (empty)           == True
21+-- > Data.IntMap.null (singleton 1 'a') == False
22+
23hunk ./Data/IntMap.hs 287
24+--
25+-- > size empty                                   == 0
26+-- > size (singleton 1 'a')                       == 1
27+-- > size (fromList([(1,'a'), (2,'c'), (3,'b')])) == 3
28hunk ./Data/IntMap.hs 299
29+--
30+-- > member 5 (fromList [(5,'a'), (3,'b')]) == True
31+-- > member 1 (fromList [(5,'a'), (3,'b')]) == False
32+
33hunk ./Data/IntMap.hs 310
34+--
35+-- > notMember 5 (fromList [(5,'a'), (3,'b')]) == False
36+-- > notMember 1 (fromList [(5,'a'), (3,'b')]) == True
37+
38hunk ./Data/IntMap.hs 317
39--- | /O(min(n,W))/. Lookup the value at a key in the map.
40+-- | /O(min(n,W))/. Lookup the value at a key in the map. See also 'Data.Map.lookup'.
41hunk ./Data/IntMap.hs 348
42+--
43+-- > findWithDefault 'x' 1 (fromList [(5,'a'), (3,'b')]) == 'x'
44+-- > findWithDefault 'x' 5 (fromList [(5,'a'), (3,'b')]) == 'a'
45+
46hunk ./Data/IntMap.hs 362
47+--
48+-- > empty      == fromList []
49+-- > size empty == 0
50+
51hunk ./Data/IntMap.hs 371
52+--
53+-- > singleton 1 'a'        == fromList [(1, 'a')]
54+-- > size (singleton 1 'a') == 1
55+
56hunk ./Data/IntMap.hs 386
57+--
58+-- > insert 5 'x' (fromList [(5,'a'), (3,'b')]) == fromList [(3, 'b'), (5, 'x')]
59+-- > insert 7 'x' (fromList [(5,'a'), (3,'b')]) == fromList [(3, 'b'), (5, 'a'), (7, 'x')]
60+-- > insert 5 'x' empty                         == singleton 5 'x'
61+
62hunk ./Data/IntMap.hs 409
63+--
64+-- > insertWith (++) 5 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "xxxa")]
65+-- > insertWith (++) 7 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "xxx")]
66+-- > insertWith (++) 5 "xxx" empty                         == singleton 5 "xxx"
67+
68hunk ./Data/IntMap.hs 423
69+--
70+-- > let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value
71+-- > insertWithKey f 5 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:xxx|a")]
72+-- > insertWithKey f 7 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "xxx")]
73+-- > insertWithKey f 5 "xxx" empty                         == singleton 5 "xxx"
74+
75hunk ./Data/IntMap.hs 445
76+--
77+-- > let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value
78+-- > insertLookupWithKey f 5 "xxx" (fromList [(5,"a"), (3,"b")]) == (Just "a", fromList [(3, "b"), (5, "5:xxx|a")])
79+-- > insertLookupWithKey f 7 "xxx" (fromList [(5,"a"), (3,"b")]) == (Nothing,  fromList [(3, "b"), (5, "a"), (7, "xxx")])
80+-- > insertLookupWithKey f 5 "xxx" empty                         == (Nothing,  singleton 5 "xxx")
81+--
82+-- This is how to define @insertLookup@ using @insertLookupWithKey@:
83+--
84+-- > let insertLookup kx x t = insertLookupWithKey (\_ a _ -> a) kx x t
85+-- > insertLookup 5 "x" (fromList [(5,"a"), (3,"b")]) == (Just "a", fromList [(3, "b"), (5, "x")])
86+-- > insertLookup 7 "x" (fromList [(5,"a"), (3,"b")]) == (Nothing,  fromList [(3, "b"), (5, "a"), (7, "x")])
87+
88hunk ./Data/IntMap.hs 476
89+--
90+-- > delete 5 (fromList [(5,"a"), (3,"b")]) == singleton 3 "b"
91+-- > delete 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")]
92+-- > delete 5 empty                         == empty
93+
94hunk ./Data/IntMap.hs 495
95+--
96+-- > adjust ("new " ++) 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "new a")]
97+-- > adjust ("new " ++) 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")]
98+-- > adjust ("new " ++) 7 empty                         == empty
99+
100hunk ./Data/IntMap.hs 506
101+--
102+-- > let f key x = (show key) ++ ":new " ++ x
103+-- > adjustWithKey f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:new a")]
104+-- > adjustWithKey f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")]
105+-- > adjustWithKey f 7 empty                         == empty
106+
107hunk ./Data/IntMap.hs 519
108+--
109+-- > let f x = if x == "a" then Just "new a" else Nothing
110+-- > update f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "new a")]
111+-- > update f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")]
112+-- > update f 3 (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
113+
114hunk ./Data/IntMap.hs 532
115+--
116+-- > let f k x = if x == "a" then Just ((show k) ++ ":new a") else Nothing
117+-- > updateWithKey f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:new a")]
118+-- > updateWithKey f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")]
119+-- > updateWithKey f 3 (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
120+
121hunk ./Data/IntMap.hs 553
122+-- The function returns original value, if it is updated.
123+-- This is different behavior than 'Data.Map.updateLookupWithKey'.
124+-- Returns the original key value if the map entry is deleted.
125+--
126+-- > let f k x = if x == "a" then Just ((show k) ++ ":new a") else Nothing
127+-- > updateLookupWithKey f 5 (fromList [(5,"a"), (3,"b")]) == (Just "a", fromList [(3, "b"), (5, "5:new a")])
128+-- > updateLookupWithKey f 7 (fromList [(5,"a"), (3,"b")]) == (Nothing,  fromList [(3, "b"), (5, "a")])
129+-- > updateLookupWithKey f 3 (fromList [(5,"a"), (3,"b")]) == (Just "b", singleton 5 "a")
130+
131hunk ./Data/IntMap.hs 580
132--- In short : @'lookup' k ('alter' f k m) = f ('lookup' k m)@
133+-- In short : @'lookup' k ('alter' f k m) = f ('lookup' k m)@.
134hunk ./Data/IntMap.hs 605
135+--
136+-- > unions [(fromList [(5, "a"), (3, "b")]), (fromList [(5, "A"), (7, "C")]), (fromList [(5, "A3"), (3, "B3")])]
137+-- >     == fromList [(3, "b"), (5, "a"), (7, "C")]
138+-- > unions [(fromList [(5, "A3"), (3, "B3")]), (fromList [(5, "A"), (7, "C")]), (fromList [(5, "a"), (3, "b")])]
139+-- >     == fromList [(3, "B3"), (5, "A3"), (7, "C")]
140+
141hunk ./Data/IntMap.hs 615
142--- | The union of a list of maps, with a combining operation
143+-- | The union of a list of maps, with a combining operation.
144+--
145+-- > unionsWith (++) [(fromList [(5, "a"), (3, "b")]), (fromList [(5, "A"), (7, "C")]), (fromList [(5, "A3"), (3, "B3")])]
146+-- >     == fromList [(3, "bB3"), (5, "aAA3"), (7, "C")]
147+
148hunk ./Data/IntMap.hs 624
149--- | /O(n+m)/. The (left-biased) union of two maps.
150+-- | /O(n+m)/. The (left-biased) union of two maps.
151hunk ./Data/IntMap.hs 627
152+--
153+-- > union (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == fromList [(3, "b"), (5, "a"), (7, "C")]
154+
155hunk ./Data/IntMap.hs 650
156--- | /O(n+m)/. The union with a combining function.
157+-- | /O(n+m)/. The union with a combining function.
158+--
159+-- > unionWith (++) (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == fromList [(3, "b"), (5, "aA"), (7, "C")]
160+
161hunk ./Data/IntMap.hs 658
162--- | /O(n+m)/. The union with a combining function.
163+-- | /O(n+m)/. The union with a combining function.
164+--
165+-- > let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value
166+-- > unionWithKey f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == fromList [(3, "b"), (5, "5:a|A"), (7, "C")]
167+
168hunk ./Data/IntMap.hs 686
169--- | /O(n+m)/. Difference between two maps (based on keys).
170+-- | /O(n+m)/. Difference between two maps (based on keys).
171+--
172+-- > difference (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 3 "b"
173+
174hunk ./Data/IntMap.hs 713
175--- | /O(n+m)/. Difference with a combining function.
176+-- | /O(n+m)/. Difference with a combining function.
177+--
178+-- > let f al ar = if al == "b" then Just (al ++ ":" ++ ar) else Nothing
179+-- > differenceWith f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (3, "B"), (7, "C")])
180+-- >     == singleton 3 "b:B"
181+
182hunk ./Data/IntMap.hs 727
183+--
184+-- > let f k al ar = if al == "b" then Just ((show k) ++ ":" ++ al ++ "|" ++ ar) else Nothing
185+-- > differenceWithKey f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (3, "B"), (10, "C")])
186+-- >     == singleton 3 "3:b|B"
187+
188hunk ./Data/IntMap.hs 762
189--- | /O(n+m)/. The (left-biased) intersection of two maps (based on keys).
190+-- | /O(n+m)/. The (left-biased) intersection of two maps (based on keys).
191+--
192+-- > intersection (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 5 "a"
193+
194hunk ./Data/IntMap.hs 791
195--- | /O(n+m)/. The intersection with a combining function.
196+-- | /O(n+m)/. The intersection with a combining function.
197+--
198+-- > intersectionWith (++) (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 5 "aA"
199+
200hunk ./Data/IntMap.hs 799
201--- | /O(n+m)/. The intersection with a combining function.
202+-- | /O(n+m)/. The intersection with a combining function.
203+--
204+-- > let f k al ar = (show k) ++ ":" ++ al ++ "|" ++ ar
205+-- > intersectionWithKey f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 5 "5:a|A"
206+
207hunk ./Data/IntMap.hs 836
208+--
209+-- > updateMinWithKey (\ k a -> Just ((show k) ++ ":" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3,"3:b"), (5,"a")]
210+-- > updateMinWithKey (\ _ _ -> Nothing)                     (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
211+
212hunk ./Data/IntMap.hs 854
213+--
214+-- > updateMaxWithKey (\ k a -> Just ((show k) ++ ":" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3,"b"), (5,"5:a")]
215+-- > updateMaxWithKey (\ _ _ -> Nothing)                     (fromList [(5,"a"), (3,"b")]) == singleton 3 "b"
216+
217hunk ./Data/IntMap.hs 874
218+--
219+-- > v <- maxViewWithKey (fromList [(5,"a"), (3,"b")])
220+-- > v == ((5,"a"), singleton 3 "b")
221+-- > maxViewWithKey empty              Error: empty map
222+
223hunk ./Data/IntMap.hs 885
224-        Nil -> fail "maxView: empty map has no maximal element"
225+        Nil -> fail "maxViewWithKey: empty map has no maximal element"
226hunk ./Data/IntMap.hs 894
227+--
228+-- > v <- minViewWithKey (fromList [(5,"a"), (3,"b")])
229+-- > v ==  ((3,"b"), singleton 5 "a")
230+-- > minViewWithKey empty              Error: empty map
231+
232hunk ./Data/IntMap.hs 905
233-        Nil -> fail "minView: empty map has no minimal element"
234+        Nil -> fail "minViewWithKey: empty map has no minimal element"
235hunk ./Data/IntMap.hs 914
236+--
237+-- > updateMax (\ a -> Just ("X" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "Xa")]
238+-- > updateMax (\ _ -> Nothing)         (fromList [(5,"a"), (3,"b")]) == singleton 3 "b"
239+
240hunk ./Data/IntMap.hs 922
241+--
242+-- > updateMin (\ a -> Just ("X" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3, "Xb"), (5, "a")]
243+-- > updateMin (\ _ -> Nothing)         (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
244+
245hunk ./Data/IntMap.hs 1029
246-{- | /O(n+m)/.
247+{- | /O(n+m)/.
248hunk ./Data/IntMap.hs 1045
249-
250hunk ./Data/IntMap.hs 1061
251+--
252+-- > map (++ "x") (fromList [(5,"a"), (3,"b")]) == fromList [(3, "bx"), (5, "ax")]
253+
254hunk ./Data/IntMap.hs 1069
255+--
256+-- > let f key x = (show key) ++ ":" ++ x
257+-- > mapWithKey f (fromList [(5,"a"), (3,"b")]) == fromList [(3, "3:b"), (5, "5:a")]
258+
259hunk ./Data/IntMap.hs 1082
260+--
261+-- > let f a b = (a ++ b, b ++ "X")
262+-- > mapAccum f "Everything: " (fromList [(5,"a"), (3,"b")]) == ("Everything: ba", fromList [(3, "bX"), (5, "aX")])
263+
264hunk ./Data/IntMap.hs 1092
265+--
266+-- > let f a k b = (a ++ " " ++ (show k) ++ "-" ++ b, b ++ "X")
267+-- > mapAccumWithKey f "Everything:" (fromList [(5,"a"), (3,"b")]) == ("Everything: 3-b 5-a", fromList [(3, "bX"), (5, "aX")])
268+
269hunk ./Data/IntMap.hs 1127
270+--
271+-- > filter (> "a") (fromList [(5,"a"), (3,"b")]) == singleton 3 "b"
272+-- > filter (> "x") (fromList [(5,"a"), (3,"b")]) == empty
273+-- > filter (< "a") (fromList [(5,"a"), (3,"b")]) == empty
274+
275hunk ./Data/IntMap.hs 1137
276+--
277+-- > filterWithKey (\k _ -> k > 4) (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
278+
279hunk ./Data/IntMap.hs 1150
280--- | /O(n)/. partition the map according to some predicate. The first
281+-- | /O(n)/. Partition the map according to some predicate. The first
282hunk ./Data/IntMap.hs 1153
283+--
284+-- > partition (> "a") (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", singleton 5 "a")
285+-- > partition (< "x") (fromList [(5,"a"), (3,"b")]) == (fromList [(3, "b"), (5, "a")], empty)
286+-- > partition (> "x") (fromList [(5,"a"), (3,"b")]) == (empty, fromList [(3, "b"), (5, "a")])
287+
288hunk ./Data/IntMap.hs 1162
289--- | /O(n)/. partition the map according to some predicate. The first
290+-- | /O(n)/. Partition the map according to some predicate. The first
291hunk ./Data/IntMap.hs 1165
292+--
293+-- > partitionWithKey (\ k _ -> k > 3) (fromList [(5,"a"), (3,"b")]) == (singleton 5 "a", singleton 3 "b")
294+-- > partitionWithKey (\ k _ -> k < 7) (fromList [(5,"a"), (3,"b")]) == (fromList [(3, "b"), (5, "a")], empty)
295+-- > partitionWithKey (\ k _ -> k > 7) (fromList [(5,"a"), (3,"b")]) == (empty, fromList [(3, "b"), (5, "a")])
296+
297hunk ./Data/IntMap.hs 1183
298+--
299+-- > let f x = if x == "a" then Just "new a" else Nothing
300+-- > mapMaybe f (fromList [(5,"a"), (3,"b")]) == singleton 5 "new a"
301+
302hunk ./Data/IntMap.hs 1192
303+--
304+-- > let f k _ = if k < 5 then Just ("key : " ++ (show k)) else Nothing
305+-- > mapMaybeWithKey f (fromList [(5,"a"), (3,"b")]) == singleton 3 "key : 3"
306+
307hunk ./Data/IntMap.hs 1205
308+--
309+-- > let f a = if a < "c" then Left a else Right a
310+-- > mapEither f (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")])
311+-- >     == (fromList [(3,"b"), (5,"a")], fromList [(1,"x"), (7,"z")])
312+-- >
313+-- > mapEither (\ a -> Right a) (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")])
314+-- >     == (empty, fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")])
315+
316hunk ./Data/IntMap.hs 1218
317+--
318+-- > let f k a = if k < 5 then Left (k * 2) else Right (a ++ a)
319+-- > mapEitherWithKey f (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")])
320+-- >     == (fromList [(1,2), (3,6)], fromList [(5,"aa"), (7,"zz")])
321+-- >
322+-- > mapEitherWithKey (\_ a -> Right a) (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")])
323+-- >     == (empty, fromList [(1,"x"), (3,"b"), (5,"a"), (7,"z")])
324+
325hunk ./Data/IntMap.hs 1240
326+--
327+-- > split 2 (fromList [(5,"a"), (3,"b")]) == (empty, fromList [(3,"b"), (5,"a")])
328+-- > split 3 (fromList [(5,"a"), (3,"b")]) == (empty, singleton 5 "a")
329+-- > split 4 (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", singleton 5 "a")
330+-- > split 5 (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", empty)
331+-- > split 6 (fromList [(5,"a"), (3,"b")]) == (fromList [(3,"b"), (5,"a")], empty)
332+
333hunk ./Data/IntMap.hs 1276
334+--
335+-- > splitLookup 2 (fromList [(5,"a"), (3,"b")]) == (empty, Nothing, fromList [(3,"b"), (5,"a")])
336+-- > splitLookup 3 (fromList [(5,"a"), (3,"b")]) == (empty, Just "b", singleton 5 "a")
337+-- > splitLookup 4 (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", Nothing, singleton 5 "a")
338+-- > splitLookup 5 (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", Just "a", empty)
339+-- > splitLookup 6 (fromList [(5,"a"), (3,"b")]) == (fromList [(3,"b"), (5,"a")], Nothing, empty)
340+
341hunk ./Data/IntMap.hs 1319
342+-- > let f a len = len + (length a)
343+-- > fold f 0 (fromList [(5,"a"), (3,"bbb")]) == 4
344+
345hunk ./Data/IntMap.hs 1332
346+-- > let f k a result = result ++ "(" ++ (show k) ++ ":" ++ a ++ ")"
347+-- > foldWithKey f "Map: " (fromList [(5,"a"), (3,"b")]) == "Map: (5:a)(3:b)"
348+
349hunk ./Data/IntMap.hs 1361
350+--
351+-- > elems (fromList [(5,"a"), (3,"b")]) == ["b","a"]
352+-- > elems empty == []
353+
354hunk ./Data/IntMap.hs 1370
355+--
356+-- > keys (fromList [(5,"a"), (3,"b")]) == [3,5]
357+-- > keys empty == []
358+
359hunk ./Data/IntMap.hs 1379
360+--
361+-- > keysSet (fromList [(5,"a"), (3,"b")]) == Data.IntSet.fromList [3,5]
362+-- > keysSet empty == Data.IntSet.empty
363+
364hunk ./Data/IntMap.hs 1388
365+--
366+-- > assocs (fromList [(5,"a"), (3,"b")]) == [(3,"b"), (5,"a")]
367+-- > assocs empty == []
368+
369hunk ./Data/IntMap.hs 1401
370+--
371+-- > toList (fromList [(5,"a"), (3,"b")]) == [(3,"b"), (5,"a")]
372+-- > toList empty == []
373+
374hunk ./Data/IntMap.hs 1411
375+--
376+-- > toAscList (fromList [(5,"a"), (3,"b")]) == [(3,"b"), (5,"a")]
377+
378hunk ./Data/IntMap.hs 1420
379+--
380+-- > fromList [] == empty
381+-- > fromList [(5,"a"), (3,"b"), (5, "c")] == fromList [(5,"c"), (3,"b")]
382+-- > fromList [(5,"c"), (3,"b"), (5, "a")] == fromList [(5,"a"), (3,"b")]
383+
384hunk ./Data/IntMap.hs 1431
385--- | /O(n*min(n,W))/.  Create a map from a list of key\/value pairs with a combining function. See also 'fromAscListWith'.
386+-- | /O(n*min(n,W))/. Create a map from a list of key\/value pairs with a combining function. See also 'fromAscListWith'.
387+--
388+-- > fromListWith (++) [(5,"a"), (5,"b"), (3,"b"), (3,"a"), (5,"a")] == fromList [(3, "ab"), (5, "aba")]
389+-- > fromListWith (++) [] == empty
390+
391hunk ./Data/IntMap.hs 1440
392--- | /O(n*min(n,W))/.  Build a map from a list of key\/value pairs with a combining function. See also fromAscListWithKey'.
393+-- | /O(n*min(n,W))/. Build a map from a list of key\/value pairs with a combining function. See also fromAscListWithKey'.
394+--
395+-- > fromListWith (++) [(5,"a"), (5,"b"), (3,"b"), (3,"a"), (5,"a")] == fromList [(3, "ab"), (5, "aba")]
396+-- > fromListWith (++) [] == empty
397+
398hunk ./Data/IntMap.hs 1453
399+--
400+-- > fromAscList [(3,"b"), (5,"a")]          == fromList [(3, "b"), (5, "a")]
401+-- > fromAscList [(3,"b"), (5,"a"), (5,"b")] == fromList [(3, "b"), (5, "b")]
402+
403hunk ./Data/IntMap.hs 1463
404+--
405+-- > fromAscListWith (++) [(3,"b"), (5,"a"), (5,"b")] == fromList [(3, "b"), (5, "ba")]
406+
407hunk ./Data/IntMap.hs 1472
408+--
409+-- > fromAscListWith (++) [(3,"b"), (5,"a"), (5,"b")] == fromList [(3, "b"), (5, "ba")]
410+
411hunk ./Data/IntMap.hs 1481
412+--
413+-- > fromDistinctAscList [(3,"b"), (5,"a")] == fromList [(3, "b"), (5, "a")]
414+
415hunk ./Data/Map.hs 7
416+--                (c) Andriy Palamarchuk 2008
417hunk ./Data/Map.hs 35
418+--
419+-- Operation comments contain the operation time complexity in
420+-- the Big-O notation <http://en.wikipedia.org/wiki/Big_O_notation>.
421hunk ./Data/Map.hs 99
422-           , mapKeys
423-           , mapKeysWith
424-           , mapKeysMonotonic
425+            , mapKeys
426+            , mapKeysWith
427+            , mapKeysMonotonic
428hunk ./Data/Map.hs 110
429-           , keysSet
430+            , keysSet
431hunk ./Data/Map.hs 203
432+--
433+-- > fromList [(5,'a'), (3,'b')] ! 1    Error: element not in the map
434+-- > fromList [(5,'a'), (3,'b')] ! 5 == 'a'
435+
436hunk ./Data/Map.hs 210
437--- | /O(n+m)/. See 'difference'.
438+-- | Same as 'difference'.
439hunk ./Data/Map.hs 250
440+--
441+-- > Data.Map.null (empty)           == True
442+-- > Data.Map.null (singleton 1 'a') == False
443+
444hunk ./Data/Map.hs 261
445+--
446+-- > size empty                                   == 0
447+-- > size (singleton 1 'a')                       == 1
448+-- > size (fromList([(1,'a'), (2,'c'), (3,'b')])) == 3
449+
450hunk ./Data/Map.hs 273
451--- | /O(log n)/. Lookup the value at a key in the map.
452+-- | /O(log n)/. Lookup the value at a key in the map.
453hunk ./Data/Map.hs 279
454+--
455+-- > let m = fromList [(5,'a'), (3,'b'), (7,'c')]
456+-- > value1 <- Data.Map.lookup 5 m
457+-- > value1
458+-- >   'a'
459+-- > value2 <- Data.Map.lookup 1 m
460+-- >   Error: Key not found
461+--
462+-- An example of using @lookup@ with @Maybe@ monad:
463+--
464+-- > import Prelude hiding (lookup)
465+-- > import Data.Map
466+-- >
467+-- > employeeDept = fromList([("John","Sales"), ("Bob","IT")])
468+-- > deptCountry = fromList([("IT","USA"), ("Sales","France")])
469+-- > countryCurrency = fromList([("USA", "Dollar"), ("France", "Euro")])
470+-- >
471+-- > employeeCurrency :: String -> Maybe String
472+-- > employeeCurrency name = do
473+-- >     dept <- lookup name employeeDept
474+-- >     country <- lookup dept deptCountry
475+-- >     lookup country countryCurrency
476+-- >
477+-- > main = do
478+-- >     putStrLn $ "John's currency: " ++ (show (employeeCurrency "John"))
479+-- >     putStrLn $ "Pete's currency: " ++ (show (employeeCurrency "Pete"))
480+--
481+-- The output of this program:
482+--
483+-- >   John's currency: Just "Euro"
484+-- >   Pete's currency: Nothing
485+
486hunk ./Data/Map.hs 335
487--- | /O(log n)/. Is the key a member of the map?
488+-- | /O(log n)/. Is the key a member of the map? See also 'notMember'.
489+--
490+-- > member 5 (fromList [(5,'a'), (3,'b')]) == True
491+-- > member 1 (fromList [(5,'a'), (3,'b')]) == False
492+
493hunk ./Data/Map.hs 346
494--- | /O(log n)/. Is the key not a member of the map?
495+-- | /O(log n)/. Is the key not a member of the map? See also 'member'.
496+--
497+-- > notMember 5 (fromList [(5,'a'), (3,'b')]) == False
498+-- > notMember 1 (fromList [(5,'a'), (3,'b')]) == True
499+
500hunk ./Data/Map.hs 363
501--- the value at key @k@ or returns @def@ when the key is not in the map.
502+-- the value at key @k@ or returns default value @def@
503+-- when the key is not in the map.
504+--
505+-- > findWithDefault 'x' 1 (fromList [(5,'a'), (3,'b')]) == 'x'
506+-- > findWithDefault 'x' 5 (fromList [(5,'a'), (3,'b')]) == 'a'
507+
508hunk ./Data/Map.hs 381
509+--
510+-- > empty      == fromList []
511+-- > size empty == 0
512+
513hunk ./Data/Map.hs 390
514+--
515+-- > singleton 1 'a'        == fromList [(1, 'a')]
516+-- > size (singleton 1 'a') == 1
517+
518hunk ./Data/Map.hs 403
519--- replaced with the supplied value, i.e. 'insert' is equivalent to
520+-- replaced with the supplied value. 'insert' is equivalent to
521hunk ./Data/Map.hs 405
522+--
523+-- > insert 5 'x' (fromList [(5,'a'), (3,'b')]) == fromList [(3, 'b'), (5, 'x')]
524+-- > insert 7 'x' (fromList [(5,'a'), (3,'b')]) == fromList [(3, 'b'), (5, 'a'), (7, 'x')]
525+-- > insert 5 'x' empty                         == singleton 5 'x'
526+
527hunk ./Data/Map.hs 420
528--- | /O(log n)/. Insert with a combining function.
529+-- | /O(log n)/. Insert with a function, combining new value and old value.
530hunk ./Data/Map.hs 425
531+--
532+-- > insertWith (++) 5 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "xxxa")]
533+-- > insertWith (++) 7 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "xxx")]
534+-- > insertWith (++) 5 "xxx" empty                         == singleton 5 "xxx"
535+
536hunk ./Data/Map.hs 440
537--- | /O(log n)/. Insert with a combining function.
538+-- | /O(log n)/. Insert with a function, combining key, new value and old value.
539hunk ./Data/Map.hs 446
540+--
541+-- > let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value
542+-- > insertWithKey f 5 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:xxx|a")]
543+-- > insertWithKey f 7 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "xxx")]
544+-- > insertWithKey f 5 "xxx" empty                         == singleton 5 "xxx"
545+
546hunk ./Data/Map.hs 474
547--- | /O(log n)/. The expression (@'insertLookupWithKey' f k x map@)
548+-- | /O(log n)/. Combines insert operation with old value retrieval.
549+-- The expression (@'insertLookupWithKey' f k x map@)
550hunk ./Data/Map.hs 478
551+--
552+-- > let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value
553+-- > insertLookupWithKey f 5 "xxx" (fromList [(5,"a"), (3,"b")]) == (Just "a", fromList [(3, "b"), (5, "5:xxx|a")])
554+-- > insertLookupWithKey f 7 "xxx" (fromList [(5,"a"), (3,"b")]) == (Nothing,  fromList [(3, "b"), (5, "a"), (7, "xxx")])
555+-- > insertLookupWithKey f 5 "xxx" empty                         == (Nothing,  singleton 5 "xxx")
556+--
557+-- This is how to define @insertLookup@ using @insertLookupWithKey@:
558+--
559+-- > let insertLookup kx x t = insertLookupWithKey (\_ a _ -> a) kx x t
560+-- > insertLookup 5 "x" (fromList [(5,"a"), (3,"b")]) == (Just "a", fromList [(3, "b"), (5, "x")])
561+-- > insertLookup 7 "x" (fromList [(5,"a"), (3,"b")]) == (Nothing,  fromList [(3, "b"), (5, "a"), (7, "x")])
562+
563hunk ./Data/Map.hs 506
564+--
565+-- > delete 5 (fromList [(5,"a"), (3,"b")]) == singleton 3 "b"
566+-- > delete 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")]
567+-- > delete 5 empty                         == empty
568+
569hunk ./Data/Map.hs 521
570--- | /O(log n)/. Adjust a value at a specific key. When the key is not
571+-- | /O(log n)/. Update a value at a specific key with the result of the provided function.
572+-- When the key is not
573hunk ./Data/Map.hs 524
574+--
575+-- > adjust ("new " ++) 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "new a")]
576+-- > adjust ("new " ++) 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")]
577+-- > adjust ("new " ++) 7 empty                         == empty
578+
579hunk ./Data/Map.hs 535
580+--
581+-- > let f key x = (show key) ++ ":new " ++ x
582+-- > adjustWithKey f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:new a")]
583+-- > adjustWithKey f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")]
584+-- > adjustWithKey f 7 empty                         == empty
585+
586hunk ./Data/Map.hs 548
587+--
588+-- > let f x = if x == "a" then Just "new a" else Nothing
589+-- > update f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "new a")]
590+-- > update f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")]
591+-- > update f 3 (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
592+
593hunk ./Data/Map.hs 562
594+--
595+-- > let f k x = if x == "a" then Just ((show k) ++ ":new a") else Nothing
596+-- > updateWithKey f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:new a")]
597+-- > updateWithKey f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")]
598+-- > updateWithKey f 3 (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
599+
600hunk ./Data/Map.hs 580
601--- | /O(log n)/. Lookup and update.
602+-- | /O(log n)/. Lookup and update. See also 'updateWithKey'.
603+-- The function returns changed value, if it is updated.
604+-- Returns the original key value if the map entry is deleted.
605+--
606+-- > let f k x = if x == "a" then Just ((show k) ++ ":new a") else Nothing
607+-- > updateLookupWithKey f 5 (fromList [(5,"a"), (3,"b")]) == (Just "5:new a", fromList [(3, "b"), (5, "5:new a")])
608+-- > updateLookupWithKey f 7 (fromList [(5,"a"), (3,"b")]) == (Nothing,  fromList [(3, "b"), (5, "a")])
609+-- > updateLookupWithKey f 3 (fromList [(5,"a"), (3,"b")]) == (Just "b", singleton 5 "a")
610+
611hunk ./Data/Map.hs 603
612--- In short : @'lookup' k ('alter' f k m) = f ('lookup' k m)@
613+-- In short : @'lookup' k ('alter' f k m) = f ('lookup' k m)@.
614+--
615+-- > let f _ = Nothing
616+-- > alter f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")]
617+-- > alter f 5 (fromList [(5,"a"), (3,"b")]) == singleton 3 "b"
618+-- >
619+-- > let f _ = Just "c"
620+-- > alter f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "c")]
621+-- > alter f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "c")]
622+
623hunk ./Data/Map.hs 633
624+--
625+-- > findIndex 2 (fromList [(5,"a"), (3,"b")])    Error: element is not in the map
626+-- > findIndex 3 (fromList [(5,"a"), (3,"b")]) == 0
627+-- > findIndex 5 (fromList [(5,"a"), (3,"b")]) == 1
628+-- > findIndex 6 (fromList [(5,"a"), (3,"b")])    Error: element is not in the map
629+
630hunk ./Data/Map.hs 646
631--- /0/ up to, but not including, the 'size' of the map.
632+-- /0/ up to, but not including, the 'size' of the map.
633+--
634+-- > isJust (lookupIndex 2 (fromList [(5,"a"), (3,"b")]))   == False
635+-- > fromJust (lookupIndex 3 (fromList [(5,"a"), (3,"b")])) == 0
636+-- > fromJust (lookupIndex 5 (fromList [(5,"a"), (3,"b")])) == 1
637+-- > isJust (lookupIndex 6 (fromList [(5,"a"), (3,"b")]))   == False
638+
639hunk ./Data/Map.hs 667
640+--
641+-- > elemAt 0 (fromList [(5,"a"), (3,"b")]) == (3,"b")
642+-- > elemAt 1 (fromList [(5,"a"), (3,"b")]) == (5, "a")
643+-- > elemAt 2 (fromList [(5,"a"), (3,"b")])    Error: index out of range
644+
645hunk ./Data/Map.hs 684
646+--
647+-- > updateAt (\ _ _ -> Just "x") 0    (fromList [(5,"a"), (3,"b")]) == fromList [(3, "x"), (5, "a")]
648+-- > updateAt (\ _ _ -> Just "x") 1    (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "x")]
649+-- > updateAt (\ _ _ -> Just "x") 2    (fromList [(5,"a"), (3,"b")])    Error: index out of range
650+-- > updateAt (\ _ _ -> Just "x") (-1) (fromList [(5,"a"), (3,"b")])    Error: index out of range
651+-- > updateAt (\_ _  -> Nothing)  0    (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
652+-- > updateAt (\_ _  -> Nothing)  1    (fromList [(5,"a"), (3,"b")]) == singleton 3 "b"
653+-- > updateAt (\_ _  -> Nothing)  2    (fromList [(5,"a"), (3,"b")])    Error: index out of range
654+-- > updateAt (\_ _  -> Nothing)  (-1) (fromList [(5,"a"), (3,"b")])    Error: index out of range
655+
656hunk ./Data/Map.hs 708
657+--
658+-- > deleteAt 0  (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
659+-- > deleteAt 1  (fromList [(5,"a"), (3,"b")]) == singleton 3 "b"
660+-- > deleteAt 2 (fromList [(5,"a"), (3,"b")])     Error: index out of range
661+-- > deleteAt (-1) (fromList [(5,"a"), (3,"b")])  Error: index out of range
662+
663hunk ./Data/Map.hs 722
664--- | /O(log n)/. The minimal key of the map.
665+-- | /O(log n)/. The minimal key of the map. Calls 'error' is the map is empty.
666+--
667+-- > findMin (fromList [(5,"a"), (3,"b")]) == (3,"b")
668+-- > findMin empty                            Error: empty map has no minimal element
669+
670hunk ./Data/Map.hs 732
671--- | /O(log n)/. The maximal key of the map.
672+-- | /O(log n)/. The maximal key of the map. Calls 'error' is the map is empty.
673+--
674+-- > findMax (fromList [(5,"a"), (3,"b")]) == (5,"a")
675+-- > findMax empty                            Error: empty map has no maximal element
676+
677hunk ./Data/Map.hs 742
678--- | /O(log n)/. Delete the minimal key.
679+-- | /O(log n)/. Delete the minimal key. Returns an empty map if the map is empty.
680+--
681+-- > deleteMin (fromList [(5,"a"), (3,"b"), (7,"c")]) == fromList [(5,"a"), (7,"c")]
682+-- > deleteMin empty == empty
683+
684hunk ./Data/Map.hs 752
685--- | /O(log n)/. Delete the maximal key.
686+-- | /O(log n)/. Delete the maximal key. Returns an empty map if the map is empty.
687+--
688+-- > deleteMax (fromList [(5,"a"), (3,"b"), (7,"c")]) == fromList [(3,"b"), (5,"a")]
689+-- > deleteMax empty == empty
690+
691hunk ./Data/Map.hs 763
692+--
693+-- > updateMin (\ a -> Just ("X" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3, "Xb"), (5, "a")]
694+-- > updateMin (\ _ -> Nothing)         (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
695+
696hunk ./Data/Map.hs 772
697+--
698+-- > updateMax (\ a -> Just ("X" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "Xa")]
699+-- > updateMax (\ _ -> Nothing)         (fromList [(5,"a"), (3,"b")]) == singleton 3 "b"
700+
701hunk ./Data/Map.hs 782
702+--
703+-- > updateMinWithKey (\ k a -> Just ((show k) ++ ":" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3,"3:b"), (5,"a")]
704+-- > updateMinWithKey (\ _ _ -> Nothing)                     (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
705+
706hunk ./Data/Map.hs 796
707+--
708+-- > updateMaxWithKey (\ k a -> Just ((show k) ++ ":" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3,"b"), (5,"5:a")]
709+-- > updateMaxWithKey (\ _ _ -> Nothing)                     (fromList [(5,"a"), (3,"b")]) == singleton 3 "b"
710+
711hunk ./Data/Map.hs 811
712+--
713+-- > v <- minViewWithKey (fromList [(5,"a"), (3,"b")])
714+-- > v ==  ((3,"b"), singleton 5 "a")
715+-- > minViewWithKey empty              Error: empty map
716+
717hunk ./Data/Map.hs 817
718-minViewWithKey Tip = fail "Map.minView: empty map"
719+minViewWithKey Tip = fail "Map.minViewWithKey: empty map"
720hunk ./Data/Map.hs 822
721+--
722+-- > v <- maxViewWithKey (fromList [(5,"a"), (3,"b")])
723+-- > v == ((5,"a"), singleton 3 "b")
724+-- > maxViewWithKey empty              Error: empty map
725+
726hunk ./Data/Map.hs 828
727-maxViewWithKey Tip = fail "Map.maxView: empty map"
728+maxViewWithKey Tip = fail "Map.maxViewWithKey: empty map"
729hunk ./Data/Map.hs 833
730+--
731+-- > v <- minView (fromList [(5,"a"), (3,"b")])
732+-- > v == ("b", singleton 5 "a")
733+-- > minView empty                     Error: empty map
734+
735hunk ./Data/Map.hs 844
736+--
737+-- > v <- maxView (fromList [(5,"a"), (3,"b")])
738+-- > v == ("a", singleton 3 "b")
739+-- > maxView empty                     Error: empty map
740+
741hunk ./Data/Map.hs 862
742+--
743+-- > unions [(fromList [(5, "a"), (3, "b")]), (fromList [(5, "A"), (7, "C")]), (fromList [(5, "A3"), (3, "B3")])]
744+-- >     == fromList [(3, "b"), (5, "a"), (7, "C")]
745+-- > unions [(fromList [(5, "A3"), (3, "B3")]), (fromList [(5, "A"), (7, "C")]), (fromList [(5, "a"), (3, "b")])]
746+-- >     == fromList [(3, "B3"), (5, "A3"), (7, "C")]
747+
748hunk ./Data/Map.hs 874
749+--
750+-- > unionsWith (++) [(fromList [(5, "a"), (3, "b")]), (fromList [(5, "A"), (7, "C")]), (fromList [(5, "A3"), (3, "B3")])]
751+-- >     == fromList [(3, "bB3"), (5, "aAA3"), (7, "C")]
752+
753hunk ./Data/Map.hs 887
754--- Hedge-union is more efficient on (bigset `union` smallset)
755+-- Hedge-union is more efficient on (bigset \``union`\` smallset).
756+--
757+-- > union (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == fromList [(3, "b"), (5, "a"), (7, "C")]
758+
759hunk ./Data/Map.hs 927
760+--
761+-- > unionWith (++) (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == fromList [(3, "b"), (5, "aA"), (7, "C")]
762+
763hunk ./Data/Map.hs 936
764--- Hedge-union is more efficient on (bigset `union` smallset).
765+-- Hedge-union is more efficient on (bigset \``union`\` smallset).
766+--
767+-- > let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value
768+-- > unionWithKey f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == fromList [(3, "b"), (5, "5:a|A"), (7, "C")]
769+
770hunk ./Data/Map.hs 965
771+-- Return elements of the first map not existing in the second map.
772hunk ./Data/Map.hs 967
773+--
774+-- > difference (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 3 "b"
775+
776hunk ./Data/Map.hs 986
777+-- When two equal keys are
778+-- encountered, the combining function is applied to the values of these keys.
779+-- If it returns 'Nothing', the element is discarded (proper set difference). If
780+-- it returns (@'Just' y@), the element is updated with a new value @y@.
781hunk ./Data/Map.hs 991
782+--
783+-- > let f al ar = if al == "b" then Just (al ++ ":" ++ ar) else Nothing
784+-- > differenceWith f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (3, "B"), (7, "C")])
785+-- >     == singleton 3 "b:B"
786+
787hunk ./Data/Map.hs 1005
788+--
789+-- > let f k al ar = if al == "b" then Just ((show k) ++ ":" ++ al ++ "|" ++ ar) else Nothing
790+-- > differenceWithKey f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (3, "B"), (10, "C")])
791+-- >     == singleton 3 "3:b|B"
792+
793hunk ./Data/Map.hs 1038
794--- | /O(n+m)/. Intersection of two maps. The values in the first
795--- map are returned, i.e. (@'intersection' m1 m2 == 'intersectionWith' 'const' m1 m2@).
796+-- | /O(n+m)/. Intersection of two maps.
797+-- Return data in the first map for the keys existing in both maps.
798+-- (@'intersection' m1 m2 == 'intersectionWith' 'const' m1 m2@).
799+--
800+-- > intersection (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 5 "a"
801+
802hunk ./Data/Map.hs 1049
803+--
804+-- > intersectionWith (++) (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 5 "aA"
805+
806hunk ./Data/Map.hs 1057
807--- Intersection is more efficient on (bigset `intersection` smallset)
808+-- Intersection is more efficient on (bigset \``intersection`\` smallset).
809+--
810+-- > let f k al ar = (show k) ++ ":" ++ al ++ "|" ++ ar
811+-- > intersectionWithKey f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 5 "5:a|A"
812+
813hunk ./Data/Map.hs 1078
814-
815hunk ./Data/Map.hs 1101
816--- | /O(n+m)/.
817+-- | /O(n+m)/.
818hunk ./Data/Map.hs 1103
819+--
820hunk ./Data/Map.hs 1108
821-{- | /O(n+m)/.
822+{- | /O(n+m)/.
823hunk ./Data/Map.hs 1123
824+
825+
826hunk ./Data/Map.hs 1160
827
828+
829hunk ./Data/Map.hs 1171
830+--
831+-- > filter (> "a") (fromList [(5,"a"), (3,"b")]) == singleton 3 "b"
832+-- > filter (> "x") (fromList [(5,"a"), (3,"b")]) == empty
833+-- > filter (< "a") (fromList [(5,"a"), (3,"b")]) == empty
834+
835hunk ./Data/Map.hs 1181
836+--
837+-- > filterWithKey (\k _ -> k > 4) (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
838+
839hunk ./Data/Map.hs 1191
840--- | /O(n)/. partition the map according to a predicate. The first
841+-- | /O(n)/. Partition the map according to a predicate. The first
842hunk ./Data/Map.hs 1194
843+--
844+-- > partition (> "a") (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", singleton 5 "a")
845+-- > partition (< "x") (fromList [(5,"a"), (3,"b")]) == (fromList [(3, "b"), (5, "a")], empty)
846+-- > partition (> "x") (fromList [(5,"a"), (3,"b")]) == (empty, fromList [(3, "b"), (5, "a")])
847+
848hunk ./Data/Map.hs 1203
849--- | /O(n)/. partition the map according to a predicate. The first
850+-- | /O(n)/. Partition the map according to a predicate. The first
851hunk ./Data/Map.hs 1206
852+--
853+-- > partitionWithKey (\ k _ -> k > 3) (fromList [(5,"a"), (3,"b")]) == (singleton 5 "a", singleton 3 "b")
854+-- > partitionWithKey (\ k _ -> k < 7) (fromList [(5,"a"), (3,"b")]) == (fromList [(3, "b"), (5, "a")], empty)
855+-- > partitionWithKey (\ k _ -> k > 7) (fromList [(5,"a"), (3,"b")]) == (empty, fromList [(3, "b"), (5, "a")])
856+
857hunk ./Data/Map.hs 1221
858+--
859+-- > let f x = if x == "a" then Just "new a" else Nothing
860+-- > mapMaybe f (fromList [(5,"a"), (3,"b")]) == singleton 5 "new a"
861+
862hunk ./Data/Map.hs 1230
863+--
864+-- > let f k _ = if k < 5 then Just ("key : " ++ (show k)) else Nothing
865+-- > mapMaybeWithKey f (fromList [(5,"a"), (3,"b")]) == singleton 3 "key : 3"
866+
867hunk ./Data/Map.hs 1241
868+--
869+-- > let f a = if a < "c" then Left a else Right a
870+-- > mapEither f (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")])
871+-- >     == (fromList [(3,"b"), (5,"a")], fromList [(1,"x"), (7,"z")])
872+-- >
873+-- > mapEither (\ a -> Right a) (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")])
874+-- >     == (empty, fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")])
875+
876hunk ./Data/Map.hs 1254
877+--
878+-- > let f k a = if k < 5 then Left (k * 2) else Right (a ++ a)
879+-- > mapEitherWithKey f (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")])
880+-- >     == (fromList [(1,2), (3,6)], fromList [(5,"aa"), (7,"zz")])
881+-- >
882+-- > mapEitherWithKey (\_ a -> Right a) (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")])
883+-- >     == (empty, fromList [(1,"x"), (3,"b"), (5,"a"), (7,"z")])
884+
885hunk ./Data/Map.hs 1276
886+--
887+-- > map (++ "x") (fromList [(5,"a"), (3,"b")]) == fromList [(3, "bx"), (5, "ax")]
888+
889hunk ./Data/Map.hs 1284
890+--
891+-- > let f key x = (show key) ++ ":" ++ x
892+-- > mapWithKey f (fromList [(5,"a"), (3,"b")]) == fromList [(3, "3:b"), (5, "5:a")]
893+
894hunk ./Data/Map.hs 1295
895+--
896+-- > let f a b = (a ++ b, b ++ "X")
897+-- > mapAccum f "Everything: " (fromList [(5,"a"), (3,"b")]) == ("Everything: ba", fromList [(3, "bX"), (5, "aX")])
898+
899hunk ./Data/Map.hs 1305
900+--
901+-- > let f a k b = (a ++ " " ++ (show k) ++ "-" ++ b, b ++ "X")
902+-- > mapAccumWithKey f "Everything:" (fromList [(5,"a"), (3,"b")]) == ("Everything: 3-b 5-a", fromList [(3, "bX"), (5, "aX")])
903+
904hunk ./Data/Map.hs 1337
905--- | /O(n*log n)/.
906+-- | /O(n*log n)/.
907hunk ./Data/Map.hs 1343
908+--
909+-- > mapKeys (+ 1) (fromList [(5,"a"), (3,"b")])                        == fromList [(4, "b"), (6, "a")]
910+-- > mapKeys (\ _ -> 1) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")]) == singleton 1 "c"
911+-- > mapKeys (\ _ -> 3) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")]) == singleton 3 "c"
912hunk ./Data/Map.hs 1351
913--- | /O(n*log n)/.
914+-- | /O(n*log n)/.
915hunk ./Data/Map.hs 1357
916+--
917+-- > mapKeysWith (++) (\ _ -> 1) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")]) == singleton 1 "cdab"
918+-- > mapKeysWith (++) (\ _ -> 3) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")]) == singleton 3 "cdab"
919hunk ./Data/Map.hs 1369
920+-- That is, for any values @x@ and @y@, if @x@ < @y@ then @f x@ < @f y@.
921hunk ./Data/Map.hs 1376
922+--
923+-- This means that @f@ maps distinct original keys to distinct resulting keys.
924+-- This function has better performance than 'mapKeys'.
925+--
926+-- > mapKeysMonotonic (\ k -> k * 2) (fromList [(5,"a"), (3,"b")]) == fromList [(6, "b"), (10, "a")]
927+-- > valid (mapKeysMonotonic (\ k -> k * 2) (fromList [(5,"a"), (3,"b")])) == True
928+-- > valid (mapKeysMonotonic (\ _ -> 1)     (fromList [(5,"a"), (3,"b")])) == False
929hunk ./Data/Map.hs 1399
930+-- > let f a len = len + (length a)
931+-- > fold f 0 (fromList [(5,"a"), (3,"bbb")]) == 4
932+
933hunk ./Data/Map.hs 1412
934+-- > let f k a result = result ++ "(" ++ (show k) ++ ":" ++ a ++ ")"
935+-- > foldWithKey f "Map: " (fromList [(5,"a"), (3,"b")]) == "Map: (5:a)(3:b)"
936+
937hunk ./Data/Map.hs 1439
938+--
939+-- > elems (fromList [(5,"a"), (3,"b")]) == ["b","a"]
940+-- > elems empty == []
941+
942hunk ./Data/Map.hs 1448
943+--
944+-- > keys (fromList [(5,"a"), (3,"b")]) == [3,5]
945+-- > keys empty == []
946+
947hunk ./Data/Map.hs 1457
948+--
949+-- > keysSet (fromList [(5,"a"), (3,"b")]) == Data.Set.fromList [3,5]
950+-- > keysSet empty == Data.Set.empty
951+
952hunk ./Data/Map.hs 1465
953+--
954+-- > assocs (fromList [(5,"a"), (3,"b")]) == [(3,"b"), (5,"a")]
955+-- > assocs empty == []
956+
957hunk ./Data/Map.hs 1478
958+-- If the list contains more than one value for the same key, the last value
959+-- for the key is retained.
960+--
961+-- > fromList [] == empty
962+-- > fromList [(5,"a"), (3,"b"), (5, "c")] == fromList [(5,"c"), (3,"b")]
963+-- > fromList [(5,"c"), (3,"b"), (5, "a")] == fromList [(5,"a"), (3,"b")]
964+
965hunk ./Data/Map.hs 1492
966+--
967+-- > fromListWith (++) [(5,"a"), (5,"b"), (3,"b"), (3,"a"), (5,"a")] == fromList [(3, "ab"), (5, "aba")]
968+-- > fromListWith (++) [] == empty
969+
970hunk ./Data/Map.hs 1501
971+--
972+-- > let f k a1 a2 = (show k) ++ a1 ++ a2
973+-- > fromListWithKey f [(5,"a"), (5,"b"), (3,"b"), (3,"a"), (5,"a")] == fromList [(3, "3ab"), (5, "5a5ba")]
974+-- > fromListWithKey f [] == empty
975+
976hunk ./Data/Map.hs 1513
977+--
978+-- > toList (fromList [(5,"a"), (3,"b")]) == [(3,"b"), (5,"a")]
979+-- > toList empty == []
980+
981hunk ./Data/Map.hs 1521
982+--
983+-- > toAscList (fromList [(5,"a"), (3,"b")]) == [(3,"b"), (5,"a")]
984+
985hunk ./Data/Map.hs 1527
986--- | /O(n)/.
987+-- | /O(n)/.
988hunk ./Data/Map.hs 1541
989+--
990+-- > fromAscList [(3,"b"), (5,"a")]          == fromList [(3, "b"), (5, "a")]
991+-- > fromAscList [(3,"b"), (5,"a"), (5,"b")] == fromList [(3, "b"), (5, "b")]
992+-- > valid (fromAscList [(3,"b"), (5,"a"), (5,"b")]) == True
993+-- > valid (fromAscList [(5,"a"), (3,"b"), (5,"b")]) == False
994+
995hunk ./Data/Map.hs 1553
996+--
997+-- > fromAscListWith (++) [(3,"b"), (5,"a"), (5,"b")] == fromList [(3, "b"), (5, "ba")]
998+-- > valid (fromAscListWith (++) [(3,"b"), (5,"a"), (5,"b")]) == True
999+-- > valid (fromAscListWith (++) [(5,"a"), (3,"b"), (5,"b")]) == False
1000+
1001hunk ./Data/Map.hs 1565
1002+--
1003+-- > let f k a1 a2 = (show k) ++ ":" ++ a1 ++ a2
1004+-- > fromAscListWithKey f [(3,"b"), (5,"a"), (5,"b"), (5,"b")] == fromList [(3, "b"), (5, "5:b5:ba")]
1005+-- > valid (fromAscListWithKey f [(3,"b"), (5,"a"), (5,"b"), (5,"b")]) == True
1006+-- > valid (fromAscListWithKey f [(5,"a"), (3,"b"), (5,"b"), (5,"b")]) == False
1007+
1008hunk ./Data/Map.hs 1590
1009+--
1010+-- > fromDistinctAscList [(3,"b"), (5,"a")] == fromList [(3, "b"), (5, "a")]
1011+-- > valid (fromDistinctAscList [(3,"b"), (5,"a")])          == True
1012+-- > valid (fromDistinctAscList [(3,"b"), (5,"a"), (5,"b")]) == False
1013+
1014hunk ./Data/Map.hs 1681
1015--- the keys in @map1@ are smaller than @k@ and the keys in @map2@ larger than @k@. Any key equal to @k@ is found in neither @map1@ nor @map2@.
1016+-- the keys in @map1@ are smaller than @k@ and the keys in @map2@ larger than @k@.
1017+-- Any key equal to @k@ is found in neither @map1@ nor @map2@.
1018+--
1019+-- > split 2 (fromList [(5,"a"), (3,"b")]) == (empty, fromList [(3,"b"), (5,"a")])
1020+-- > split 3 (fromList [(5,"a"), (3,"b")]) == (empty, singleton 5 "a")
1021+-- > split 4 (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", singleton 5 "a")
1022+-- > split 5 (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", empty)
1023+-- > split 6 (fromList [(5,"a"), (3,"b")]) == (fromList [(3,"b"), (5,"a")], empty)
1024+
1025hunk ./Data/Map.hs 1700
1026+--
1027+-- > splitLookup 2 (fromList [(5,"a"), (3,"b")]) == (empty, Nothing, fromList [(3,"b"), (5,"a")])
1028+-- > splitLookup 3 (fromList [(5,"a"), (3,"b")]) == (empty, Just "b", singleton 5 "a")
1029+-- > splitLookup 4 (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", Nothing, singleton 5 "a")
1030+-- > splitLookup 5 (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", Just "a", empty)
1031+-- > splitLookup 6 (fromList [(5,"a"), (3,"b")]) == (fromList [(3,"b"), (5,"a")], Nothing, empty)
1032+
1033hunk ./Data/Map.hs 1810
1034+--
1035+-- > deleteFindMin (fromList [(5,"a"), (3,"b"), (10,"c")]) == ((3,"b"), fromList[(5,"a"), (10,"c")])
1036+-- > deleteFindMin                                            Error: can not return the minimal element of an empty map
1037+
1038hunk ./Data/Map.hs 1822
1039+--
1040+-- > deleteFindMax (fromList [(5,"a"), (3,"b"), (10,"c")]) == ((10,"c"), fromList [(3,"b"), (5,"a")])
1041+-- > deleteFindMax empty                                      Error: can not return the maximal element of an empty map
1042+
1043hunk ./Data/Map.hs 1980
1044--- in a compressed, hanging format.
1045+-- in a compressed, hanging format. See 'showTreeWith'.
1046hunk ./Data/Map.hs 2081
1047+--
1048+-- > valid (fromAscList [(3,"b"), (5,"a")]) == True
1049+-- > valid (fromAscList [(5,"a"), (3,"b")]) == False
1050+
1051}
1052
1053Context:
1054
1055[Fix a link in haddock docs
1056Ian Lynagh <[email protected]>**20071126184450]
1057[Fix some URLs
1058Ian Lynagh <[email protected]>**20071126214233]
1059[Add tiny regression test
1060David Benbennick <[email protected]>**20071113045358]
1061[Fix ticket 1762
1062David Benbennick <[email protected]>**20071111201939]
1063[Specify build-type: Simple
1064Duncan Coutts <[email protected]>**20071018125404]
1065[Add a boring file
1066Ian Lynagh <[email protected]>**20070913204647]
1067[TAG 2007-09-13
1068Ian Lynagh <[email protected]>**20070913215901]
1069Patch bundle hash:
1070245f259beed9afa1702486da444186d49a821a33