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 |
The package that linked you here is now pure ESM. It cannot be require()
'd from CommonJS.
This means you have the following choices:
import foo from 'foo'
instead of const foo = require('foo')
to import the package. You also need to put "type": "module"
in your package.json and more. Follow the below guide.await import(…)
from CommonJS instead of require(…)
.macOS has ncurses version 5.7 which does not ship the terminfo description for tmux. There're two ways that can help you to solve this problem.
Instead of tmux-256color
, use screen-256color
which comes with system. Place this command into ~/.tmux.conf
or ~/.config/tmux/tmux.conf
(for version 3.1 and later):
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; |
var flatten = Function.prototype.apply.bind([].concat, []) | |
Array.prototype.chain = function(f) { | |
return flatten(this.map(f)) | |
} | |
var stepNext = function (x) { return {value: x, done: false }; }; | |
var stepDone = function (x) { return {value: x, done: true }; }; | |
Array.chainRec = function _chainRec(f, i) { | |
var todo = [i]; | |
var res = []; |
--dropWhereRepeated [1, 2, 2, 3, 3, 5, 7, 10] | |
--[1,5,7,10] | |
dropWhereRepeated :: (Eq a) => [a] -> [a] | |
dropWhereRepeated [] = [] | |
dropWhereRepeated [x] = [x] | |
dropWhereRepeated (x : y : xs) | |
| x == y = dropWhereRepeated (dropWhile (== x) (xs)) | |
| otherwise = x : dropWhereRepeated (y : xs) |
I published a library which implements this idea; furry.
# | From | To | Normal | Alternative |
---|---|---|---|---|
1 | a → b → c |
a → c |
f(_, b)(a) |
f(_, b)(a) |
2 | a → b → c |
b → a → c |
nope | f(_)(b, a) |
3 | a → b → c → d |
b → d |
f(a, _, c)(b) |
f(a, _, c)(b) |
4 | a → b → c → d |
a → b → d |
f(_, _, c)(a, b) |
f(_, _, c)(a, b) |
5 | a → b → c → d |
a → c → d |
f(_, b)(a, c) |
f(_, b, _)(a, c) |
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)) |
const { Future, IO } = require('ramda-fantasy'); | |
const join2 = curryN(2, require('path').join); | |
const npa = require('npm-package-arg'); | |
const ALIAS = /:([^!]+)/; | |
const EXTEND = /!$/; | |
const parseAlias = pipe( | |
S.match(ALIAS), chain(nth(1))); | |
const parseExtend = pipe( | |
S.match(EXTEND), map(T)); |