Skip to content

Instantly share code, notes, and snippets.

@philosopherdog
Last active April 5, 2021 13:59
Show Gist options
  • Save philosopherdog/61050802f3e7565342e422c3a18dc70c to your computer and use it in GitHub Desktop.
Save philosopherdog/61050802f3e7565342e422c3a18dc70c to your computer and use it in GitHub Desktop.
flatMap
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