there is find-first in contrib

(find-first #(not (nil? %)) sol)



On May 27, 3:12 pm, Meikel Brandmeyer <m...@kotka.de> wrote:
> Hi,
>
> Am Freitag, 27. Mai 2011 15:56:47 UTC+2 schrieb MarisO:
>
>
>
> > To find first defined Option in scala  I do this:
>
> > sol.find(_.isDefined).getOrElse(None)
>
> > I managed to do the same in clojure:
>
> > (some #(if (nil? %) false %) sol)
>
> > Is there a better way ?
>
> Another way: (first (keep identity coll)).
>
> user=> (first (keep identity [nil false 1 2 3]))
> false
> user=> (first (keep identity [nil 1 2 3]))
> 1
> user=> (first (keep identity [nil nil nil]))
> nil
> user=> (first (keep identity []))
> nil
>
> If your collection does never contain false, you can simply use (some
> identity coll).
>
> 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

Reply via email to