remove a Set of keys from a Map
 
            I have (x :: Set key) and (m :: Map key a) and want to remove all keys and corresponding values from m that are in x. I could solve it efficiently with a differenceSet :: Map key a -> Set key -> Map key a or with a Map.fromKeySet :: a -> Set key -> Map key a or a Map.fromKeySet :: (key -> a) -> Set key -> Map key a but I did not find one of these functions in containers-0.4.2.
 
            * Henning Thielemann 
I have (x :: Set key) and (m :: Map key a) and want to remove all keys and corresponding values from m that are in x. I could solve it efficiently with a
differenceSet :: Map key a -> Set key -> Map key a
or with a
Map.fromKeySet :: a -> Set key -> Map key a
or a
Map.fromKeySet :: (key -> a) -> Set key -> Map key a
but I did not find one of these functions in containers-0.4.2.
You can implement e.g. fromKeySet as fromKeySet a = Map.fromAscList . map (, a) . Set.toAscList In practice, when conversion between Sets and Maps is needed often, I found it convenient (and efficient) to emulate "Set a" by "Map a ()". -- Roman I. Cheplyaka :: http://ro-che.info/
 
            Hi,
I have (x :: Set key) and (m :: Map key a) and want to remove all keys and corresponding values from m that are in x. I could solve it efficiently with a
differenceSet :: Map key a -> Set key -> Map key a
or with a
Map.fromKeySet :: a -> Set key -> Map key a
or a
Map.fromKeySet :: (key -> a) -> Set key -> Map key a
but I did not find one of these functions in containers-0.4.2.
Map.fromSet :: (key -> a) -> Set key -> Map key a will very likely be available in containers-0.5. Cheers, Milan Straka
 
            On Sat, Dec 10, 2011 at 12:33, Henning Thielemann wrote:
I have (x :: Set key) and (m :: Map key a) and want to remove all keys and corresponding values from m that are in x. I could solve it efficiently with a
differenceSet :: Map key a -> Set key -> Map key a
I have implemented this in the past, though it was certainly inefficient. It would be nice to have something similar and efficient. Regards, Sean
participants (4)
- 
                 Henning Thielemann Henning Thielemann
- 
                 Milan Straka Milan Straka
- 
                 Roman Cheplyaka Roman Cheplyaka
- 
                 Sean Leather Sean Leather