Skip to content

Instantly share code, notes, and snippets.

@philipjkim
Created February 12, 2018 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philipjkim/a14558872dad79044a8950f616e80ddb to your computer and use it in GitHub Desktop.
Save philipjkim/a14558872dad79044a8950f616e80ddb to your computer and use it in GitHub Desktop.
genny sample template for list
package list
import (
"github.com/cheekybits/genny/generic"
)
// Something .
type Something generic.Type
// SomethingList .
type SomethingList []Something
func NewSomethingList(l []Something) SomethingList {
if l == nil {
return SomethingList([]Something{})
}
return SomethingList(l)
}
type MappedType generic.Type
func (l *SomethingList) Map(f func(s Something) MappedType) []MappedType {
result := []MappedType{}
for _, item := range []Something(*l) {
result = append(result, f(item))
}
return result
}
// cat template.go | genny gen "Something=string MappedType=int" > list.go # fine
// cat template.go | genny gen "Something=string MappedType=int,string" > list.go # error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment