git.iko.soy/typeable/ordered-containers
on master help sign in
7 files changed+39−3
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+13 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+13
@@ -1,12 +1,23 @@
1+{-# LANGUAGE CPP #-}
12{-# LANGUAGE DataKinds #-}
3+{-# LANGUAGE DeriveDataTypeable #-}
4+{-# LANGUAGE DeriveFoldable #-}
5+{-# LANGUAGE DeriveFunctor #-}
6+{-# LANGUAGE DeriveTraversable #-}
27{-# LANGUAGE KindSignatures #-}
38
49module Data.Map.Util where
510
11+import Data.Data (Data, Typeable)
612import Data.Map (Map)
713import Data.Monoid -- so that the docs for Monoid link to the right place
814import qualified Data.Map as M
915
16+#if !(MIN_VERSION_base(4,8,0))
17+import Data.Foldable (Foldable)
18+import Data.Traversable (Traversable)
19+#endif
20+
1021-- | An internal index used to track ordering only -- its magnitude doesn't
1122-- matter. If you manage to see this documentation, the library author has made
1223-- a mistake!
@@ -38,6 +49,8 @@ readsPrecList fromList d = readParen (d > 10) $ \r -> do
3849-- tells whether 'mappend' will prefer the indices of its first or second
3950-- argument if there are shared elements in both.
4051newtype Bias (dir :: IndexPreference) a = Bias { unbiased :: a }
52+ deriving (Data, Eq, Foldable, Functor, Ord, Read, Show, Traversable, Typeable)
4153data IndexPreference = L | R
54+ deriving Typeable
4255type L = 'L
4356type 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