

<p>The following example uses the <code>prefix(while:)</code> method to find the
positive numbers at the beginning of the <code>numbers</code> array. Every element
of <code>numbers</code> up to, but not including, the first negative value is
included in the result.</p>

<pre><code class="language-swift">let numbers = [3, 7, 4, -2, 9, -6, 10, 1]
let positivePrefix = numbers.prefix(while: { $0 &gt; 0 })
// positivePrefix == [3, 7, 4]</code></pre>

<p>If <code>predicate</code> matches every element in the se