Created
April 19, 2018 01:48
-
-
Save natecook1000/1b3ece02f15ef04ef302ed842cb07ba8 to your computer and use it in GitHub Desktop.
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
extension BidirectionalCollection { | |
func drop(first: Int, last: Int) -> SubSequence { | |
return self.dropFirst(first).dropLast(last) | |
} | |
} | |
let numbers = 0..<10 | |
numbers.drop(first: 1, last: 1) // 1..<9 | |
numbers.drop(first: 2, last: 4) // 2..<6 |
🤔 Maybe because if we extend Collection
we'd be able to do
let set = Set(arrayLiteral: 1,2,3,4,5).drop(first: 1, last: 3)
let dictionary = [1:2, 2:3, 4:5].drop(first: 1, last: 3)
which does not seem to make much sense
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm wondering what's the reason for the use of
BidirectionalCollection
instead ofCollection
. 😉