<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>partialapplication &#8211; Software, Fitness, and Gaming &#8211; Jesse Warden</title>
	<atom:link href="https://jessewarden.com/tag/partialapplication/feed" rel="self" type="application/rss+xml" />
	<link>https://jessewarden.com</link>
	<description>Software &#124; Fitness &#124; Gaming</description>
	<lastBuildDate>Fri, 28 Dec 2018 17:42:14 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://jessewarden.com/wp-content/uploads/2016/08/cropped-Lambda2-32x32.png</url>
	<title>partialapplication &#8211; Software, Fitness, and Gaming &#8211; Jesse Warden</title>
	<link>https://jessewarden.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>What Are Partial Applications?</title>
		<link>https://jessewarden.com/2018/12/what-are-partial-applications.html</link>
		
		<dc:creator><![CDATA[JesterXL]]></dc:creator>
		<pubDate>Thu, 27 Dec 2018 17:10:59 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[curry]]></category>
		<category><![CDATA[defaultarguments]]></category>
		<category><![CDATA[functionalprogramming]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[partialapplication]]></category>
		<guid isPermaLink="false">http://jessewarden.com/?p=5742</guid>

					<description><![CDATA[tl;dr; A Partial Application is a function where some or all of the arguments are packed inside, ready to go and it&#8217;s just waiting for a few more before the main function is invoked. They&#8217;re like functions that have default arguments, but are pure functions with a fixed amount of parameters. Introduction The following article [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">tl;dr;</h2>



<p>A Partial Application is a function where some or all of the arguments are packed inside, ready to go and it&#8217;s just waiting for a few more before the main function is invoked. They&#8217;re like functions that have default arguments, but are pure functions with a fixed amount of parameters.</p>



<h2 class="wp-block-heading">Introduction</h2>



<p>The following article and <a href="https://www.youtube.com/watch?v=uIBMz4-zOf8&amp;list=PLZEZPz6HkCZnsdr7kPQIiN3lCdBBClClI">companion video playlist</a> will cover what a partial application is and how it can be used for a more pure function option for default arguments. It&#8217;s assumed you know what <a href="https://jesterxl.github.io/real-world-functional-programming-book/part1/">pure functions</a> are. We&#8217;ll cover:</p>



<ul class="wp-block-list"><li>basic function arguments</li><li>default arguments and how order can make them harder/easier to use</li><li>function arity</li><li>function currying with closures and show how the parameter order is reversed compared to default arguments</li><li> building partial applications to show how to make using default arguments pure</li><li>creating partial applications with no arguments</li></ul>



<span id="more-5742"></span>



<h2 class="wp-block-heading">Video Playlist</h2>



<p>In case you want an interactive example, I&#8217;ll walk through each section.</p>



<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="What Are Partial Applications? - 1 of 11 - Introduction" width="500" height="281" src="https://www.youtube.com/embed/uIBMz4-zOf8?list=PLZEZPz6HkCZnsdr7kPQIiN3lCdBBClClI" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div><figcaption>What Are Partial Applications?</figcaption></figure>



<h2 class="wp-block-heading">Basic Arguments</h2>



<p>The function below pings google.com:<br>
<code>const pingGoogle = () =&gt; fetch('http://google.com')</code>. If it resolves, Google is there and your computer can talk to the internets. If it throws an error, your computer is probably having wireless trouble.</p>



<p>You call (or invoke) it like <code>pingGoogle()</code>. If you want better logs, you&#8217;d go:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">pingGoogle()
.then(<span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Connected to the internet!"</span>))
.catch( <span class="hljs-function"><span class="hljs-params">error</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Not connected to the internet:"</span>, error))</code></span></pre>


<p>In software development, you&#8217;re often testing YOUR server, code that will exist in YOUR url, not googles&#8217;. Example, I wonder if my blog is up?</p>



<p><code>const pingJessesBlog = () =&gt; fetch('http://jessewarden.com')</code></p>



<p>However, while small, those are all hardcoded. While not a religion, it DOES violate DRY: Don&#8217;t Repeat Yourself. How can we make the function more re-usable? Parameters or arguments!</p>



<p><code>const ping = url =&gt; fetch(url)</code></p>



<p>Rad, now we can test Google again:</p>



<p><code>ping('http://google.com')</code></p>



<p>Or my blog:</p>



<p><code>ping('http://jessewarden.com')</code></p>



<p>… or even see if we&#8217;re connected to the internet first, THEN my blog:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">ping(<span class="hljs-string">'http://google.com'</span>)
.then(<span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> ping(<span class="hljs-string">'http://jessewarden.com'</span>))
.catch(<span class="hljs-function"><span class="hljs-params">error</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Something failed:"</span>, error))</code></span></pre>


<h2 class="wp-block-heading">Default Arguments &amp; Pure Functions</h2>



<p>However, we know if we call <code>ping</code>, we&#8217;re going to do this google thing a lot, so to prevent ourselves from typing so much, let&#8217;s just default to &#8220;http://google.com&#8221; unless someone gives us a URL:</p>



<p><code>const ping = (url='http://google.com') =&gt; fetch(url)</code></p>



<p>Now, we only have to supply the URL parameter if we want something other than Google:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">ping()
.then(<span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> ping(<span class="hljs-string">'http://jessewarden.com'</span>))
.catch(<span class="hljs-function"><span class="hljs-params">error</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Something failed:"</span>, error))</code></span></pre>


<p>Notice that the function <code>ping</code> is now pre-baked with an argument as a backup. &#8220;If you don&#8217;t send me one, or send me <code>undefined</code>, I&#8217;ll just use &#8216;http://google.com&#8217; instead.&#8221; This is what&#8217;s called a default argument. If you supply something, great, but if you don&#8217;t, still great, we got your back.</p>



<p>Now, <code>ping</code> is not a pure function. A pure function is:</p>



<ol class="wp-block-list"><li>same input, same output</li><li>no side effects</li></ol>



<p>A more pure version would be if we forced the developer to declare where they are getting the dependency <code>fetch</code>:</p>



<p><code>const pingPure = (fetch, url='http://jessewarden.com') =&gt; fetch(url))</code></p>



<p>All we changed was requiring <code>fetch</code> as the first parameter, the 2nd, <code>url</code> is still optional and defaults to Google. Now the <code>fetch</code> has side effects, like making an HTTP call, but as long as we handle the <code>.catch</code> or use a try/catch with async/await syntax, it&#8217;s good enough.</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">ping(fetch)
.then(<span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> ping(fetch, <span class="hljs-string">'http://jessewarden.com'</span>))
.catch(<span class="hljs-function"><span class="hljs-params">error</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Something failed:"</span>, error))</code></span></pre>


<h2 class="wp-block-heading">Function Parameter Order</h2>



<p>… however, that&#8217;s a pain in the ass. As you can see argument order can really make a function hard to use, and merely thinking about argument order, or testing a function out, then iterating on a new version of it with a different order can make things easier. Let&#8217;s do that by reversing the order, AND making <code>fetch</code> have a default as well.</p>



<p><code>const pingPure = (url='http://jessewarden.com', fetchModule=fetch) =&gt; fetchModule(url))</code></p>



<p>Now, it&#8217;s easy to use again, but can be more pure:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">ping()
.then(<span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> ping(<span class="hljs-string">'http://jessewarden.com'</span>))
.catch(<span class="hljs-function"><span class="hljs-params">error</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Something failed:"</span>, error))</code></span></pre>


<p>Nice, and if you&#8217;re in older browsers, or even in Node but want fetch, you can go:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript"><span class="hljs-keyword">import</span> fetch <span class="hljs-keyword">from</span> <span class="hljs-string">'cross-fetch'</span> <span class="hljs-comment">// polyfill for older browsers, or if you're in Node</span>

ping(<span class="hljs-literal">undefined</span>, fetch)
.then(<span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> ping(<span class="hljs-string">'http://jessewarden.com'</span>, fetch))
.catch(<span class="hljs-function"><span class="hljs-params">error</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Something failed:"</span>, error))</code></span></pre>


<p>Note we pass <code>undefined</code> manually. In JavaScript function parameters, <code>undefined</code> is the same thing as &#8220;not passing anything&#8221;. The function says, &#8220;Well, I didn&#8217;t get anything, I guess I&#8217;ll use the default then.&#8221; which is google.</p>



<p>Pure, flexible, easy to use.</p>



<p>What we learned:</p>



<ul class="wp-block-list"><li>default arguments make functions easier to use by requiring less arguments, and providing reasonable defaults</li><li>the developer using them can type less</li><li>less typing, but more importantly, less reading makes the code easier to understand</li><li>pure functions require same input, same input, and no side effects</li><li>pure functions more importantly, though, have to get all variables they don&#8217;t make themselves from function arguments, in this case <code>fetch</code>.</li><li>function parameter order really helps a function be more useable and easier to read</li></ul>



<h2 class="wp-block-heading">Function Arity</h2>



<p>Let&#8217;s briefly cover function arity. You can learn more here https://jesterxl.github.io/real-world-functional-programming-book/part4/arity.html or watch a short video here https://www.youtube.com/watch?v=NoITQ4jU6jg</p>



<p>Function Arity is how many parameters/arguments does a function have. <code>yo()</code> has 0, <code>dude(wat)</code> has 1, and so on. You can query this via <code>theFunction.length</code>.</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript"><span class="hljs-built_in">console</span>.log(yo.length) <span class="hljs-comment">// 0</span>
<span class="hljs-built_in">console</span>.log(dude.length) <span class="hljs-comment">// 1</span></code></span></pre>


<p>However, deafult arguments don&#8217;t count against that. Worse, if you put them first, it&#8217;ll basically say &#8220;Oh, if the first argument has a default, I guess the entire function doesn&#8217;t require any arguments, and thus has an Arity of 0&#8221;.</p>



<p>So our <code>pingPure</code> above would have an arity of 0.</p>



<p>What we learned:</p>



<ul class="wp-block-list"><li>Function Arity means how many parameters does a function take</li><li>… unless you use default arguments, then arity is meaningless in JavaScript, heh</li></ul>



<h2 class="wp-block-heading">Currying</h2>



<p>Now a fundamental question: Do default arguments affect function purity?</p>



<p>The answer: Yes.</p>



<p>While things like Strings are copied by val, like our &#8216;http://google.com&#8217;, the Objects/Arrays are not.</p>



<p><code>const pingPure = (url='http://jessewarden.com', fetchModule=fetch) =&gt; fetchModule(url))</code></p>



<p>Note the <code>fetch</code>; where does that come from? A global or closure defined variable and it only knows that when the function is run (or defined if you use function declarations, like <code>function pingPure</code> vs fat arrow functions).</p>



<p>So how do we make it pure, yet still allow default arguments?</p>



<p>Currying, also known as function currying. Currying ensures all functions take 1, and only 1, argument. To say it another way, all functions return functions until the last argument is passed; THAT is the one that actually triggers all the work.</p>



<p>Now functions that return functions isn&#8217;t some &#8220;new, whack&#8221; thing. For example, you can wrap things in closures that return functions:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript"><span class="hljs-keyword">const</span> ping = <span class="hljs-function"><span class="hljs-params">url</span> =&gt;</span> fetch(url)
<span class="hljs-keyword">const</span> pingGoogle = <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
    <span class="hljs-keyword">return</span> ping(<span class="hljs-string">'http://google.com'</span>)
}</code></span></pre>


<p>Now you have a function that returns a function… which returns a Prmoise. Notice how we baked the google URL into the function itself. It&#8217;s in the closure, and stored there, ready for use. That&#8217;s how currying can work in JavaScript.</p>



<p>You can also use it for debugging, like in the Node debug module: https://www.npmjs.com/package/debug</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript"><span class="hljs-keyword">var</span> debug = <span class="hljs-built_in">require</span>(<span class="hljs-string">'debug'</span>)(<span class="hljs-string">'ping'</span>)

<span class="hljs-keyword">const</span> ping = <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
    debug(<span class="hljs-string">"Pinging Google..."</span>)
    <span class="hljs-keyword">return</span> fetch(<span class="hljs-string">'http://google.com'</span>)
    .then(<span class="hljs-function"><span class="hljs-params">result</span> =&gt;</span> {
        debug(<span class="hljs-string">"Done!"</span>)
    })
    .catch(<span class="hljs-function"><span class="hljs-params">error</span> =&gt;</span> {
        debug(<span class="hljs-string">"Oh, it went boom:"</span>, error)
    })
}</code></span></pre>


<p>Before module systems like Node, Require.js or ES6/Webpack formalized things, people would define modules using Immediately Invoked Function Expressions, or IIFE.</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Person</span>(<span class="hljs-params">name</span>) </span>{
        <span class="hljs-keyword">this</span>.name = name
    }
    Person.prototype.sayName = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{ 
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"this.name:"</span>, <span class="hljs-keyword">this</span>.name)
    }
    <span class="hljs-keyword">return</span> Person
})()</code></span></pre>


<p>Notice the last <code>()</code> actually invokes the function, but since the variables are local, you don&#8217;t have to worry about your <code>Person</code> class accidentally destroying another, previously defined class on <code>window</code> or global in Node. JQuery used to have version conflicts all the time when everyone started using it, and people would include it, and you never had an idea of which version you were using, when because of that, so IIFE fixed it.</p>



<p>However, none of those functions are pure; they don&#8217;t declare their dependencies in the function arguments; they&#8217;re magical closures (i.e. the debug module, or the fetch module).)</p>



<p>The easiest way is to use a library like Ramda or Lodash to take your existing code and curry it, but I and others now do it the manual way:</p>



<p><code>const ping = url =&gt; fetch =&gt; fetch(url)</code></p>



<p>What this means, is instead of calling it like before:<br>
<code>ping('http://google.com', fetch)</code></p>



<p>You have to call it a slightly weirder way:</p>



<p><code>ping('http://google.com')(fetch)</code></p>



<p>This is why Dr Axel Rauschmayer says <a href="http://2ality.com/2017/11/currying-in-js.html">currying is not idiomatic JavaScript</a>. What <em>is</em> idiomatic JavaScript, heh?</p>



<p>The reason is the first parameter returns a function, the 2nd invokes the returned function. To say it another way:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript"><span class="hljs-keyword">const</span> allINeedIsFetch = ping(<span class="hljs-string">'http://google.com'</span>)
<span class="hljs-built_in">console</span>.log(allINeedIsFetch) <span class="hljs-comment">// function</span>
<span class="hljs-keyword">const</span> result = allINeedIsFetch(fetch) <span class="hljs-comment">// Promise</span></code></span></pre>


<p>To do it the old fashioned way:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">ping</span>(<span class="hljs-params">url</span>) </span>{ 
    <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">fetch</span>) </span>{ 
        <span class="hljs-keyword">return</span> fetch(url)
    } 
}</code></span></pre>


