Suppose I want to run a fold using a function that expects a tuple, f (x, y). This can be done with
List.fold (fun x y -> f (x, y)) x xs
I kind of feel there ought to be a higher-order function that abstracts out that pattern, takes a function that expects a tuple and turns it into a function that expects two separate arguments.
Is there such a function in the F# standard library? If not, easy enough to write but what should it idiomatically be called? untuple
?
That function is normally called curry in most functional languages. It's definition is:
let curry f x y = f (x, y)
Unfortunately it's not in the F# core lib, but it's available in many external base libraries, like F#x and F#+.
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