Created
December 5, 2017 22:15
-
-
Save pixelrevision/b4f8c003734620885d936c3b96cb7f9e to your computer and use it in GitHub Desktop.
Sequence+Walk
This file contains hidden or 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 Sequence { | |
func walk(_ childSelector: (Element) -> [Element], handler: (Element) -> Void) { | |
for item in self { | |
handler(item) | |
let children = childSelector(item) | |
if children.count > 0 { | |
children.walk(childSelector, handler: handler) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment