Skip to content

Instantly share code, notes, and snippets.

@hamsternik
Created November 12, 2018 12:57
Show Gist options
  • Save hamsternik/266cdff69a4fa441771e7581421fa7f2 to your computer and use it in GitHub Desktop.
Save hamsternik/266cdff69a4fa441771e7581421fa7f2 to your computer and use it in GitHub Desktop.
import Foundation
public protocol EnumerableEnum: RawRepresentable where RawValue == Int {
static var firstIndex: Int { get }
}
public extension EnumerableEnum {
static var firstIndex: Int { return 0 }
static var all: [Self] {
var index = firstIndex
return Array(AnyIterator {
defer { index += 1 }
return Self(rawValue: index)
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment