On Wednesday, 9 August 2017 09:10:30 UTC+2, marti...@programmfabrik.de 
> Volker thanks for the reply. Coming from Python I can do a simple test like
> if item in my_array:
>    # do something
> else:
>    # do something else
> I can understand that it cannot be that easy in Go (and then, why not, 
> "equals" is already defined), but image you
> have to use a for-loop every time or a specialized function every time. 
> That is awkward and unnecessary.

See Jan's comment. This is the exact problem here.

(I think you may well assume that most people in this list know
and have experience in Python and possible a dozen other
languages too. So there is not much need showing how
something is done in Python: The question is how it could
be done in Go and we argue that it cannot be made that


> I agree, that the more complex idea to have a "findFirst" with a dedicated 
> matching function
> is more complicated, but hey, sort.Slice is the same thing, isn't it? It 
> takes a comparison func to return -1, 0, or 1.
> func findFirst(slice interface{}, matches func(i int 
> <https://golang.org/pkg/builtin/#int>) int)

There is a major difference in sort.SortSlice and your proposed 
The complicated logic is in different places.
For SortSlice it is in the sorting code (and not in the less function).
For FindFirst it is in the match function (and not in finding code).
That's why it is sensible to have a function doing the heavy lifting,
the sorting but hiding a trivial (because all logic is in match) for loop
for finding the first element is not needed.


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.

Reply via email to