diff options
author | Robert Attard <robert.attard@mail.mcgill.ca> | 2021-04-13 10:04:17 -0400 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2021-04-14 21:23:32 +0100 |
commit | 53471ea469a5ce92a500194405a121237de5d131 (patch) | |
tree | 7af335b2afebb9098e58560367c5362de6adf86b /test | |
parent | fb129be0608b54412f5a70faefff5903acd5d014 (diff) | |
download | gleam_stdlib-53471ea469a5ce92a500194405a121237de5d131.tar.gz gleam_stdlib-53471ea469a5ce92a500194405a121237de5d131.zip |
add list.scan
Diffstat (limited to 'test')
-rw-r--r-- | test/gleam/list_test.gleam | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/gleam/list_test.gleam b/test/gleam/list_test.gleam index bf93203..572812c 100644 --- a/test/gleam/list_test.gleam +++ b/test/gleam/list_test.gleam @@ -622,3 +622,26 @@ pub fn reduce_test() { |> list.reduce(with: fn(x, y) { x + y }) |> should.equal(Ok(15)) } + +pub fn scan_test() { + [] + |> list.scan(from: 0, with: fn(i, acc) { i + acc }) + |> should.equal([]) + + [1, 2, 3, 4] + |> list.scan(from: 0, with: fn(i, acc) { 2 * i + acc }) + |> should.equal([2, 6, 12, 20]) + + [1, 2, 3, 4] + |> list.scan( + from: "", + with: fn(i, acc) { + case int.is_even(i) { + True -> "Even" + False -> "Odd" + } + |> string.append(acc, _) + }, + ) + |> should.equal(["Odd", "OddEven", "OddEvenOdd", "OddEvenOddEven"]) +} |