Trott / fs-tools

fs helper utilities (walk, copy, remove, mkdir -p)
http://trott.github.com/fs-tools/
MIT License
20 stars 4 forks source link

walk(Array, ) #11

Closed dvv closed 12 years ago

dvv commented 12 years ago

In addition to walk(String, ...) it would be feasible to have walk_many(Array, ...) to merge the results of walking across multiple sources. This would ease honoring globing arguments in ndoc and hopefully other tools.

ixti commented 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();
}
dvv commented 12 years ago

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

puzrin commented 12 years ago

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.

ixti commented 12 years ago

@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 ;))

ixti commented 12 years ago

Updated code sample