Skip to content

Instantly share code, notes, and snippets.

@JadenGeller
Last active August 29, 2015 14: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 JadenGeller/6f5c5dcb16c39b936d17 to your computer and use it in GitHub Desktop.
Save JadenGeller/6f5c5dcb16c39b936d17 to your computer and use it in GitHub Desktop.
Swift Global Map2 Function
func map2<S : SequenceType, T : SequenceType, U>(lhs: S, rhs: T, transform: (S.Generator.Element, T.Generator.Element) -> U) -> [U] {
return Array(Zip2(lhs, rhs)).map(transform)
}
func &&(lhs: Array<Bool>, rhs: Array<Bool>) -> Array<Bool> {
return map2(lhs, rhs, { (lhs, rhs) in lhs && rhs })
}
println([true, true, false] && [false, true, true]) // -> [false, true, false]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment