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
/** | |
* @template T1 | |
*/ | |
class CacheChain { | |
/** | |
* @param {function():*|function():CacheChain<*>} fn | |
*/ | |
constructor(fn) { | |
this._fn = fn; |
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 forEachChar = (str, fn) => { | |
if (str.length === 0) { | |
return; | |
} | |
const iter = str[Symbol.iterator](); | |
let it = iter.next(); | |
let prev = it.value; | |
do { |
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 AbortablePromise{ | |
constructor(fn, parent) { | |
this._reject; | |
this._aborted = false; | |
this._parent = parent; | |
this._promise = Promise.race([ | |
new Promise((res, rej) => { | |
this._reject = rej; | |
}), | |
new Promise(fn) |
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 makeBody(body, ex, im){ | |
return `function (${im}) { | |
${body} | |
return ${ex}; | |
}` | |
} | |
const im_re = /(?:^|\s|;)import +(\S[\S\s]*?) +from +"(\S+)" *;/; | |
const ex_re = /(?:^|\s|;)export +default +(\S+);$/; |
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
<html> | |
<body> | |
<button id='button'>up</button> | |
<div id='display'></div> | |
<script> | |
function coroutine(gen){ | |
return function(...args){ | |
const genObj = gen(...args); | |
genObj.next(); | |
return genObj; |
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
var noop = []; | |
function clone (arr){ | |
return arr.slice(0); | |
} | |
function stream(arr){ | |
if(arr.length === 0) return noop; | |
return cons(function (){return arr[0]}, function (){ return stream(arr.slice(1))}) | |
} | |
function cons(head, tail){ |
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 stringify(o){ | |
var visited = []; | |
var q = [{type: typeof o, target: o}]; | |
var res = ''; | |
var t; | |
while(t=q.shift()){ | |
var tar = t.target; | |
if(!tar){ | |
res += 'null'; | |
continue; |
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 stream(initArr, fn){ | |
initArr = Array.prototype.slice.call(initArr||[],0); | |
initArr._fn = fn; | |
return initArr; | |
} | |
function streamRef(arr, i){ | |
if(arr[i])return arr[i]; | |
if(!arr._fn)return null; | |
while(arr._fn&&arr.length<=i){ | |
var res = arr._fn(arr[arr.length-1], arr); |