3 ms·
I'd like to see a best-practices range-compatible depth-first preorder push iterator for a tree. Any tree implementation would do for purposes of exposition; fo
by euroderf 2y ago
I'd like to see a best-practices range-compatible depth-first preorder push iterator for a tree. Any tree implementation would do for purposes of exposition; for example package ast, where node order is important, unlike package filepath. FWIW there is current discussion in issue 64341 (and also 61405).
- EdiX 2y agoYou could do: func inspect(n ast.Node) func(func(ast.Node) bool) { return func(f func(ast.Node) bool) { ast.Inspect(n, f) } } used: for n := range inspect(f) { fmt.Printf("%T\n", n) }
- euroderf 2y agoOK, this works cos package ast already has `func Inspect`. So how about a more general case ? A case where we do not have a `func Inspect` already in the stdlib ? Maybe just replace it with (for example) `filepath.WalkDir` ?