// This example demonstrates how enhanced visitable types can be
// visited with a function.
This example demonstrates how enhanced visitable types can be
visited with a function.
// This example demonstrates how enhanced visitable types can be // visited with a function .
func Example_walk() {
	data, _ := demo.NewContainer(true)
	var container, byVal, byRef int
	_, _, err := data.WalkTarget(func(ctx demo.TargetContext, x demo.Target) (d demo.TargetDecision) {
		switch x.(type) {
		case *demo.ContainerType:
			container++
		case *demo.ByValType:
			byVal++
		case *demo.ByRefType:
			byRef++
		default:
			return ctx.Error(fmt.Errorf("unknown type %s", reflect.TypeOf(x)))
		}
		return
	})
	if err != nil {
		panic(err)
	}
	fmt.Printf("Saw %d Container, %d ByValType, and %d ByRefType",
		container, byVal, byRef)
}
func Example_walk ( ) { data , _ := demo . NewContainer ( true ) var container , byVal , byRef int _ , _ , err := data . WalkTarget ( func ( ctx demo . TargetContext , x demo . Target ) ( d demo . TargetDecision ) { switch x . ( type ) { case * demo . ContainerType : container ++ case * demo . ByValType : byVal ++ case * demo . ByRefType : byRef ++ default : return ctx . Error ( fmt . Errorf ( " " , reflect . TypeOf ( x ) ) ) } return } ) if err != nil { panic ( err ) } fmt . Printf ( " " , container , byVal , byRef ) }
This example demonstrates how enhanced visitable types can be
visited with a function.
This example demonstrates how enhanced visitable types can be visited with a function .
//Output: //Saw 1 Container, 17 ByValType, and 6 ByRefType