I am new to F# and writing some simple algorithm to get used to the language, which needs argMax
. Does the standard library come with a function for searching for a list element that maximizes a function? That is, if there's an existing function that behaves like this one:
let argMax f xs =
let rec go a fa zs =
match zs with
| [] -> a
| z :: zs' ->
let fz = f z
if fz > fa
then go z fz zs'
else go a fa zs'
match xs with
| [] -> invalidArg "xs" "empty"
| x :: xs' -> go x (f x) xs'