From 6ad66f973f4a26d67983fae645b79585d4e12c47 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 20 Jan 2021 11:57:25 +1100 Subject: Add list.fold_until --- test/gleam/list_test.gleam | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test') diff --git a/test/gleam/list_test.gleam b/test/gleam/list_test.gleam index 2aa1b3e..3277e47 100644 --- a/test/gleam/list_test.gleam +++ b/test/gleam/list_test.gleam @@ -177,6 +177,20 @@ pub fn index_fold_test() { |> should.equal([tuple(2, "c"), tuple(1, "b"), tuple(0, "a")]) } +pub fn fold_until_test() { + [1, 2, 3, 4] + |> list.fold_until( + from: 0, + with: fn(n, acc) { + case n < 4 { + True -> list.Continue(acc + n) + False -> list.Stop(acc) + } + }, + ) + |> should.equal(6) +} + pub fn try_fold_test() { [1, 2, 3] |> list.try_fold( -- cgit v1.2.3