aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGiacomo Cavalieri <giacomo.cavalieri@icloud.com>2023-04-18 17:46:08 +0200
committerLouis Pilfold <louis@lpil.uk>2023-04-21 12:01:36 +0100
commit8afbd47799925c962521e72b42664ceafd413a55 (patch)
tree323ba6c50e345e0661d4aa82a35a66a7af089420 /test
parentc733b50e025577c71a3adeb215fe7345c0498cfe (diff)
downloadgleam_stdlib-8afbd47799925c962521e72b42664ceafd413a55.tar.gz
gleam_stdlib-8afbd47799925c962521e72b42664ceafd413a55.zip
try_each tests
Diffstat (limited to 'test')
-rw-r--r--test/gleam/list_test.gleam23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/gleam/list_test.gleam b/test/gleam/list_test.gleam
index 4c76169..a0db992 100644
--- a/test/gleam/list_test.gleam
+++ b/test/gleam/list_test.gleam
@@ -863,6 +863,29 @@ pub fn each_test() {
)
}
+pub fn try_each_test() {
+ list.try_each(
+ over: [1, 1, 1],
+ with: fn(x) {
+ let assert 1 = x
+ Ok(Nil)
+ },
+ )
+
+ // `try_each` actually stops when `fun` returns error
+ list.try_each(
+ over: [1, 2, 3],
+ with: fn(x) {
+ let assert 1 = x
+ Error(Nil)
+ },
+ )
+
+ // TCO test
+ list.repeat(1, recursion_test_cycles)
+ |> list.try_each(with: fn(_) { Ok(Nil) })
+}
+
pub fn partition_test() {
[1, 2, 3, 4, 5, 6, 7]
|> list.partition(int.is_odd)