<p>Yeah no, heh! Using Lodash/Ramda, you could just:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript"><span class="hljs-keyword">const</span> curry = <span class="hljs-built_in">require</span>(<span class="hljs-string">'lodash/fp/curry'</span>)

<span class="hljs-keyword">const</span> ping = <span class="hljs-function">(<span class="hljs-params">url, fetch</span>) =&gt;</span> fetch(url)
<span class="hljs-keyword">const</span> pingCurried = curry(ping)</code></span></pre>


<p>Now, you can do either way, and both work:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">pingCurried(<span class="hljs-string">'http://google.com'</span>, fetch)
pingCurried(<span class="hljs-string">'http://google.com'</span>)(fetch)</code></span></pre>


<p>What We Learned:</p>



<ul class="wp-block-list"><li>function currying is ensuring all functions only take 1 argument</li><li>functions will return functions until the last argument is passed, then it actually runs</li><li>libraries like Lodash/Ramda allow you to take existing, normal comma functions and make the curried, but they still work both ways</li></ul>



<p>I don&#8217;t have time to cover how this works with functions that already have default arguments, heh.</p>



<h2 class="wp-block-heading">Partial Application</h2>



<p>… so what&#8217;s a partial application?</p>



<p>A partial application is what a curried function returns when you didn&#8217;t call the last argument.</p>



