Hacker News new | ask | show | jobs
by EdiX 678 days ago
You 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)
    }
1 comments

OK, 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` ?