If I specify function value as:
let applyFirst f elements =
if Seq.isEmpty elements then None else elements |> Seq.head |> f
then F# infers the f type as f: 'a -> b' option. It’s ok, I understand why F# infers f‘s return type as 'b option. But I want f to be f: 'a -> 'b, and it can be done by changing applyFirst function:
let applyFirst f elements =
if Seq.isEmpty elements then None else elements |> Seq.head |> f |> Some
But wonder if there’s some more elegant way to do this?
You can do
But I think I prefer
as more readable.