mirror of
https://github.com/rjNemo/functional-programming-jargon
synced 2026-06-10 12:36:48 +00:00
New points-free example and discussion
This commit is contained in:
parent
cc5fcc4f89
commit
2fbc65d2c3
1 changed files with 15 additions and 2 deletions
17
readme.md
17
readme.md
|
|
@ -119,14 +119,27 @@ executions with the the same input parameters.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Point Free
|
## Points-Free
|
||||||
|
|
||||||
> A function whose definition does not include information regarding its arguments.
|
> A function whose definition does not include information regarding its arguments.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
let abs = Math.abs
|
// Given
|
||||||
|
let combine = curry((fn, initialVal, list) => list.reduce(fn, initialVal));
|
||||||
|
let add = (a, b) => a + b;
|
||||||
|
|
||||||
|
// Then
|
||||||
|
|
||||||
|
// Not points-free
|
||||||
|
let total1 = (numbers) => combine(add, 0, numbers);
|
||||||
|
|
||||||
|
// Points-free
|
||||||
|
let total2 = combine(add, 0);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`total1` lists and uses the parameter `numbers`, so it is not points-free. `total2` is written just by combining functions and values, making no mention of its arguments. It _is_ points-free.
|
||||||
|
|
||||||
|
It is easy to recognize points-free function definitions; they are the ones that contain no '`function`' keywords and no fat arrows.
|
||||||
---
|
---
|
||||||
|
|
||||||
## Contracts
|
## Contracts
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue