This issue was raised in the mailing list: https://groups.google.com/forum/#!topic/julia-users/iBydnBqQgxg
Although we can define a custom type and specialize the < operator for it, sometimes we may be interested in testing different operators on the spot. What are your thoughts on an additional option a la C++?
findmin(array, lt=<)
It should probably be like sort and also take a by? And shouldn't the same options apply to the minimum function?
@stevengj I'm planning to add just this option for now, others can contribute more options in the future if they find it useful. Can I move forward and send a PR?
Actually I'm not sure if that is a good addition. From one side it looks like an useful option, from the other side I think one can always convert the set of objects to a numeric score with a simple map, apply indmin and query the desired object.
What is more Julian and clean?
Yes, I am closing this one as non-Julian.
Actually, I think by and lt keywords, analogous to sort, would be a good idea in findmin, minimum, and median. Avoiding allocation of additional arrays, not to mention consistency with sort, is typically Julian.
You are assuming that each collection is indexable. This doesn't work e.g. with dictionaries:
julia> d = Dict(3=>'a', 2=>'b')
Dict{Int64,Char} with 2 entries:
2 => 'b'
3 => 'a'
julia> findmin(d)
(2=>'b',1)
julia> d[1]
ERROR: KeyError: 1 not found
That is, one first has to convert the dictionary to an array while converting the element types, then apply findmin, then get the respective array element. It is much more efficient to write a for loop while traversing the dictionary.
Agreed. I'll send the PR soon.
-J煤lio
@juliohm, please look at how by and lt are implemented for sort and use the same mechanism.
@stevengj could you please add the label up for grabs and intro issue to this issue?
Lovely meeting you last week Julio! :) I added the up for grabs label, but forewent adding the intro issue label (which I am not certain is accurate for this project). Best!
The same Sacha! Thanks for adding the label, we should set a meetup at Stanford for Julia users at some point. :) Best!
I believe this issue is being addressed somewhere else already for Julia v0.7? If it is a duplicate, could you please close it?
I'm not aware of changes which would have fixed this at this point.
Thank you @nalimilan, plans to address this issue in your recent PR (https://github.com/JuliaLang/julia/pull/24673) or in the 1.0 milestone?
No, the priority for 0.7 is to make the API consistent, new features can be added later.
Makes sense, this issue can be viewed as a new feature since the option is not implemented yet.
Maybe we could add this issue to some milestone? Like Julia 1.2?
If somebody does the work it can be merged at any point, but we use time-based releases rather than feature-based releases.