git.iko.soy/typeable/ordered-containers
on master help sign in
7 files changed+28−5
since splitsnapshots
unifiedsplit
ChangeLog.md+5 Data/Map/Ordered.hs+2 Data/Map/Ordered/Internal.hs+6 Data/Map/Ordered/Strict.hs+4−2 Data/Map/Util.hs+2−2 Data/Set/Ordered.hs+8 ordered-containers.cabal+1−1
ChangeLog.md+5
@@ -1,5 +1,10 @@
11# Revision history for ordered-containers
22
3+## 0.2.2 -- 2019-07-05
4+
5+* Add `toMap` and `toSet`, which support efficient conversions from
6+ `OMap`s/`OSet`s to `Map`s/`Set`s, respectively.
7+
38## 0.2.1 -- 2019-03-25
49
510* Compatibility fixes from Ryan Scott (thanks!)
Data/Map/Ordered.hs+2
@@ -32,6 +32,8 @@ module Data.Map.Ordered
3232 , Index, findIndex, elemAt
3333 -- * List conversions
3434 , fromList, assocs, toAscList
35+ -- * 'M.Map' conversion
36+ , toMap
3537 ) where
3638
3739import qualified Data.Map as M ()
Data/Map/Ordered/Internal.hs+6
@@ -242,3 +242,9 @@ assocs (OMap _ kvs) = map snd $ M.toAscList kvs
242242-- | Return key-value pairs in order of increasing key.
243243toAscList :: OMap k v -> [(k, v)]
244244toAscList (OMap tvs kvs) = map (\(k, (t, v)) -> (k, v)) $ M.toAscList tvs
245+
246+-- | Convert an 'OMap' to a 'Map'.
247+--
248+-- /O(n)/, where /n/ is the size of the 'OMap'.
249+toMap :: OMap k v -> Map k v
250+toMap (OMap tvs _) = fmap snd tvs
Data/Map/Ordered/Strict.hs+4−2
@@ -32,13 +32,15 @@ module Data.Map.Ordered.Strict
3232 , Index, findIndex, elemAt
3333 -- * List conversions
3434 , fromList, assocs, toAscList
35+ -- * 'M.Map' conversion
36+ , toMap
3537 ) where
3638
3739import Data.Foldable (foldl')
3840import qualified Data.Map.Strict as M
3941import Data.Map.Ordered.Internal
40− ( OMap(..), empty, (<>|), (|<>), delete, filter, (\\), (|/\), (/\|), null, size
41− , member, notMember, lookup, findIndex, elemAt, assocs, toAscList, fromTV )
42+ ( OMap(..), empty, (<>|), (|<>), delete, filter, (\\), (|/\), (/\|), null, size
43+ , member, notMember, lookup, findIndex, elemAt, assocs, toAscList, fromTV, toMap )
4244import Data.Map.Util
4345import Prelude hiding (filter, lookup, null)
4446
Data/Map/Util.hs+2−2
@@ -49,8 +49,8 @@ readsPrecList fromList d = readParen (d > 10) $ \r -> do
4949-- tells whether 'mappend' will prefer the indices of its first or second
5050-- argument if there are shared elements in both.
5151newtype Bias (dir :: IndexPreference) a = Bias { unbiased :: a }
52− deriving (Data, Eq, Foldable, Functor, Ord, Read, Show, Traversable, Typeable)
52+ deriving (Data, Eq, Foldable, Functor, Ord, Read, Show, Traversable, Typeable)
5353data IndexPreference = L | R
54− deriving Typeable
54+ deriving Typeable
5555type L = 'L
5656type R = 'R
Data/Set/Ordered.hs+8
@@ -28,6 +28,8 @@ module Data.Set.Ordered
2828 , Index, findIndex, elemAt
2929 -- * List conversions
3030 , fromList, toAscList
31+ -- * 'Set' conversion
32+ , toSet
3133 ) where
3234
3335import Control.Monad (guard)
@@ -216,3 +218,9 @@ elemAt o@(OSet ts vs) i = do
216218-- insertion order.)
217219toAscList :: OSet a -> [a]
218220toAscList o@(OSet ts _) = fmap fst (M.toAscList ts)
221+
222+-- | Convert an 'OSet' to a 'Set'.
223+--
224+-- /O(n)/, where /n/ is the size of the 'OSet'.
225+toSet :: OSet a -> Set a
226+toSet (OSet ts _) = M.keysSet ts
ordered-containers.cabal+1−1
@@ -1,5 +1,5 @@
11name: ordered-containers
2−version: 0.2.1
2+version: 0.2.2
33synopsis: Set- and Map-like types that remember the order elements were inserted
44license: BSD3
55license-file: LICENSE