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
const Loop = (fn, ... init) => { | |
let r = fn (... init) | |
while (r instanceof Recur) r = fn (... r) | |
return r | |
} | |
// Fixed based on a SO discussion: https://stackoverflow.com/a/78940799 | |
const Recur = function ( ...v) { | |
return Object .create ( | |
Recur .prototype, |
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
// https://stackoverflow.com/a/75251817 | |
// crawl :: ((a -> Promise b), (b -> [a]), (b -> c), ((Map a c) -> d), Int?) -> [a] -> Promise d | |
const crawl = (search, extract, convert, collect, simul = 1) => async (inits) => { | |
const toCheck = new Set (inits) | |
const found = new Map () | |
while (toCheck .size !== 0) { | |
const nextBlock = [...toCheck .values ()] .slice (0, simul) | |
const results = await Promise .all (nextBlock .map ((x) => search (x))) | |
results .forEach ((res, i) => { |
OlderNewer