Add tryInsert for sets and maps
- Dominant language
- Haskell
- Stars
- 355
- Forks
- 194
- Avg merge
- 3d 4h
- Merged PRs (30d)
- 4
Description
```hs
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`:
https://github.com/haskell/containers/blob/d82a404141537c97df421d589a946a09272cc6d6/containers/src/Data/Containers/ListUtils.hs#L86-L88
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.
Contributor guide
Assessment
This issue has not been assessed yet.