Make Bluebird countFiles example idiomatic#40
Open
joepie91 wants to merge 1 commit intoyortus:masterfrom
Open
Conversation
Given that this is supposed to be a comparison of code styles, it's rather important that the examples reflect the idiomatic/optimal style for a given approach. This wasn't the case with the original Bluebird example, which used virtually no Bluebird utility methods and contained superfluous code.
Owner
|
Hi @joepie91, Looks good, thanks! Before committing this, would you mind replacing the arrow functions with ordinary function expressions? None of the code examples have been upgraded to use ES5 features yet, and I'd like to do that consistently across all of them as a separate PR (if you feel like doing this, be my guest!) Once we are using ES5, I'd probably shorten your code even more as: module.exports = function countFiles(dir, cb) {
return Promise
.try(() => fs.readdirAsync(dir))
.map(file => path.join(dir, file))
.map(file => fs.statAsync(file))
.filter(stat => stat.isFile())
.then(stats => stats.length)
.nodeify(cb);
} |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Given that this is supposed to be a comparison of code styles, it's rather important that the examples reflect the idiomatic/optimal style for a given approach. This wasn't the case with the original Bluebird example, which used virtually no Bluebird utility methods and contained superfluous code.