Follow

You know how there’s a way to say foo?.bar to just return NIL if foo is NIL in Swift? Is there a way to do the same for Bar(foo) ? I.e. if Bar() doesn’t take an optional, can I just collapse Bar to NIL when foo is NIL?

@uliwitness seems you are looking for a monadic “bind” Operation on the optional type (like “>>=“ in Haskell). AFAIK Swift has no syntax for it, but you could define the operator yourself.

Sign in to participate in the conversation
Mastodon for Tech Folks

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!