<div dir="ltr"><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif">I have often wanted to use a guard in a lambda function and had thought it wasn&#39;t possible. But apparently the case construct allows a viable approach. Here is a silly example.</font></font></font><div>

<font class="Apple-style-span" color="#003333" face="&#39;trebuchet ms&#39;, sans-serif"><br></font></div><div><font size="2"></font><font class="Apple-style-span" color="#003333" face="&#39;trebuchet ms&#39;, sans-serif"><div>

<font class="Apple-style-span" face="&#39;courier new&#39;, monospace">testCase = map </font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">             (\xs -&gt; case xs of </font></div>

<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">                     []              -&gt; &quot;empty list&quot;</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">                     [y] | y &lt; 5     -&gt; &quot;small singleton&quot; </font></div>

<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">                         | otherwise -&gt; &quot;large singleton&quot; </font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">                     _               -&gt; &quot;multi-element list&quot;)</font></div>

<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div></font><div><font color="#003333"><font size="2"><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></font></font></div>

<div><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif"><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">&gt; testCase [[], [2], [7], [1,2,3]]</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">[&quot;empty&quot;,&quot;small singleton&quot;,&quot;large singleton&quot;,&quot;multi-element list&quot;]</font></div>

<div><br></div><div>It seems particularly useful to be able to include both patterns and guards in case expressions. I haven&#39;t seen this usage anywhere. Is it considered bad form?</div></font></font></font></div><div>

<div dir="ltr"><font><font face="&#39;trebuchet ms&#39;, sans-serif"><i><font color="#003333"><br>-- Russ </font></i></font></font></div></div></div></div>