Created
April 4, 2022 04:09
-
-
Save jakehawken/b340de341908c8407a98982e9a5ebdbb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} | |
} |
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
And of course this is more in the spirit of your scan() function: