# By= argument for maximum, minimum, findmax, findmin

**URL:** <https://discourse.julialang.org/t/by-argument-for-maximum-minimum-findmax-findmin/88135>\
**Category:** Internals & Design\
**Created:** [October 2, 2022, 11:50pm UTC](https://discourse.julialang.org/t/by-argument-for-maximum-minimum-findmax-findmin/88135 "2022-10-02T23:50:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [October 2, 2022, 11:50pm UTC](https://discourse.julialang.org/t/by-argument-for-maximum-minimum-findmax-findmin/88135/1 "2022-10-02T23:50:46Z")

</div>

What do you think about having a `by=` argument for `maximum`, `minimum`, `findmax`, `findmin`? The difference from the `f` argument is that the return value of the `f` form is in the codomain of `f` while for `by` it would be in the domain.

For instance

```julia
julia> maximum(abs, [-10, -20])
20

julia> maximum([-10, -20]; by=abs)
-20

```

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [October 3, 2022, 12:01am UTC](https://discourse.julialang.org/t/by-argument-for-maximum-minimum-findmax-findmin/88135/2 "2022-10-03T00:01:18Z")

</div>

> <https://github.com/JuliaLang/julia/issues/28210>
>
> Essentially the same thing that already exists for \`\`sort\`\`: an option to specif…y a selector function, so that the maximum is determined by whatever the selector function returns, but then the \`maximum\` function returns an element from the original input sequence.
> 
> For example, \`\`maximum(\[(a=1,b=2),(a=2,b=1)\], by=i-\>i.b)\`\` would return \`\`(a=1,b=2)\`\`.
