<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Johnny Reina</title>
    <description>The latest articles on Forem by Johnny Reina (@jreina).</description>
    <link>https://forem.com/jreina</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F13246%2F77138a1a-7134-4890-bf05-73abc9a18141.jpg</url>
      <title>Forem: Johnny Reina</title>
      <link>https://forem.com/jreina</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/jreina"/>
    <language>en</language>
    <item>
      <title>What [I think] I know about van Laarhoven lenses</title>
      <dc:creator>Johnny Reina</dc:creator>
      <pubDate>Mon, 20 Aug 2018 15:26:25 +0000</pubDate>
      <link>https://forem.com/jreina/what-i-think-i-know-about-van-laarhoven-lenses-ag7</link>
      <guid>https://forem.com/jreina/what-i-think-i-know-about-van-laarhoven-lenses-ag7</guid>
      <description>&lt;p&gt;&lt;em&gt;this post was originally published on &lt;a href="http://johnnyreina.com/programming/functional/2018/08/19/van-laarhoven-lenses-v2.html"&gt;my Github Pages site&lt;/a&gt; on August 19th, 2018&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Mo' functions, mo' problems
&lt;/h2&gt;

&lt;p&gt;We are always told to avoid mutation in functional programming. This is primarily achieved by using constant variables and in the case of reference types (objects, arrays, etc.), using methods and functions which avoid mutation. While there are a plethora of functions that are well-suited to this idea with arrays, such as map, filter, and reduce, such functions are much more cumbersome to use with objects and are not widely used. We have object spread and static methods like Object.assign, which can help tremendously but can also lead to messy syntax for all but the simplest of object structures. Most examples that I have seen in JavaScript look something like this:&lt;br&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
 

&lt;p&gt;While this is generally fine for very shallow objects, the story gets much more complicated when trying to enforce immutability in complex objects while changing deeply-nested values...&lt;br&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
  

&lt;p&gt;This is obviously not very idiomatic. The problem is made worse when a library like React enforces the idea of immutability (this isn't React's fault, though). So how do we deal with this in a way that feels a bit more natural? For this, I have turned to lenses. Lenses are a special type of object that combines a setter and getter such that you can perform standard operations, most commonly setting, getting, and mapping, on values of an object in a way that the original object is not modified. Not only do lenses allow you to operate on objects while enforcing immutability, they also compose together such that each lens digs deeper into your complex objects and exposes a set of immutable operations for the entire object.&lt;/p&gt;

&lt;h2&gt;
  
  
  So how do we make a lens?
&lt;/h2&gt;

&lt;p&gt;Generally speaking, there should exist a lens package in your language of choice. For JavaScript, I use the lenses built into Ramda since Ramda also comes with functions that I tend to use including getters and immutable setters. The following example shows a lens being created for a name property.&lt;br&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
  

&lt;p&gt;While this is neat, lenses are not very useful on their own (just like any other structure). There is not a whole lot we can do with &lt;code&gt;nameLens&lt;/code&gt; on its own. This is where lens operators come in. The three operators provided by Ramda are &lt;code&gt;view&lt;/code&gt;, &lt;code&gt;set&lt;/code&gt;, and &lt;code&gt;over&lt;/code&gt;, which allow you to get, set, and map the focused property, respectively.&lt;/p&gt;

&lt;p&gt;The examples below will use the following object:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
  

&lt;h3&gt;
  
  
  &lt;code&gt;view&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;This function accepts a lens, then an object, and returns the value of the focused property of the lens. This essentially just calls the getter of the lens and is fairly straightforward. Here, we can use &lt;code&gt;nameLens&lt;/code&gt; to view the value of the focused property:&lt;br&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
  

&lt;h3&gt;
  
  
  &lt;code&gt;set&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;This function accepts a lens, a value, and then an object, and returns a copy of the object with the focused property set to the provided value. Again &lt;code&gt;set&lt;/code&gt; essentially just calls the setter of the lens and is fairly straightforward. Here, we use the &lt;code&gt;set&lt;/code&gt; operator along with &lt;code&gt;nameLens&lt;/code&gt; to set the value of the focused property. Note that the original object remains unchanged.&lt;br&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
  

&lt;h3&gt;
  
  
  &lt;code&gt;over&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;This function accepts a lens, a transform function, and then an object, and returns a copy of the object with the focused property set to the original value of the focused property *after* passing it through the provided transform function. This operator is a little harder to understand. This function is just like the &lt;code&gt;map&lt;/code&gt; function since it runs a function *over* the focused value. Here we use the &lt;code&gt;over&lt;/code&gt; operator to call the &lt;code&gt;toUpperCase&lt;/code&gt; method of the string. Just like before, the original object remains unchanged.&lt;br&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
  

&lt;h2&gt;
  
  
  What if we need to change a value in the &lt;code&gt;parking&lt;/code&gt; object?
&lt;/h2&gt;