<p>If we take our curried ping function:</p>



<p><code>const ping = url =&gt; fetch =&gt; fetch(url)</code></p>



<p>… and call it with both arguments:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript"><span class="hljs-keyword">const</span> result = ping(<span class="hljs-string">'http://google.com'</span>)(fetch)
<span class="hljs-built_in">console</span>.log(result) <span class="hljs-comment">// Promise</span></code></span></pre>


<p>… it runs our function and returns a <code>Promise</code>.</p>



<p>But what happens if we call it with just 1 parameter, the url?</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript"><span class="hljs-keyword">const</span> wat = ping(<span class="hljs-string">'http://google.com'</span>)
<span class="hljs-built_in">console</span>.log(wat) <span class="hljs-comment">// function</span></code></span></pre>


<p>The <code>wat</code> is a function. If you log it out int he browser, it actually looks like this:</p>



<p><code>fetch =&gt; fetch(url)</code></p>



<p>Rad, right? But wait… where is this <code>url</code> coming from? The closure! Same as if we did like before:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript"><span class="hljs-keyword">const</span> url = <span class="hljs-string">'http://google.com'</span>
<span class="hljs-keyword">const</span> wat = <span class="hljs-function"><span class="hljs-params">fetch</span> =&gt;</span> fetch(url)</code></span></pre>


