{- Copyright (c) 2011 Robert Henderson
This source file is distributed under the terms of a BSD3-style
license, which can be found in the file LICENSE at the root of
this package. -}

-- | Extends "Data.Map"
--
module Data.Map.Rosso1
    (module Data.Map

    ,insertMany
    ,extract

    ) where

------------------------------------------------------
import Data.Map


-- | Passes down the list from left to right, inserting each entry
-- into the map.
--
insertMany :: Ord k => [(k, a)] -> Map k a -> Map k a
insertMany xs m = foldl (flip . uncurry $ insert) m xs


-- | Simultaneous lookup and delete.
--
extract :: Ord k => k -> Map k a -> (Maybe a, Map k a)
extract = updateLookupWithKey (\ _ _ -> Nothing)



-----------------------------------------------------------
{- UNIT TESTS

*Rosso.Map1> insertMany [] $ fromList [(2, 'a'), (5, 'b')]
fromList [(2,'a'),(5,'b')]
*Rosso.Map1> insertMany [(4, 'x'), (2, 'b'), (4, 'y'), (7, 'a')] $ fromList [(2, 'a'), (5, 'b')]
fromList [(2,'b'),(4,'y'),(5,'b'),(7,'a')]

*Rosso.Map1> extract 5 empty
(Nothing,fromList [])
*Rosso.Map1> extract 3 $ fromList [(2, 'a'), (5, 'c')]
(Nothing,fromList [(2,'a'),(5,'c')])
*Rosso.Map1> extract 2 $ fromList [(2, 'a'), (5, 'c')]
(Just 'a',fromList [(5,'c')])

-}