Sorry, the predicate should be var b T pred := func(a T) bool { return cmp(a, b) >= 0 }
On Tue, Apr 5, 2022 at 7:27 AM Axel Wagner <axel.wagner...@googlemail.com> wrote: > Hm I must say, I also don't really understand removing the predicate-based > one. It is easy, when you have a comparison function, to get to a predicate: > pred := func(a, b T) bool { return cmp(a, b) >= 0 } > But not the other way around, so a predicate is more general. > > I used the predicate version of `sort.Search` to look for prefix-matches > in a sorted slice of paths. i.e. I was not looking for an equality match of > the needle, but also something of which the needle is a prefix. > > When I saw #50340 <https://github.com/golang/go/issues/50340> fly by, I > assumed this would be about adding a simpler version of `sort.Search` to > make the common use-case simpler, which was very much fine with me, so I > didn't follow that discussion. I would've spoken up sooner, if I expected > the more general version to disappear. > > On Tue, Apr 5, 2022 at 1:08 AM Sudhir Jonathan <sudhi...@gmail.com> wrote: > >> The earlier method signature for slices.BinarySearchFunc was very useful: >> >> It was of the form >> ``` >> slices.BinarySearchFunc(array, func(e T) bool) >> ``` >> which returned the smallest index at which predicate would return true. >> >> This was incredibly useful to do inequality operation binary searches - >> like find the smallest index in a sorted slice where the element was >> greater than this (helps figure out the index of the last repeat of an >> element in the sorted slice). >> >> I understand the new method is true-er to its name, but can we bring the >> old one back as well, maybe as slices.BinarySearchPredicate ? >> >> -- >> 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/f5f8c4a8-56da-4f00-a43b-20015828fdb5n%40googlegroups.com >> <https://groups.google.com/d/msgid/golang-nuts/f5f8c4a8-56da-4f00-a43b-20015828fdb5n%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- 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/CAEkBMfHPXtAzbM7bq3FPoo0J2Nz9g1%3DbrpxpBXrAqqG_ViU5RA%40mail.gmail.com.