https://github.com/mtso/hof
Higher-order functions in different languages.
https://github.com/mtso/hof
example-code higher-order-functions hof
Last synced: about 2 months ago
JSON representation
Higher-order functions in different languages.
- Host: GitHub
- URL: https://github.com/mtso/hof
- Owner: mtso
- Created: 2017-10-20T17:05:56.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-11-21T06:45:53.000Z (over 4 years ago)
- Last Synced: 2024-08-03T03:04:35.550Z (11 months ago)
- Topics: example-code, higher-order-functions, hof
- Language: TypeScript
- Homepage:
- Size: 37.1 KB
- Stars: 5
- Watchers: 2
- Forks: 7
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Higher-Order Functions
Higher-order functions in different languages. Inspired by: [FizzBuzz](https://github.com/zenware/FizzBuzz) and [hello-world](https://github.com/leachim6/hello-world).
Higher-order functions (HOF) are functions that satisfy one or both rules:
- Returns a function.
- Take one or more function parameters.## Spec
The two example higher-order functions are:
### `add`
`add` takes an integer as a parameter and returns a second function that takes an integer, which returns the overall result.
##### type signature
```
function(int) -> function(int) -> int
```### `each`
`each` is a void function takes a list as its first parameter and a function as its second parameter. It then iterates over the given list passing in each element into the function.##### type signature
```
function([int], function(int) -> void) -> void
```#### Example Usage
Show how the function is used by calling them in the program's entry point. For example:
```js
const three = add(1)(2);
each([1, 2, 3], console.log);
```