Created
February 12, 2018 09:51
-
-
Save philipjkim/a14558872dad79044a8950f616e80ddb to your computer and use it in GitHub Desktop.
genny sample template for list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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