Skip to content

Commit

Permalink
added map2
Browse files Browse the repository at this point in the history
  • Loading branch information
miampf committed Jun 5, 2024
1 parent d92649e commit 3930edf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/glitzer.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}
16 changes: 16 additions & 0 deletions src/glitzer/progress.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3930edf

Please sign in to comment.