Skip to content

Instantly share code, notes, and snippets.

@mikekavouras
Created May 11, 2016 16:02
Show Gist options
  • Save mikekavouras/74692c3f03afa779303fd464610feae7 to your computer and use it in GitHub Desktop.
Save mikekavouras/74692c3f03afa779303fd464610feae7 to your computer and use it in GitHub Desktop.
extension RangeReplaceableCollectionType {
public func slice(start: Int, _ stop: Int = 0, _ step: Int = 1) -> [Generator.Element] {
var _stop = stop
if stop == 0 {
_stop = self.count as! Int
}
var sliced = Array<Generator.Element>()
for (idx, val) in self.enumerate() {
if idx % step != 0 {
continue
}
if idx < start {
continue
}
if idx > _stop {
continue
}
sliced.append(val)
}
return sliced
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment