UNPKG

rc-js-util

Version:

A collection of TS and C++ utilities to help writing performant and correct applications, achieved through strict typing and (removable) invariant checking.

29 lines 866 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.treeIterate = void 0; /** * @public * Iterates over the whole tree, in a depth first fashion. * * @param node - The start point. * @param callback - Called for each node, including the start point. * * @remarks * See {@link treeIterate}. */ function treeIterate(node, callback) { callback(node, null, 0); treeRecurseImpl(node, node.getChildren(), 1, callback); } exports.treeIterate = treeIterate; function treeRecurseImpl(parent, children, depth, callback) { if (children == null) { return; } for (let i = 0, iEnd = children.length; i < iEnd; i++) { const node = children[i]; callback(node, parent, depth); treeRecurseImpl(node, node.getChildren(), depth + 1, callback); } } //# sourceMappingURL=tree-iterate.js.map