Skip to content
This repository has been archived by the owner on Apr 4, 2022. It is now read-only.

Support more than 3 types #2

Open
schancel opened this issue Jan 7, 2015 · 5 comments
Open

Support more than 3 types #2

schancel opened this issue Jan 7, 2015 · 5 comments

Comments

@schancel
Copy link

schancel commented Jan 7, 2015

Should support more than 3 types. They could be defined in the go generic source via:

type Param generic.Type;

The gengen.go could scan the file for these top-level decls and add them to generic types.

If you'd accept a PR for this, I could do it probably.

@joeshaw
Copy link
Owner

joeshaw commented Jan 12, 2015

Sure, I'd be happy to accept a PR for this.

@ghost
Copy link

ghost commented Aug 5, 2015

whatever happened with this idea?

@joeshaw
Copy link
Owner

joeshaw commented Aug 5, 2015

I'd still like to do this at some point, but it hasn't been an issue for me thus far. The command-line should probably take key/value arguments to support this. Something like:

$ gengen github.com/example/foo Param=int

If the key (Param) isn't provided it'd still work with generic.T et al for backward compatibility.

@ghost
Copy link

ghost commented Aug 6, 2015

The 'key=value' syntax seems good to me. :)

@james-lawrence
Copy link
Contributor

I'd like to see something like this (just to have explicit examples, I think I'm in agreement with schancel):

type Value gengen.Generic

type SortedSet interface {
  Insert(Value) bool
  Remove(value) bool
  Pop() Value
}

func NewSortedSet(comparator func(a, b Value) int) SortedSet { ... }
// go:generate gengen github.com/example/SortedSet Value=int
// would result in the following code:
type SortedSet interface {
  Insert(int) bool
  Remove(int) bool
  Pop() int
}

func NewSortedSet(comparator func(a, b int) int) SortedSet { ... }
// go:generate gengen github.com/example/SortedSet Value=string
// would result in the following code:
type SortedSet interface {
  Insert(string) bool
  Remove(string) bool
  Pop() string
}

func NewSortedSet(comparator func(a, b string) int) SortedSet { ... }

Multiple Generic Types example:

type Key gengen.Generic
type Value gengen.Generic

type Map interface {
  Insert(Key, Value) bool
  Delete(Key) bool
}
// go:generate gengen github.com/example/Map Key=int Value=string
// would result in the following code:
type Map interface {
  Insert(int, string) bool
  Delete(int) bool
}

This would support arbitrary number of polymorphic parameters, and be straight forward to use, can still leverage golang's ast package, and would still be valid go code.

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

No branches or pull requests

3 participants