From 09345ec7864fd2d1b1ccc3f6e042c91743b72876 Mon Sep 17 00:00:00 2001 From: Ico Doornekamp Date: Fri, 26 May 2023 17:50:26 +0200 Subject: [PATCH] file/linex now only acceps a file, not a path name --- src/boot/boot.janet | 17 ++++++----------- test/suite0009.janet | 5 +++-- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index bf39ce44..f05914c5 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -1749,18 +1749,13 @@ (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))))) + "Return an iterator over the lines of a file." + [file] + (coro + (while (def line (file/read file :line)) + (yield line)))) ### ### diff --git a/test/suite0009.janet b/test/suite0009.janet index 2b9b2205..c0c26ab0 100644 --- a/test/suite0009.janet +++ b/test/suite0009.janet @@ -110,8 +110,9 @@ (defer (:close outstream) (:write outstream buf1)) (var buf2 "") - (each line (file/lines "unique.txt") - (set buf2 (string buf2 line))) + (with [f (file/open "unique.txt" :r)] + (each line (file/lines f) + (set buf2 (string buf2 line)))) (assert (= buf1 buf2) "file/lines iterator") (os/rm "unique.txt"))