shorten preorderWalk

This commit is contained in:
Josh Deprez 2021-09-23 12:14:03 +10:00
parent 80a0132c39
commit eed623647c

View file

@ -181,14 +181,12 @@ func preorderWalk(component, parent interface{}, visit func(component, parent in
if err := visit(component, parent); err != nil {
return err
}
sc, ok := component.(Scanner)
if !ok {
return nil
if sc, ok := component.(Scanner); ok {
return sc.Scan(func(c interface{}) error {
return preorderWalk(c, component, visit)
})
}
scv := func(c interface{}) error {
return preorderWalk(c, component, visit)
}
return sc.Scan(scv)
return nil
}
// PostorderWalk calls visit with every component and its parent, reachable from