diff --git a/src/glitzer.gleam b/src/glitzer.gleam index 2dbb65b..4ce9586 100644 --- a/src/glitzer.gleam +++ b/src/glitzer.gleam @@ -14,6 +14,7 @@ pub fn main() { do_something(bar, 0) do_something_else() + do_cool_shit_with_2_it() } fn do_something(bar, count) { @@ -40,3 +41,18 @@ fn do_something_else() { sleep(100) }) } + +fn do_cool_shit_with_2_it() { + let bar = + progress.default_bar() + |> progress.with_length(10) + let i1 = iterator.range(0, 10) + let i2 = iterator.range(100, 150) + progress.map2_iterator(i1, i2, bar, fn(bar, e1, e2) { + progress.with_left_text(bar, int.to_string(e1) <> " ") + |> progress.with_right_text(" " <> int.to_string(e2)) + |> progress.print_bar + sleep(100) + }) + |> iterator.run +} diff --git a/src/glitzer/progress.gleam b/src/glitzer/progress.gleam index 7e63e4f..b4b3d54 100644 --- a/src/glitzer/progress.gleam +++ b/src/glitzer/progress.gleam @@ -406,6 +406,22 @@ fn tick_bar_by_i(bar, i) -> ProgressStyle { } } +pub fn map2_iterator( + iterator1 i1: Iterator(a), + iterator2 i2: Iterator(b), + bar bar: ProgressStyle, + with fun: fn(ProgressStyle, a, b) -> c, +) -> Iterator(c) { + iterator.zip(i1, i2) + |> iterator.index + |> iterator.map(fn(pair) { + let #(pair, i) = pair + let #(el1, el2) = pair + tick_bar_by_i(bar, i) + |> fun(el1, el2) + }) +} + pub fn each_iterator( over i: Iterator(a), bar bar: ProgressStyle,