MCPcopy Create free account
hub / github.com/cogentcore/core / WalkUp

Method WalkUp

tree/nodebase.go:444–456  ·  view source on GitHub ↗

WalkUp calls the given function on the node and all of its parents, sequentially in the current goroutine (generally necessary for going up, which is typically quite fast anyway). It stops walking if the function returns [Break] and keeps walking if it returns [Continue]. It returns whether walking

(fun func(n Node) bool)

Source from the content-addressed store, hash-verified

442// returns [Break] and keeps walking if it returns [Continue]. It returns
443// whether walking was finished (false if it was aborted with [Break]).
444func (n *NodeBase) WalkUp(fun func(n Node) bool) bool {
445 cur := n.This
446 for {
447 if !fun(cur) { // false return means stop
448 return false
449 }
450 parent := cur.AsTree().Parent
451 if parent == nil || parent == cur { // prevent loops
452 return true
453 }
454 cur = parent
455 }
456}
457
458// WalkUpParent calls the given function on all of the node's parents (but not
459// the node itself), sequentially in the current goroutine (generally necessary

Callers 2

isExternalMethod · 0.80
TestNodeWalkFunction · 0.80

Calls 1

AsTreeMethod · 0.65

Tested by 1

TestNodeWalkFunction · 0.64