Skip to content

Instantly share code, notes, and snippets.

@ofemmy
ofemmy / promise_map.js
Created March 1, 2022 00:18 — forked from tokland/promise_map.js
Execute promises sequentially (one at at a time) and return array with the results
function promiseMap(inputValues, mapper) {
const reducer = (acc$, inputValue) =>
acc$.then(acc => mapper(inputValue).then(result => acc.push(result) && acc));
return inputValues.reduce(reducer, Promise.resolve([]));
}
/* Example */
const axios = require('axios');
@ofemmy
ofemmy / README.md
Created December 25, 2021 16:50 — forked from lmammino/README.md
Node.js design pattern: Asynchronous serial iteration over a collection using callbacks

This is an example of a very common Node.js design pattern: a serial asynchronous iteration over a collection (array) using callbacks.

If you are interested in learning more about common (and even less common!) Node.js design patterns, you should check out the book Node.js Design Patterns by Mario Casciaro and Luciano Mammino (spoiler alert: that's me :P):

https://www.nodejsdesignpatterns.com/


To run the example:

@ofemmy
ofemmy / currencies.json
Created March 13, 2021 18:36 — forked from joseluisq/currencies.json
JSON list of all currency symbols available from the Open Exchange Rates API - https://docs.openexchangerates.org/docs/currencies-json
{
"AED": "United Arab Emirates Dirham",
"AFN": "Afghan Afghani",
"ALL": "Albanian Lek",
"AMD": "Armenian Dram",
"ANG": "Netherlands Antillean Guilder",
"AOA": "Angolan Kwanza",
"ARS": "Argentine Peso",
"AUD": "Australian Dollar",
"AWG": "Aruban Florin",