title: Is there a way to break from an array's reduce function in Swift?
body: <p>Is there a way to do something similar to <code>break</code> from a <code>for</code> loop but in array's <code>reduce()</code> function?</p>
  
  <p>E.g. consider I have an array:</p>
  
  <pre><code>var flags = [false, false, true, false, false, true, false]
  </code></pre>
  
  <p>... and I need to get a cumulative <code>||</code> on them.  With a <code>for</code> loop, the following would be possible:</p>
  
  <pre><code>var resultByFor = false
  
  for flag in flags {
      if flag {
          resultByFor = true
          break
      }
  }
  </code></pre>
  
  <p>... i.e. at the moment we get our first <code>true</code> there is no need to finish the loop as the result will be <code>true</code> anyway.</p>
  
  <p>With <code>reduce()</code>, the following looks quite neat and tidy:</p>
  
  <pre><code>var resultByReduce = flags.reduce(false) { $0 || $1 }
  </code></pre>
  
  <p>However, with the array given in the example, the <code>for</code> loop body would be executed only 3 times, while <code>reduce()</code> function closure would get triggered full 7 times.</p>
  
  <p>Is there a way to make <code>reduce()</code> to bail out on 3rd iteration as well (just like it can be done in <code>for</code> loop)?</p>
  
  <p><strong>[UPD]</strong></p>
  
  <p>I oversimplified the question.  The original problem was more like this:</p>
  
  <pre><code>extension Int {
      func isWholeMultiplesOf(base: Int) -&gt; Bool {
          return (self % base) == 0
      }
  }
  
  var numbers = [3, 5, 6, 7, 2, 3, 8]
  
  var resultByFor = false
  
  // The loop body will be triggered only 3 times
  for number in numbers {
      if number.isWholeMultiplesOf(2) {
          resultByFor = true
          break
      }
  }
  
  // The closure of reduce() will be triggered 7 times
  var resultByReduce = numbers.reduce(false) {
      $0 || $1.isWholeMultiplesOf(2)
  }
  </code></pre>
  
  <p>... i.e. I have an array of objects and I want to know if there is at least one of them that has certain method evaluating to <code>true</code>.</p>