diff options
author | Louis Pilfold <louis@lpil.uk> | 2019-10-25 18:47:50 +0100 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2019-10-25 19:05:54 +0100 |
commit | 427dde6a252f4af02af7de1c83f5acbf701c9a8f (patch) | |
tree | 4a37bae6f99201b01119b7b3927a72c024236561 /test | |
parent | 0bf78a366609d460fa2546b17e12dcbc66cbc238 (diff) | |
download | gleam_stdlib-427dde6a252f4af02af7de1c83f5acbf701c9a8f.tar.gz gleam_stdlib-427dde6a252f4af02af7de1c83f5acbf701c9a8f.zip |
list.find and list.find_map
Diffstat (limited to 'test')
-rw-r--r-- | test/gleam/list_test.gleam | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/test/gleam/list_test.gleam b/test/gleam/list_test.gleam index 4be1795..d4322fe 100644 --- a/test/gleam/list_test.gleam +++ b/test/gleam/list_test.gleam @@ -142,11 +142,11 @@ pub fn fold_test() { pub fn fold_right_test() { [1, 2, 3] - |> list.fold_right(_, [], fn(x, acc) { [x | acc] }) - |> expect.equal(_, [1, 2, 3]) + |> list.fold_right(_, from: [], with: fn(x, acc) { [x | acc] }) + |> expect.equal(_, [1, 2, 3]) } -pub fn find_test() { +pub fn find_map_test() { let f = fn(x) { case x { | 2 -> Ok(4) @@ -155,15 +155,33 @@ pub fn find_test() { } [1, 2, 3] - |> list.find(_, f) + |> list.find_map(_, with: f) |> expect.equal(_, Ok(4)) [1, 3, 2] - |> list.find(_, f) + |> list.find_map(_, with: f) |> expect.equal(_, Ok(4)) [1, 3] - |> list.find(_, f) + |> list.find_map(_, with: f) + |> expect.equal(_, Error(Nil)) +} + +pub fn find_test() { + let is_two = fn(x) { + x == 2 + } + + [1, 2, 3] + |> list.find(_, one_that: is_two) + |> expect.equal(_, Ok(2)) + + [1, 3, 2] + |> list.find(_, one_that: is_two) + |> expect.equal(_, Ok(2)) + + [1, 3] + |> list.find(_, one_that: is_two) |> expect.equal(_, Error(Nil)) } |