This file contains 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* enumerate(arr) { | |
for (const index in arr) { | |
yield [index, arr[index]]; | |
} | |
} |
This file contains 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
/** | |
* @params manager {{ | |
source: S, | |
open(source: S): R, | |
close(resource: R): void, | |
}} - An object with a source, and two functions used to connect and clean-up the resource. | |
*/ | |
function using(manager, cb) { | |
const resource = manager.open(manager.source); | |
try { |
This file contains 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 forEach(cb, arr) { | |
class Break extends Error {}; | |
const _break = _ => { throw new Break(); }; | |
try { | |
for (const index in arr) { | |
cb(arr[index], index, arr, _break); | |
} | |
} | |
catch (e) { | |
if (e instanceof Break) return; |
This file contains 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 yet(promise) { | |
const states = Object.freeze({ | |
PENDING: "pending", | |
FULFILLED: "filfilled", | |
REJECTED: "rejected" | |
}); | |
const yettable = { | |
state: "pending", | |
_result: undefined, |