Skip to content

Instantly share code, notes, and snippets.

@oisdk
Created July 6, 2015 13:56
Show Gist options
  • Save oisdk/606759112ee392147363 to your computer and use it in GitHub Desktop.
Save oisdk/606759112ee392147363 to your computer and use it in GitHub Desktop.
func map<T, U, V>(vals: (T?, U?), transform: (T, U) -> V) -> V? {
if let x = vals.0, y = vals.1 {
return transform(x, y)
} else {
return nil
}
}
func map<T, U, V>(val0: T?, _ val1: U?, transform: (T, U) -> V) -> V? {
if let x = val0, y = val1 {
return transform(x, y)
} else {
return nil
}
}
func flatMap<T, U, V>(vals: (T?, U?), transform: (T, U) -> V?) -> V? {
if let x = vals.0, y = vals.1 {
return transform(x, y)
} else {
return nil
}
}
func flatMap<T, U, V>(val0: T?, _ val1: U?, transform: (T, U) -> V?) -> V? {
if let x = val0, y = val1 {
return transform(x, y)
} else {
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment