[swift-evolution] [Proposal] Add Binary Search functions to SequenceType

Lorenzo Racca lorenzo.racca at live.it
Tue Mar 15 13:58:07 CDT 2016

> On Mar 15, 2016, at 6:49 PM, Haravikk <swift-evolution at haravikk.me> wrote:
>> On 15 Mar 2016, at 15:48, Lorenzo Racca <lorenzo.racca at live.it <mailto:lorenzo.racca at live.it>> wrote:
>> I already knew the impossibility of applying such a predicate as “$0 == 3” and I actually couldn’t quite figure out a solution.
> I thought so, and I don’t think there is a way to do it, my point was really just that your swift doc comments weren’t clear on that point, then I went off at a bit of a tangent ;)
No problem! What I am trying to figure out here is how we should implement the lowerBound and upperBound functions. Should they exactly reflect their C++ counterparts? 
Anyway, it seems all of our implementations have the same problem, that they cannot be univocally called with any predicate whatsoever, (or at least it seemed to me during some tests with the implementations :) ), so I don’t really know how we should act. I am a little blocked.
Does anyone have ideas on how that could work no matter what predicate is given? Especially, an upperBound() function, which is a little trickier. 

>> On Mar 15, 2016, at 6:07 PM, Jeff Hajewski  <jeff.hajewski at gmail.come> wrote:
>> I suspect there is an easy solution here and I'm just having a mental block...

Jeff, I really do feel you, I’m in the same situation! 
I think your solution could be applicable though, just in a little more complicated way than C++ did, which is to extract the complement of the predicate and act differently upon that. 
As of now I don’t have the time to put down some code (time zone sucks) but will try asap.


Lorenzo Racca
+39 345 9294756
lorenzo.racca at live.it

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160315/c7a60b11/attachment.html>

More information about the swift-evolution mailing list