Skip to content

Instantly share code, notes, and snippets.

@jakehawken
Created April 4, 2022 04:09
Show Gist options
  • Save jakehawken/b340de341908c8407a98982e9a5ebdbb to your computer and use it in GitHub Desktop.
Save jakehawken/b340de341908c8407a98982e9a5ebdbb to your computer and use it in GitHub Desktop.
extension Array {
func scan(forEachNeighbors action: (Element, Element) -> Void) {
guard count >= 2 else {
return
}
var indexA = 0
var indexB = 1
while indexB <= count - 1 {
let elementA = self[indexA]
let elementB = self[indexB]
action(elementA, elementB)
indexA += 1
indexB += 1
}
}
}
@jakehawken
Copy link
Author

I gotta ask: Snake case in Swift? Surely you need more boundaries in your life.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment