April 2017
Intermediate to advanced
316 pages
9h 33m
English
Our previous example demonstrated single optional value mapping using FP techniques. What if we need to map multiple optional values together? In the optional binding section, we covered a non-functional way to handle multiple optional value binding, and in this section, we will look at multiple optional value mapping. As Optionals are high-kinded types, we will develop an apply function to use over Optionals:
func apply<T, V>(transform: ((T) -> V)?, input: T?) -> V? { switch transform { case .some(let fx): return fx <^> input case .none: return .none } }
The apply function is very similar to the fmap function. The transform function is optional, and we use pattern matching to return none or some over ...
Read now
Unlock full access