diff options
author | Marcin Puc <marcin.e.puc@gmail.com> | 2021-03-21 12:02:30 +0100 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2021-04-13 10:50:44 +0100 |
commit | ffeb3757f291dbff55c772b7d622e22dac79352c (patch) | |
tree | 7c301008788f1ba91d1b7d41599461a065301c3c /test | |
parent | 593eeae98d21da64d0e6a956413d3874fe762369 (diff) | |
download | gleam_stdlib-ffeb3757f291dbff55c772b7d622e22dac79352c.tar.gz gleam_stdlib-ffeb3757f291dbff55c772b7d622e22dac79352c.zip |
Add {iterator. list}.reduce
Diffstat (limited to 'test')
-rw-r--r-- | test/gleam/iterator_test.gleam | 10 | ||||
-rw-r--r-- | test/gleam/list_test.gleam | 10 |
2 files changed, 20 insertions, 0 deletions
diff --git a/test/gleam/iterator_test.gleam b/test/gleam/iterator_test.gleam index 81a2908..492bb1e 100644 --- a/test/gleam/iterator_test.gleam +++ b/test/gleam/iterator_test.gleam @@ -373,3 +373,13 @@ pub fn group_test() { tuple(2, [2, 5]), ])) } + +pub fn reduce_test() { + iterator.from_list([]) + |> iterator.reduce(with: fn(x, y) { x + y }) + |> should.equal(Error(Nil)) + + iterator.from_list([1, 2, 3, 4, 5]) + |> iterator.reduce(with: fn(x, y) { x + y }) + |> should.equal(Ok(15)) +} diff --git a/test/gleam/list_test.gleam b/test/gleam/list_test.gleam index b7470ac..fc8ea11 100644 --- a/test/gleam/list_test.gleam +++ b/test/gleam/list_test.gleam @@ -612,3 +612,13 @@ pub fn sized_chunk_test() { |> list.sized_chunk(into: 3) |> should.equal([[1, 2, 3], [4, 5, 6], [7, 8]]) } + +pub fn reduce_test() { + [] + |> list.reduce(with: fn(x, y) { x + y }) + |> should.equal(Error(Nil)) + + [1, 2, 3, 4, 5] + |> list.reduce(with: fn(x, y) { x + y }) + |> should.equal(Ok(15)) +} |