I’ve said many time, the CGG example you cite here is not generic code. If I want to pass a different user type and use that method I can’t, I need to change the source of Sum(). That is not generic programming...
> On Sep 18, 2018, at 10:58 AM, Wojciech S. Czarnecki <o...@fairbe.org> wrote: > > On Tue, 18 Sep 2018 08:26:29 -0700 (PDT) > alan.f...@gmail.com wrote: > >> There's no way that your generic Sum function can deal with big.Int > > Oh, with CGG (https://github.com/ohir/gonerics) of course there is: > > func (x type []K) Sum() (r type K) { > for type switch { > case K range int64(), uint64(), float64(), complex128(): > for _, v := range x { > r += v > } > case K big.Int: > for _, v := range x { > r.Add(r,v) > } > break // or return in every case instead > } > return > } > > :) Your welcome. > >> Alan >> > > -- > 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. -- 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.