Last active
April 5, 2021 13:59
-
-
Save philosopherdog/61050802f3e7565342e422c3a18dc70c to your computer and use it in GitHub Desktop.
flatMap
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
import UIKit | |
func g(_ b: String) -> String { | |
b | |
} | |
func f(_ s: String?) -> String? { | |
guard let unwrappedS = s else { | |
return nil | |
} | |
return g(unwrappedS) | |
} | |
func f2(_ s: String?) -> String? { | |
s.flatMap{ g($0) } | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment