go-goast / goast

goast is a Go AST utility with the aim of providing idiomatic meta-programming facilities for Go.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Match on more than just interface{}

jamesgarfield opened this issue · comments

Provide the ability for metacode to specify an interface that must satisfied (beyond interface{}) to have a matching type. This will work in a somewhat analogous way to how Concepts are supposed to work in C++

E.g. Allow for code along the lines of https://gist.github.com/egonelbre/d6787bfff0684cddbd10 to be generated

package set
type Elem interface {
    Hash() int64
    Equals(e Elem) bool
}

type _Set struct {
    buckets map[int64][]Elem
    size int
    ...
}

func New_Set() *Set { return &Set{make(map[int64][]Elem)} }
func (s *Set) Insert(v Elem) { ... }
func (s *Set) Remove(v Elem) { ... }
func (s *Set) Union(s *Set) *Set { ... }
func (s *Set) Count() int { ... }
func (s *Set) Contains(v Elem) bool { ... }
func (s *Set) ForEach(fn func(Elem)) { ... }