From e8030bb1131bafbf2a5db3ab978c431cd84616fc Mon Sep 17 00:00:00 2001 From: inoas Date: Sat, 25 Jun 2022 16:40:51 +0200 Subject: add fix for List.any --- src/gleam/list.gleam | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gleam/list.gleam b/src/gleam/list.gleam index 8beeeb9..50c7565 100644 --- a/src/gleam/list.gleam +++ b/src/gleam/list.gleam @@ -829,7 +829,19 @@ fn all_tail_recursive( pub fn any(in list: List(a), satisfying predicate: fn(a) -> Bool) -> Bool { case list { [] -> False - [x, ..rest] -> predicate(x) || any(rest, predicate) + list -> any_tail_recursive(list, predicate, False) + } +} + +fn any_tail_recursive( + list: List(a), + predicate: fn(a) -> Bool, + accumulator: Bool, +) -> Bool { + case list { + [] -> accumulator + [x, ..rest] -> + any_tail_recursive(rest, predicate, accumulator || predicate(x)) } } -- cgit v1.2.3