Re:Ladies, look at your code. Now back to mine.
by didip on Saturday August 28, 2010 @04:34PM
(#1642349)
Joining the club, in Python:
[e for e in employees if e.isPartTime()]
You can even push it further:
[e for e in employees if e.isPartTime() or e.lazy() or e.havePassiveIncomeAlready()]
and further:
[e for e in employees if e.isPartTime() or e.lazy() or e.havePassiveIncomeAlready() or e in [exec for exec in BoardofDirector.all() if exec.haveTooManyPortfolio()]]
Above is your friendly neighborhood List Comprehension available since Jython 2.0
Re:Ladies, look at your code. Now back to mine.
by erikpukinskis on Saturday August 28, 2010 @04:01AM
(#1641445)
In Ruby:
employees.find_all &:isPartTime
Re:Ladies, look at your code. Now back to mine.
by patio11 on Saturday August 28, 2010 @04:58AM
(#1641493)
And I liked employees.select {|employee| employee.part_time?}
Crikey, should buy a book...
Re:Ladies, look at your code. Now back to mine.
by Confusion on Saturday August 28, 2010 @06:15AM
(#1641553)
Personally, I prefer your version; the &: version starts reeking of Perl line noise. Although I believe Ruby would benefit from an _ for not explicitly named block arguments.
Re:Ladies, look at your code. Now back to mine.
by steveklabnik on Saturday August 28, 2010 @02:25PM
(#1642130)
As a random note for anyone who's wondering how this syntax came about, this is the Symbol#to_proc [1] method, which was actually a monkeypatch from Rails that ended up making its way back into Ruby proper.
Re:Ladies, look at your code. Now back to mine.
by mark_l_watson on Saturday August 28, 2010 @11:58AM
(#1641859)
I agree, I also prefer the slightly longer version. OK, enough small talk ... :-)
Re:Ladies, look at your code. Now back to mine.
by jarin on Saturday August 28, 2010 @06:59AM
(#1641588)
Thank goodness Symbol#to_proc was introduced in Ruby 1.9, the Rails implementation of it was slow as hell: http://www.lukeredpath.co.uk/blog/optimising-symbol-to_proc....
Re:Ladies, look at your code. Now back to mine.
by wuputah on Saturday August 28, 2010 @12:35PM
(#1641915)
That was fixed some time ago. It is very marginally slower to use Symbol#to_proc now (a constant time difference to actually create the Proc), but not enough to warrant a change in practical use.
employees.filter( _.isPartTime )
And it runs in the same virtual machine.