PROPOSAL: Add Data.Set.mapMaybe

Thomas Schilling nominolo at
Wed Oct 31 09:29:56 EDT 2007

Hi there.

I recently find myself missing Data.Set.mapMaybe.  This function is
implemented for Data.Map.Map, but is strangely missing from
Data.Set.mapMaybe.  I believe it could be implemented using
Data.Foldable, but not as efficiently.  The obvious implementation would

mapMaybe :: (Ord a, Ord b) => (a -> Maybe b) -> Set a -> Set b
mapMaybe f Tip = Tip
mapMaybe f (Bin _ x l r) = case f x of
  Nothing -> merge (mapMaybe f l) (mapMaybe f r)
  Just y  -> union y (mapMaybe f l) (mapMaybe f r)

Any comments?

Preliminary deadline: Nov 21, 2007 (3 weeks)

More information about the Libraries mailing list