Skip to content

Instantly share code, notes, and snippets.

@lunaspeed
Created June 19, 2020 00:48
Show Gist options
  • Save lunaspeed/676f072de712ddfc8d820e33af44bba3 to your computer and use it in GitHub Desktop.
Save lunaspeed/676f072de712ddfc8d820e33af44bba3 to your computer and use it in GitHub Desktop.
go to functional
func sum(list []int) int {
var t int
for _, i := range list {
t += i
}
return t
}
//只能加總數字?
type Appendable interface {
Append(Appendable) Appendable
}
func sum(list []Appendable) Appendable {
var t Appendable
for _, a := range list {
t = t.Append(a)
}
return t
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment