cheekybits / genny

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

define more type separately in 1 go file #32

Open fastfading opened 7 years ago

fastfading commented 7 years ago

check code below , I just want to define 2 type separately in 1 file however it generate ReadPairInt8 ReadPairInt16 many times, could u find a way fix it, like if there is only 1 type in one function , do not repeat it or define a generic.SingleType ` //go:generate genny -in=$GOFILE -out=../util/$GOFILE gen "T1=int8,int16,int32,int64,int,uint8,uint16,uint32,uint64,uint T2=float32,float64"

package util

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

type T1 generic.Type

func ReadPairT1(data string) (x, y T1) { splits := SplitParams(data) lx, := strconv.Atoi(splits[0]) ly, := strconv.Atoi(splits[1]) x = T1(lx) y = T1(ly) return }

type T2 generic.Type

func ReadPairT2(data string) (x, y T2) { splits := SplitParams(data) lx, := strconv.ParseFloat(splits[0], 32) ly, := strconv.ParseFloat(splits[1], 32) x = T2(lx) y = T2(ly) return } `

fastfading commented 7 years ago

one more question the go:generate xxxxxx command is too long, how can I write it into several lines

fastfading commented 7 years ago

I just want to write ReadPair in one file , and use different generic function for int and float

icock commented 7 years ago

Also, given S=More,Than,One,Type T=Multiple,Types, and

func f(s S) {}
func g(s S, t T) {}

genny will generate redundant definitions for f(S).

olivoil commented 6 years ago

I experienced the same issue. Would appreciate any guidance on how to implement a fix if a PR would be welcome.

pdrum commented 6 years ago

@olivoil parser.go generates the whole code once for each combination of specific types. For example it tends to generate the code once for S=More, T=Multiple, Once for S=Than, T=Multiple and so on (Each of these mappings is represented via a so called typeset). This leads to the bug mentioned in this issue.

Are you still thinking of making the PR? Please let me know if any more details would help.

picasso250 commented 3 years ago

3 year passed