This is precisely what ifSome(_:)
, ifNone(_:)
did in my pitch here: API Additions to Optional (filter, ifSome, ifNone, peek) - #16 by salutis
However, I haven't had time to learn how to implement it into the standard library, which is a precondition for a formal proposal.