Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SWIFT

circular array swift

extension Array {
	subscript(circular index: Int) -> Element? {
		guard index >= 0 && !isEmpty else { return nil }
		guard index >= count else { return self[index] }
		return self[index % count]
	}
}
Source by gist.github.com #
 
PREVIOUS NEXT
Tagged: #circular #array #swift
ADD COMMENT
Topic
Name
6+7 =