Last active
August 29, 2015 14:17
-
-
Save JadenGeller/6f5c5dcb16c39b936d17 to your computer and use it in GitHub Desktop.
Swift Global Map2 Function
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
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) | |
} |
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
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