Re: find first non nil element of sequence

2011-05-27 Thread Michael Wood
On 27 May 2011 18:30, Michael Wood wrote: [...] > or: > > (first (filter (complement nil?) coll)) Ah, sorry, I see Sam already suggested this one. -- Michael Wood -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email t

Re: find first non nil element of sequence

2011-05-27 Thread Michael Wood
On 27 May 2011 18:01, MarisO wrote: > there is find-first in contrib > > (find-first #(not (nil? %)) sol) Or: (find-first (complement nil?) coll) or: (first (filter (complement nil?) coll)) but I like Meikel's (first (keep identity coll)) suggestion, even if I find it less straight-forward.

Re: find first non nil element of sequence

2011-05-27 Thread MarisO
there is find-first in contrib (find-first #(not (nil? %)) sol) On May 27, 3:12 pm, Meikel Brandmeyer 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

Aw: find first non nil element of sequence

2011-05-27 Thread Meikel Brandmeyer
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 ide

Re: find first non nil element of sequence

2011-05-27 Thread Ulises
> false is not nil. Ugh! Well spotted :) U -- 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 uns

Re: find first non nil element of sequence

2011-05-27 Thread B Smith-Mannschott
On Fri, May 27, 2011 at 16:03, Ulises wrote: > You could use identity as a predicate to filter: > > user=> (def s [nil nil 1 2 3]) > #'user/s > user=> (first (filter identity s)) > 1 > user=> (first (filter identity [nil false :oops])) --> :oops false is not nil. -- You received this message b

Re: find first non nil element of sequence

2011-05-27 Thread Ulises
You could use identity as a predicate to filter: user=> (def s [nil nil 1 2 3]) #'user/s user=> (first (filter identity s)) 1 user=> U -- 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

Re: find first non nil element of sequence

2011-05-27 Thread Sam Ritchie
Hey, how about this? (defn first-non-nil [xs] (first (filter (complement nil?) xs))) On Fri, May 27, 2011 at 9:56 AM, MarisO wrote: > To find first defined Option in scala I do this: > > sol.find(_.isDefined).getOrElse(None) > > I managed to do the same in clojure: > > (so

find first non nil element of sequence

2011-05-27 Thread 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 ? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this