Skip to content

Commit 439cf4c

Browse files
committed
improvements
1 parent e202ec2 commit 439cf4c

File tree

1 file changed

+10
-6
lines changed
  • 1-js/06-advanced-functions/11-currying-partials

1 file changed

+10
-6
lines changed

1-js/06-advanced-functions/11-currying-partials/article.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,18 @@ Sometimes people mix up partial function application mentioned above with anothe
113113

114114
[Currying](https://en.wikipedia.org/wiki/Currying) is translating a function from callable as `f(a, b, c)` into callable as `f(a)(b)(c)`.
115115

116-
Let's make `curry` function that performs currying for binary functions. In other words, it translates `f(a, b)` into `f(a)(b)`:
116+
Literally, currying is a transformation of functions: from one way of calling into another. In JavaScript, we usually make a wrapper to keep the original function.
117+
118+
Currying doesn't call a function. It just transforms it. We'll see use cases soon.
119+
120+
Let's make `curry` function that performs currying for two-argument functions. In other words, `curry(f)` for two-argument `f(a, b)` translates it into `f(a)(b)`
117121

118122
```js run
119123
*!*
120-
function curry(func) {
124+
function curry(f) { // curry(f) does the currying transform
121125
return function(a) {
122126
return function(b) {
123-
return func(a, b);
127+
return f(a, b);
124128
};
125129
};
126130
}
@@ -156,7 +160,7 @@ function curry(f) {
156160

157161
## Currying? What for?
158162

159-
Advanced currying allows both to keep the function callable normally and to get partials easily. To understand the benefits we definitely need a worthy real-life example.
163+
To understand the benefits we definitely need a worthy real-life example. Advanced currying allows the function to be both callable normally and get partials.
160164

161165
For instance, we have the logging function `log(date, importance, message)` that formats and outputs the information. In real projects such functions also have many other useful features like: sending it over the network or filtering:
162166

@@ -208,7 +212,7 @@ So:
208212

209213
## Advanced curry implementation
210214

211-
In case you're interested, here's the "advanced" curry implementation that we could use above.
215+
In case you're interested, here's the "advanced" curry implementation that we could use above, it's pretty short:
212216

213217
```js run
214218
function curry(func) {
@@ -241,7 +245,7 @@ alert( curriedSum(1)(2,3) ); // 6
241245
alert( curriedSum(1)(2)(3) ); // 6
242246
```
243247

244-
The new `curry` may look complicated, but it's actually pretty easy to understand.
248+
The new `curry` may look complicated, but it's actually easy to understand.
245249

246250
The result of `curry(func)` is the wrapper `curried` that looks like this:
247251

0 commit comments

Comments
 (0)