title: How do I break out of a map/collect and return whatever has been collected up to that point?
body: <p>I'm rewriting this question in code:</p>
  
  <pre><code>many = 1000
  
  # An expensive method.
  #
  # It returns some data or nil if no result is available.
  expensive_method = lambda do
    rand(5) == 0 ? nil : "foo"
  end
  
  # Now, let's collect some data and stop collecting when no more data is
  # available.
  
  # This is concise but doesn't work.
  collection = many.times.map do
    expensive_method.call || break
  end
  
  puts collection.is_a? Array # false
  
  # This is less concise but works.
  collection = []
  many.times do
    collection &lt;&lt; (expensive_method.call || break)
  end
  
  puts collection.is_a? Array # true
  
  # My inner Rubyist ponders: Is it possible to accomplish this more concisely
  # using map?
  </code></pre>