<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Functional-Programming on Jake Worth</title><link>https://jakeworth.com/tags/functional-programming/</link><description>Recent content in Functional-Programming on Jake Worth</description><image><title>Jake Worth</title><url>https://jakeworth.com/twittercard.png</url><link>https://jakeworth.com/twittercard.png</link></image><generator>Hugo</generator><language>en-us</language><lastBuildDate>Thu, 27 Jun 2024 09:57:29 -0400</lastBuildDate><atom:link href="https://jakeworth.com/tags/functional-programming/index.xml" rel="self" type="application/rss+xml"/><item><title>Filtering By Identity</title><link>https://jakeworth.com/tils/filtering-by-identity/</link><pubDate>Thu, 27 Jun 2024 09:57:29 -0400</pubDate><guid>https://jakeworth.com/tils/filtering-by-identity/</guid><description>&lt;p&gt;I&amp;rsquo;m reading &lt;em&gt;Functional-Light JavaScript&lt;/em&gt; by Kyle Simpson, and learning a lot!
Today I learned about the functional programming utility known as &amp;lsquo;identity&amp;rsquo;.&lt;/p&gt;
&lt;p&gt;Identity is a unary function that simply returns its argument. A simple idea
that can be powerfully applied, as JavaScript coerces the returned argument to
boolean:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-js" data-lang="js"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;const&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;identity&lt;/span&gt; &lt;span style="color:#f92672"&gt;=&lt;/span&gt; (&lt;span style="color:#a6e22e"&gt;arg&lt;/span&gt;) =&amp;gt; &lt;span style="color:#a6e22e"&gt;arg&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;&amp;gt;&lt;/span&gt; [&lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;, &lt;span style="color:#66d9ef"&gt;false&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;keep&amp;#34;&lt;/span&gt;, &lt;span style="color:#66d9ef"&gt;null&lt;/span&gt;, &lt;span style="color:#66d9ef"&gt;undefined&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;these&amp;#34;&lt;/span&gt;].&lt;span style="color:#a6e22e"&gt;filter&lt;/span&gt;(&lt;span style="color:#a6e22e"&gt;identity&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;[ &lt;span style="color:#e6db74"&gt;&amp;#39;keep&amp;#39;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#39;these&amp;#39;&lt;/span&gt; ]
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I&amp;rsquo;ve done something similar for years by filtering to boolean, or writing my own
(I didn&amp;rsquo;t know it had this name) anonymous identity function.&lt;/p&gt;</description></item></channel></rss>