Skip to content

Instantly share code, notes, and snippets.

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
@andyyhope
andyyhope / SwiftEvolution_EnumCaseCountFunctionality_AndyyHope.md
Last active March 12, 2020 13:05
Swift Evolution - Enum Case Count Functionality

Swift Evolution Proposal

Author: Andyy Hope

Enum Values() Functionality (Update)

It has been brought to my attention that there was more use for the unintended values() functionality that I had outline in my "Other Languages" Java example below.

On the Swift Evolution mailing list, one developer outlined their requirement to loop through an array of enum case values to add different states to objects.

Another example where a values array would be useful if the developer wants to do something different for each different case, such as setting an image on a UIButton subclass for each different UIControlState