Skip to content

Instantly share code, notes, and snippets.

@kmuralidharan91
Last active April 10, 2020 15:24
Show Gist options
  • Save kmuralidharan91/028339c525d70eb79655a9815468038a to your computer and use it in GitHub Desktop.
Save kmuralidharan91/028339c525d70eb79655a9815468038a to your computer and use it in GitHub Desktop.
ArraySlice
public extension Array {
func slice(_ from: Int, count: Int) -> ArraySlice<Element>? {
guard (0 <= from && from < self.count) && (from < from+count && from+count < self.count) else {
return nil
}
return self[from...from+count-1]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment