Skip to content

Instantly share code, notes, and snippets.

@oisdk
Created July 7, 2015 17:03
Show Gist options
  • Save oisdk/b80427a3c2157a00de06 to your computer and use it in GitHub Desktop.
Save oisdk/b80427a3c2157a00de06 to your computer and use it in GitHub Desktop.
extension CollectionType {
subscript(i1: Index, i2: Index, rest: Index...) -> PermutationGenerator<Self, [Self.Index]> {
get {
return PermutationGenerator(elements: self, indices: [i1, i2] + rest)
}
}
}
extension Array {
subscript(i1: Index, i2: Index, rest: Index...) -> [T] {
get {
return ([i1, i2] + rest).map{self[$0]}
} set(vals) {
for (ind, val) in zip([i1, i2] + rest, vals) {
self[ind] = val
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment