Skip to content

Instantly share code, notes, and snippets.

@pixelrevision
Created December 5, 2017 22:15

Revisions

  1. pixelrevision created this gist Dec 5, 2017.
    13 changes: 13 additions & 0 deletions Sequence+Walk.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    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)
    }
    }
    }

    }