Skip to content

Commit

Permalink
Clarify comparison example between pure and impure functions
Browse files Browse the repository at this point in the history
  • Loading branch information
KtorZ committed Feb 20, 2016
1 parent 1eb8b6a commit 4631c31
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ch3.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,31 @@ var signUp = function(attrs) {
welcomeUser(user);
};

var saveUser = function(attrs) {
var user = Db.save(attrs);
...
};

var welcomeUser = function(user) {
Email(user, ...);
...
};

//pure
var signUp = function(Db, Email, attrs) {
return function() {
var user = saveUser(Db, attrs);
welcomeUser(Email, user);
};
};

var saveUser = function(Db, attrs) {
...
};

var welcomeUser = function(Email, user) {
...
};
```

The example here demonstrates that the pure function must be honest about its dependencies and, as such, tell us exactly what it's up to. Just from its signature, we know that it will use a `Db`, `Email`, and `attrs` which should be telling to say the least.
Expand Down

0 comments on commit 4631c31

Please sign in to comment.