Skip to content

Instantly share code, notes, and snippets.

View therealklanni's full-sized avatar
👨‍💻
Learning Rust

Kevin Lanni therealklanni

👨‍💻
Learning Rust
View GitHub Profile
const Y = Yfact => {
return (x => Yfact(v => x(x)(v)))(x => Yfact(v => x(x)(v)))
}
const fact = n => n <= 1 ? n : n * fact(n - 1)
// expanded as
const fact = n => {
return n <= 1 ? n : n * fact(n - 1)
}
const Yfact = Y(g => n => n <= 1 ? n : n * g(n - 1))
// expanded as
const Yfact = Y(g => {
return n => {
return n <= 1 ? n : n * g(n - 1)
}
})
const Y = f => {
return (x => f(v => x(x)(v)))(x => f(v => x(x)(v)))
// --------------------------^
}
const Y = f => (x => f(v => x(x)(v)))(x => f(v => x(x)(v)))
@therealklanni
therealklanni / y-combinator.md
Last active August 29, 2015 14:23
The Mysterious Y-Combinator

The Mysterious Y-Combinator

You may have heard the term before—you may even know what it is already. If you want a really technical description of the Y-combinator, look no further than Wikipedia (though we can certainly do better). However, this will leave most of us laymen more confused than we were going in. So what is the Y-combinator, really?

Getting right to it, written in ES6 this would look like the following (courtesy Brendan Eich):

let Y = f => (x => f(v => x(x)(v)))(x => f(v => x(x)(v)))
@therealklanni
therealklanni / y-memo.js
Last active October 2, 2016 22:37
Memoized Y-Combinator in ES6
let Ym = (f, s = JSON.stringify) => (g => g(g))(x => f((...v) => (k => k in x ? x[k] : x[k] = x(x)(...v))(s(v))))
let fib = Ym(f => n => n <= 1 ? n : f(n - 1) + f(n - 2))
console.log('fib(1000)', fib(1000)) // => 4.346655768693743e+208
@therealklanni
therealklanni / using-git-guppy.md
Last active September 5, 2017 09:02
Supercharge your git hooks with gulp — Introducing git-guppy

Supercharge your git hooks with gulp

Introducing git-guppy

Automate your developer workflow with git-guppy. git-guppy allows you to add git-hooks to your project repository that are automatically installed when users clone and install your repository, so you won't have to worry about developers skipping essential workflow steps and bypassing your project guidelines.

Getting Started

So let's use a unit test scenario to illustrate an example. We're going to run unit tests before every commit (pre-commit hook) and reject the commit if the tests fail (giving the developer a chance to fix their tests before committing broken code).

@therealklanni
therealklanni / README.md
Last active January 27, 2020 17:07
Infinitely repeating arrays in JavaScript ... kind of

repeat(a) -> [a]

Inspired by Haskell, I wanted to see if I could replicate, using ES6 features, the repeat function:

repeat :: a -> [a]

So as you can see in repeat.js, I have done exactly that. However there are some caveats.

@therealklanni
therealklanni / ES6.sublime-build
Last active July 10, 2019 18:09
ES6 REPL in Sublime Text
{
"cmd": ["/usr/local/bin/babel-node $file"],
"shell": true,
"selector": "*.js"
}