aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gleam/list.gleam10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/gleam/list.gleam b/src/gleam/list.gleam
index 6977338..71f332a 100644
--- a/src/gleam/list.gleam
+++ b/src/gleam/list.gleam
@@ -167,7 +167,15 @@ pub fn is_empty(list: List(a)) -> Bool {
pub fn contains(list: List(a), any elem: a) -> Bool {
case list {
[] -> False
- [head, ..rest] -> head == elem || contains(rest, elem)
+ list -> do_contains(list, elem, False)
+ }
+}
+
+fn do_contains(list: List(a), any elem: a, accumulator: Bool) -> Bool {
+ case list {
+ _ if accumulator == True -> True
+ [] -> accumulator
+ [head, ..rest] -> do_contains(rest, elem, head == elem || accumulator)
}
}