Null Object Pattern in Swift
medium.com
medium.com
What I wanted to show here among other things and why optional chaining would not help is if we wanted to have a special case handling on failure. Optional chaining fails silently. So if we wanted to log an error or to terminate the app every time the request fails, we'd have to do it on every function call.
phoneCallRegistry.callWithIdentifier(identifier)?.hangUp()
The ? means that hangUp() will not be called if callWithIdentifier(identifier) returns nil.The abstracting over them is pretty mind blowing though.
Array and Optional are examples. RAC's SignalProducer is... maybe one? Maybe three?
That's really all there is.
There's some saying about Java "design patterns" that can just be replaced with closures. There should probably be another for for ADTs.
It's a neat idea but I don't think it's as good as optionals.
Why would you ever want to maintain such code when the language already solves all that for you with optional chaining and flatMap?
i guess its something you could get used to though...