How do I break out of a map/collect and return whatever has been collected up to that point?

Sure seems the only way to do this in Ruby is a filter type method then passing results to map. I’m not sure if this works in 1.8, but in 1.9 you could:

[0,1,2,1,0].take_while {|val| val < 2}.map(&:some_function)

Or in the times example

3.times.take_while {|count| count <= 1 } #=> [0,1]

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)