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 |
const I = x => x | |
const K = x => y => x | |
const A = f => x => f (x) | |
const T = x => f => f (x) | |
const W = f => x => f (x) (x) | |
const C = f => y => x => f (x) (y) | |
const B = f => g => x => f (g (x)) | |
const S = f => g => x => f (x) (g (x)) | |
const S_ = f => g => x => f (g (x)) (x) | |
const S2 = f => g => h => x => f (g (x)) (h (x)) |
ssh user@remote gpg --export-secret-key KeyId | gpg --allow-secret-key-import --import |
# 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' |
// | |
// 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; |
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.
'use strict'; | |
const request = require('request'); | |
const Future = require('fluture'); | |
module.exports = o => Future((l, r) => { | |
const socket = request(o, (err, res) => err ? l(err) : r(res)); | |
return () => socket.abort(); | |
}); |
const S = f => g => x => f(x)(g(x)) | |
const K = x => y => x | |
const I = S(K)(K) | |
const B = S(K(S))(K) | |
const C = S(S(K(B))(S))(K(K)) | |
const A = S(K(I)) | |
const T = C(A) | |
const W = S(S)(K(I)) |
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) |
I hereby claim:
To claim this, I am signing this object: