From 41e2f2fc58f42929b882ef75acf3e7229452219d Mon Sep 17 00:00:00 2001 From: Pedro Correa Date: Tue, 18 Nov 2025 21:57:51 -0300 Subject: [PATCH] :sparkles: using stream to read file --- src/day_07.gleam | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/day_07.gleam b/src/day_07.gleam index f07f9b9..54d2d93 100644 --- a/src/day_07.gleam +++ b/src/day_07.gleam @@ -1,3 +1,4 @@ +import file_streams/file_stream.{type FileStream} import gleam/bool import gleam/int import gleam/list @@ -111,3 +112,25 @@ pub fn filter_valid_calibration_v2( validate_calibration_v2(numbers_to_operate, target, 0, False) }) } + +fn rec_read_stream( + stream: FileStream, + acc: List(Calibration), +) -> List(Calibration) { + case file_stream.read_line(stream) { + Ok(line) -> { + let parsed_line = + line + |> string.trim_end + |> parse_line + + rec_read_stream(stream, [parsed_line, ..acc]) + } + Error(_) -> acc + } +} + +pub fn read_stream_file_into_string(input: FileStream) -> List(Calibration) { + input + |> rec_read_stream([]) +} -- 2.51.2