1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 13:50:32 +05:30
yattee/Extensions/Array+Next.swift

18 lines
367 B
Swift
Raw Normal View History

2021-06-28 16:13:07 +05:30
extension Array where Element: Equatable {
2021-10-17 04:18:58 +05:30
func next(after element: Element?) -> Element? {
if element.isNil {
return first
}
let idx = firstIndex(of: element!)
2021-06-28 16:13:07 +05:30
if idx.isNil {
2021-06-28 16:13:07 +05:30
return first
}
let next = index(after: idx!)
return self[next == endIndex ? startIndex : next]
}
}