cheekybits / genny

Elegant generics for Go
MIT License
1.71k stars 167 forks source link

Are slices supported? #65

Open pablote opened 4 years ago

pablote commented 4 years ago

This is what I'm trying to do, works fine for simple types, but fails with slices:

package providers

import (
    "github.com/cheekybits/genny/generic"
)

//go:generate genny -in=$GOFILE -out=gen_$GOFILE gen "T=[]string"

type T generic.Type

type TProvider interface {
    Get() (T, error)
}

thanks

damoon commented 3 years ago

I believe the "[]" can not be used as part of the function name.

type []StringProvider interface {
    Get() ([]string, error)
}

It works to define a type alias.

type StringSlice []string

type StringSliceProvider interface {
    Get() (StringSlice, error)
}