1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.walkThroughTree = walkThroughTree;
|
7 | exports.walkThroughTreeGen = walkThroughTreeGen;
|
8 | function walkThroughTree(fn, options, ...args) {
|
9 | options = options || {};
|
10 | let first = true,
|
11 | result;
|
12 | for (const current of walkThroughTreeGen(fn, options, ...args)) if (first || !options.firstResult) {
|
13 | result = current;
|
14 | first = false;
|
15 | }
|
16 | return result;
|
17 | }
|
18 |
|
19 | function* walkThroughTreeGen(fn, options, ...args) {
|
20 | options = options || {};
|
21 | const dequeue = Array.prototype[options.horizontal ? 'shift' : 'pop'];
|
22 | const tokens = [args],
|
23 | nextTokens = [];
|
24 | const scope = {
|
25 | next(...args) {
|
26 | nextTokens.push(args);
|
27 | }
|
28 | };
|
29 | while (tokens.length) {
|
30 | yield fn.apply(scope, dequeue.call(tokens));
|
31 | if (nextTokens.length) {
|
32 | Array.prototype.push.apply(tokens, nextTokens);
|
33 | nextTokens.length = 0;
|
34 | }
|
35 | }
|
36 | } |
\ | No newline at end of file |