3 ms·
This is a pattern that I've started using everywhere and it's incredibly useful. The common closure format of: (T?, Error?) -> () means you have possibly fo
by Chazprime 8y ago
This is a pattern that I've started using everywhere and it's incredibly useful. The common closure format of:
(T?, Error?) -> ()
means you have possibly four different options for the return value, it's much simpler to represent as:
enum Result<T> {
case success(T)
case error(Error)
}
Here's a great read about how Swift enums are algebraic sum types:
https://mislavjavor.github.io/2017-04-19/Swift-enums-are-sum-types.-That-makes-them-very-interesting/ https://mislavjavor.github.io/2017-04-19/Swift-enums-are-sum...