aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Puc <marcin.e.puc@gmail.com>2021-12-04 15:00:01 +0100
committerLouis Pilfold <louis@lpil.uk>2021-12-04 14:32:50 +0000
commit9fd5575d2525bfecc509e6378af704a8e822b710 (patch)
treefa6b2f166fbcdce7bdc9eecee72e8d6adc244cfa
parentf14accf184cad3ae5dbc8a9b265add0fc87c604e (diff)
downloadgleam_stdlib-9fd5575d2525bfecc509e6378af704a8e822b710.tar.gz
gleam_stdlib-9fd5575d2525bfecc509e6378af704a8e822b710.zip
Fix docs and usage for iterator.reduce
-rw-r--r--src/gleam/iterator.gleam6
-rw-r--r--test/gleam/iterator_test.gleam4
2 files changed, 5 insertions, 5 deletions
diff --git a/src/gleam/iterator.gleam b/src/gleam/iterator.gleam
index 097e6c2..babebc6 100644
--- a/src/gleam/iterator.gleam
+++ b/src/gleam/iterator.gleam
@@ -920,16 +920,16 @@ pub fn group(
/// This function acts similar to fold, but does not take an initial state.
/// Instead, it starts from the first yielded element
/// and combines it with each subsequent element in turn using the given function.
-/// The function is called as f(current_element, accumulator).
+/// The function is called as f(accumulator, current_element).
///
/// Returns `Ok` to indicate a successful run, and `Error` if called on an empty iterator.
///
/// ## Examples
///
-/// > from_list([]) |> reduce(fn(x, y) { x + y })
+/// > from_list([]) |> reduce(fn(acc, x) { acc + x })
/// Error(Nil)
///
-/// > from_list([1, 2, 3, 4, 5]) |> reduce(fn(x, y) { x + y })
+/// > from_list([1, 2, 3, 4, 5]) |> reduce(fn(acc, x) { acc + x })
/// Ok(15)
///
pub fn reduce(
diff --git a/test/gleam/iterator_test.gleam b/test/gleam/iterator_test.gleam
index d8da969..67637f0 100644
--- a/test/gleam/iterator_test.gleam
+++ b/test/gleam/iterator_test.gleam
@@ -377,11 +377,11 @@ pub fn group_test() {
pub fn reduce_test() {
iterator.empty()
- |> iterator.reduce(with: fn(x, y) { x + y })
+ |> iterator.reduce(with: fn(acc, x) { acc + x })
|> should.equal(Error(Nil))
iterator.from_list([1, 2, 3, 4, 5])
- |> iterator.reduce(with: fn(x, y) { x + y })
+ |> iterator.reduce(with: fn(acc, x) { acc + x })
|> should.equal(Ok(15))
}