Skip to content

re: Currying - An Introduction With Function Declarations & Expressions VIEW POST


Thanks for writing this.

I learned about currying in school, but in the years since I've mostly written in the prevailing "objects plus side effects" style. In my experience, even though languages like JS and Ruby have first-class functions, one mostly writes methods there, and pure functions aren't the norm, so you don't get a ton of opportunities to make use of currying. But I'm trying now to revisit FP, immutable data, etc., in my free time (largely because of this talk).

I like the const addOneCurried = ar => example. Another nice thing trick is (assuming map is a function rather than a method) to curry map with your array, so then you can do things like: curriedMap(compose(increment, square, ...)).

The gold standard, IMO, is when the language automatically does partial application, but it's pretty good if you can get a curried version of a non-curried function on the spot, e.g. curry(suchWow) in JS with the Ramda library. I don't like baking it into the function definition, since you lose the ability to call it with all of the arguments at once.

(Clojure takes a neat approach -- it doesn't do automatic partial evaluation, but you can curry with eg. (partial such_wow) and there's a macro called ->> which enables a pointfree style.)

FWIW I really like Professor Frisby's Mostly Adequate Guide... as an introduction to currying & pointfree style in JS. Chapters 3-5 are the relevant ones. There are some live in-browser exercises too.

code of conduct - report abuse