Here’s a little challenge for you: given a collection A find a_{max} \in A s.t. f(a_{max}) \ge f(a) ~ \forall a \in A (in other words, find the supremum of the set f(A)).

Here’s the naive implementation:

```
function maxf(A, f::Function)
amax = first(A)
fofamax = f(amax)
for i ∈ 2:length(A)
fofa = f(A[i])
if fofa ≥ fofamax
fofamax = fofa
amax = A[i]
end
end
amax
end
```

The challenge is, can you find a way to do this, as efficiently as in the naive implementation, using only stdlib and `Base`

(i.e. no control structures!)? This seems like a fair ask, since this is a pretty basic task.

This is close, but no cigar, since it returns f(a_{max}) rather than a_{max}

```
mapreduce(f, max, A)
```

(by the way, this actually has amazingly identical performance to the naive implementation)

Maybe I’m missing something, but the reason I decided to create this post was that thinking about this raised a larger question in my mind: do we have nice ways of reducing over collections without allocating? I think that mostly the answer is no. Should there be some simple, intuitive way to do this sort of thing?

I fear that the initial instinct of the vast majority of people would be to do something like `last(sort(A, by=f))`

which has absolutely abysmal performance due to the allocation.