On Mon, Aug 7, 2017 at 7:44 AM, <martin.r...@programmfabrik.de> wrote: >> >> > 2) find(sliceB, item_i_look_for) int, -1 for not found >> > >> > Why can I not find easily search for an item inside a Slice. Every other >> > language I know has this. And I need this in a generic form. >> >> As you have probably heard, Go does not have generics. Sorry. The >> loop that you need to write is fairly short. > > > The loop might be short, but I need to know the type of the items in my > Slice. > > So I need a loop for every datatype!?
Yes. > And I need to name it for each type differently? Yes. > Why? Because Go does not have generics. There has been a enormous amount of discussion on this in the past that I won't try to summarize here. You could read https://golang.org/issue/15292. > All I want to be able to do is to find an item in a Slice. > > Why does "append" work with all types then? Because it's easy to write a short correct find loop for the type you are using, but a good implementation of append is a much larger function. See also http://www.airs.com/blog/archives/559 . Ian -- 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.