Last active
August 29, 2015 14:02
-
-
Save vascoorey/476d3344b803bb5f0682 to your computer and use it in GitHub Desktop.
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 zip<X, Y, Z>(first: X[], second: Y[], transform: (X, Y) -> (Z)) -> Array<Z> { | |
var zipped = Z[]() | |
for i in 0..min(first.count, second.count) { | |
zipped.append(transform(first[i], second[i])) | |
} | |
return zipped | |
} | |
func all<X>(array: X[], satisfy test: (X) -> Bool) -> Bool { | |
for i in array { | |
if !test(i) { | |
return false | |
} | |
} | |
return true | |
} | |
func any<X>(array: X[], satisfies test: (X) -> Bool) -> Bool { | |
return !all(array, { (x: X) -> Bool in | |
return !test(x) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment