dagolden / Path-Tiny

File path utility
41 stars 59 forks source link

Add for_lines method #249

Closed bigpresh closed 2 years ago

bigpresh commented 2 years ago

Add a for_lines() method, which behaves similarly to edit_lines, calling a callback for every line, but without changing the file.

Shares the guts of edit_lines, refactored to _iterate_lines() to share.

shlomif commented 2 years ago

@bigpresh : hi, thanks for the pullreq. I think I/we can come up with a more meaningful test though: pushing values into an array + is_deeply().

xdg commented 2 years ago

I appreciate the thought and the PR, but iterating without modifying is trivially done getting a filehandle via openr and iterating in a normal for loop. It may seem similar to edit_lines, but that has to juggle two filehandles (including one temp file) to efficiently read and write and do an atomic replacement at the end, so it isn't trivial in the same way. I'm going to pass on accepting this PR.