vapor / core

🌎 Utility package containing tools for byte manipulation, Codable, OS APIs, and debugging.
MIT License
82 stars 50 forks source link

"Free" ReflectionDecodable conformance for CaseIterable enums #148

Closed bre7 closed 6 years ago

bre7 commented 6 years ago
extension ReflectionDecodable where Self: CaseIterable {

    public static func reflectDecoded() throws -> (Self, Self) {
        guard !allCases.isEmpty, allCases.count > 1 else { throw ReflectionError() }
        guard let first = allCases.first, let last = allCases.last else { throw ReflectionError() }
        return (first, last)
    }
}

4.2 PR ?

tanner0101 commented 6 years ago

Yes, please!