Skip to content

by= parameter for findmax #46932

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

Closed
jariji opened this issue Sep 27, 2022 · 1 comment
Closed

by= parameter for findmax #46932

jariji opened this issue Sep 27, 2022 · 1 comment

Comments

@jariji
Copy link
Contributor

jariji commented Sep 27, 2022

For example, if f might return nothing, I can call findmax(f, xs; by=x->isnothing(x) ? -Inf : x) to get the maximum value and its index in one pass while treating the nothing values as -Inf for the purpose of comparison.

passnothing(f) = x->isnothing(x) ? nothing : f(x)
findmax(passnothing(abs), [-2., -4., nothing]; by=x->isnothing(x) ? -Inf : x) == (4., 2)
@jariji
Copy link
Contributor Author

jariji commented Oct 3, 2022

#28210

@jariji jariji closed this as completed Oct 3, 2022
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

1 participant