Skip to content

Instantly share code, notes, and snippets.

@macbellingrath
Created April 12, 2017 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macbellingrath/ceab3cba75d57bb94ac0311de3e135a3 to your computer and use it in GitHub Desktop.
Save macbellingrath/ceab3cba75d57bb94ac0311de3e135a3 to your computer and use it in GitHub Desktop.
extension Optional {
func flatMapWith<T, U>(_ other: T?, _ transform: (Wrapped, T) -> U?) -> U? {
guard case .some(let `self`) = self else {
return nil
}
guard let element = other else {
return nil
}
return transform(self, element)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment