Skip to content

Instantly share code, notes, and snippets.

@Siilwyn
Last active September 19, 2016 20:55
Show Gist options
  • Save Siilwyn/02e113304b1a7488b0e1c40a5dd9cbcf to your computer and use it in GitHub Desktop.
Save Siilwyn/02e113304b1a7488b0e1c40a5dd9cbcf to your computer and use it in GitHub Desktop.
Comparison of function style, Ramda & flattening
async function displaySteamApps() {
const paths = await getSteamAppsPaths();
const appIdLibraries = await Promise.all(paths.map(getSteamAppIds));
const appIds = Array.prototype.concat.apply([], appIdLibraries);
const appsData = appIds.map(getSteamAppInfo);
appsData.forEach(function (appData) {
Promise.resolve(appData).then(renderSteamApp);
});
};
displaySteamApps();
// Ramda + unnest
getSteamAppsPaths()
.then(paths => Promise.all(paths.map(getSteamAppIds)))
.then(R.unnest)
.then(R.map(getSteamAppInfo))
.then(R.forEach(function (appData) {
Promise.resolve(appData).then(renderSteamApp);
}));
// Ramda
getSteamAppsPaths()
.then(paths => Promise.all(paths.map(getSteamAppIds)))
.then(R.map(R.map(getSteamAppInfo)))
.then(R.forEach(R.forEach(function (appData) {
Promise.resolve(appData).then(renderSteamApp);
})));
// Vanilla arrow style + unnest
getSteamAppsPaths()
.then(paths => Promise.all(paths.map(getSteamAppIds)))
.then(appIdLibraries => {
return Array.prototype.concat.apply([], appIdLibraries);
})
.then(appIds => appIds.map(getSteamAppInfo))
.then(appsData => {
appsData.forEach(function (appData) {
Promise.resolve(appData).then(renderSteamApp);
});
});
// Vanilla function style
getSteamAppsPaths()
.then(function (paths) {
return Promise.all(paths.map(getSteamAppIds));
})
.then(function (appIdLibraries) {
return appIdLibraries.map(function (appIds) {
return appIds.map(getSteamAppInfo);
});
})
.then(function (appDataLibraries) {
return appDataLibraries.forEach(function (appsData) {
appsData.forEach(function (appData) {
Promise.resolve(appData).then(renderSteamApp);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment