Closed
Description
For Data.Set
, I am missing something comparable to Map.lookupInsertWithKey
that combines a lookup
and an insert
. Suggestion (specification):
insertUnlessMember :: Ord a => a -> Set a -> Maybe (Set a)
insertUnlessMember a s = if member a s then Nothing else Just $ insert a s
Of course, that should have an efficient implementation that only traverses the tree once.