git.iko.soy/monoidal-containers
on master help sign in
More conveniences
commit2026f4ddb80ab2f48ff29024d01b2adef8d1b376 authorBen Gamari <bgamari.foss@gmail.com> dateTue 20 Jan 2015, 12:12 (12 years ago) parent7e046db
1 file changed+21
src/Data/Map/Monoidal.hs+21
src/Data/Map/Monoidal.hs+21
@@ -24,6 +24,8 @@ module Data.Map.Monoidal
2424 , member
2525 , notMember
2626 , findWithDefault
27+ , elems
28+ , keys
2729 ) where
2830
2931import Data.Monoid
@@ -134,3 +136,22 @@ notMember k = not . M.member k . unpack
134136findWithDefault :: Ord k => a -> k -> MonoidalMap k a -> a
135137findWithDefault def k = M.findWithDefault def k . unpack
136138{-# INLINE findWithDefault #-}
139+
140+-- | /O(log n)/. Delete a key and its value from the map. When the key is not
141+-- a member of the map, the original map is returned.
142+delete :: Ord k => k -> MonoidalMap k a -> MonoidalMap k a
143+delete k = _Wrapping' MM %~ M.delete k
144+{-# INLINE delete #-}
145+
146+-- | /O(n)/.
147+-- Return all elements of the map in the ascending order of their keys.
148+-- Subject to list fusion.
149+elems :: MonoidalMap k a -> [a]
150+elems = M.elems . unpack
151+{-# INLINE elems #-}
152+
153+-- | /O(n)/. Return all keys of the map in ascending order. Subject to list
154+-- fusion.
155+keys :: MonoidalMap k a -> [k]
156+keys = M.keys . unpack
157+{-# INLINE keys #-}