DEV Community


Discussion on: What the heck is Currying anyway?

functional_js profile image
Functional Javascript

Good summary on the fundamentals of currying, Tulsi.

I use curried funcs (funcs that return funcs) every day.
However I do not use them for reuse sakes. i.e. to define new functions (that's too much like inheritance).

I will define a func that has two or more parameters — and who's purpose is to be used in a pipe — as a curried func (nested func).
This allows one to delay final execution until the final value for the pipe is satisfied.
So a curried func is simply a closure.

So I think in terms of making pipeable funcs, which are a more generalized design pattern than currying since it applies also to uncurried funcs that take zero or one argument.

Btw, here is an example screenshot of method chaining verses functional pipelining.
Note that the funcs in the functional pipeline may or may not be curried, but they are all pipeable funcs.
functional pipeline example

heytulsiprasad profile image
Tulsi Prasad Author

Yeah, thanks for sharing a real world insight into using currying.

I've used method chaining for uncountable times however I am new to the term piping, but do understand the concept of it though. If possible, can you show a small example of how to make piping functions and how they're useful?

functional_js profile image
Functional Javascript

Hey Tulsi,

It turned out to be a big example :), so I posted it here...

Forem Open with the Forem app