Skip to content

Commit 295b136

Browse files
committed
expand and unify style of collect, exists and forall examples
1 parent 472b9eb commit 295b136

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

_cheatsheets/index.md

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

0 commit comments

Comments
 (0)