@@ -9,7 +9,8 @@ module Control.Distributed.Process.Internal.BiMultiMap
99 , delete
1010 , deleteAllBy1st
1111 , deleteAllBy2nd
12− , partitionWithKey
12+ , partitionWithKeyBy1st
13+ , partitionWithKeyBy2nd
1314 , flip
1415 ) where
1516
@@ -91,15 +92,23 @@ deleteAllBy2nd b = flip . deleteAllBy1st b . flip
9192
9293-- | Yields the triplets satisfying the given predicate, and a multimap
9394-- with all this triplets removed.
94−partitionWithKey :: (Ord a, Ord b, Ord v)
95− => (a -> Set (b, v) -> Bool) -> BiMultiMap a b v
96− -> (Map a (Set (b, v)), BiMultiMap a b v)
97−partitionWithKey f (BiMultiMap m r) =
98− let (m0, m1) = Map.partitionWithKey f m
95+partitionWithKeyBy1st :: (Ord a, Ord b, Ord v)
96+ => (a -> Set (b, v) -> Bool) -> BiMultiMap a b v
97+ -> (Map a (Set (b, v)), BiMultiMap a b v)
98+partitionWithKeyBy1st p (BiMultiMap m r) =
99+ let (m0, m1) = Map.partitionWithKey p m
99100 r1 = foldl' (\rr (a, mb) -> reverseDelete a (Set.toList mb) rr) r $
100101 Map.toList m0
101102 in (m0, BiMultiMap m1 r1)
102103
104+-- | Like 'partitionWithKeyBy1st' but the predicates takes the second component
105+-- of the triplets as first argument.
106+partitionWithKeyBy2nd :: (Ord a, Ord b, Ord v)
107+ => (b -> Set (a, v) -> Bool) -> BiMultiMap a b v
108+ -> (Map b (Set (a, v)), BiMultiMap a b v)
109+partitionWithKeyBy2nd p b = let (m, b') = partitionWithKeyBy1st p $ flip b
110+ in (m, flip b')
111+
103112-- | Exchange the first and the second components of all triplets.
104113flip :: BiMultiMap a b v -> BiMultiMap b a v
105114flip (BiMultiMap m r) = BiMultiMap r m