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