@@ -18,7 +18,6 @@ module Data.Map
1818 , findMax
1919 , fromFoldable
2020 , fromFoldableWith
21- , toList
2221 , toUnfoldable
2322 , toAscUnfoldable
2423 , delete
@@ -98,7 +97,7 @@ instance traversableMap :: Traversable (Map k) where
9897 sequence = traverse id
9998
10099-- | Render a `Map` as a `String`
101- showTree :: forall k v . ( Show k , Show v ) => Map k v -> String
100+ showTree :: forall k v . Show k => Show v => Map k v -> String
102101showTree Leaf = " Leaf"
103102showTree (Two left k v right) =
104103 " Two (" <> showTree left <>
@@ -164,7 +163,7 @@ lookup = unsafePartial \k tree ->
164163
165164
166165-- | Lookup a value for the specified key, or the greatest one less than it
167- lookupLE :: forall k v . ( Ord k ) => k -> Map k v -> Maybe { key :: k , value :: v }
166+ lookupLE :: forall k v . Ord k => k -> Map k v -> Maybe { key :: k , value :: v }
168167lookupLE _ Leaf = Nothing
169168lookupLE k (Two left k1 v1 right) = case compare k k1 of
170169 EQ -> Just { key: k1, value: v1 }
@@ -176,7 +175,7 @@ lookupLE k (Three left k1 v1 mid k2 v2 right) = case compare k k2 of
176175 LT -> lookupLE k $ Two left k1 v1 mid
177176
178177-- | Lookup a value for the greatest key less than the specified key
179- lookupLT :: forall k v . ( Ord k ) => k -> Map k v -> Maybe { key :: k , value :: v }
178+ lookupLT :: forall k v . Ord k => k -> Map k v -> Maybe { key :: k , value :: v }
180179lookupLT _ Leaf = Nothing
181180lookupLT k (Two left k1 v1 right) = case compare k k1 of
182181 EQ -> findMax left
@@ -188,7 +187,7 @@ lookupLT k (Three left k1 v1 mid k2 v2 right) = case compare k k2 of
188187 LT -> lookupLT k $ Two left k1 v1 mid
189188
190189-- | Lookup a value for the specified key, or the least one greater than it
191- lookupGE :: forall k v . ( Ord k ) => k -> Map k v -> Maybe { key :: k , value :: v }
190+ lookupGE :: forall k v . Ord k => k -> Map k v -> Maybe { key :: k , value :: v }
192191lookupGE _ Leaf = Nothing
193192lookupGE k (Two left k1 v1 right) = case compare k k1 of
194193 EQ -> Just { key: k1, value: v1 }
@@ -200,7 +199,7 @@ lookupGE k (Three left k1 v1 mid k2 v2 right) = case compare k k1 of
200199 GT -> lookupGE k $ Two mid k2 v2 right
201200
202201-- | Lookup a value for the least key greater than the specified key
203- lookupGT :: forall k v . ( Ord k ) => k -> Map k v -> Maybe { key :: k , value :: v }
202+ lookupGT :: forall k v . Ord k => k -> Map k v -> Maybe { key :: k , value :: v }
204203lookupGT _ Leaf = Nothing
205204lookupGT k (Two left k1 v1 right) = case compare k k1 of
206205 EQ -> findMin right
@@ -371,21 +370,16 @@ update f k m = alter (maybe Nothing f) k m
371370
372371-- | Convert any foldable collection of key/value pairs to a map.
373372-- | On key collision, later values take precedence over earlier ones.
374- fromFoldable :: forall f k v . ( Ord k , Foldable f ) => f (Tuple k v ) -> Map k v
373+ fromFoldable :: forall f k v . Ord k => Foldable f => f (Tuple k v ) -> Map k v
375374fromFoldable = foldl (\m (Tuple k v) -> insert k v m) empty
376375
377376-- | Convert any foldable collection of key/value pairs to a map.
378377-- | On key collision, the values are configurably combined.
379- fromFoldableWith :: forall f k v . ( Ord k , Foldable f ) => (v -> v -> v ) -> f (Tuple k v ) -> Map k v
378+ fromFoldableWith :: forall f k v . Ord k => Foldable f => (v -> v -> v ) -> f (Tuple k v ) -> Map k v
380379fromFoldableWith f = foldl (\m (Tuple k v) -> alter (combine v) k m) empty where
381380 combine v (Just v') = Just $ f v v'
382381 combine v Nothing = Just v
383382
384- -- | Convert a map to a list of key/value pairs.
385- -- | DEPRECATED: use toUnfoldable or toAscUnfoldable instead.
386- toList :: forall k v . Map k v -> List (Tuple k v )
387- toList = toAscUnfoldable
388-
389383-- | Convert a map to an unfoldable structure of key/value pairs
390384toUnfoldable :: forall f k v . Unfoldable f => Map k v -> f (Tuple k v )
391385toUnfoldable m = unfoldr go (m : Nil ) where
@@ -427,7 +421,7 @@ values (Three left _ v1 mid _ v2 right) = values left <> pure v1 <> values mid <
427421-- | Compute the union of two maps, using the specified function
428422-- | to combine values for duplicate keys.
429423unionWith :: forall k v . Ord k => (v -> v -> v ) -> Map k v -> Map k v -> Map k v
430- unionWith f m1 m2 = foldl go m2 (toList m1)
424+ unionWith f m1 m2 = foldl go m2 (toUnfoldable m1 :: List ( Tuple k v ) )
431425 where
432426 go m (Tuple k v) = alter (Just <<< maybe v (f v)) k m
433427
@@ -437,7 +431,7 @@ union :: forall k v. Ord k => Map k v -> Map k v -> Map k v
437431union = unionWith const
438432
439433-- | Compute the union of a collection of maps
440- unions :: forall k v f . ( Ord k , Foldable f ) => f (Map k v ) -> Map k v
434+ unions :: forall k v f . Ord k => Foldable f => f (Map k v ) -> Map k v
441435unions = foldl union empty
442436
443437-- | Calculate the number of key/value pairs in a map
0 commit comments