Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Iterate through all elements in pair tuples
import Foundation
public extension Array {
// Iterate through all elements in pair tuples
// e.g. [1, 2, 3, 4].allPairs = [(1, 2), (2, 3), (3, 4)]
var allPairs: [(Element, Element)] {
var array: [(Element, Element)] = []
for i in 0..<self.count - 1 {
array.append((self[i], self[i+1]))
}
return array
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment