Skip to content

Commit 3a654a4

Browse files
authored
Merge pull request #225 from hemanth/jethrolarson-combinator
added definition for functional combinator #126
2 parents daa11c4 + ddf6a95 commit 3a654a4

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

readme.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ __Table of Contents__
5050
* [Equational Reasoning](#equational-reasoning)
5151
* [Lambda](#lambda)
5252
* [Lambda Calculus](#lambda-calculus)
53+
* [Functional Combinator](#functional-combinator)
5354
* [Lazy evaluation](#lazy-evaluation)
5455
* [Monoid](#monoid)
5556
* [Monad](#monad)
@@ -580,6 +581,24 @@ const add1 = (a) => a + 1
580581
## Lambda Calculus
581582
A branch of mathematics that uses functions to create a [universal model of computation](https://en.wikipedia.org/wiki/Lambda_calculus).
582583

584+
## Functional Combinator
585+
A higher-order function, usually curried, which returns a new function changed in some way. Functional combinators are often used in [Point-Free Style](#point-free-style) to write especially terse programs.
586+
587+
```js
588+
// The "C" combinator takes a curried two-argument function and returns one which calls the original function with the arguments reversed.
589+
const C = (f) => (a) => (b) => f(b)(a)
590+
591+
const divide = (a) => (b) => a / b
592+
593+
const divideBy = C(divide)
594+
595+
const divBy10 = divideBy(10)
596+
597+
divBy10(30) // => 3
598+
```
599+
600+
See also [List of Functional Combinators in JavaScript](https://gist.github.com/Avaq/1f0636ec5c8d6aed2e45) which includes links to more references.
601+
583602
## Lazy evaluation
584603

585604
Lazy evaluation is a call-by-need evaluation mechanism that delays the evaluation of an expression until its value is needed. In functional languages, this allows for structures like infinite lists, which would not normally be available in an imperative language where the sequencing of commands is significant.

0 commit comments

Comments
 (0)