What is the best way to test whether a list contains a given value in Clojure?
In particular, the behaviour of contains? is currently confusing me:
contains?
Since Clojure is built on Java, you can just as easily call the .indexOf Java function. This function returns the index of any element in a collection, and if it can't find this element, returns -1.
.indexOf
Making use of this we could simply say:
(not= (.indexOf [1 2 3 4] 3) -1) => true