Skip to content

Instantly share code, notes, and snippets.

Kevin Smith zenparsing

Block or report user

Report or block zenparsing

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@zenparsing
zenparsing / async-io-1.js
Last active Aug 29, 2015
Reading and Writing Files with Async Generators
View async-io-1.js
/*
This example uses an inner generator and skips over the first iteration in order to
prevent data loss which occurs on the first call to next.
*/
import * as FS from "async-fs";
export function readFile(path) {
View measure-await.js
async function queueAlways() {
let x;
for (let i = 0; i < 100000; ++i)
x = await i;
}
async function queueIf() {
@zenparsing
zenparsing / abstract-references.md
Last active Aug 29, 2015
Abstract References for ECMAScript
View abstract-references.md

Abstract References for ECMAScript

Overview and Motivation

Despite its functional programming facilities, ECMAScript exhibits a strong preference for object-oriented "left-to-right" composition using instance methods. Unfortunately, composition by means of instance methods requires that extensibility be achieved by adding function-valued properties to the object or a prototype ancestor of the object. This leads to the following difficulties:

View jquery-direct.js
(function($) { "use strict";
function wrap(method) {
return function() {
var jq = $(this),
result = jq[method].apply(jq, arguments);
if (result && result.constructor === $)
@zenparsing
zenparsing / jake.js
Last active Aug 29, 2015
jQuery Reimagined
View jake.js
/* Redefine jQuery methods as "raw" methods */
(function($) { "use strict";
function wrap(method) {
return function() {
var jq = $(this),
result = jq[method].apply(jq, arguments);
@zenparsing
zenparsing / definitely-maybe.js
Last active Aug 29, 2015
Definitely Maybe with Proxy
View definitely-maybe.js
const unwrapSymbol = Symbol();
function Definitely(x) {
if (x == null || !(unwrapSymbol in x))
return x;
return x[unwrapSymbol];
}
@zenparsing
zenparsing / observable-scheduling.js
Last active Aug 29, 2015
Scheduling Observable using Promises
View observable-scheduling.js
Observable.from = function(iterable) {
return new Observable((push, error, close) => {
try { for (let x of iterable) push(x) }
catch (x) { error(x) }
finally { close() }
});
};
@zenparsing
zenparsing / toObservable.js
Created May 28, 2015
Async Iterator to Observable
View toObservable.js
function toObservable(asyncIter) {
return new Observable(sink => {
let abort = false;
(async _=> {
try {
for async (let x of asyncIter) {
if (abort) return;
sink.next(x);
View flip-it-and-reverse-it.js
function toObservable(asyncIter) {
return new Observable(sink => {
let abort = false;
(async _=> {
try {
for async (let x of asyncIter) {
if (abort) return;
sink.next(x);
@zenparsing
zenparsing / async-iterators.js
Last active Aug 29, 2015
mergeStreams with Async Iterators and Observables
View async-iterators.js
async function* flattenStreams(asyncIterList) {
function deferred() {
let capability = {};
capability.promise = new Promise((resolve, reject) => {
capability.resolve = resolve;
capability.reject = reject;
});
return capability;
}
You can’t perform that action at this time.