&lt;p&gt;Suppose we need to update the value in &lt;code&gt;person.parking.row&lt;/code&gt; while maintaining immutability. This is where the compositional nature of lenses come in handy since lenses compose using the standard compose operator! This is how we could create a lens for this scenario:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
  

&lt;p&gt;Now, our &lt;code&gt;parkingRowLens&lt;/code&gt; can be used with the lens operators to do the same setting, getting, and mapping operations. Best of all, the original object will still remain unchanged due to the nature of lenses.&lt;/p&gt;

&lt;h2&gt;
  
  
  Is there an easier way to create lenses?
&lt;/h2&gt;

&lt;p&gt;If you are using Ramda, then definitely yes. Otherwise, be sure to check the owner's manual for your lens package. Ramda provides a few convenience functions to help us create lenses:  &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Function&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;R.lensProp&lt;/td&gt;
&lt;td&gt;Creates a lens which focuses on the provided property.&lt;/td&gt;
&lt;td&gt;&lt;code&gt;R.lensProp('name')&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;R.lensPath&lt;/td&gt;
&lt;td&gt;Creates a composition of lenses to focus on the provided path.&lt;/td&gt;
&lt;td&gt;&lt;code&gt;R.lensPath(['parking', 'row'])&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;R.lensIndex&lt;/td&gt;
&lt;td&gt;Create a lens to focus on the provided array index.&lt;/td&gt;
&lt;td&gt;&lt;code&gt;R.lensIndex(0)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Additional reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/ekmett/lens/wiki"&gt;Haskell Lens package wiki&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/ekmett/lens/wiki/History-of-Lenses"&gt;History of Lenses (from same wiki as above)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://ramdajs.com/docs/#lens"&gt;Ramda Docs - lens&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>functional</category>
      <category>javascript</category>
      <category>lenses</category>
    </item>
    <item>
      <title>What's up with currying?</title>
      <dc:creator>Johnny Reina</dc:creator>
      <pubDate>Thu, 21 Sep 2017 10:22:40 +0000</pubDate>
      <link>https://forem.com/jreina/whats-up-with-currying</link>
      <guid>https://forem.com/jreina/whats-up-with-currying</guid>
      <description>&lt;p&gt;&lt;em&gt;this post was originally published on &lt;a href="http://johnnyreina.com/programming/functional/2017/09/21/whats-up-with-currying.html" rel="noopener noreferrer"&gt;my Github Pages site&lt;/a&gt; on September 21st, 2017&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you've been exposed to functional programming, you have almost certainly come across the concept of curried functions. Named after the man himself, &lt;a href="https://en.wikipedia.org/wiki/Haskell_Curry" rel="noopener noreferrer"&gt;Haskell B. Curry&lt;/a&gt;, a curried function is one that requires multiple arguments but cannot accept all of them in a single call. Consider the following example:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
What is happening here? &lt;code&gt;magnitude&lt;/code&gt; is rather straightforward in that we take three values and calculate the root of the sum of their squares. &lt;code&gt;magnitude_curried&lt;/code&gt;, however, is quite a bit different and the syntax used to declare it is perhaps a bit offputting. Here is the same function as full function expressions:&lt;br&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
If we walk through what occurs with &lt;code&gt;magnitude_curried&lt;/code&gt;, we'll find that it, too, is straightforward, albeit somewhat strange (at first). When we apply the first argument &lt;code&gt;x&lt;/code&gt;, as &lt;code&gt;1&lt;/code&gt;, we get back a function. Same thing when we apply the second argument, &lt;code&gt;y&lt;/code&gt; as &lt;code&gt;28&lt;/code&gt;. Finally, when we apply the final argument, &lt;code&gt;z&lt;/code&gt;, as &lt;code&gt;76&lt;/code&gt;, the magnitude function is called and its result is returned.

&lt;h3&gt;
  
  
  Where does currying come from?
&lt;/h3&gt;

&lt;p&gt;Currying is a concept pulled out of the mathematical basis of functional programming, the lambda calculus. In mathematics, you cannot just go out and grab some value from the world at large and drop it in the middle of your functions. You must specify these outside values as parameters and pass them into your functions. The lambda calculus, as a formal system of arranging functions and how they are used, places additional restrictions on how your function can interact with outside information. In the lambda calculus, functions can have only a single input. In pure-functional programming languages like Haskell, every function is understood to be a curried function.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why would we ever need currying?
&lt;/h3&gt;

&lt;p&gt;You need currying when you need a function to be:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Reusable&lt;/li&gt;
&lt;li&gt;Minimally dependent on context&lt;/li&gt;
&lt;li&gt;Callable after specifying some arguments&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;What do I mean by this? Consider how these three points apply to the following example:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
Here we see the &lt;code&gt;values&lt;/code&gt; function being declared as a curried function. It takes an array of strings which represent keys of an object, and an actual object, and returns the values corresponding to the given keys from the provided object. In its most simple form, values could be called like so: &lt;code&gt;values(['a'])({ a: 'hello' })&lt;/code&gt; and it would return &lt;code&gt;['hello']&lt;/code&gt;. So how is this useful to us? On line number 8, we apply an array of strings to values and assign the resulting function to a variable called &lt;code&gt;getNameAndDepartment&lt;/code&gt;. As we see on line number 9, this new variable is a fully-callable function. We pass in the first value in the &lt;code&gt;courses&lt;/code&gt; array and as expected, we get back the &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;department&lt;/code&gt; values from this object. Here comes the cool part. Since &lt;code&gt;getNameAndDepartment&lt;/code&gt; is a callable function and has some of the body pre-filled, we can map over the entire courses array and use the &lt;code&gt;getNameAndDepartment&lt;/code&gt; function as seen on line 12.

