Closed dvv closed 12 years ago
I don't think it should be a library feature. I believe library should stay as tiny as possible. walk_many
is dead simple and can be implemented right in place:
// walk_many(Array, ...)
function walk_many(paths, pattern, iterator, callback) {
function next(err) {
var path;
// find first valuable path
while (paths.length && !path) {
path = paths.shift();
}
// an error occured or no paths left
if (err || !path) {
callback(err);
return;
}
fstools.walk(path, pattern, iterator, next);
};
next();
}
This should go to wiki, after fixing the wrong assumption that !path
denotes the end of array. Arrays can freely contain null
, ''
, 0
,false
-- any falsy values.
Thanks for feedback
Any extentions of code/wiki/examples in libraries expects, that we have at least 2 strong use cases from real life. In other case we can fall into to writing useless frameworks instead of doing really significant things.
Currently, there is only 1 use case, so nothing to discuss.
@dvv Yes, I absoutey agree about the check, the only thing is that I was showing this example from the real place, where I'm sure about what is going to be in that array ;))
Updated code sample
In addition to
walk(String, ...)
it would be feasible to havewalk_many(Array, ...)
to merge the results of walking across multiple sources. This would ease honoring globing arguments inndoc
and hopefully other tools.