Well, I imagine there's only a few types in any code where the logic would require retrieving the "last" member of a list or array. Something like the following could address that and be more performant than using reflection - https://play.golang.org/p/XTbuf7RegF2.
On Sunday, June 14, 2020 at 9:06:48 AM UTC-6, Tom Limoncelli wrote: > > Thank you for the feedback! > > I took Jan Mercl's suggestion and wrote the short function to see if > it is useful. It is based on C Banning's suggested code. I'm going to > start using it on my projects to see if it helps. > > The module is called "hind": https://github.com/TomOnTime/hind > > hind.S(x) works on strings. The compiler should inline this. It should > be no different that "len(x)-1" (other than conveying intent better). > > hind.G(x) uses reflect to work on anything you pass it. It is slow > but it is a good placeholder until we have generics or whatever. It > is useful for when showing intent is more important than performance. > > Feedback on the module would be greatly appreciated! If you use the > module, I'd love to know if you felt it reduced your off-by-one errors > (or the potential for them). > > Best, > Tom > > On Sat, Jun 13, 2020 at 1:09 PM Jan Mercl <0xj...@gmail.com <javascript:>> > wrote: > > > > On Sat, Jun 13, 2020 at 5:37 PM Jake Montgomery <jake...@gmail.com > <javascript:>> wrote: > > > > > You cant really write a short 'end()' function. You have to write an > end function for every type of slice. Or use reflection, which would make > the function slow, and not inlined. Generics anyone? > > > > I haven't mentioned anything about the function being universal. IMO > > in the majority of cases, it does not have to be. Why is such > > limitation being inserted? > > > > It takes probably less time to write the "specialized" end function > > than we have already spent discussing it. And that's assuming it's a > > good idea to do so in the first place, which I don't really accept. > > > > -- > > 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 golan...@googlegroups.com <javascript:>. > > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/CAA40n-VbNBCKkbrtwG7mb4GEKmM6OBe_AetPRMG6jAsVf_ULxA%40mail.gmail.com. > > > > > > -- > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/6b0e0b94-b4f3-44e8-b9f5-d2cadeb21f2fo%40googlegroups.com.