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 unwrapSymbol = Symbol(); | |
function Definitely(x) { | |
if (x == null || !(unwrapSymbol in x)) | |
return x; | |
return x[unwrapSymbol]; | |
} |
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
Observable.from = function(iterable) { | |
return new Observable((push, error, close) => { | |
try { for (let x of iterable) push(x) } | |
catch (x) { error(x) } | |
finally { close() } | |
}); | |
}; |
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
async function* flattenStreams(asyncIterList) { | |
function deferred() { | |
let capability = {}; | |
capability.promise = new Promise((resolve, reject) => { | |
capability.resolve = resolve; | |
capability.reject = reject; | |
}); | |
return capability; | |
} |
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 toObservable(asyncIter) { | |
return new Observable(sink => { | |
let abort = false; | |
(async _=> { | |
try { | |
for async (let x of asyncIter) { | |
if (abort) return; | |
sink.next(x); |
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 toObservable(asyncIter) { | |
return new Observable(sink => { | |
let abort = false; | |
(async _=> { | |
try { | |
for async (let x of asyncIter) { | |
if (abort) return; | |
sink.next(x); |
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() { '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(); |
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
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); |
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 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)) |
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
// 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({ |
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
// 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. |