An overview of algebraic laws from the perspective of a functional programmer. I've used a Haskell-esque syntax for the definitions of the laws and examples.
| name | definition | example | 
|---|---|---|
| Identity [¹][] | f x = x | 
add 0 42 = 42 | 
I hereby claim:
To claim this, I am signing this object:
The modular version of Fluture no longer works with Node version 9, 10, and 11 using --experimental-modules. In order to load the modular version into those runtimes, one has to use the esm loader.
Furthermore, the modular code must now be "deep" imported from fluture/index.js. That is, import 'fluture/index.js' for EcmaScript modules, or require ('fluture') for CommonJS modules.
| -- Create our directories table. | |
| CREATE TABLE `directories` ( | |
| `id` int(11) NOT NULL AUTO_INCREMENT, | |
| `name` varchar(255) DEFAULT NULL, | |
| `lft` int(11) NOT NULL, | |
| `rgt` int(11) NOT NULL, | |
| PRIMARY KEY (`id`), | |
| UNIQUE KEY `directory_lft` (`lft`), | |
| UNIQUE KEY `directory_rgt` (`rgt`) | |
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8; | 
| // pipe :: Array (Any -> Any) -> Any -> Any | |
| const pipe = fs => x => fs.reduce ((y, f) => f (y), x) | |
| // lmap :: (a -> b) -> Array a -> Array b | |
| const lmap = f => xs => xs.map (f) | |
| // append :: a -> Array a -> Array a | |
| const append = x => xs => [...xs, x] | |
| # Exit with code 1 if the FILE has *modified* lines | |
| git diff --quiet $FILE || [ $(git diff --numstat $FILE | cut -f 2) = '0' ] | |
| # Output a visual graph of commits | |
| git log --all --graph --pretty='format:%C(auto)%h% D%Creset %Cgreen%an, %ar%Creset %C(white)(%s)%Creset' | 
| const after = t => x => cont => { | |
| const id = setTimeout (cont, t, x) | |
| return () => clearTimeout (id) | |
| } | |
| const map = f => run => cont => run(x => cont (f (x))) | |
| const chain = f => run => cont => run(x => f (x) (cont)) | |
| const run = chain (x => after (2000) (`${x}C`)) | |
| (map (x => `${x}B`) | 
| // | |
| // utils | |
| // | |
| const thrush = x => f => f(x); | |
| const indexBy = k => xs => xs.reduce((index, x) => { | |
| if(index[x[k]] != null) index[x[k]].push(x); | |
| else index[x[k]] = [x]; | |
| return index; | 
| const after = (n, x) => Future((l, r) => setTimeout(r, n, x)); | |
| const Do = (f, of) => { | |
| return of(undefined).chain(() => { | |
| const g = f() | |
| const step = value => { | |
| const result = g.next(value) | |
| return result.done ? | |
| of(result.value) : | |
| result.value.chain(step) | 
| Ramda | Sanctuary | 
|---|---|
add(a, b) | 
add(b, a) | 
addIndex(f) | 
`` | 
adjust(f, i, xs) | 
`` | 
all(f, xs) | 
`` | 
allPass(fs, x) | 
allPass(fs, x) | 
always(x) | 
K(x) | 
and(a, b) | 
and(a, b) | 
any(f, x) | 
`` |