@@ -9,7 +9,8 @@ module Control.Distributed.Process.Internal.BiMultiMap
10 , deleteAllBy1st
10 , deleteAllBy1st
11 , deleteAllBy2nd
11 , deleteAllBy2nd
12− , partitionWithKey
12+ , partitionWithKeyBy1st
13+ , partitionWithKeyBy2nd
@@ -91,15 +92,23 @@ deleteAllBy2nd b = flip . deleteAllBy1st b . flip
92-- | Yields the triplets satisfying the given predicate, and a multimap
93-- | Yields the triplets satisfying the given predicate, and a multimap
93-- with all this triplets removed.
94-- with all this triplets removed.
94−partitionWithKey :: (Ord a, Ord b, Ord v)
95+partitionWithKeyBy1st :: (Ord a, Ord b, Ord v)
95− => (a -> Set (b, v) -> Bool) -> BiMultiMap a b v
96+ => (a -> Set (b, v) -> Bool) -> BiMultiMap a b v
96− -> (Map a (Set (b, v)), BiMultiMap a b v)
97+ -> (Map a (Set (b, v)), BiMultiMap a b v)
97−partitionWithKey f (BiMultiMap m r) =
98+partitionWithKeyBy1st p (BiMultiMap m r) =
98− let (m0, m1) = Map.partitionWithKey f m
99+ let (m0, m1) = Map.partitionWithKey p m
99 r1 = foldl' (\rr (a, mb) -> reverseDelete a (Set.toList mb) rr) r $
100 r1 = foldl' (\rr (a, mb) -> reverseDelete a (Set.toList mb) rr) r $
100 Map.toList m0
101 Map.toList m0
101 in (m0, BiMultiMap m1 r1)
102 in (m0, BiMultiMap m1 r1)
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
103-- | Exchange the first and the second components of all triplets.
112-- | Exchange the first and the second components of all triplets.
104flip :: BiMultiMap a b v -> BiMultiMap b a v
113flip :: BiMultiMap a b v -> BiMultiMap b a v
105flip (BiMultiMap m r) = BiMultiMap r m
114flip (BiMultiMap m r) = BiMultiMap r m