diff options
author | Julian Schurhammer <julian.schurhammer@gmail.com> | 2023-12-08 10:06:47 +1300 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2023-12-09 09:57:32 +0000 |
commit | d07f9640a0157f5f661eb2908147605ea339fbff (patch) | |
tree | 8681c77c86c9b5ba3b3994b6ef61c7c54bf13064 | |
parent | eaa795fe6597f8bd9b8b95045f293ff5e81dd96d (diff) | |
download | gleam_stdlib-d07f9640a0157f5f661eb2908147605ea339fbff.tar.gz gleam_stdlib-d07f9640a0157f5f661eb2908147605ea339fbff.zip |
iterator.index: change to #(a, Int)
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | src/gleam/iterator.gleam | 8 | ||||
-rw-r--r-- | test/gleam/iterator_test.gleam | 2 |
3 files changed, 6 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index ef76982..5e9d6b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog - Changed `list.index_map` callback signature to `fn(a, Int) -> b` from `fn(Int, a) -> b`, to be consistent with `list.index_fold`. +- Changed `iterator.index` to return `Iterator(#(a, Int))` instead of `Iterator(#(Int, a))`. ## v0.33.1 - 2023-12-02 diff --git a/src/gleam/iterator.gleam b/src/gleam/iterator.gleam index c57e7fd..c41a3c2 100644 --- a/src/gleam/iterator.gleam +++ b/src/gleam/iterator.gleam @@ -689,12 +689,12 @@ pub fn find( fn do_index( continuation: fn() -> Action(element), next: Int, -) -> fn() -> Action(#(Int, element)) { +) -> fn() -> Action(#(element, Int)) { fn() { case continuation() { Stop -> Stop Continue(e, continuation) -> - Continue(#(next, e), do_index(continuation, next + 1)) + Continue(#(e, next), do_index(continuation, next + 1)) } } } @@ -705,10 +705,10 @@ fn do_index( /// /// ```gleam /// > from_list(["a", "b", "c"]) |> index |> to_list -/// [#(0, "a"), #(1, "b"), #(2, "c")] +/// [#("a", 0), #("b", 1), #("c", 2)] /// ``` /// -pub fn index(over iterator: Iterator(element)) -> Iterator(#(Int, element)) { +pub fn index(over iterator: Iterator(element)) -> Iterator(#(element, Int)) { iterator.continuation |> do_index(0) |> Iterator diff --git a/test/gleam/iterator_test.gleam b/test/gleam/iterator_test.gleam index a83decc..3066c16 100644 --- a/test/gleam/iterator_test.gleam +++ b/test/gleam/iterator_test.gleam @@ -362,7 +362,7 @@ pub fn index_test() { iterator.from_list(["a", "b", "c"]) |> iterator.index |> iterator.to_list - |> should.equal([#(0, "a"), #(1, "b"), #(2, "c")]) + |> should.equal([#("a", 0), #("b", 1), #("c", 2)]) } pub fn iterate_test() { |