Skip to content

Instantly share code, notes, and snippets.

@vascoorey
Last active August 29, 2015 14:02
Show Gist options
  • Save vascoorey/476d3344b803bb5f0682 to your computer and use it in GitHub Desktop.
Save vascoorey/476d3344b803bb5f0682 to your computer and use it in GitHub Desktop.
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