aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gleam/list.gleam14
1 files changed, 13 insertions, 1 deletions
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))
}
}