<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Quentin Gerodel on Medium]]></title>
        <description><![CDATA[Stories by Quentin Gerodel on Medium]]></description>
        <link>https://medium.com/@Swizz?source=rss-477f64bc6ec9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*HdI88rrNWyYhEqe7eFOENA.jpeg</url>
            <title>Stories by Quentin Gerodel on Medium</title>
            <link>https://medium.com/@Swizz?source=rss-477f64bc6ec9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 16:46:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Swizz/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The most beautiful Javascript Functional Programming syntax]]></title>
            <link>https://medium.com/@Swizz/the-most-beautiful-javascript-functional-programming-syntax-f0698208da07?source=rss-477f64bc6ec9------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0698208da07</guid>
            <category><![CDATA[es6]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[flowtype]]></category>
            <category><![CDATA[babel]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Quentin Gerodel]]></dc:creator>
            <pubDate>Mon, 03 Oct 2016 12:53:19 GMT</pubDate>
            <atom:updated>2016-10-03T15:00:47.284Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Aq_kcOZeELQ8YLyWTWoajQ.jpeg" /><figcaption><a href="https://unsplash.com/aleskrivec">Ales Krivec</a></figcaption></figure><p>Originally seduced by the <a href="https://www.erlang.org/">Erlang </a>weird syntax, I walked around some functional oriented languages. All was providing a sweet and smart syntax. The last one I played around was <a href="http://elm-lang.org/">Elm</a>. The <a href="http://elm-lang.org/docs/style-guide">syntax of Elm</a> was clean, and beautiful.</p><p>Meeting Elm, raise in my mind a new challenge : Find the most beautiful “pure” Javascript Functional Programming syntax.</p><p>The biggest part of this challenge is to keep all the javascript capabilities with the minimum of requirements. Or by keeping the common requirements.</p><p>Let’s do this !</p><h3>Functional you said ?</h3><p>So, functional programming is a paradigm based on the way that mathematical functions would be evaluated in code. Software as driven as a big function which is the combination of many little one. Where each function use their input to give its output in a linear way.</p><p>I do not have the pretension, to be able to teach you, in this little paragraph, how to lead functional programming. So, I will let Charles Scalfani to do that thing for me.</p><blockquote><a href="https://medium.com/@cscalfani/so-you-want-to-be-a-functional-programmer-part-1-1f15e387e536"><strong>So You Want to be a Functional Programmer</strong></a> — <a href="https://medium.com/@cscalfani?source=post_header_lockup">Charles Scalfani</a></blockquote><h3>The perfect example</h3><p>Since <a href="http://gladwell.com/blink/">I am able to learn only by examples</a>, I took the choice to share you my thoughts unwinding with an example.</p><p>I choose as perfect example, the <a href="http://me.dt.in.th/page/Quicksort/">quicksort algorithm</a>. No more sputters : This is my javascript version of this algorithm.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4cb919cbee8f892bdc6c10ee77f2d8b/href">https://medium.com/media/c4cb919cbee8f892bdc6c10ee77f2d8b/href</a></iframe><p>This function works into the recursivity way and is visibly splitted into three parts. <br>The first line, is the termination condition (or base case) : attempt to sort a list without any element returns an empty list.<br>Second block, is the internal variables definition ; with in line 6 &amp; 7, the two parts of the list regarding to the pivot.<br>Then, the last line, was the concatenation of sorted parts and the pivot as function return.</p><p>Pretty easy, isnt it ?</p><h4><strong>Divide and rule</strong></h4><p>As said earlier, composition, is a great part of functional programing. So let’s refactor our code for further compositions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fdd5578741161f7cd9fe6852532c4654/href">https://medium.com/media/fdd5578741161f7cd9fe6852532c4654/href</a></iframe><p>At this state, this does not look very cool or sexy, because we turn a simple ten-lines function into a thirty-lines composed code.</p><p>But, this is an example ; and this is not the end.</p><h3>ES2015 is awesome !</h3><p>ES2015 (or ES6) came with a lot of great features. And the most awesome is <a href="http://es6-features.org/#ExpressionBodies">fat arrow function</a> notation. Fat arrows provides many functionalities, but, we will choose them, first, for their light syntax.</p><p>Fat arrows functions was used to illustrate all examples into the great <a href="https://github.com/hemanth/functional-programming-jargon">Functional Programming Jargon</a> reading.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d230f352713ded89be8246cee77bdac7/href">https://medium.com/media/d230f352713ded89be8246cee77bdac7/href</a></iframe><p>You look good, fat arrows are not the only one ES2015 features used here. <br>I walked accross more of them.</p><h4>A litle bit triky..</h4><p>Firstly, I used <a href="http://es6-features.org/#ParameterContextMatching">Parameter Matching</a> and the <a href="http://es6-features.org/#RestParameter">Rest Operator</a>, both are new ES2015 features, that made working with lists as easy as done in <a href="http://learnyousomeerlang.com/starting-out-for-real#highlighter_272060">Erlang</a>.<br>As the same, I used the <a href="http://es6-features.org/#SpreadOperator">Spead Operator</a> for lists concatenation.</p><p>But, I decided to go further to turn this into a more sweet functional code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ee60a741c9fd529abe90cbc43468313/href">https://medium.com/media/8ee60a741c9fd529abe90cbc43468313/href</a></iframe><p>Easily, I removed all variable definitions, functions compositions, is really great at this state.</p><p>And a new weird trick appaeared (line 10). This, is a <a href="http://learnyouahaskell.com/syntax-in-functions#guards-guards">guard</a> using the form <a href="https://github.com/hemanth/functional-programming-jargon/pull/53#issuecomment-233566046">I proposed to Functionnal Programming Jargon</a>.</p><p><em>TL;DR explanation : This guard form is based on </em><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator"><em>ternary operator</em></a><em>. So if the [condition ?] is evaluated to true, the first part is used as return the empty array in this case. However, if the guard is evaluated to false, the function corpse is executed. You can use as many guard as you wish by stacking ternaries.</em></p><h4>ES2078 is coming</h4><p>To perform ES2015 transformation into “vanilla” Javascript sources, I use <a href="https://babeljs.io/">Babel</a>. And Babel come with a lot of plugins, I have selected two of them for you.</p><p>The first one, <a href="https://github.com/HitoriSensei/babel-plugin-transform-curry">Transform Curry</a> seem really cool IMHO, It provided a way to use currying placeholders. And this is a great value for going deep into functionnal programming.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fef2c01a02fbecbf3a0f4d5bc6254e49/href">https://medium.com/media/fef2c01a02fbecbf3a0f4d5bc6254e49/href</a></iframe><p>The second “one”, is a more a way to add pipe operator to perform function composition. Thanks to three different approach but for reaching the same goal. <a href="https://github.com/miraks/babel-plugin-pipe-operator">Pipe Operator</a>, <a href="https://github.com/Swizz/babel-plugin-pipe-operator-curry">Pipe Operator Curry</a>, <a href="https://github.com/ondreian/babel-plugin-pipe-composition">Pipe Composition</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/937a9c6714bec8c4ee5ec821d5427099/href">https://medium.com/media/937a9c6714bec8c4ee5ec821d5427099/href</a></iframe><p>This example, show you my work for the plugin <a href="https://github.com/Swizz/babel-plugin-pipe-operator-curry">Pipe Operator Curry</a>.</p><h3>Looks Good To Me</h3><p>So, our code, look really good right now !</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ee60a741c9fd529abe90cbc43468313/href">https://medium.com/media/8ee60a741c9fd529abe90cbc43468313/href</a></iframe><p>All functions, are greatly sized, and pretty sweet to read. We use some tricks, but not too easy to understand.</p><p>But we can do a little bit more to enhance a bit further.</p><h4>Type, Types, Typed</h4><p>I am one of those who think, type checking is a good advancement in Javascript. So as many of us, I used <a href="https://flowtype.org/">Flow</a>. Flow, look really good and can be invisibly part of the code.</p><p>So, let’s add type checking to our new sweet syntax.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2fdae0a3683f9773c4000da895e2766b/href">https://medium.com/media/2fdae0a3683f9773c4000da895e2766b/href</a></iframe><h4>Do you comment your code ?</h4><p>The final part is about comments ; I tried several ways to comment out functions. And finally, I have decided to create mine.</p><p>A one line way to describe function accoding to the function programming common definition, based on its inputs and ouptut.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b2fdf3905d1fa8565fdb87aa0ce824fb/href">https://medium.com/media/b2fdf3905d1fa8565fdb87aa0ce824fb/href</a></iframe><p><strong>So, what are you thinking about this most beautiful Javascript Functional Programming syntax ?</strong></p><p>All feedbacks are excessively welcome !<br>I apologize for my broken english, even so we learn by our mistakes.</p><p>Thank you for taking the time to read me ; If you love this work do not miss to take the time to click on the ❤ and share it with world.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0698208da07" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>