on master help sign in
Mess with style, perf, and docs

Add filter and partition to visible documentation for Set. Use a style for type annotations that will look better when published online. Don’t use partial application for now.

commit1edc02fab908e1292e98e87d1c6dc984be89d9b1 authorEvan Czaplicki <info@elm-lang.org> dateWed 16 Apr 2014, 15:51 (13 years ago) parent3889b11
2 files changed+10−16
libraries/Dict.elm+6−10 libraries/Set.elm+4−6
libraries/Dict.elm+6−10
@@ -353,20 +353,16 @@ fromList : [(comparable,v)] -> Dict comparable v
353353fromList assocs = List.foldl (\(k,v) d -> insert k v d) empty assocs
354354
355355{-| Keep a key-value pair when it satisfies a predicate. -}
356−filter : (comparable -> v -> Bool)
357− -> Dict comparable v
358− -> Dict comparable v
359−filter p =
356+filter : (comparable -> v -> Bool) -> Dict comparable v -> Dict comparable v
357+filter p dict =
360358 let add k v t = if p k v then insert k v t else t
361− in foldl add empty
359+ in foldl add empty dict
362360
363361{-| Partition the Dict according to a predicate. The first Dict contains all
364362key-value pairs which satisfy it; the second contains the rest. -}
365−partition : (comparable -> v -> Bool)
366− -> Dict comparable v
367− -> (Dict comparable v, Dict comparable v)
368−partition p =
363+partition : (comparable -> v -> Bool) -> Dict comparable v -> (Dict comparable v, Dict comparable v)
364+partition p dict =
369365 let add k v (t1, t2) = if p k v
370366 then (insert k v t1, t2)
371367 else (t1, insert k v t2)
372− in foldl add (empty, empty)
368+ in foldl add (empty, empty) dict
libraries/Set.elm+4−6
@@ -26,7 +26,7 @@ Insert, remove, and query operations all take *O(log n)* time.
2626@docs toList, fromList
2727
2828# Transform
29−@docs map, foldl, foldr
29+@docs map, foldl, foldr, filter, partition
3030
3131-}
3232
@@ -92,11 +92,9 @@ map f s = fromList (List.map f (toList s))
9292
9393{-| Create a new set consisting only of elements which satisfy a predicate. -}
9494filter : (comparable -> Bool) -> Set comparable -> Set comparable
95−filter p = Dict.filter (\k _ -> p k)
95+filter p set = Dict.filter (\k _ -> p k) set
9696
9797{-| Create two new sets; the first consisting of elements which satisfy a
9898predicate, the second consisting of elements which do not. -}
99−partition : (comparable -> Bool)
100− -> Set comparable
101− -> (Set comparable, Set comparable)
102−partition p = Dict.partition (\k _ -> p k)
99+partition : (comparable -> Bool) -> Set comparable -> (Set comparable, Set comparable)
100+partition p set = Dict.partition (\k _ -> p k) set