Hi,

On Apr 13, 4:20 pm, Chris Jenkins <cdpjenk...@gmail.com> wrote:

> Is there a standard function to test to see if an object is an element of a
> sequence? I'm looking for an equivalent of Haskell's elem function.
>
> I wrote my own (badly)...
>
> (defn elem? [obj l]
>   (if (empty? l)
>     false
>     (if (= obj (first l))
>       true
>       (elem? obj (rest l)))))
>
> ...but it strikes me that there must be a standard function to do this.

(some #(= % obj) l) (or (some #{obj} l) if obj is neither nil nor
false).

Sincerely
Meikel

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

To unsubscribe, reply using "remove me" as the subject.

Reply via email to