Skip to content

Feature request - maximum/minimum and related functions with arbitrary orderings #39721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jlumpe opened this issue Feb 18, 2021 · 3 comments

Comments

@jlumpe
Copy link
Contributor

jlumpe commented Feb 18, 2021

I'm constantly missing the key argument to Python's max() and min() functions which can be used to specify a function that returns a sort key, just like the by argument to Julia's sort().

Given that finding the minimum/maximum is equivalent to finding the first/last element of a collection in sorted order, it only makes sense to allow alternate Base.Order.Orderings just as in Base.sort(). This would entail adding by, lt, and ord keyword arguments to max, maximum, findmax, argmax, and their counterparts.

I'm definitely prepared to write the implementation myself if this is a desired feature.

@kimikage
Copy link
Contributor

Is what you're asking for different from this?

julia> maximum(abs, [-2, 1, 0])
2

@jakobnissen
Copy link
Member

Dup of #28210 , I think

@jlumpe
Copy link
Contributor Author

jlumpe commented Feb 19, 2021

More or less a duplicate, but I'm proposing we also add the lt and ord arguments from Base.sort. I'd expect those to be used far less but it makes sense to make the API consistent with sort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants