Skip to content

Instantly share code, notes, and snippets.

@tdreyno
Last active October 23, 2019 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdreyno/873d58661361f8f02afa1ce088f62523 to your computer and use it in GitHub Desktop.
Save tdreyno/873d58661361f8f02afa1ce088f62523 to your computer and use it in GitHub Desktop.
It's like map, but you get the whole list.
interface Array<T> {
andThen: <U>(this: T[], fn: (items: T[]) => U) => U;
}
Array.prototype.andThen = function<T, U>(this: T[], fn: (items: T[]) => U): U {
return fn(this);
};
const users = await ["userid1", "userid2"].map(fetch).andThen(Promise.all);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment