Skip to content

Instantly share code, notes, and snippets.

View caseymorrisus's full-sized avatar
🏠
Working from home

Casey Morris caseymorrisus

🏠
Working from home
View GitHub Profile
@caseymorrisus
caseymorrisus / notEqual_reduction.js
Created October 12, 2018 22:46
Functional JS -- Not Equal Reduction
// original and function
const _notEqual = (x) => (y) => cond(not(y))(y)(x)
// this function can also be written as:
// λx.λy.cond y (not y) x
// it uses `cond` internally which can be written as:
// cond = λe1.λe2.λc.c e1 e2
// it uses `not` internally which can be written as:
@caseymorrisus
caseymorrisus / equal_reduction.js
Created October 12, 2018 22:40
Functional JS -- Equal Reduction
// original and function
const _equal = (x) => (y) => cond(y)(not(y))(x)
// this function can also be written as:
// λx.λy.cond y (not y) x
// it uses `cond` internally which can be written as:
// cond = λe1.λe2.λc.c e1 e2
// it uses `not` internally which can be written as:
@caseymorrisus
caseymorrisus / or_reduction.js
Created October 12, 2018 22:30
Functional JS -- Or Reduction
// original and function
const _or = (x) => (y) => cond(TRUE)(y)(x)
// this function can also be written as:
// λx.λy.cond TRUE y x
// it uses `cond` internally which can be written as:
// cond = λe1.λe2.λc.c e1 e2
// let's grab the function body and start reducing
@caseymorrisus
caseymorrisus / and_reduction.js
Last active October 15, 2018 13:44
Functional JS -- And Reduction
// original and function
const _and = (x) => (y) => cond(y)(FALSE)(x)
// this function can also be written as:
// λx.λy.cond y FALSE x
// it uses `cond` internally which can be written as:
// cond = λe1.λe2.λc.c e1 e2
// let's grab the function body and start reducing
@caseymorrisus
caseymorrisus / notEqual.js
Last active October 15, 2018 13:44
Functional JS -- Not Equal (!=)
const notEqual = (x) => (y) => cond(not(y))(y)(x)
notEqual(TRUE)(FALSE) // => TRUE
notEqual(FALSE)(TRUE) // => TRUE
notEqual(FALSE)(FALSE) // => FALSE
notEqual(TRUE)(TRUE) // => FALSE
@caseymorrisus
caseymorrisus / equal.js
Last active October 15, 2018 13:44
Functional JS -- Equal (==)
const equal = (x) => (y) => cond(y)(not(y))(x)
equal(TRUE)(FALSE) // => FALSE
equal(FALSE)(TRUE) // => FALSE
equal(FALSE)(FALSE) // => TRUE
equal(TRUE)(TRUE) // => TRUE
@caseymorrisus
caseymorrisus / and.js
Created October 10, 2018 22:58
Functional JS -- And (&&)
const and = (x) => (y) => cond(y)(FALSE)(x)
and(TRUE)(FALSE) // => FALSE
and(FALSE)(TRUE) // => FALSE
and(FALSE)(FALSE) // => FALSE
and(TRUE)(TRUE) // => TRUE
@caseymorrisus
caseymorrisus / or.js
Created October 10, 2018 22:54
Functional JS -- Or (||)
const or = (x) => (y) => cond(TRUE)(y)(x)
or(TRUE)(FALSE) // => TRUE
or(FALSE)(FALSE) // => FALSE
or(FALSE)(TRUE) // => TRUE
or(TRUE)(TRUE) // => TRUE
@caseymorrisus
caseymorrisus / not.js
Created October 10, 2018 22:49
Functional JS -- Not (!)
const not = (x) => cond(FALSE)(TRUE)(x)
not(FALSE) // => TRUE
not(TRUE) // => FALSE
cond('Foo')('Bar')(not(TRUE)) // => 'Bar'
@caseymorrisus
caseymorrisus / FALSE.js
Created October 10, 2018 17:00
Functional JS -- FALSE (false)
const FALSE = (x) => (y) => y
FALSE('foo')('bar') // => 'bar'
FALSE(10)(5) // => 5