You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/06-advanced-functions/11-currying-partials/article.md
+10-6Lines changed: 10 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -113,14 +113,18 @@ Sometimes people mix up partial function application mentioned above with anothe
113
113
114
114
[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)`.
115
115
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)`
117
121
118
122
```js run
119
123
*!*
120
-
functioncurry(func) {
124
+
functioncurry(f) {// curry(f) does the currying transform
121
125
returnfunction(a) {
122
126
returnfunction(b) {
123
-
returnfunc(a, b);
127
+
returnf(a, b);
124
128
};
125
129
};
126
130
}
@@ -156,7 +160,7 @@ function curry(f) {
156
160
157
161
## Currying? What for?
158
162
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.
160
164
161
165
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:
162
166
@@ -208,7 +212,7 @@ So:
208
212
209
213
## Advanced curry implementation
210
214
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:
0 commit comments