I am reading Functional Programming in Scala, and going through different exericses. I encountered currying.

Can someone explain to me this curried function and how does this work? I can seem to understand this piece of code. compared to the ones I saw on different blogs regarding currying in Scala.

```
def curry[A,B,C](f: (A, B) => C): A => (B => C) = a => b => f(a,b)
```

is `a`

from a => b => f(a,b) a function if so what are its arguments?

Also update what does this mean? `a`

in `a => b => f(a,b)`

means? is a function that will return a function named b that takes single parameter and will return a function?

# Best How To :

I'll assume you understand the concept of currying and that the type definition makes sense to you: `A => B => C`

.

The implementation is: `a => b => f(a,b)`

, you could read it as:

```
... = { a =>
{ b =>
{ f(a,b) }
}
}
```

So `a`

is the parameter accepted as input of your function of type `A => (B => C)`

. And this function returns a second function - of type `B => C`

, that takes `b:B`

and apply `f`

to both.

Edit: you could use this very verbose version if it helps you understand:

```
def curry[A,B,C](f: (A, B) => C): A => (B => C) = {
def aToBToC(a: A): B => C = {
def bToC(b: B): C = {
f(a,b)
}
bToC
}
aToBToC
}
```

See how I define private functions in nested scopes? (I haven't tried in the REPL, maybe there is a typo, but you get the idea.)