tryInsert :: Ord k => k -> a -> Map k a -> Maybe (Map k a)
tryInsert :: Ord a => a -> Set a -> Maybe (Set a)
tryInsert :: Int -> a -> IntMap a -> Maybe (IntMap a)
tryInsert :: Int -> IntSet -> Maybe IntSet
Inserts the value if the key is not in the map/set, otherwise returns Nothing.
This will be useful in nubOrdOn to avoid member+insert:
|
go s (x:xs) |
|
| fx `Set.member` s = go s xs |
|
| otherwise = x : go (Set.insert fx s) xs |
Alternate name suggestions are welcome.
If we go with tryInsert I think we should rename pop from #1134 to tryDelete for consistency. I didn't think of this name at that time. Luckily we haven't released it yet, so we can still change the name.
Inserts the value if the key is not in the map/set, otherwise returns
Nothing.This will be useful in
nubOrdOnto avoidmember+insert:containers/containers/src/Data/Containers/ListUtils.hs
Lines 86 to 88 in d82a404
Alternate name suggestions are welcome.
If we go with
tryInsertI think we should renamepopfrom #1134 totryDeletefor consistency. I didn't think of this name at that time. Luckily we haven't released it yet, so we can still change the name.