RFC: seachsorted(a,x,by=f) no longer applies by
to the key argument x
#16056
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Following #9429, this pull request modifies
searchsorted
and friends to not apply to optionalby
argument to the sought for keyx
. As explained in #9429, this makes sense because it is not always possible to come up with a value x such thatby(x)
is the determinant is the binary search. In addition to the examples in #9429, consider a line of people ordered according to height. It is possible that a user is interested in the first person taller then 1.66 meters, even though no person in the line-up actually has that height.The behaviour of
searchsorted
before these modifications can be achieved by callingThe tests in
test/sorting.jl
have been modified to pass. In particular, consider:Before, this test read
This demonstrates how unnatural the previous behaviour was. The key
1
is arbitrarily chosen from the set of values that giveby(x) == false
. In addition, the previous behaviour obfuscates that in order forsearchsorted
to work correctly, it relies on the Julia conventionfalse < true
.