Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: more deprecation warnings for Gleam stdlib #29

Merged
merged 5 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,19 @@ You can access the progress bars with `import glitzer/progress`.

```gleam
import gleam/int
import gleam/iterator
import gleam/yielder

import glitzer/progress

pub fn main() {
let bar =
progress.new_bar()
let bar =
progress.new_bar()
|> progress.with_length(100)
|> 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
Expand Down Expand Up @@ -117,7 +117,7 @@ fn do_stuff(bar, count) {
// some heavy lifting
do_stuff(bar, count + 1)
}
False -> Nil
False -> Nil
}
}
```
Expand All @@ -140,7 +140,7 @@ pub fn main() {
|> spinner.spin // this will continuously spin your spinner

// do some stuff

// update the text
spinner.with_left_text(s, "Now imma spin some more :] ")
|> spinner.with_frame_transform(fn(s) {"<" <> s <> ">"})
Expand All @@ -166,7 +166,7 @@ New code and pull requests are greatly appreciated! If you want to contribute,
check the [contributing guidelines](#contributing) and submit a PR :3

If you have any questions, feel free to
[create a question]((https://github.com/miampf/glitzer/issues/new?assignees=&labels=question&template=04_SUPPORT_QUESTION.md&title=support%3A+))!
[create a question](<(https://github.com/miampf/glitzer/issues/new?assignees=&labels=question&template=04_SUPPORT_QUESTION.md&title=support%3A+)>)!
Please note that it may take some time for me to respond. I am not paid for
doing this and do have a private life (surprise!) :]

Expand Down
2 changes: 1 addition & 1 deletion birdie_snapshots/test_progress_map2_iterator.accepted
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
version: 1.1.6
version: 1.2.4
title: Test progress.map2_iterator
file: ./test/glitzer_test.gleam
test_name: progress_map2_iterator_test
Expand Down
7 changes: 7 additions & 0 deletions birdie_snapshots/test_progress_map2_yielder.accepted
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
version: 1.2.4
title: Test progress.map2_yielder
file: ./test/glitzer_test.gleam
test_name: progress_map2_yielder_test
---
Yielder(//fn() { ... })
2 changes: 1 addition & 1 deletion birdie_snapshots/test_progress_map_iterator.accepted
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
version: 1.1.6
version: 1.2.4
title: Test progress.map_iterator
file: ./test/glitzer_test.gleam
test_name: progress_map_iterator_test
Expand Down
7 changes: 7 additions & 0 deletions birdie_snapshots/test_progress_map_yielder.accepted
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
version: 1.2.4
title: Test progress.map_yielder
file: ./test/glitzer_test.gleam
test_name: progress_map_yielder_test
---
Yielder(//fn() { ... })
1 change: 1 addition & 0 deletions gleam.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand All @@ -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" }
Expand Down
85 changes: 75 additions & 10 deletions src/glitzer/progress.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
///
/// ```gleam
/// import gleam/int
/// import gleam/iterator
/// import gleam/yielder
///
/// import glitzer/progress
///
Expand All @@ -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
Expand Down Expand Up @@ -52,6 +52,7 @@ import gleam/iterator.{type Iterator}
import gleam/option.{type Option}
import gleam/string
import gleam/string_tree.{type StringTree}
import gleam/yielder.{type Yielder}

import gleam_community/ansi

Expand Down Expand Up @@ -460,6 +461,7 @@ fn get_finished_fill(fill: StringTree, bar: ProgressStyle) -> StringTree {
/// ```
///
/// </details>
@deprecated("`map_iterator` was deprecated and will be removed in the next release. Use `map_yielder` instead.")
pub fn map_iterator(
over i: Iterator(a),
bar bar: ProgressStyle,
Expand All @@ -473,13 +475,7 @@ pub fn map_iterator(
})
}

fn tick_bar_by_i(bar, i) -> ProgressStyle {
case i > 0 {
True -> tick_bar_by_i(tick(bar), i - 1)
False -> bar
}
}

@deprecated("`map2_iterator` was deprecated and will be removed in the next release. Use `map2_yielder` instead.")
pub fn map2_iterator(
iterator1 i1: Iterator(a),
iterator2 i2: Iterator(b),
Expand All @@ -496,6 +492,7 @@ pub fn map2_iterator(
})
}

@deprecated("`each_iterator` was deprecated and will be removed in the next release. Use `each_yielder` instead.")
pub fn each_iterator(
over i: Iterator(a),
bar bar: ProgressStyle,
Expand All @@ -508,3 +505,71 @@ pub fn each_iterator(
|> fun(el)
})
}

/// Map a yielder to a function with a bar that ticks every run of the
/// function.
///
/// <details>
/// <summary>Example:</summary>
///
/// ```gleam
/// import glitzer/progress
///
/// fn example(bar) {
/// yielder.range(0, 100)
/// |> progress.map_yielder(fn(bar, element) {
/// progress.print_bar(bar)
/// // do some heavy calculations here >:)
/// })
/// }
/// ```
///
/// </details>
pub fn map_yielder(
over y: Yielder(a),
bar bar: ProgressStyle,
with fun: fn(ProgressStyle, a) -> b,
) -> Yielder(b) {
yielder.index(y)
|> yielder.map(fn(pair) {
let #(el, i) = pair
tick_bar_by_i(bar, i)
|> fun(el)
})
}

fn tick_bar_by_i(bar, i) -> ProgressStyle {
case i > 0 {
True -> tick_bar_by_i(tick(bar), i - 1)
False -> bar
}
}

pub fn map2_yielder(
yielder1 y1: Yielder(a),
yielder2 y2: Yielder(b),
bar bar: ProgressStyle,
with fun: fn(ProgressStyle, a, b) -> c,
) -> 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)
|> fun(el1, el2)
})
}

pub fn each_yielder(
over y: Yielder(a),
bar bar: ProgressStyle,
with fun: fn(ProgressStyle, a) -> b,
) -> Nil {
yielder.index(y)
|> yielder.each(fn(pair) {
let #(el, i) = pair
tick_bar_by_i(bar, i)
|> fun(el)
})
}
18 changes: 18 additions & 0 deletions test/glitzer_test.gleam
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import gleam/iterator
import gleam/yielder
import gleeunit

import birdie
Expand Down Expand Up @@ -166,6 +167,23 @@ pub fn progress_map2_iterator_test() {
|> birdie.snap(title: "Test progress.map2_iterator")
}

pub fn progress_map_yielder_test() {
let bar = progress.new_bar()
yielder.empty()
|> progress.map_yielder(bar, fn(_, _) { progress.print_bar(bar) })
|> pprint.format
|> birdie.snap(title: "Test progress.map_yielder")
}

pub fn progress_map2_yielder_test() {
let bar = progress.new_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_yielder")
}

pub fn spinner_frames_from_list_test() {
spinner.frames_from_list(["a", "b", "c"])
|> pprint.format
Expand Down