-- | Partition a map of 'Either's into a map containing only left-values and
-- another containing right-values.
partitionEithers :: Ord k => Map k (Either a b) -> (Map k a, Map k b)
partitionEithers = (Map.fromList *** Map.fromList) . foldr insert ([], []) . Map.toList
  where
    insert (k, Left x) (lefts, rights)  = ((k,x):lefts, rights)
    insert (k, Right y) (lefts, rights) = (lefts, (k,y):rights)
partitionEithers :: Ord k => Map k (Either a b) -> (Map k a, Map k b)
partitionEithers = (Map.fromList *** Map.fromList) . foldr insert ([], []) . Map.toList
  where
    insert (k, Left x) (lefts, rights)  = ((k,x):lefts, rights)
    insert (k, Right y) (lefts, rights) = (lefts, (k,y):rights)
partitionEithers = (Map.fromList *** Map.fromList) . foldr insert ([], []) . Map.toList
  where
    insert (k, Left x) (lefts, rights)  = ((k,x):lefts, rights)
    insert (k, Right y) (lefts, rights) = (lefts, (k,y):rights)