Merge pull request #9 from davidchambers/higher-order-functions

correct the definition of higher-order functions, and update examples
This commit is contained in:
hemanth.hm 2015-09-20 13:54:17 +05:30
commit ef40834ed6

View file

@ -19,16 +19,28 @@ console.log(arity);
```
---
## Higher Order Functions (HOF)
## Higher-Order Functions (HOF)
> A function for which both the input and the output are functions.
> A function which takes a function as an argument and/or returns a function.
```js
let greet = (name) => () => `Hello ${name}!`;
const filter = (pred, xs) => {
const result = [];
for (var idx = 0; idx < xs.length; idx += 1) {
if (pred(xs[idx])) {
result.push(xs[idx]);
}
}
return result;
};
```
```js
greet("HOF")(); // Hello HOF!
const is = type => x => Object(x) instanceof type;
```
```js
filter(is(Number), [0, '1', 2, null]); //=> [0, 2]
```
## Partial Application