&lt;p&gt;Big deal. This still seems like a complicated way to get the values of some objects, right? Consider the fact that the &lt;code&gt;values&lt;/code&gt; function doesn't know about any particular array or object. It doesn't describe the context, it only describes functionality. This satisfies requirement number 2 for me. Additionally, since it remained a callable function after applying the keys which we eventually map over, it satisfies number 3 as well.&lt;/p&gt;

&lt;p&gt;This all seems fine, but what about requirement number 1: reusability? Since the &lt;code&gt;values&lt;/code&gt; function doesn't describe the context, it is automatically reusable for another set of arguments. That is, we can pass in another set of values for &lt;code&gt;keys&lt;/code&gt; and &lt;code&gt;obj&lt;/code&gt; and it will work there, too! We see this on line number 26 where we apply the &lt;code&gt;carKeys&lt;/code&gt; array and on line number 27 where we pass in a cars object and get back the &lt;code&gt;make&lt;/code&gt;, &lt;code&gt;style&lt;/code&gt;, and &lt;code&gt;id&lt;/code&gt; values as expected. Just as before, we can use &lt;code&gt;getMakeStyleAndId&lt;/code&gt;, a partially-applied function, to map over an array of car objects and get these values for each object in the &lt;code&gt;cars&lt;/code&gt; array.&lt;/p&gt;

&lt;h3&gt;
  
  
  Currying vs partial application
&lt;/h3&gt;

&lt;p&gt;There seems to be some confusion regarding the difference between currying and another similar concept called partial application. This confusion is further compounded by the fact that sometimes they are the same thing. Currying takes a function which requires &lt;code&gt;n&lt;/code&gt; arguments and reduces it to a series of functions which accept &lt;code&gt;1&lt;/code&gt; argument, whereas partial application takes a function which requires &lt;code&gt;n&lt;/code&gt; arguments and reduces it to a function which accepts &lt;code&gt;n - 1&lt;/code&gt; arguments. Semantically speaking, currying is a &lt;em&gt;form of partial application&lt;/em&gt;. In fact, in the case of a function which only needs two arguments, to begin with, these definitions are the same. This is the case for our &lt;code&gt;values&lt;/code&gt; function above. We are &lt;em&gt;partially applying&lt;/em&gt; the required arguments, but since the function only ever accepts one argument at a time, it is also a curried function.&lt;/p&gt;

&lt;h3&gt;
  
  
  Is there more insidious terminology hidden in functional programming that I should be aware of?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F01n0fh9q59rhowozsl12.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F01n0fh9q59rhowozsl12.gif" alt="fur sure"&gt;&lt;/a&gt;&lt;br&gt;
I recommend taking a look at the &lt;a href="https://github.com/hemanth/functional-programming-jargon" rel="noopener noreferrer"&gt;functional programming jargon repo&lt;/a&gt; from &lt;a href="https://dev.to/hemanth"&gt;hemanth&lt;/a&gt; for a huge list of well-defined FP terms. If you're feeling daring, the &lt;a href="https://github.com/fantasyland/fantasy-land" rel="noopener noreferrer"&gt;fantasy-land spec&lt;/a&gt; provides the formal definitions of algebraic JavaScript and is what I consider to be reference material for FP in JavaScript.&lt;/p&gt;

&lt;h3&gt;
  
  
  Parting notes
&lt;/h3&gt;

&lt;p&gt;I want to stress that the three requirements I listed are sort of the rule of thumb that I use to determine if a function needs to be curried or if I should just leave it alone. Since currying is a concept that many people are unfamiliar with, using curried functions where it doesn't make any sense to do so is a sure-fire way to increase the probability of bugs down the road and stands to alienate newer devs and people who just don't care for FP. If you're &lt;a href="https://github.com/jreina/Superlatives/blob/master/index.es6#L10" rel="noopener noreferrer"&gt;just currying because it kinda looks cool&lt;/a&gt;, you are obfuscating the meaning of your code.&lt;/p&gt;

&lt;p&gt;What do you think? Are these sound guidelines? Does this help you understand the concept?&lt;/p&gt;

