News for hackers. Stuff that matters.
Re:Functional Programming Jargon by masklinn on Tuesday November 07, 2017 @10:52AM (#15644389)
> Currying as an example, I'm none the wiser as to why it's a preferable way of composing a function and it's arguments, or when either is applicable.

The primary advantage of curried functions is that they're trivially partially applicable.

With an uncurried function, if you have a function of two arguments and you want to apply the first but "hold off" on the second you have to wrap the thing in a new function with a single argument which will do the application later (the language may also provide a helper) whereas with curried functions, you can just apply one of the parameters:

    let add5 = (a) => a.map((n) => n + 5)
versus

    let add5 = map (\n -> n + 5)
This means you can very easily create "small specialisations" of very generic functions.

Languages with curried functions also tend to provide features like the ability to treat operators as functions ("sections"):

    let add5 = map (+5)
and more function composition tooling:

    let add5ToEven = map (+5) . filter even
though these are not really intrinsic.

There are no comments on this comment yet.