@@ -20,9 +20,19 @@ pre_visit <- function(pd_nested, funs) {
20
20
if (is.null(pd_nested )) {
21
21
return ()
22
22
}
23
+ if (length(funs ) == 0 ) {
24
+ return (pd_nested )
25
+ }
23
26
pd_nested <- visit_one(pd_nested , funs )
24
27
25
- pd_nested $ child <- map(pd_nested $ child , pre_visit , funs = funs )
28
+ children <- pd_nested $ child
29
+ for (i in seq_along(children )) {
30
+ child <- children [[i ]]
31
+ if (! is.null(child )) {
32
+ children [[i ]] <- pre_visit(child , funs )
33
+ }
34
+ }
35
+ pd_nested $ child <- children
26
36
pd_nested
27
37
}
28
38
@@ -32,8 +42,19 @@ post_visit <- function(pd_nested, funs) {
32
42
if (is.null(pd_nested )) {
33
43
return ()
34
44
}
45
+ if (length(funs ) == 0 ) {
46
+ return (pd_nested )
47
+ }
48
+
49
+ children <- pd_nested $ child
50
+ for (i in seq_along(children )) {
51
+ child <- children [[i ]]
52
+ if (! is.null(child )) {
53
+ children [[i ]] <- post_visit(child , funs )
54
+ }
55
+ }
56
+ pd_nested $ child <- children
35
57
36
- pd_nested $ child <- map(pd_nested $ child , post_visit , funs = funs )
37
58
visit_one(pd_nested , funs )
38
59
}
39
60
@@ -46,7 +67,10 @@ post_visit <- function(pd_nested, funs) {
46
67
# ' @family visitors
47
68
# ' @keywords internal
48
69
visit_one <- function (pd_flat , funs ) {
49
- Reduce(function (x , fun ) fun(x ), funs , init = pd_flat )
70
+ for (f in funs ) {
71
+ pd_flat <- f(pd_flat )
72
+ }
73
+ pd_flat
50
74
}
51
75
52
76
# ' Propagate context to terminals
0 commit comments