ghostty/macos/Sources/Helpers/Extensions/Array+Extension.swift
2025-06-05 07:05:11 -07:00

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
}
}