mirror of
https://github.com/yattee/yattee.git
synced 2024-12-15 23:00:32 +05:30
16 lines
411 B
Swift
16 lines
411 B
Swift
extension CaseIterable where Self: Equatable {
|
|
func next(nilAtEnd: Bool = false) -> Self! {
|
|
let all = Self.allCases
|
|
let index = all.firstIndex(of: self)!
|
|
let next = all.index(after: index)
|
|
|
|
if nilAtEnd == true {
|
|
if next == all.endIndex {
|
|
return nil
|
|
}
|
|
}
|
|
|
|
return all[next == all.endIndex ? all.startIndex : next]
|
|
}
|
|
}
|