</description>
      <category>functional</category>
      <category>javascript</category>
      <category>currying</category>
    </item>
    <item>
      <title>Intro to the zip function</title>
      <dc:creator>Johnny Reina</dc:creator>
      <pubDate>Tue, 19 Sep 2017 12:10:02 +0000</pubDate>
      <link>https://forem.com/jreina/intro-to-the-zip-function</link>
      <guid>https://forem.com/jreina/intro-to-the-zip-function</guid>
      <description>&lt;p&gt;&lt;em&gt;this post was originally published on &lt;a href="http://johnnyreina.com/programming/functional/2017/09/19/intro-zip.html"&gt;my Github Pages site&lt;/a&gt; on September 19th, 2017&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now that we have covered the fundamental iterative functions, I want to take some time to look at some more functions that you will typically find lurking in functional-first programming languages or functional utility libraries. While not as prevalent as map, filter, and fold, these functions have their use cases and though they can be easily implemented by way of fold, they are more purpose built so you will find the syntax to be tidier.&lt;/p&gt;

&lt;p&gt;The first of these functions I want to talk about is the convolution function, more widely known as zip. In Haskell, the zip function has a type signature of &lt;code&gt;zip :: [a] -&amp;gt; [b] -&amp;gt; [(a, b)]&lt;/code&gt;. What this means is that the zip function accepts two lists, and combines them into a single list by merging each value of each list. Traditionally, zip outputs a tuple (the &lt;code&gt;(a, b)&lt;/code&gt; part of the type signature), however, since JavaScript doesn't have tuples (nor a zip function) we will use a two-value array to represent pairs and we will define the zip function ourselves.&lt;/p&gt;

&lt;p&gt;We'll start off by defining zip as a function of map.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
Note that this is not a battle-proven production-ready solution. This is just to get us going without worrying about external libraries. I would recommend looking into &lt;a href="http://underscorejs.org/"&gt;Underscore.js&lt;/a&gt;, &lt;a href="https://lodash.com/"&gt;Lodash&lt;/a&gt;, or &lt;a href="http://ramdajs.com/"&gt;Ramda&lt;/a&gt; for tested and well-designed implementations of zip. In the wild, zip will usually only map over the shortest length array so that your output array isn't longer than the shortest input array.

&lt;p&gt;So what can we do with this? As usual, we'll start off with a very basic example.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
And just like that, we've constructed the discrete sequence of values for &lt;code&gt;f(x) = x&lt;sup&gt;2&lt;/sup&gt;&lt;/code&gt; where &lt;code&gt;{ 0 &amp;lt;= x &amp;lt;= 10 }&lt;/code&gt;. Pretty cool, eh? Now we can send that off to Chart.js or the like and get back a nice chart.

&lt;p&gt;Because of the flexible type signature (read: non-existent) of our zip implementation, the return value can be an array of anything. It's an array by default, but in the second zip above we constructed some objects from our pairs. If you made it through map and fold, this should make sense to you right away (because you are a higher-order programmer now!), but I will show this same example done in an imperative style just in case.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;As long as you know your two arrays match up one-to-one, you can use zip to compose objects of sublists into incrementally larger objects. Though there are varying opinions on the subject, I tend to prefer composing objects rather than inheriting and I think MPJ at Fun Fun Function &lt;a href="https://www.youtube.com/watch?v=wfMtDGfHWpA"&gt;makes a solid case for this idea&lt;/a&gt; as well. So how would we do this with zip? Well lets take our previous example where we took our x-values and y-values and combined them into an object, and lets take these boring 2-dimensional points and turn them into boring 3-dimensional points. We'll then consider these points to represent the directed endpoints of 3-dimensional vectors from the origin and calculate their magnitude.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Zip gives us a concise syntax for doing a good chunk of work. What if we want to take a list of two vectors and calculate their dot product and resultant vector?&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
Very easy. Note that since I'm such a smart guy I accidentally made the original arrays have more even-indexed members than odd, that's why I passed in the odds first. This is an example of something a &lt;em&gt;good&lt;/em&gt; implementation of zip would do automatically. If I were to have passed the evens in as the first argument, we would have gotten an error since we are accessing the items in the second array by index.

&lt;h2&gt;
  
  
  Where should I use zip?
&lt;/h2&gt;

&lt;p&gt;When you want to combine two or more lists with a one-to-one correspondence. Note that since zip combines things in some way, the result of consecutive zips usually ends in progressively larger, more complex items. Also, like all of the iterative functions I've covered so far, zip does not mutate the original arrays. This means that you can put some stuff in an array, zip it, and the original stuff will still be there untouched.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which languages have zip?
&lt;/h2&gt;

