Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Providing Helper function to walk a Shape #651

Closed
harjitdotsingh opened this issue Dec 15, 2017 · 1 comment
Closed

Providing Helper function to walk a Shape #651

harjitdotsingh opened this issue Dec 15, 2017 · 1 comment
Milestone

Comments

@harjitdotsingh
Copy link

There is no easy way to Walk the Shape object. Right now we get ambigious info from the Optimize calls.
Example

I hve the following code

type Collector []shape.Shape

func (t *Tagger) OptimizeShape(s shape.Shape) (shape.Shape, bool) {

    log.Println("||||", reflect.TypeOf(s))
    l, ok := s.(shape.Lookup)
    if !ok {
        t.Collector = append(t.Collector, s)
        return s, false // no changes to query
    }
    // generate a new tag
    t.n++
    tag := fmt.Sprintf("t%d", t.n)

    // replace with Save to tag of old shape
    return shape.Save{
        From: l,
        Tags: []string{tag},
    }, true
}

This returns ambigious information. Need a better way to Walk the Shape

@dennwc dennwc added this to the v0.7 milestone Dec 16, 2017
@dennwc dennwc closed this as completed in 633828c Dec 16, 2017
@dennwc
Copy link
Member

dennwc commented Dec 16, 2017

You can now walk the tree with a helper:

var arr []shape.Lookup
shape.Walk(s, func(s Shape) bool {
	if l, ok := s.(shape.Lookup); ok {
		arr = append(arr, l)
	}
	return true // continue
})

It will not produce duplicates, but will not allow modifications either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants