Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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