&lt;p&gt;The language you use probably has it so by sure to check the owner's manual. As far as I know, the following languages and libraries have zip:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Language&lt;/th&gt;
&lt;th&gt;Function&lt;/th&gt;
&lt;th&gt;Note&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;C#&lt;/td&gt;
&lt;td&gt;Enumerable.Zip&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Haskell&lt;/td&gt;
&lt;td&gt;zip&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;JavaScript (Underscore.js)&lt;/td&gt;
&lt;td&gt;&lt;a href="http://underscorejs.org/#zip"&gt;_.zip&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Be sure to check the docs on this.&lt;br&gt;This implementation doesn't appear to accept a "zipping" function&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;JavaScript (lodash)&lt;/td&gt;
&lt;td&gt;&lt;a href="https://lodash.com/docs/4.17.4#zip"&gt;_.zip&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Be sure to check the docs on this.&lt;br&gt;This implementation doesn't appear to accept a "zipping" function&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;JavaScript (lodash)&lt;/td&gt;
&lt;td&gt;&lt;a href="https://lodash.com/docs/4.17.4#zipWith"&gt;_.zipWith&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;JavaScript (Ramda)&lt;/td&gt;
&lt;td&gt;&lt;a href="http://ramdajs.com/docs/#zip"&gt;R.zip&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Be sure to check the docs on this.&lt;br&gt;This implementation doesn't appear to accept a "zipping" function&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;JavaScript (Ramda)&lt;/td&gt;
&lt;td&gt;&lt;a href="http://ramdajs.com/docs/#zipWith"&gt;R.zipWith&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;JavaScript (Immutable)&lt;/td&gt;
&lt;td&gt;&lt;a href="https://facebook.github.io/immutable-js/docs/#/List/zip"&gt;zip&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Be sure to check the docs on this.&lt;br&gt;This implementation doesn't appear to accept a "zipping" function&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;JavaScript (Immutable)&lt;/td&gt;
&lt;td&gt;&lt;a href="https://facebook.github.io/immutable-js/docs/#/List/zipWith"&gt;zipWith&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Python&lt;/td&gt;
&lt;td&gt;zip&lt;/td&gt;
&lt;td&gt;Be sure to check the docs on this.&lt;br&gt;This implementation doesn't appear to accept a "zipping" function&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>functional</category>
      <category>javascript</category>
      <category>zip</category>
    </item>
    <item>
      <title>Intro to the fold function (aka reduce or aggregate)</title>
      <dc:creator>Johnny Reina</dc:creator>
      <pubDate>Sun, 17 Sep 2017 00:25:44 +0000</pubDate>
      <link>https://forem.com/jreina/intro-to-the-fold-function-aka-reduce-or-aggregate</link>
      <guid>https://forem.com/jreina/intro-to-the-fold-function-aka-reduce-or-aggregate</guid>
      <description>&lt;p&gt;&lt;em&gt;this post was originally published on &lt;a href="http://johnnyreina.com/programming/functional/2017/09/16/intro-fold.html" rel="noopener noreferrer"&gt;my Github Pages site&lt;/a&gt; on September 16th, 2017&lt;/em&gt;  &lt;/p&gt;

&lt;p&gt;This might sound a bit outlandish or ridiculous, but I seldom write loops nowadays. What I have found is that just about every programming language includes a set of methods or applicable functions that can replace just about every loop that I was previously writing. These &lt;a href="https://github.com/hemanth/functional-programming-jargon#higher-order-functions-hof" rel="noopener noreferrer"&gt;higher-order functions&lt;/a&gt; are called map, filter, and fold.&lt;/p&gt;

&lt;p&gt;In the previous two articles, we got a glimpse of the power of the map and filter functions. In this article, I want to discuss the Ma Dukes of iterative functions: the fold function, and hopefully, convey the importance of this function.  &lt;/p&gt;

&lt;p&gt;Keep in mind that fold is generally not called fold in programming languages. This is true for JavaScript, where fold is actually called reduce. In this article, I will refer to the fold function, but the examples will show &lt;code&gt;Array.prototype.reduce&lt;/code&gt;. The array type in JavaScript is said to be &lt;a href="https://github.com/hemanth/functional-programming-jargon#foldable" rel="noopener noreferrer"&gt;foldable&lt;/a&gt; because it implements fold as &lt;code&gt;Array.prototype.reduce&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fold
&lt;/h2&gt;

&lt;p&gt;Fold accepts an accumulator function which it applies to the each item in the array and passes the result on to the next execution of the accumulator. Fold accepts an optional seed value to use as the starting point for your folding. This is rather difficult for me to express in words, so here's a diagram:&lt;br&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhcztr4205drn7tfk78sx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhcztr4205drn7tfk78sx.png" alt="fold execution diagram"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;
Here, &lt;code&gt;f&lt;/code&gt; is the accumulator function. Notice that each instance of &lt;code&gt;f&lt;/code&gt; has two arrows pointing to it. That means the accumulator function you provide must accept two parameters: the value from the last execution, and the current value from the array. As a convention, I tend to use &lt;code&gt;(memo, value)&lt;/code&gt; as my parameter names.  &lt;/p&gt;
&lt;h2&gt;
  
  
  Starting off slow
&lt;/h2&gt;

