On Tue, 18 Sep 2018 10:11:52 -0700 (PDT) mhhc...@gmail.com wrote: > I agree with Robert, this is not re usable.
What is not reusable? A generic Sum function allowed by the CGG that can sum any type of any base that accidentally has anything countable in it? > I much prefer this > > func Sum(some []K, add func(l,r K) K) (ret K) { > for _, v := range some { > ret = add(ret, v) > } > return ret > } > > func main(){ > total := Sum([]int{1,2,3,4}, func(l,r int) int {return l+r}) > } How clever and generic it looks. Generic, javish and cpluplusish. And how readable call site it gave. In CGG Go user code call is exactly the same for ANY type. total := Sum(x) // For var x []AnyType. ANY. var x []string total := Sum(x) may return sum of all runes in all strings and sprintf-ed to the resulting string. > this is not re usable. How can I call your example to get string result of sum of all runes? CGG's is as with any other type: `total := Sum(x)` -- Wojciech S. Czarnecki << ^oo^ >> OHIR-RIPE -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.