Last active
September 19, 2016 20:55
-
-
Save Siilwyn/02e113304b1a7488b0e1c40a5dd9cbcf to your computer and use it in GitHub Desktop.
Comparison of function style, Ramda & flattening
This file contains hidden or 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
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(); |
This file contains hidden or 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
// 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); | |
})); |
This file contains hidden or 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
// 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); | |
}))); |
This file contains hidden or 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
// 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); | |
}); | |
}); |
This file contains hidden or 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
// 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