From 427dde6a252f4af02af7de1c83f5acbf701c9a8f Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Fri, 25 Oct 2019 18:47:50 +0100 Subject: list.find and list.find_map --- test/gleam/list_test.gleam | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'test') 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)) } -- cgit v1.2.3