@@ -1,8 +1,8 @@
11module Dict (empty,singleton,insert,update
22 ,lookup,findWithDefault
33 ,remove,member
4− ,filter,filterWithKey
5− ,partition,partitionWithKey
4+ ,filter
5+ ,partition
66 ,foldl,foldr,map
77 ,union,intersect,diff
88 ,keys,values
@@ -329,7 +329,7 @@ union t1 t2 = foldl insert t2 t1
329329{-| Keep a key-value pair when its key appears in the second dictionary.
330330Preference is given to values in the first dictionary. -}
331331intersect : Dict comparable v -> Dict comparable v -> Dict comparable v
332−intersect t1 t2 = filterWithKey (\k _ -> k `member` t2) t1
332+intersect t1 t2 = filter (\k _ -> k `member` t2) t1
333333
334334{-| Keep a key-value pair when its key does not appear in the second dictionary.
335335Preference is given to the first dictionary. -}
@@ -352,31 +352,20 @@ toList t = foldr (\k v acc -> (k,v) :: acc) [] t
352352fromList : [(comparable,v)] -> Dict comparable v
353353fromList assocs = List.foldl (\(k,v) d -> insert k v d) empty assocs
354354
355−{-| Keep only key-value pairs where the value satisfies a predicate. -}
356−filter : (v -> Bool) -> Dict comparable v -> Dict comparable v
357−filter p = filterWithKey (\_ v -> p v)
358−
359−{-| Keep only key-value pairs which satisfy a predicate. -}
360−filterWithKey : (comparable -> v -> Bool)
355+{-| Keep a key-value pair when it satisfies a predicate. -}
356+filter : (comparable -> v -> Bool)
361357 -> Dict comparable v
362358 -> Dict comparable v
363−filterWithKey p =
359+filter p =
364360 let add k v t = if p k v then insert k v t else t
365361 in foldl add empty
366362
367363{-| Partition the Dict according to a predicate. The first Dict contains all
368−values which satisfy a predicate; the second contains the rest. -}
369−partition : (v -> Bool)
364+key-value pairs which satisfy it; the second contains the rest. -}
365+partition : (comparable -> v -> Bool)
370366 -> Dict comparable v
371367 -> (Dict comparable v, Dict comparable v)
372−partition p = partitionWithKey (\_ v -> p v)
373−
374−{-| Partition the Dict according to a predicate. The first Dict contains all
375−key-value pairs which satisfy a predicate; the second contains the rest. -}
376−partitionWithKey : (comparable -> v -> Bool)
377− -> Dict comparable v
378− -> (Dict comparable v, Dict comparable v)
379−partitionWithKey p =
368+partition p =
380369 let add k v (t1, t2) = if p k v
381370 then (insert k v t1, t2)
382371 else (t1, insert k v t2)