It’s about the elements in a versus :b.
The elements in a are Pair{Symbol, Int64}, e.g. :a=>1
In the list of such elements you are looking for the first :b
If I am right so far, it’s about comparing a Pair{Symbol, Int64} with a Symbol, therefor x[1] vs y where x[1]is the Symbol from inside the Pair, and y is just the Symbol :b.
Is this understandable? I am not sure and not good in being short and on the point.
Actually I don’t understand the by keyword, as the list is expected to be already sorted…
So, using by=first here, seems to also apply first to :b which raises the original error. Therefor my idea not using by but defining lt.
The :by keyword tells which part of the objects should be compared.
I thought that the object to compare would be compared to the by part since the following works:
Yes, but you are searching for :b which is a Symbol, and first(::Symbol) raises the original error, because a single Symbol:b is not iterable as it is not a collection.`
julia> first(:b)
ERROR: MethodError: no method matching iterate(::Symbol)
So defining first on type Symbol, as in my last post, resolves this, but it’s not the recommended solution. The recommended solution is defining the less-than relation between Pair{Symbol, Int64} and Symbol.
Now you are editing your replies… this is becoming to awkward, so I think, it’s all said, perhaps not in the best understandable way.
I edit my posts when I have written a mistake and hope the edit is before you read.
I think I understand: the by is also applied to the value I want to compare (unfortunately)
and my last example works by a fluke (that first is valid for an Int).
It works since first((:b,)) is defined and returns :b. I think I projected in my mind a better interface for the searchsorted... routines in case of by keyword that the actual interface,that is I hoped that the by function would not be applied to the value given to compare, which seemed natural.
I think that I was convinced that that is the reasonable behavior, but I don’t remember why. Let me see if I find the thread. (I found the thread, but it was not really related, I just learnt that there, not really with a good justification).
Perhaps we could ask for a compromise, that is a keyword to the searchsorted... function which would signify that the by function is not applied to the object to compare.