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

Commit 389b7ef

Browse files
author
aratama
committed
fix toUnfoldable
1 parent c972269 commit 389b7ef

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/Data/Map.purs

+1-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ toUnfoldable = unfoldr go
378378
go :: Map k v -> Maybe (Tuple (Tuple k v) (Map k v))
379379
go Leaf = Nothing
380380
go (Two left k v right) = Just $ Tuple (Tuple k v) (left <> right)
381-
go (Three left k1 v1 mid k2 v2 right) = Just $ Tuple (Tuple k1 v1) (Two left k2 v2 right)
381+
go (Three left k1 v1 mid k2 v2 right) = Just $ Tuple (Tuple k1 v1) (insert k2 v2 (left <> mid <> right))
382382

383383
-- | Get a list of the keys contained in a map
384384
keys :: forall k v. Map k v -> List k

test/Test/Data/Map.purs

+4
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ mapTests = do
202202
quickCheck $ \(TestMap m) -> let f m' = M.fromFoldable (M.toList m') in
203203
M.toList (f m) == M.toList (m :: M.Map SmallKey Int) <?> show m
204204

205+
log "fromFoldable . toUnfoldable = id"
206+
quickCheck $ \(TestMap m) -> let f m' = M.fromFoldable (M.toUnfoldable m' :: List (Tuple SmallKey Int)) in
207+
f m == (m :: M.Map SmallKey Int) <?> show m
208+
205209
log "fromFoldableWith const = fromFoldable"
206210
quickCheck $ \arr -> M.fromFoldableWith const arr ==
207211
M.fromFoldable (arr :: List (Tuple SmallKey Int)) <?> show arr

0 commit comments

Comments
 (0)