Currying

The promised topic about currying in functional programming is on its way!

Currying is yet another FP trick, where a function that takes several arguments transforms into a series of functions, with each of these functions taking only one argument.

Alternatively, you can return a Python lambda like this (although it may not be advisable in terms of readability):

Currying

"look everybody I'm so clever elite one-liners fucker" coding style

But, you definitely want to do in with nested def’s, like:

    def add(x):
        def inner(y):
        return x + y
    return inner

Isn’t it pretty neat? We’re crafting here a curried function ‘f’ that takes one argument and returns a function that takes another argument.

Please pardon me, but these FP tricks truly feel like magic spells, especially after constantly coding in a simple imperative or OOP-ish way.

Now, let’s recap on the pros and cons of currying in FP.

Pros:

Cons:

Uncle Ben

So, go ahead and experiment with currying; learn that spell, it might be pretty handy, at least for your brains 🪄✨

Until we meet again! 💀