• Search through children in a path-like manner.

    It finds the first child of root that matches continuePredicate. The function gets passed a depth of 1 to begin with. It recurses, looking for the next sub-child, etc.

    If it can't find a child, it stops.

    This is different to 'find' functions, which exhausively search all possible child nodes, regardless of position in tree.

    const path = 'a.aa.aaa'.split('.');
    const pred = (nodeValue, depth) => {
    if (nodeValue === path[0]) {
    path.shift(); // Remove first element
    return true;
    }
    return false;
    }

    // Assuming we have a tree of string values:
    // a
    // - aa
    // - aaa
    // - ab
    // b
    // - ba
    for (const c of follow(tree, pred)) {
    // Returns nodes: a, aa and then aaa
    }

    Type Parameters

    • T

    Parameters

    • root: TraversableTree<T>
    • continuePredicate: ((nodeValue: T, depth: number) => boolean)
        • (nodeValue, depth): boolean
        • Parameters

          • nodeValue: T
          • depth: number

          Returns boolean

    • depth: number = 1

    Returns IterableIterator<T>