&lt;p&gt;I'll show some basic examples and try to work our way up to some heavier folding.&lt;br&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
What is happening here? The first example describes the sum of all of the elements of the &lt;code&gt;nums&lt;/code&gt; array. If you follow the diagram, 0 is our seed value. So we start at 0, add 1, pass that on to the next execution where we add 2, pass that on to the next execution where we add 3, and so on. The second example is functionally equivalent to &lt;code&gt;f(5) =&amp;gt; 5!&lt;/code&gt;. In the third example, we are simply taking each letter and appending it onto &lt;code&gt;memo&lt;/code&gt;. Notice that since a seed value wasn't specified, we just got back the first item in the array.  

&lt;p&gt;This is pretty cool, eh? It may take some staring at for the concept to fall into place, but once you figure it out you will want to fold everything! &lt;/p&gt;
&lt;h2&gt;
  
  
  We added some numbers. Big whoop. Why are you so excited about fold?
&lt;/h2&gt;

&lt;p&gt;I consider fold to be the end-all-be-all iterative function. The bee's knees, if you will. The reason I say that is because the seed value can be &lt;strong&gt;of any type&lt;/strong&gt;. That means we can fold over an array and kick out an object, array, number, string, boolean, or whatever your heart desires! Say we have an array of pairs that we want to transpose onto an object, this is easily done with fold:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
The first fold transposes the pairs onto a new object. The second fold, which acts on the new &lt;code&gt;person&lt;/code&gt; object, pulls those pairs back out. This proves that we did not lose any information during the process.

&lt;p&gt;The other two iterative functions that I've covered, map and filter, can easily be implemented as a function of fold! Consider the following:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
Implementing map and filter as a function of fold are a little bit verbose, due to the fact that map and filter are purpose-built. But, this example clearly shows the relationship between all three functions and thus why I lump these functions into the same bag.

&lt;p&gt;Here's an example of fold being used to flatten an array of objects into a big chunk of CSV text:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  Holy shit! This is amazing!
&lt;/h2&gt;

&lt;p&gt;I know, right!? I cannot stress enough how powerful this array transform is.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where should fold be used?
&lt;/h2&gt;

&lt;p&gt;Due to the flexible nature of fold, it's rather difficult and limiting to say "definitely use it in &lt;em&gt;scenario a&lt;/em&gt; or &lt;em&gt;scenario b&lt;/em&gt;." Basically, when you want to accumulate the items of a collection in some way, fold is a great tool for doing so.  &lt;/p&gt;

&lt;p&gt;Just as map and filter avoid mutating the original array, so does fold. This is important because we want to transform the list with fold, but we might also want to map and filter afterward. This idea of avoiding mutating data goes a bit beyond the scope of this article but I think Eric Normand did a great job of explaining &lt;a href="https://dev.to/ericnormand/immutable-paper"&gt;why you might want to treat data as unchangeable&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which languages have fold?
&lt;/h2&gt;

&lt;p&gt;The ones I use day-to-day have fold. Here's a table of the ones I know about:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Language&lt;/th&gt;
&lt;th&gt;Function/Method&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;JavaScript&lt;/td&gt;
&lt;td&gt;Array.prototype.reduce&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C#&lt;/td&gt;
&lt;td&gt;Enumerable.Aggregate (as part of System.Linq)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Haskell&lt;/td&gt;
&lt;td&gt;foldl, foldl1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PHP&lt;/td&gt;
&lt;td&gt;array_reduce&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;MongoDB&lt;/td&gt;
&lt;td&gt;$reduce (as part of an aggregation pipeline)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
There are definitely more languages with the fold function baked in, so be sure to check your local listings.&lt;/p&gt;

</description>
      <category>functional</category>
      <category>javascript</category>
      <category>fold</category>
      <category>reduce</category>
    </item>
    <item>
      <title>Intro to the filter function</title>
      <dc:creator>Johnny Reina</dc:creator>
      <pubDate>Sat, 16 Sep 2017 02:25:16 +0000</pubDate>
      <link>https://forem.com/jreina/intro-to-the-filter-function</link>
      <guid>https://forem.com/jreina/intro-to-the-filter-function</guid>
      <description>&lt;p&gt;&lt;em&gt;this post was originally published on &lt;a href="http://johnnyreina.com/programming/functional/2017/09/15/intro-filter.html"&gt;my Github Pages site&lt;/a&gt; on September 15th, 2017&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This might sound a bit outlandish or ridiculous, but I seldom write loops nowadays. What I have found is that just about every programming language includes a set of methods or applicable functions that can replace just about every loop that I was previously writing. These &lt;a href="https://github.com/hemanth/functional-programming-jargon#higher-order-functions-hof"&gt;higher-order functions&lt;/a&gt; are called map, filter, and fold.&lt;/p&gt;

&lt;h2&gt;
  
  
  Filter
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;filter&lt;/code&gt; function takes a predicate, a function which accepts an item from your array and returns a boolean result, and returns a new array containing the elements that return true when passed through the predicate.&lt;/p&gt;

&lt;h3&gt;
  
  
  Baby steps
&lt;/h3&gt;

&lt;p&gt;We'll start off with some easy examples:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Unlike its counterparts map and fold, filter's name immediately and obviously expresses what it does. Though it's a rather simple function, it is very powerful nonetheless.&lt;/p&gt;

