This repository was archived by the owner on Oct 4, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +11
-0
lines changed
Expand file tree Collapse file tree 2 files changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ module Data.Map
1919 , fromFoldable
2020 , fromFoldableWith
2121 , toList
22+ , toAscList
2223 , toUnfoldable
2324 , delete
2425 , pop
@@ -384,6 +385,10 @@ toList Leaf = Nil
384385toList (Two left k v right) = toList left <> Tuple k v : toList right
385386toList (Three left k1 v1 mid k2 v2 right) = toList left <> Tuple k1 v1 : toList mid <> Tuple k2 v2 : toList right
386387
388+ -- | Convert a map to a list of key/value pairs where the keys are in ascending order
389+ toAscList :: forall k v . Map k v -> List (Tuple k v )
390+ toAscList = toList
391+
387392-- | Convert a map to an unfoldable structure of key/value pairs
388393toUnfoldable :: forall f k v . Unfoldable f => Map k v -> f (Tuple k v )
389394toUnfoldable m = unfoldr go (m : Nil ) where
Original file line number Diff line number Diff line change @@ -218,6 +218,12 @@ mapTests = do
218218 groupBy ((==) `on` fst) <<< sortBy (compare `on` fst) in
219219 M .fromFoldableWith (<>) arr === f (arr :: List (Tuple String String ))
220220
221+ log " toAscList is sorted version of toList"
222+ quickCheck $ \(TestMap m) ->
223+ let list = M .toList (m :: M.Map SmallKey Int )
224+ ascList = M .toAscList m
225+ in ascList === sortBy (compare `on` fst) list
226+
221227 log " Lookup from union"
222228 quickCheck $ \(TestMap m1) (TestMap m2) k ->
223229 M .lookup (smallKey k) (M .union m1 m2) == (case M .lookup k m1 of
You can’t perform that action at this time.
0 commit comments