View trampolines.es6
// See http://raganwald.com/2013/03/28/trampolines-in-javascript.html
function trampoline (fn) {
return function trampolined (...args) {
let result = fn.apply(this, args);
while (result instanceof Function) {
result = result();
}
View curated-links-to-javascript-allonge.md
View execute_array_of_functions.js
var a = [
function () { console.log(1); },
function () { console.log(2); },
function () { console.log(3); }
];
a.forEach(Function.prototype.call.bind(Function.prototype.call));
View hash_sieve.es6
function * multiplesOf (startingWith, n) {
let number = startingWith;
while (true) {
yield number;
number = number + n;
}
}
class HashSieve {
View naïve.es6
function * nullEveryNth (skipFirst, n, iterable) {
const iterator = iterable[Symbol.iterator]();
yield * take(skipFirst, iterator);
while (true) {
yield * take(n - 1, iterator);
iterator.next();
yield null;
}
View valid-or-invalid.es6
function * append (...iterables) {
for (const iterable of iterables) {
yield * iterable;
}
}
const lyrics = append(["a", "b", "c"], ["one", "two", "three"], ["do", "re", "me"]);
for (const word of lyrics) {
console.log(word);
View fb.es6
function * zipWith (zipper, ...iterables) {
const iterators = iterables.map(i => i[Symbol.iterator]());
while (true) {
const pairs = iterators.map(j => j.next()),
dones = pairs.map(p => p.done),
values = pairs.map(p => p.value);
if (dones.indexOf(true) >= 0) break;
yield zipper(...values);
View doSomething.js
// I expect:
doSomething().then(doSomethingElse())
.then(finalHandler);
// To act like:
/*
doSomething
|-----------------|
View even-stevens.es6
const evenStevens = (n) => {
if (n === 0) {
return true;
}
else if (n == 1) {
return false;
}
else {
n = n - 2;
return evenStevens(n);