mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 16:26:08 +03:00
20 lines
449 B
Swift
20 lines
449 B
Swift
extension Array {
|
|
/// Returns the index before i, with wraparound. Assumes i is a valid index.
|
|
func indexWrapping(before i: Int) -> Int {
|
|
if i == 0 {
|
|
return count - 1
|
|
}
|
|
|
|
return i - 1
|
|
}
|
|
|
|
/// Returns the index after i, with wraparound. Assumes i is a valid index.
|
|
func indexWrapping(after i: Int) -> Int {
|
|
if i == count - 1 {
|
|
return 0
|
|
}
|
|
|
|
return i + 1
|
|
}
|
|
}
|