Last active
April 12, 2016 22:59
-
-
Save harlanhaskins/9fa0242f44d34fe2244af6ad05ccc7b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// note the signature => (T?, T -> U?) -> U? | |
func flatMap<T, U>(value: T?, transform: T -> U?) -> U? { | |
switch value { | |
case .None: return .None | |
case .Some(let contained): return transform(contained) | |
} | |
} | |
// different from this => (T?, T -> U) -> U? | |
func map<T, U>(value: T?, transform: T -> U) -> U? { | |
switch value { | |
case .None: return .None | |
case .Some(let contained): return Optional.Some(transform(contained)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment