github.com/searKing/golang/go@v1.2.117/container/traversal/traversal.go (about)

     1  // Copyright 2020 The searKing Author. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package traversal
     6  
     7  // TODO template in Go2.0 is expected
     8  func traversal(node any,
     9  	traversalOrder traversaler,
    10  	handler Handler) {
    11  	traversalOrder.traversal([]levelNode{{
    12  		node: node,
    13  	}}, levelNodeHandlerFunc(func(ln levelNode) (goon bool) {
    14  		if handler == nil {
    15  			// traversal no node
    16  			return false
    17  		}
    18  		return handler.Handle(ln.node, ln.depth)
    19  	}))
    20  }