Add `filter` and `ifSome(then:)` to Optional

I don't think that's a particularly useful comparison to make. Optional doesn't have map because it's a Collection, Optional and Collection are both functors. Similarly, Optional doesn't have flatMap because it's a Collection, Optional and Collection are both monads. I have body hair, not because I'm secrely a mouse, but because both mice and I are mammals.

This is the case for functions that return Void, yes, but there are functions that return results you might not care about, and might want to discard. As I note, Set.remove(_:) is an example of this. It will either remove the element from the set (returning the element), or it will do nothing (returning nil). If your interest is just to ensure the Set no longer contains the element you pass into remove(_:), then you have no use for the result, so you'll want to discard it.

7 Likes