This is almost a fold, but seemingly not quite? I know I&#39;ve seem some talk of folds that potentially &quot;quit&quot; early. but not sure where I saw that, or if it fits. <br><div class="highlight"><pre><span id="li-903-1"><span class="nf">f</span> <span class="n">xs</span> <span class="kt">[]</span> <span class="ow">=</span> <span class="kt">False</span><br>
</span><span id="li-903-2"><span class="nf">f</span> <span class="n">xs</span> <span class="p">(</span><span class="n">y</span><span class="kt">:</span><span class="n">ys</span><span class="p">)</span> <span class="o">|</span> <span class="n">any</span> <span class="n">c</span> <span class="n">ys&#39;</span> <span class="ow">=</span> <span class="kt">True</span><br>
</span><span id="li-903-3">            <span class="o">|</span> <span class="n">otherwise</span> <span class="ow">=</span> <span class="n">f</span> <span class="p">(</span><span class="n">nub</span> <span class="p">(</span><span class="n">y</span><span class="kt">:</span><span class="n">xs</span><span class="p">))</span> <span class="p">(</span><span class="n">ys&#39;</span> <span class="o">++</span> <span class="n">ys</span><span class="p">)</span><br>
</span><span id="li-903-4">   <span class="kr">where</span> <span class="n">ys&#39;</span> <span class="ow">=</span> <span class="n">g</span> <span class="n">y</span> <span class="n">xs</span><br><br><br><br></span></pre>
</div>