December 2018
Intermediate to advanced
414 pages
10h 19m
English
Now that we have seen how to implement generic functions, let's have a look at how to implement it with other data structures such as enums.
One of the popular addition swift programmers often like to have in their tool chain is the Result or Either types. These two types are best represented with enum as they can only hold a finite number of different values (two).
Result is used when a function can resolve with either a success value or an error (Error). Either is used when a function can resolve with two different values (a left value or a right value):
enum Result<T> { case success(T), error(Error)}enum Either<T, U> { case left(T), right(U)}
Both of these implementations are unconstrained generics, unlike the previous ...
Read now
Unlock full access