The difference between nil and false is really handy in some cases
and for many people removing nil (or keeping not-nil) values from a seq
is not removing falsy values.

I just wanted to point out the issues that may arise from a blind use of 
(filter identity [...]) ;)

On Friday, October 26, 2012 4:36:16 PM UTC+2, Luc wrote:

> I avoid making explicit distinctions between false and nil in my code. 
> In Clojure a falsy value is either nil or false. 
>
> In interop I ensure that null and false when returned in the upper layers 
> are made consistent (including Boolean objects set to false). 
>
> Too much potential trouble in my opinion to let this slip everywhere in 
> your 
> code, it's not semantically coherent with Clojure. 
>
> Luc P. 
>
>
> > Be careful with the (filter identity ...) which will also remove 
> "falses" 
> > from seqs. 
> > (filter identity [nil 2 3 nil false true 4]) 
> > => (2 3 true 4) 
> > Since (identity false) and (identity nil) returns respectively false and 
> > nil they are BOTH rejected by filter. 
> > 
> > This could do the trick: 
> > (filter (comp not nit?) [nil 2 3 nil false true 4]) 
> > => (2 3 false true 4) 
> > 
> > On Wednesday, November 17, 2010 2:37:16 AM UTC+1, Luc wrote: 
> > 
> > > user=> (time (filter identity [ nil 1 2 nil 4])) 
> > > "Elapsed time: 0.053219 msecs" 
> > > (1 2 4) 
> > > 
> > > user=> (time (remove nil? [ nil 1 2 nil 4])) 
> > > "Elapsed time: 0.065092 msecs" 
> > > (1 2 4) 
> > > 
> > > Choose the flavor your prefer... 
> > > 
> > > Luc P. 
> > > 
> > > Glen Rubin <rubi...@gmail.com <javascript:>> wrote .. 
> > > > What is the fastest way to remove nils from a sequence? 
> > > > 
> > > > I usually use the filter function, but I see there are other 
> functions 
> > > > like remove that should also do the trick. 
> > > > 
> > > > -- 
> > > > You received this message because you are subscribed to the Google 
> > > > Groups "Clojure" group. 
> > > > To post to this group, send email to 
> > > > clo...@googlegroups.com<javascript:> 
>
> > > > Note that posts from new members are moderated - please be patient 
> with 
> > > your first 
> > > > post. 
> > > > To unsubscribe from this group, send email to 
> > > > clojure+u...@googlegroups.com <javascript:> 
> > > > For more options, visit this group at 
> > > > http://groups.google.com/group/clojure?hl=en 
> > > Luc P. 
> > > 
> > > ================ 
> > > The rabid Muppet 
> > > 
> > > 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> > Groups "Clojure" group. 
> > To post to this group, send email to clo...@googlegroups.com<javascript:> 
> > Note that posts from new members are moderated - please be patient with 
> your first post. 
> > To unsubscribe from this group, send email to 
> > clojure+u...@googlegroups.com <javascript:> 
> > For more options, visit this group at 
> > http://groups.google.com/group/clojure?hl=en 
> -- 
> Softaddicts<lprefo...@softaddicts.ca <javascript:>> sent by ibisMail from 
> my ipad! 
>

-- 
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