Skip to content

Instantly share code, notes, and snippets.

@pixelrevision
Created December 5, 2017 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pixelrevision/b4f8c003734620885d936c3b96cb7f9e to your computer and use it in GitHub Desktop.
Save pixelrevision/b4f8c003734620885d936c3b96cb7f9e to your computer and use it in GitHub Desktop.
Sequence+Walk
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