Merge pull request #382 from brentguf/currying

Currying/Partials chapter
This commit is contained in:
Ilya Kantor 2018-03-03 09:36:28 +03:00 committed by GitHub
commit 228873c901
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View file

@ -8,7 +8,7 @@ The task is a little more complex variant of <info:task/question-use-bind>.
The `user` object was modified. Now instead of two functions `loginOk/loginFail`, it has a single function `user.login(true/false)`.
What to pass `askPassword` in the code below, so that it calls `user.login(true)` as `ok` and `user.login(fail)` as `fail`?
What to pass `askPassword` in the code below, so that it calls `user.login(true)` as `ok` and `user.login(false)` as `fail`?
```js
function askPassword(ok, fail) {

View file

@ -5,7 +5,7 @@ libs:
# Currying and partials
Till now we were only talking about binding `this`. Now let's make a step further.
Until now we have only been talking about binding `this`. Let's take it a step further.
We can bind not only `this`, but also arguments. That's rarely done, but sometimes can be handy.
@ -146,7 +146,7 @@ More advanced implementations of currying like [_.curry](https://lodash.com/docs
```js
function curry(f) {
return function(..args) {
return function(...args) {
// if args.length == f.length (as many arguments as f has),
// then pass the call to f
// otherwise return a partial function that fixes args as first arguments