&lt;h3&gt;
  
  
  Learning to crawl
&lt;/h3&gt;

&lt;p&gt;Here's an example of filtering an array of objects:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;In the first filter, we are looking for people in the list whose name is Mary. Since there is only one person in the list with this name, we only get one result. Note that since &lt;code&gt;filter&lt;/code&gt; always returns an array, we just got back an empty array when we looked for someone named Fred in the second filter. In the third example, we look for people whose age is greater than 40. Finally, in the last example, we look for people who have two hobbies.&lt;/p&gt;

&lt;p&gt;If this is taking a bit to click, I'll show an example of &lt;code&gt;filter&lt;/code&gt; done in an imperative style. This is a pattern I used to write quite often before I knew how to use filter.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;While these loops have the same result as the previous examples, they are much more explicit and there is much more typing involved.&lt;/p&gt;

&lt;h3&gt;
  
  
  Up and running!
&lt;/h3&gt;

&lt;p&gt;These examples are pretty easy, right? Well, there really isn't a whole lot to it.  &lt;/p&gt;

&lt;p&gt;Out of the map-filter-fold family of functions, &lt;code&gt;filter&lt;/code&gt; is the function I use the least in JavaScript. However, C#'s counterpart, Where, is definitely my workhorse when working in C#.  &lt;/p&gt;

&lt;p&gt;When I am filtering data based on multiple conditions, I like to define the predicates as named variables ahead of time. I've found that this improves the readability of the code tremendously, in addition to providing opportunities to reusing the pre-defined functions. Consider the following example:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Since &lt;code&gt;filter&lt;/code&gt; always returns an array, you can chain together your calls to &lt;code&gt;filter&lt;/code&gt; and drill down to the data you want &lt;em&gt;incrementally&lt;/em&gt;. You &lt;strong&gt;must be careful&lt;/strong&gt; with your logic, though, especially when the filtering logic you are trying to apply requires mixing &lt;strong&gt;AND&lt;/strong&gt; and &lt;strong&gt;OR&lt;/strong&gt; logic.  &lt;/p&gt;

&lt;h3&gt;
  
  
  When should I use &lt;code&gt;filter&lt;/code&gt;?
&lt;/h3&gt;

&lt;p&gt;This might not need to be said, but you should use &lt;code&gt;filter&lt;/code&gt; when you want to reduce the items in a collection to only those items which meet specific criteria.&lt;/p&gt;

&lt;h3&gt;
  
  
  JavaScript is the worst! What other languages have &lt;code&gt;filter&lt;/code&gt;?
&lt;/h3&gt;

&lt;p&gt;Pretty much all the good ones. Though the names might be a bit different. In an effort to avoid plagiarism and only write what I really know about, I'll list out a few equivalent methods/functions that I know and have used here.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Language&lt;/th&gt;
&lt;th&gt;Function/Method&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;JavaScript&lt;/td&gt;
&lt;td&gt;Array.prototype.filter&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C#&lt;/td&gt;
&lt;td&gt;IEnumerable.Where (as part of System.Linq)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Haskell&lt;/td&gt;
&lt;td&gt;filter&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PHP&lt;/td&gt;
&lt;td&gt;array_filter&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;MongoDB&lt;/td&gt;
&lt;td&gt;db.collection.find&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Alright, I'm convinced. When do I start?
&lt;/h3&gt;

&lt;p&gt;Right now! Go!&lt;br&gt;&lt;br&gt;
The best way to get familiar with &lt;code&gt;filter&lt;/code&gt; is to just start using it.&lt;/p&gt;

</description>
      <category>functional</category>
      <category>javascript</category>
      <category>filter</category>
    </item>
    <item>
      <title> Intro to the map function</title>
      <dc:creator>Johnny Reina</dc:creator>
      <pubDate>Thu, 14 Sep 2017 06:50:00 +0000</pubDate>
      <link>https://forem.com/jreina/intro-to-the-map-function</link>
      <guid>https://forem.com/jreina/intro-to-the-map-function</guid>
      <description>&lt;p&gt;&lt;em&gt;this post was originally published on &lt;a href="http://johnnyreina.com/programming/functional/2017/09/13/intro-map.html"&gt;my Github Pages site&lt;/a&gt; on September 13th, 2017&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This might sound a bit outlandish or ridiculous, but I seldom write loops nowadays. What I have found is that just about every programming language includes a set of methods or applicable functions that can replace just about every loop that I was previously writing. These &lt;a href="https://github.com/hemanth/functional-programming-jargon#higher-order-functions-hof"&gt;higher-order functions&lt;/a&gt; are called map, filter, and fold.&lt;/p&gt;

&lt;h2&gt;
  
  
  Map
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;map&lt;/code&gt; function takes a function you provide and iterates over each item in your list, applying the function you provide and putting the result in the same spot in the new array. Since &lt;code&gt;map&lt;/code&gt; takes an array and returns an array, you can chain together your &lt;code&gt;map&lt;/code&gt; calls and transform your data &lt;em&gt;incrementally&lt;/em&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Baby steps
&lt;/h3&gt;

