Skip to content

Commit a8d1dbc

Browse files
committed
expand and unify style of collect, exists and forall examples
1 parent 848b13c commit a8d1dbc

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

_overviews/cheatsheets/index.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,9 @@ println(upper.getOrElse(""))</code></pre></td>
496496
}</code></pre>
497497
<em><strong>same as</strong></em>
498498
<pre class="highlight"><code>option match {
499-
case Some(x)
500-
if f.isDefinedAt(x) =&gt; ...
501-
case _ =&gt; None
499+
case Some(x) if f.isDefinedAt(x) =&gt; ...
500+
case Some(_) =&gt; None
501+
case None =&gt; None
502502
}</code></pre></td>
503503
<td>Apply partial pattern match on optional value.</td>
504504
</tr>
@@ -596,17 +596,19 @@ println(upper.getOrElse(""))</code></pre></td>
596596
<td><pre class="highlight"><code>option.exists(f(_))</code></pre>
597597
<em><strong>same as</strong></em>
598598
<pre class="highlight"><code>option match {
599-
case Some(x) =&gt; f(x)
600-
case None =&gt; false
599+
case Some(x) if f(x) =&gt; true
600+
case Some(_) =&gt; false
601+
case None =&gt; false
601602
}</code></pre></td>
602603
<td>Apply predicate on optional value or <code>false</code> if empty.</td>
603604
</tr>
604605
<tr>
605606
<td><pre class="highlight"><code>option.forall(f(_))</code></pre>
606607
<em><strong>same as</strong></em>
607608
<pre class="highlight"><code>option match {
608-
case Some(x) =&gt; f(x)
609-
case None =&gt; true
609+
case Some(x) if f(x) =&gt; true
610+
case Some(_) =&gt; false
611+
case None =&gt; true
610612
}</code></pre></td>
611613
<td>Apply predicate on optional value or <code>true</code> if empty.</td>
612614
</tr>

0 commit comments

Comments
 (0)