Skip to content

Instantly share code, notes, and snippets.

@dividead
Last active June 21, 2017 18:22
Show Gist options
  • Save dividead/05175613cb9a65803e5cc67ffcc854b9 to your computer and use it in GitHub Desktop.
Save dividead/05175613cb9a65803e5cc67ffcc854b9 to your computer and use it in GitHub Desktop.
const log = (...args) => console.log.apply(null, args)
const cons = (x, y) => f => f(x,y)
const car = x => x((a, _) => a)
const cdr = x => x((_, b) => b)
const add = (list, el) => cons(el, list)
const inc = (x, y) => y(x)
const make = (list, from, to, step) =>
from <= to ? make(add(list, from), inc(from, step), to, step) : list
const each = (list, f) => {
f(car(list))
cdr(list) ? each(cdr(list), f) : null
}
let list = make(null, 1, 10, (x => x + 2))
each(list, log)
const compose = (f, g) => g(f)
// const log = a => console.log(a)
const y = i => (f => f(f))(f => i(v => f(f)(v)))
const fi = f => n => n == 0 ? 1 : n * f(n - 1)
const fct = n => compose(y(fi)(n), log)
fct(15)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment