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 / module-or-script-1.js
Last active Jan 7, 2016
Issues with Automatic Module Detection
View module-or-script-1.js
// OK if a script, but not ok if a "module".
// We'll have to remember this error and location as we parse.
with (x) {}
// The export declaration means that we need to throw a parse error
// using the location of the "with" statement.
export const A = "a";
// V8 doesn't remember strict mode errors like this, and the V8 team has
// previously objected to features which seem to require it.
@zenparsing
zenparsing / switch-n.js
Created Oct 7, 2015
Switch using cancellation functions
View switch-n.js
// For a nested stream, emits the elements of the inner stream contained within the
// most recent outer stream
function switch(stream, n) {
return new Observable(sink => {
let inner = [];
let outer = stream.subscribe({
@zenparsing
zenparsing / zip-subscribe-returns-function.js
Last active Sep 28, 2015
Observable zip with Various Return Types
View zip-subscribe-returns-function.js
function zip(list) {
return new Observable(sink => {
function trySend() {
// If every buffer has at least one element, then send an array
// containing every first element and remove those elements from the
// buffer
if (streams.every(s => s.buffer.length > 0))
@zenparsing
zenparsing / my-array-with-privates.js
Last active Sep 17, 2015
Self Hosted Array Supporting Private State
View my-array-with-privates.js
class X {
constructor(len) {
let target = Object.create(new.target.prototype);
let handler = {
// handler stuff - special logic for "length" and integer properties
// Otherwise, use target's properties
};
return Reflect.construct(Proxy, [target, handler], new.target);
@zenparsing
zenparsing / consuming-observable-with-generator.js
Created Sep 10, 2015
Consuming Observables with a Generator
View consuming-observable-with-generator.js
(function() { 'use strict';
function consume(observable, gen) {
return new Promise((resolve, reject) => {
if (typeof gen === "function") {
// Prime the generator to accept values
gen = gen();
gen.next();
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 / 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);
@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;
}
@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 / 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];
}
You can’t perform that action at this time.