Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: Go 2: generic type Inter int8,int16,int32,int64 #42139

Closed
hqpko opened this issue Oct 22, 2020 · 3 comments
Closed

proposal: Go 2: generic type Inter int8,int16,int32,int64 #42139

hqpko opened this issue Oct 22, 2020 · 3 comments

Comments

@hqpko
Copy link

@hqpko hqpko commented Oct 22, 2020

type Inter int8,int16,int32,int64

func Less(a,b Inter)bool{
  return a<b
}

// and
type UInter uint8,uint16,uint32,uint64
type Float float32,float64
type Number Inter,Uinter,Float

func Less(a,b Number)bool{
  return a<b
}
func Abs(n Number)Number{
  if n<0{return -n}
  return n
}
func Map(s []Number, f func(Number)Number)[]Number{
  r := make([]Number, len(s))
	for i, v := range s {
		r[i] = f(v)
	}
	return r
}

// sorter
type Sorter Number,string 
func Sort(list []Sorter){
  // ...
}

// even with interface
type Some interface{String()},string
@gopherbot gopherbot added this to the Proposal milestone Oct 22, 2020
@gopherbot gopherbot added the Proposal label Oct 22, 2020
@mvdan
Copy link
Member

@mvdan mvdan commented Oct 22, 2020

Please note that you should fill https://github.com/golang/proposal/blob/master/go2-language-changes.md when proposing a language change.

@martisch martisch changed the title proposal: generics: type Inter int8,int16,int32,int64 proposal: Go2: generic type Inter int8,int16,int32,int64 Oct 22, 2020
@ianlancetaylor ianlancetaylor changed the title proposal: Go2: generic type Inter int8,int16,int32,int64 proposal: Go 2: generic type Inter int8,int16,int32,int64 Oct 22, 2020
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Oct 22, 2020

@hqpko
Copy link
Author

@hqpko hqpko commented Oct 22, 2020

sorry, I need to think more, closed

@hqpko hqpko closed this Oct 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.