top | item 8180261

(no title)

nottombrown | 11 years 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

discuss

order

No comments yet.