mirror of
https://github.com/rjNemo/functional-programming-jargon
synced 2026-06-06 02:26:43 +00:00
Merge pull request #9 from davidchambers/higher-order-functions
correct the definition of higher-order functions, and update examples
This commit is contained in:
commit
ef40834ed6
1 changed files with 16 additions and 4 deletions
20
readme.md
20
readme.md
|
|
@ -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
|
```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
|
```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
|
## Partial Application
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue