ordered-containers 0.2.2 → 0.2.3
raw patch · 3 files changed
+13/−3 lines, 3 files
Files
- Data/Map/Ordered.hs +2/−1
- Data/Map/Ordered/Internal.hs +10/−1
- ordered-containers.cabal +1/−1
Data/Map/Ordered.hs view
@@ -23,9 +23,10 @@ , (<|), (|<), (>|), (|>) , (<>|), (|<>), unionWithL, unionWithR , Bias(Bias, unbiased), L, R- -- * Deletion+ -- * Deletion/Update , delete, filter, (\\) , (|/\), (/\|), intersectionWith+ , alter -- * Query , null, size, member, notMember, lookup -- * Indexing
Data/Map/Ordered/Internal.hs view
@@ -2,10 +2,10 @@ {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE TupleSections #-} module Data.Map.Ordered.Internal where -import Control.Applicative ((<|>)) import Control.Monad (guard) import Data.Data import Data.Foldable (Foldable, foldl', foldMap)@@ -248,3 +248,12 @@ -- /O(n)/, where /n/ is the size of the 'OMap'. toMap :: OMap k v -> Map k v toMap (OMap tvs _) = fmap snd tvs++-- | Alter the value at k, or absence of. Can be used to insert delete or update+-- with the same semantics as 'Map's alter+alter :: Ord k => (Maybe v -> Maybe v) -> k -> OMap k v -> OMap k v+alter f k om@(OMap tvs kvs) =+ case fst <$> M.lookup k tvs of+ Just t -> OMap (M.alter (fmap (t,) . f . fmap snd) k tvs)+ (M.alter (fmap (k,) . f . fmap snd) t kvs)+ Nothing -> maybe om ((om |>) . (k, )) $ f Nothing
ordered-containers.cabal view
@@ -1,5 +1,5 @@ name: ordered-containers-version: 0.2.2+version: 0.2.3 synopsis: Set- and Map-like types that remember the order elements were inserted license: BSD3 license-file: LICENSE