Skip to content

Commit 680f971

Browse files
authored
feat(list): adding list:contains?
1 parent 68ac247 commit 680f971

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

List.ark

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@
1818
# @author https://github.com/SuperFola
1919
(let find (fun (_L _x) (builtin__list:find _L _x)))
2020

21+
# @brief Search if an element is in a List
22+
# @details The original list is not modified
23+
# @param list the List to search in
24+
# @param value the element to search
25+
# =begin
26+
# (list:contains? [1 2 3] 1) # true
27+
# (list:contains? [1 2 3] 0) # false
28+
# =end
29+
# @author https://github.com/SuperFola
30+
(let contains? (fun (_L _x) (!= -1 (find _L _x))))
31+
2132
# @brief Get a slice from a List
2233
# @details The original list is not modified
2334
# @param list the list to reverse

tests/list-tests.ark

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323

2424
(test:eq (builtin__list:setAt a 0 5) (list:setAt a 0 5)) })
2525

26+
(test:case "contains?" {
27+
(test:expect (list:contains? [1 2 3] 1))
28+
(test:expect (not (list:contains? [1 2 3] "1")))
29+
(test:expect (list:contains? ["1" "2" "3"] "1")) })
30+
2631
(test:case "size" {
2732
(test:eq (list:size []) 0)
2833
(test:eq (list:size [1 2 3]) 3) })

0 commit comments

Comments
 (0)