Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.

Commit 4900da6

Browse files
committed
Don't use external API
The original implementation was based on code use external to this module. Because of that, we had an additional constraint of `Ord k`—from `union`. However, we know the implementation in this module. So, we can use that knowledge to remove the `Ord k` constraint`.
1 parent 079c2fb commit 4900da6

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/Data/Map.purs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,21 @@ instance foldableMap :: Foldable (Map k) where
7777
foldr f z m = foldr f z (values m)
7878
foldMap f m = foldMap f (values m)
7979

80-
instance traversableMap :: Ord k => Traversable (Map k) where
81-
traverse f ms = foldr (\x acc -> union <$> x <*> acc) (pure empty) ((map (uncurry singleton)) <$> (traverse f <$> toList ms))
80+
instance traversableMap :: Traversable (Map k) where
81+
traverse f Leaf = pure Leaf
82+
traverse f (Two left k v right) =
83+
Two <$> traverse f left
84+
<*> pure k
85+
<*> f v
86+
<*> traverse f right
87+
traverse f (Three left k1 v1 mid k2 v2 right) =
88+
Three <$> traverse f left
89+
<*> pure k1
90+
<*> f v1
91+
<*> traverse f mid
92+
<*> pure k2
93+
<*> f v2
94+
<*> traverse f right
8295
sequence = traverse id
8396

8497
-- | Render a `Map` as a `String`

0 commit comments

Comments
 (0)