<p>However, unlike the above, we don&#8217;t need a variable; the function &#8220;encloses&#8221; it, and keeps it safe, keeps it pure.</p>



<p>So, one could say you have a function that&#8217;s &#8220;partially applied&#8221;. The word apply comes from Category Theory where you apply functions to arguments. Basically it means, &#8220;the function takes 2 arguments, you gave us 1 of them, so take this function, and when you have the 2nd parameter ready, give it to that function I gave you, it&#8217;ll actuall do the work.&#8221;.</p>



<p>And THAT is how you do pure default arguments.</p>



<p><code>const pingGoogle = ping('http://google.com')</code></p>



<p>Now, you just have to supply <code>fetch</code>, and she&#8217;s good to go!</p>



<p><code>pingGoogle(fetch)</code></p>



<h2 class="wp-block-heading">Static Left, Dynamic Right</h2>



<p>However, we always know we&#8217;re going to use <code>fetch</code>, that&#8217;s kind of dumb; the only dynamic part is really the URL. As you saw above using default arguments, the dynamic stuff like URL&#8217;s typically goes to the left. The stuff you know that&#8217;s static, not changing much like <code>fetch</code> which is a module most poeple in the browser use, is to the right.</p>



<p>It&#8217;s reversed in currying. Static left, dynamic right, like so:</p>



