Skip to content

Instantly share code, notes, and snippets.

@tsibley
Created July 28, 2022 23:49
Show Gist options
  • Select an option

  • Save tsibley/c1a6a620b31a915d4b58c8a7ee30bd78 to your computer and use it in GitHub Desktop.

Select an option

Save tsibley/c1a6a620b31a915d4b58c8a7ee30bd78 to your computer and use it in GitHub Desktop.
async function map(iterable, fn = x => x) {
let array;
if (iterable.map) {
array = iterable;
} else {
array = [];
for await (const x of iterable) {
array.push(x);
}
}
return array.map(x => fn(x));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment