Actions
Feature #3608
openEnhancing Pathname#each_child to be lazy
Description
=begin
Right now it lists entire directory, then yields
every element, that is x.each_child(&b) means x.children.each(&b).
This is too slow for directories mounted over networked file systems etc.,
and there is currently no way to get lazy behaviour, other than leaving
convenient #each_child/#children API and moving to lower level.
With this patch:
- #children is eager like before, no change here
- #each_child becomes lazy
- #each_child without block returns lazy enumerator,
so it can be used like this dir.each_child.find(&:symlink?)
without losing laziness.
Patch is against trunk. pathname.rb was in lib/ not ext/pathname/lib/
before, but it works either way.
The part to return enumerator when called without a block wouldn't
work in 1.8. If backport is desired, that line would need to be thrown
away, and #children would need to build result array instead
of calling each_child(with_directory).to_a - this would be straightforward.
=end
Files
Actions
Like0
Like0Like0Like0Like0Like0Like0