Skip to content

Instantly share code, notes, and snippets.

@oisdk
Created June 15, 2015 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oisdk/047f86ca4ad068928f63 to your computer and use it in GitHub Desktop.
Save oisdk/047f86ca4ad068928f63 to your computer and use it in GitHub Desktop.
extension CollectionType {
subscript (inds: [Index]) -> [Generator.Element] { return inds.map{self[$0]} }
subscript (inds: Index...) -> [Generator.Element] { return inds.map{self[$0]} }
}
extension MutableCollectionType {
subscript (inds: [Index]) -> [Generator.Element] {
get { return inds.map{self[$0]} }
set(els) { for (ind, val) in zip(inds, els) { self[ind] = val } }
}
subscript (inds: Index...) -> [Generator.Element] {
get { return inds.map{self[$0]} }
set(els) { for (ind, val) in zip(inds, els) { self[ind] = val } }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment