<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class=""><div><blockquote type="cite" class=""><div class="">On 15 Mar 2016, at 15:48, Lorenzo Racca <<a href="mailto:lorenzo.racca@live.it" class="">lorenzo.racca@live.it</a>> wrote:</div><div class=""><br class="">I already knew the impossibility of applying such a predicate as “$0 == 3” and I actually couldn’t quite figure out a solution.</div></blockquote><br class=""></div><div>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 ;)</div></div><br class=""><div><blockquote type="cite" class=""><div class="">On 15 Mar 2016, at 17:07, Jeff Hajewski <<a href="mailto:jeff.hajewski@gmail.com" class="">jeff.hajewski@gmail.com</a>> wrote:</div><div class=""><div dir="ltr" class=""><br class=""><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(123, 44, 214);" class=""> /// Returns an index such that each element at or above the index is partitioned from below by the partition predicate</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><font class=""><span style="white-space:pre-wrap" class=""> </span></font><span style="color:rgb(123,44,214)" class="">///</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><font class=""><span style="white-space:pre-wrap" class=""> </span></font><span style="color:rgb(123,44,214)" class="">/// - <span style="color:rgb(123,35,170)" class="">Parameter</span> partitionPredicate: The partioning predicate returns `true` for elements in the collection that are</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><font class=""><span style="white-space:pre-wrap" class=""> </span></font><span style="color:rgb(123,44,214)" class="">/// ordered below, with respet to the partitioning predicate.</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(123, 44, 214);" class=""> /// - <span style="color:rgb(123,35,170)" class="">Complexity</span>: O(lg(n))</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(123, 44, 214);" class=""> ///</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><font class=""><span style="white-space:pre-wrap" class=""> </span></font><span style="color:rgb(123,44,214)" class="">/// - <span style="color:rgb(123,35,170)" class="">Returns</span>: An index such that each element at or above the returned index evaluates as `false` with respect to `partitionPredicate(_:)`</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><font class=""><span style="white-space:pre-wrap" class=""> </span></font><span style="color:rgb(187,44,162)" class="">@warn_unused_result</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="color:rgb(187,44,162)" class="">func</span> lowerBound(<span style="color:rgb(187,44,162)" class="">@noescape</span> partitionPredicate: <span style="color:rgb(112,61,170)" class="">Self</span>.<span style="color:rgb(112,61,170)" class="">Generator</span>.<span style="color:rgb(112,61,170)" class="">Element</span> -> <span style="color:rgb(112,61,170)" class="">Bool</span>) -> <span style="color:rgb(112,61,170)" class="">Index</span> {</div></div></div></div></blockquote><div><br class=""></div><div>Should probably have "requires: Collection is sorted" or such, as a binary search can’t really guarantee correct behaviour otherwise, no matter what your predicate is. I also kind of prefer a name of isOrderedBefore for the predicate; it matches .sort() and is very specific about what it does.</div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px" class=""><span style="white-space:pre-wrap" class="">        </span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><font class=""><span style="white-space:pre-wrap" class=""> </span></font><span style="color:rgb(123,44,214)" class="">/// Returns an index such that each element below the index is strictly less than the partition predicate</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><font class=""><span style="white-space:pre-wrap" class=""> </span></font><span style="color:rgb(123,44,214)" class="">///</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(123, 44, 214);" class=""> /// - <span style="color:rgb(123,35,170)" class="">Parameter</span> partitionPredicate: The partioning predicate. Returns `true` for elements in the collection that are</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(123, 44, 214);" class=""> /// ordered below, with respet to the partitioning predicate.</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><font class=""><span style="white-space:pre-wrap" class=""> </span></font><span style="color:rgb(123,44,214)" class="">/// - <span style="color:rgb(123,35,170)" class="">Complexity</span>: O(lg(n))</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(123, 44, 214);" class=""> ///</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><font class=""><span style="white-space:pre-wrap" class=""> </span></font><span style="color:rgb(123,44,214)" class="">/// - <span style="color:rgb(123,35,170)" class="">Returns</span>: An index such that each element evaluates as `false` with respect to `partitionPredicate(_:)`</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><font class=""><span style="white-space:pre-wrap" class=""> </span></font><span style="color:rgb(187,44,162)" class="">@warn_unused_result</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="white-space:pre-wrap" class=""> </span><span style="color:rgb(187,44,162)" class="">func</span> upperBound(<span style="color:rgb(187,44,162)" class="">@noescape</span> partitionPredicate:<span style="color:rgb(112,61,170)" class="">Self</span>.<span style="color:rgb(112,61,170)" class="">Generator</span>.<span style="color:rgb(112,61,170)" class="">Element</span> -> <span style="color:rgb(112,61,170)" class="">Bool</span>) -> <span style="color:rgb(112,61,170)" class="">Index</span> {</div></div></div></div></blockquote><div><br class=""></div><div>Did you mean “each element above the returned index evaluates as false"?</div><div><br class=""></div><div><br class=""></div><div>Implementation wise they seem fine, but I think that for correctness you should be using .successor() and .advancedBy(), as not all indexes are numeric.</div></div></body></html>