<p><code>const ping = fetch =&gt; url =&gt; fetch(url)</code></p>



<p>Once you do that, you can now do that thing we did above:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript"><span class="hljs-keyword">const</span> pingPartial = ping(fetch)

pingPartial(<span class="hljs-string">'http://google.com'</span>)
.then(<span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> pingPartial(<span class="hljs-string">'http://jessewarden.com'</span>))
.then(<span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Pinged blog!"</span>))
.catch(<span class="hljs-function"><span class="hljs-params">error</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Failed:"</span>, error))</code></span></pre>


<h2 class="wp-block-heading">Partial Applications With No Arguments</h2>



<p>… but, how do you make a partial application with no arguments? It&#8217;s hard, but for now, I&#8217;ll show you the Lodash way; they have a function called <code>partial</code> that makes it easy:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript"><span class="hljs-keyword">const</span> partial = <span class="hljs-built_in">require</span>(<span class="hljs-string">'lodash/fp/partial'</span>)
<span class="hljs-keyword">const</span> ping = <span class="hljs-function">(<span class="hljs-params">fetch, url</span>) =&gt;</span> fetch(url)

<span class="hljs-keyword">const</span> pingPartial = partial(ping, &#91;fetch])
<span class="hljs-keyword">const</span> pingGoogle = partial(ping, &#91;fetch, <span class="hljs-string">'http://google.com'</span>])
<span class="hljs-keyword">const</span> pingJesse = partial(ping, &#91;fetch, <span class="hljs-string">'http://jessewarden.com'</span>])</code></span></pre>


<p>To use:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">pingGoogle()
.then(<span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> pingJesse())
.then(<span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Pinged blog!"</span>))
.catch(<span class="hljs-function"><span class="hljs-params">error</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Failed:"</span>, error))</code></span></pre>


<p>What we learned:</p>



<ul class="wp-block-list"><li>function partials are what curried functions return if you don&#8217;t give &#8217;em all their arguments</li><li>they allow you to use default arguments in a pure way</li><li>if you want a partial application with no arguments, use a library like Lodash/Ramda</li></ul>



<h2 class="wp-block-heading">Conclusion</h2>



<p>A partial application is a pure function with some or all of its arguments stored inside as a closure. If you are using default arguments a lot, it is a more pure way to accomplish that. Partial applications are created by giving only some of the required arguments to a curried function; the return value will be a partial application until all of the arguments have been given. Parameter order for default arguments tends to favor known, static parameters to the right, and unknown, dynamic data to the left. Curried functions are the opposite. These parameter orders make the function types easier to use.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
