6 ms·
Here's an implementation of the latter try operator in swift. extension Optional { func try<U>(f: (T) -> U) -> Optional<U> { if let unw
by nottombrown 12y ago
Here's an implementation of the latter try operator in swift.
extension Optional {
func try<U>(f: (T) -> U) -> Optional<U> {
if let unwrapped = self {
return f(unwrapped)
} else {
return nil
}
}
}
You can see how to use it in this gist:
https://gist.github.com/nottombrown/c6585cad9588a9dc5383 https://gist.github.com/nottombrown/c6585cad9588a9dc5383