mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-30 03:51:05 +00:00
17 lines
456 B
Swift
17 lines
456 B
Swift
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
import Foundation
|
|
|
|
protocol Unknowable: RawRepresentable, CaseIterable where RawValue: Equatable {
|
|
static var unknownCase: Self { get }
|
|
}
|
|
|
|
extension Unknowable {
|
|
init(rawValue: RawValue) {
|
|
self = Self.allCases.first { $0.rawValue == rawValue } ?? Self.unknownCase
|
|
}
|
|
}
|
|
|
|
extension Unknowable {
|
|
static var allCasesExceptUnknown: [Self] { allCases.filter { $0 != unknownCase } }
|
|
}
|