&lt;p&gt;We'll start off with some easy examples:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;That didn't hurt too much, did it? In the first &lt;code&gt;map&lt;/code&gt;, we essentially applied &lt;code&gt;f(x) = 2x&lt;/code&gt; to each element in the sequence. Likewise, the second &lt;code&gt;map&lt;/code&gt; applied &lt;code&gt;f(x) = xÂ²&lt;/code&gt; to each element. Easy cheesy.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Learning to crawl
&lt;/h3&gt;

&lt;p&gt;Here's an example of mapping over an array of objects:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;In the first &lt;code&gt;map&lt;/code&gt; we are pulling out each person's name, their age in the second &lt;code&gt;map&lt;/code&gt;, and their second hobby in the third &lt;code&gt;map&lt;/code&gt;. If what is happening here isn't immediately apparent to you, here is the same thing in an imperative style:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Crazy, right? What we can do with a single expression with &lt;code&gt;map&lt;/code&gt;, takes FOUR lines with imperative code. Oh, and did you notice the fact that we did not mutate the value of the original array in the imperative example? This is also true for &lt;code&gt;map&lt;/code&gt;, which is important since we might need to do other things to that original array. &lt;/p&gt;

&lt;h3&gt;
  
  
  Up and running!
&lt;/h3&gt;

&lt;p&gt;Alright, "this is child's play", you say. Where are we REALLY gonna use &lt;code&gt;map&lt;/code&gt;? Well, buckle up! Check out this real world example:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
This example is straight outta &lt;a href="https://github.com/jreina/polysvg"&gt;polysvg&lt;/a&gt;, albeit cut down a bit for brevity. This &lt;code&gt;map&lt;/code&gt; chain takes an array of six zeroes and performs the following steps:  

&lt;ol&gt;
&lt;li&gt;Numbers each spot according to its index&lt;/li&gt;
&lt;li&gt;Multiplies each position by 60 to get the angles of each vertex from the centroid of a hexagon&lt;/li&gt;
&lt;li&gt;Converts each angle to radians&lt;/li&gt;
&lt;li&gt;Converts from polar to Cartesian coordinates&lt;/li&gt;
&lt;li&gt;Rounds these nasty floats&lt;/li&gt;
&lt;li&gt;Applies an offset to each point equal to the radius&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://github.com/jreina/polysvg/blob/master/n-gon.js"&gt;Without annotations, this is about nineteen lines of code.&lt;/a&gt;. Most importantly, it works and you can &lt;a href="http://polysvg.johnnyreina.com/"&gt;try it out yourself&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  When should I use &lt;code&gt;map&lt;/code&gt;?
&lt;/h3&gt;

&lt;p&gt;Since &lt;code&gt;map&lt;/code&gt; has a 1:1 relationship between the number of things you put in and the number of things you get out, you should use &lt;code&gt;map&lt;/code&gt; when you want to &lt;em&gt;transform&lt;/em&gt; &lt;code&gt;x&lt;/code&gt; amount of things into &lt;code&gt;x&lt;/code&gt; amount of other things. If you need to turn &lt;code&gt;x&lt;/code&gt; amount of things into &lt;code&gt;x - 5&lt;/code&gt; amount of things, &lt;code&gt;map&lt;/code&gt; might not be the ideal solution right away. You may need to segregate your things into subsets, and then &lt;code&gt;map&lt;/code&gt; each subset separately.&lt;/p&gt;

&lt;h3&gt;
  
  
  JavaScript is the worst! What other languages have &lt;code&gt;map&lt;/code&gt;?
&lt;/h3&gt;

&lt;p&gt;Like, all the good ones. Though the names might be a bit different. In an effort to avoid plagiarism and only write what I really know about, I'll list out a few equivalent methods/functions here.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Language&lt;/th&gt;
&lt;th&gt;Function/Method&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;JavaScript&lt;/td&gt;
&lt;td&gt;Array.prototype.map&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C#&lt;/td&gt;
&lt;td&gt;IEnumerable.Select&amp;lt;T&amp;gt; (as part of System.Linq)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Python&lt;/td&gt;
&lt;td&gt;map&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Haskell&lt;/td&gt;
&lt;td&gt;map&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PHP&lt;/td&gt;
&lt;td&gt;array_map&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;MongoDB&lt;/td&gt;
&lt;td&gt;$project (as part of an aggregation pipeline)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Alright, I'm convinced. When do I start?
&lt;/h3&gt;

&lt;p&gt;Right now! Go! &lt;code&gt;map&lt;/code&gt; all the things!&lt;br&gt;&lt;br&gt;
The best way to get familiar with &lt;code&gt;map&lt;/code&gt; is to just start using it.&lt;/p&gt;

</description>
      <category>functional</category>
      <category>javascript</category>
      <category>map</category>
    </item>
  </channel>
</rss>
