Probably a newbie question, but is there a standard function like
let apply f = f()
in F#?
No, there is not a standard function for this.
In most cases, just calling the function is shorter and more obvious than using apply
would be, so I'm not entirely sure how this would be useful:
foo ()
apply foo
Now, you can also write application using |>
, but that's not very nice either:
() |> foo
I guess the only place where apply
would be useful is:
functions |> List.map apply
functions |> List.map (fun f -> f ())
Here, the version without apply
is shorter, but I don't think it is worth having a named function in the library just for this one use case.
You could actually use |>
here to avoid fun
, which makes for a lovely piece of ASCII art :-), but not for something that I would ever want to see in my codebase:
functions |> List.map ((|>) ())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With