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

fix toUnfoldable #75

Merged
merged 1 commit into from
Nov 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Data/Map.purs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ toUnfoldable = unfoldr go
go :: Map k v -> Maybe (Tuple (Tuple k v) (Map k v))
go Leaf = Nothing
go (Two left k v right) = Just $ Tuple (Tuple k v) (left <> right)
go (Three left k1 v1 mid k2 v2 right) = Just $ Tuple (Tuple k1 v1) (Two left k2 v2 right)
go (Three left k1 v1 mid k2 v2 right) = Just $ Tuple (Tuple k1 v1) (insert k2 v2 (left <> mid <> right))

-- | Get a list of the keys contained in a map
keys :: forall k v. Map k v -> List k
Expand Down
4 changes: 4 additions & 0 deletions test/Test/Data/Map.purs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ mapTests = do
quickCheck $ \(TestMap m) -> let f m' = M.fromFoldable (M.toList m') in
M.toList (f m) == M.toList (m :: M.Map SmallKey Int) <?> show m

log "fromFoldable . toUnfoldable = id"
quickCheck $ \(TestMap m) -> let f m' = M.fromFoldable (M.toUnfoldable m' :: List (Tuple SmallKey Int)) in
f m == (m :: M.Map SmallKey Int) <?> show m

log "fromFoldableWith const = fromFoldable"
quickCheck $ \arr -> M.fromFoldableWith const arr ==
M.fromFoldable (arr :: List (Tuple SmallKey Int)) <?> show arr
Expand Down