1
0
mirror of https://github.com/janet-lang/janet synced 2025-11-14 14:27:13 +00:00

Add file/lines iterator

This commit is contained in:
Ico Doornekamp
2023-05-24 16:39:49 +02:00
parent 909c906080
commit 64e3cdeb2b
2 changed files with 26 additions and 0 deletions

View File

@@ -1749,6 +1749,19 @@
(printf (dyn *pretty-format* "%q") x)
(flush))
(defn file/lines
"Return an iterator over the lines of a file"
[file-or-path &opt mode]
(default mode :r)
(if (bytes? file-or-path)
(coro
(with [f (file/open file-or-path mode)]
(while (def line (file/read f :line))
(yield line))))
(coro
(while (def line (file/read file-or-path :line))
(yield line)))))
###
###
### Pattern Matching