diff --git a/gleam.toml b/gleam.toml index 42fd07b..512eecf 100644 --- a/gleam.toml +++ b/gleam.toml @@ -20,6 +20,7 @@ gleam_community_ansi = ">= 1.4.0 and < 2.0.0" glearray = ">= 1.0.0 and < 2.0.0" repeatedly = ">= 2.1.1 and < 3.0.0" gleam_community_colour = ">= 1.4.0 and < 2.0.0" +gleam_yielder = ">= 1.0.0 and < 2.0.0" [dev-dependencies] gleeunit = ">= 1.0.0 and < 2.0.0" diff --git a/manifest.toml b/manifest.toml index dec9b59..eb432a5 100644 --- a/manifest.toml +++ b/manifest.toml @@ -12,7 +12,8 @@ packages = [ { name = "gleam_community_colour", version = "1.4.1", build_tools = ["gleam"], requirements = ["gleam_json", "gleam_stdlib"], otp_app = "gleam_community_colour", source = "hex", outer_checksum = "386CB9B01B33371538672EEA8A6375A0A0ADEF41F17C86DDCB81C92AD00DA610" }, { name = "gleam_erlang", version = "0.30.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "760618870AE4A497B10C73548E6E44F43B76292A54F0207B3771CBB599C675B4" }, { name = "gleam_json", version = "2.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_json", source = "hex", outer_checksum = "0A57FB5666E695FD2BEE74C0428A98B0FC11A395D2C7B4CDF5E22C5DD32C74C6" }, - { name = "gleam_stdlib", version = "0.43.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "69EF22E78FDCA9097CBE7DF91C05B2A8B5436826D9F66680D879182C0860A747" }, + { name = "gleam_stdlib", version = "0.44.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "A6E55E309A6778206AAD4038D9C49E15DF71027A1DB13C6ADA06BFDB6CF1260E" }, + { name = "gleam_yielder", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_yielder", source = "hex", outer_checksum = "44C8DE196A10634667F5F7B93128A997B35DFD37E26F775D749BC6A239B499A8" }, { name = "glearray", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glearray", source = "hex", outer_checksum = "B99767A9BC63EF9CC8809F66C7276042E5EFEACAA5B25188B552D3691B91AC6D" }, { name = "gleeunit", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "F7A7228925D3EE7D0813C922E062BFD6D7E9310F0BEE585D3A42F3307E3CFD13" }, { name = "glexer", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glexer", source = "hex", outer_checksum = "BD477AD657C2B637FEF75F2405FAEFFA533F277A74EF1A5E17B55B1178C228FB" }, @@ -29,6 +30,7 @@ birdie = { version = ">= 1.1.6 and < 2.0.0" } gleam_community_ansi = { version = ">= 1.4.0 and < 2.0.0" } gleam_community_colour = { version = ">= 1.4.0 and < 2.0.0" } gleam_stdlib = { version = ">= 0.34.0 and < 2.0.0" } +gleam_yielder = { version = ">= 1.0.0 and < 2.0.0" } glearray = { version = ">= 1.0.0 and < 2.0.0" } gleeunit = { version = ">= 1.0.0 and < 2.0.0" } pprint = { version = ">= 1.0.3 and < 2.0.0" } diff --git a/src/glitzer/progress.gleam b/src/glitzer/progress.gleam index 70956cd..6fca401 100644 --- a/src/glitzer/progress.gleam +++ b/src/glitzer/progress.gleam @@ -7,7 +7,7 @@ /// /// ```gleam /// import gleam/int -/// import gleam/iterator +/// import gleam/yielder /// /// import glitzer/progress /// @@ -18,8 +18,8 @@ /// |> progress.with_fill(progress.char_from_string("+")) /// |> progress.with_empty(progress.char_from_string("-")) /// |> progress.with_left_text("Doing stuff: ") -/// iterator.range(1, 100) -/// |> progress.each_iterator(bar, fn(bar, i) { +/// yielder.range(1, 100) +/// |> progress.each_yielder(bar, fn(bar, i) { /// progress.with_left_text(bar, int.to_string(i) <> " ") /// |> progress.print_bar /// // do some other stuff here @@ -48,7 +48,7 @@ /// } /// ``` import gleam/io -import gleam/iterator.{type Iterator} +import gleam/yielder.{type Yielder} import gleam/option.{type Option} import gleam/string import gleam/string_tree.{type StringTree} @@ -441,7 +441,7 @@ fn get_finished_fill(fill: StringTree, bar: ProgressStyle) -> StringTree { } } -/// Map an iterator to a function with a bar that ticks every run of the +/// Map an yielder to a function with a bar that ticks every run of the /// function. /// ///
@@ -451,8 +451,8 @@ fn get_finished_fill(fill: StringTree, bar: ProgressStyle) -> StringTree { /// import glitzer/progress /// /// fn example(bar) { -/// iterator.range(0, 100) -/// |> progress.map_iterator(fn(bar, element) { +/// yielder.range(0, 100) +/// |> progress.map_yielder(fn(bar, element) { /// progress.print_bar(bar) /// // do some heavy calculations here >:) /// }) @@ -460,13 +460,13 @@ fn get_finished_fill(fill: StringTree, bar: ProgressStyle) -> StringTree { /// ``` /// ///
-pub fn map_iterator( - over i: Iterator(a), +pub fn map_yielder( + over y: Yielder(a), bar bar: ProgressStyle, with fun: fn(ProgressStyle, a) -> b, -) -> Iterator(b) { - iterator.index(i) - |> iterator.map(fn(pair) { +) -> Yielder(b) { + yielder.index(y) + |> yielder.map(fn(pair) { let #(el, i) = pair tick_bar_by_i(bar, i) |> fun(el) @@ -480,15 +480,15 @@ fn tick_bar_by_i(bar, i) -> ProgressStyle { } } -pub fn map2_iterator( - iterator1 i1: Iterator(a), - iterator2 i2: Iterator(b), +pub fn map2_yielder( + yielder1 y1: Yielder(a), + yielder2 y2: Yielder(b), bar bar: ProgressStyle, with fun: fn(ProgressStyle, a, b) -> c, -) -> Iterator(c) { - iterator.zip(i1, i2) - |> iterator.index - |> iterator.map(fn(pair) { +) -> Yielder(c) { + yielder.zip(y1, y2) + |> yielder.index + |> yielder.map(fn(pair) { let #(pair, i) = pair let #(el1, el2) = pair tick_bar_by_i(bar, i) @@ -496,13 +496,13 @@ pub fn map2_iterator( }) } -pub fn each_iterator( - over i: Iterator(a), +pub fn each_yielder( + over y: Yielder(a), bar bar: ProgressStyle, with fun: fn(ProgressStyle, a) -> b, ) -> Nil { - iterator.index(i) - |> iterator.each(fn(pair) { + yielder.index(y) + |> yielder.each(fn(pair) { let #(el, i) = pair tick_bar_by_i(bar, i) |> fun(el) diff --git a/test/glitzer_test.gleam b/test/glitzer_test.gleam index b25ad0c..fa54851 100644 --- a/test/glitzer_test.gleam +++ b/test/glitzer_test.gleam @@ -1,4 +1,4 @@ -import gleam/iterator +import gleam/yielder import gleeunit import birdie @@ -149,21 +149,21 @@ pub fn progress_finish_test() { |> birdie.snap(title: "Test progresss.finish") } -pub fn progress_map_iterator_test() { +pub fn progress_map_yielder_test() { let bar = progress.new_bar() - iterator.empty() - |> progress.map_iterator(bar, fn(_, _) { progress.print_bar(bar) }) + yielder.empty() + |> progress.map_yielder(bar, fn(_, _) { progress.print_bar(bar) }) |> pprint.format - |> birdie.snap(title: "Test progress.map_iterator") + |> birdie.snap(title: "Test progress.map_yielder") } -pub fn progress_map2_iterator_test() { +pub fn progress_map2_yielder_test() { let bar = progress.new_bar() - let i1 = iterator.empty() - let i2 = iterator.empty() - progress.map2_iterator(i1, i2, bar, fn(_, _, _) { progress.print_bar(bar) }) + let y1 = yielder.empty() + let y2 = yielder.empty() + progress.map2_yielder(y1, y2, bar, fn(_, _, _) { progress.print_bar(bar) }) |> pprint.format - |> birdie.snap(title: "Test progress.map2_iterator") + |> birdie.snap(title: "Test progress.map2_yielder") } pub fn spinner_frames_from_list_test() {