Last active
April 10, 2020 15:24
-
-
Save kmuralidharan91/028339c525d70eb79655a9815468038a to your computer and use it in GitHub Desktop.
ArraySlice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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