This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const M = f => f(f); | |
const Y = fn => M( | |
maker => x => fn(maker(maker))(x) | |
); | |
const YY = fn => { | |
const cache = new Map; | |
return M( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mkWrapper = () => ( | |
cache => f => n => n in cache | |
? cache[n] | |
: cache[n] = f(n) | |
)([]); | |
const M = f => f(f); | |
const Y = f => ( | |
wrapper => M( | |
maker => n => wrapper( | |
f(M(maker)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fact = n => n <= 0 ? 1 : n * fact(n-1); | |
const choose = (n, k) => fact(n) / (fact(n - k) * fact(k)); | |
const mapper = predicate => n => predicate(n) ? 1 : 0; | |
const [isEven, isOdd] = [0,1].map(k => mapper(n => n % 2 === k)); | |
const iverson = k => mapper(n => n === k); | |
const coverNegative = f => n => n < 0 ? 0 : f(n); | |
const conjugatePair = (a, b) => [a+b, a-b]; | |
const round = fn => n => Math.round(fn(n)); | |
const range = n => Array(n).fill().map((_, i) => i); | |
const reversed = xs => [...xs].reverse(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <functional> | |
#include <vector> | |
#include <iostream> | |
namespace Observable { | |
template <typename D> | |
using Callback = std::function<void(const D&)>; | |
template <typename D, typename R> | |
using Morphism = std::function<R(D)>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mapper = predicate => n => predicate(n) ? 1 : 0; | |
const [isEven, isOdd] = [0,1].map(k => mapper(n => n % 2 === k)); | |
const iverson = k => mapper(n => n === k); | |
const range = n => Array(n).fill().map((_, i) => i); | |
const coverNegative = f => n => n < 0 ? 0 : f(n); | |
const conjugatePair = (a, b) => [a+b, a-b]; | |
const a = coverNegative( | |
n => 4*b(n-1) + 2*a(n-1) + a(n-2) + iverson(0)(n) | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function *_range(from, to) { | |
if (to === undefined) { | |
yield *_range(0, from); | |
return; | |
} | |
yield [ from ]; | |
if (from >= to) return; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Creates an intermediate value that can be resolved later. | |
* @return {Object} Eventual | |
* @return {Function} Eventual.then Acts like Promise.then for the eventual value | |
* @return {Function} Eventual.resolve Acts like Promise.resolve for the eventual | |
* @return {Function} Eventual.reject Acts like Promise.reject for the eventual | |
*/ | |
const eventual = () => ( | |
_eventual => ({ | |
/** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function memoize(f) { | |
const cache = new Map; | |
return (...args) => { | |
const key = JSON.stringify(...args); | |
if (!cache.has(key)) { | |
cache.set(key, f(...args)); | |
} |