<?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 Albert Nemec on Medium]]></title>
        <description><![CDATA[Stories by Albert Nemec on Medium]]></description>
        <link>https://medium.com/@albertnemec?source=rss-430239092e1c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*A918e8iALyHuzKTnPPCQQw.png</url>
            <title>Stories by Albert Nemec on Medium</title>
            <link>https://medium.com/@albertnemec?source=rss-430239092e1c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 15:34:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@albertnemec/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[Why not 'Systems Integration Engineer'?]]></title>
            <link>https://albertnemec.medium.com/why-not-systems-integration-engineer-a06ab10dca72?source=rss-430239092e1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a06ab10dca72</guid>
            <category><![CDATA[recruiting]]></category>
            <category><![CDATA[systems-integration]]></category>
            <category><![CDATA[hiring]]></category>
            <category><![CDATA[systems-engineering]]></category>
            <dc:creator><![CDATA[Albert Nemec]]></dc:creator>
            <pubDate>Thu, 16 Dec 2021 22:18:24 GMT</pubDate>
            <atom:updated>2021-12-17T14:00:08.727Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi again. This is a follow-up to my previous piece on &quot;<a href="https://albertnemec.medium.com/what-is-deliveryops-5fa126a8b9bd">What is DeliveryOps</a>&quot;. Read first for richer context.</p><p>I admit. While I received general appreciation of the &quot;AI Blue&quot; from the last article. The amount of DeliveryOps engineers I hired is zero.</p><h4>Intro by self-busting</h4><p>I get it. I won&#39;t be a terms-coiner in this lifetime. And after all, I also do get mildly suspicious of new made-up terms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/197/1*QRBV1gb9JjUuhJjTCuI99g.jpeg" /><figcaption>A self bust</figcaption></figure><p>Zero offense to past coinages like HR to PeopleOps, hiring to talent, DevOps to Site Reliability, IT to tech, marketers to ambassadors and educators to evangelists.</p><p>If you read the <a href="https://rossum.ai/career/deliveryops-engineer-with-python/">job description</a>, you most likely concluded… Oh, you mean &quot;Systems Integration Engineer&quot;.</p><h4>Counter-bust</h4><p>If you have arrived at this conclusion, most likely, you looked at the stack, then you gazed at the anticipated output of this stack being applied, and there&#39;s the result: Integration!</p><p>Effectively, you identified <strong>what </strong>and <strong>how. </strong>Now, <strong>why</strong> did you do that?</p><h4>Why #1</h4><p>Most resumes and job descriptions are actually either <strong>skill-based</strong> or <strong>outcome-based</strong>. Together, they form the landscape in which job-searching, job evaluation, and job-offering are to be conducted.</p><p>Then, in the classic hiring process, most time will be spent on &quot;Can you do it?&quot; and &quot;What you&#39;ll get&quot;.</p><p>These two parameters are crucial. Like in any trade. But the real nature of the situation goes beyond trade. The trade is just a local &#39;game&#39;, that lives within a broader story, initiated (and to be concluded) by <strong>why</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*NWvemllGI7bkAOoO8HO5cQ.jpeg" /></figure><h4><strong>Why #2</strong></h4><p>Actually, there are 2 whys inside of that why.</p><ol><li>Why does the role exist? (Why is the company hiring for this role right now?)</li><li>Why does the candidate exist? (Bit hyperbolic.. Read as &quot;Why did the human decide to exist as candidate&quot;)</li></ol><p>That&#39;s what actually is important. Loss of &#39;why&#39; or vision of a new one, is the thing that drives this whole process through an eternal cycle of resignations and new employments.</p><h4>How far does why fly? Far out. Why?</h4><p>You can actually, build the whole process around the <strong>why. </strong>Cover letters being the default, instead of the resume, describing various whys.</p><p>Job description describing the history of the teams, of the entity, of the individuals, spin-offs, plans, experiments, failures, successes, and realizations that lead to this job description, or actually to the person reading it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/0*Z8wamUdO3sQKNDnY.jpg" /><figcaption>serious thought</figcaption></figure><p>Finding with the candidate, how this job could actually be a natural continuation to a trend in their lives.</p><p>Tailoring the name of the role to reflect the purpose, the objective of the role. Rather then just sticking to empty, essence-less description of a hand that shakes hands, a wielder of things, the sayer of words, the person who clicks.</p><p>Not to get too preachy, approaching the last part of the article, but the names above do seem bit.. dehumanizing and reductionist, don&#39;t they?</p><h4>Full circling on the &#39;DeliveryOps&#39; name</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/0*CTH_MCYtfapMZE77" /><figcaption>full circle</figcaption></figure><p>Alright. After such a flamboyant display of linguistic ethos, I guess selling &#39;DeliveryOps Engineer&#39; as humanizing doesn&#39;t feel very symmetrical in cadence, huh?</p><p>At the very least, it is a name that stems from the purpose. To &#39;ops the delivery&#39;, thus lubricating the machine of deliverance, to conduct oneself engineerly on supporting their colleagues in product delivery.</p><h4>Final remark</h4><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*vfEC0ZU9GR_-fMuS.jpg" /><figcaption>Lt. Cmdr. Geordi La Forge</figcaption></figure><p>Did you know that in Star Trek, orange uniforms do not belong to engineers, as is commonly believed, but to members of &#39;operations&#39; super-category in the crew? Maybe that&#39;ll shed some light on why Mr. Worf and all of the security team wear orange.</p><p>However, those who indeed operate (like Dr. Beverly Crusher, being a doctor) are not part of the &#39;operations&#39; team. How strange.</p><h4>Finaler remark</h4><p>Thank you for reading to the end. If you liked this article, smile faintly and lightly chuckle. It&#39;ll look like you just had a flashback.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a06ab10dca72" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is DeliveryOps?]]></title>
            <link>https://albertnemec.medium.com/what-is-deliveryops-5fa126a8b9bd?source=rss-430239092e1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/5fa126a8b9bd</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[sass]]></category>
            <category><![CDATA[professional-services]]></category>
            <category><![CDATA[delivery]]></category>
            <category><![CDATA[jobs]]></category>
            <dc:creator><![CDATA[Albert Nemec]]></dc:creator>
            <pubDate>Mon, 29 Nov 2021 20:40:36 GMT</pubDate>
            <atom:updated>2021-11-30T11:47:48.978Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7mHHCCq7r_8s3McMO2MLjA.png" /></figure><p>It&#39;s almost a year that I&#39;m leading the Global Services team in Rossum. Oh boy, was it a B2B equivalent of an ostrich race (yes it&#39;s a thing).</p><blockquote><strong><em>In 10 months, we (Rossum&#39;s Global Services)…</em></strong></blockquote><blockquote><em>📈 Scaled up the team from 4 people to 20.</em></blockquote><blockquote><em>👥 Redesigned the team from 1 role in distress (Solution Engineer — the doer of all things) into a more scalable multi-org setup consisting of 5 functional sub-teams.</em></blockquote><blockquote><em>💻 Implemented (and integrated) 3 major systems — JIRA, Zendesk and Salesforce into a mature delivery coordination platform.</em></blockquote><blockquote><em>💰 Delivered Rossum to an ever growing number of &quot;deal of century&quot; customers brought under the reign of the very Unicorn Breeder — </em><a href="https://www.linkedin.com/in/theowl"><em>Isaac Buahnik</em></a><em> (the mf sales assassin), who had successfully declared a delivery war upon the unsuspecting end of the funnel.</em></blockquote><blockquote><em>And much more..</em></blockquote><p>However, this post isn&#39;t about how awesome we are. It&#39;s about DeliveryOps which I hope you can help me with.</p><p>Let me walk you through it…</p><h4>The Hero we need vs. the Hero we deserve (rise of my alter-ego)</h4><p>I admit, these successes were not some glorious managerial hyper-operation on my part (after all, back in the day I joined this party only to paint a few buttons in respectable <em>AI Blue </em>as a frontend dev.. yes, Rossum is a bit of a scope creep for me<em>), </em>but more of a spectacular display of work ethic and inventiveness by the individual team members.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*aqbCl6sM1nd6W_VsRRsO9w.png" /></figure><p>As an engineer, my default fix to all problems were technical in nature. Spending too much time on this task? Let me automate it. Not sure what to do? Let me adjust the workflow.</p><p>Not to say, it was all bad approach. Actually, I believe hyper-growth (exponential growth) is inevitably such a non-intuitive process for the human mind it does require technical solutions.</p><p>However, after a while it got quite obvious that the leader&#39;s first priority should be of flesh and blood. That&#39;s what the team deserved.</p><h4>The period of rogue Werewolf Engineering</h4><p>And thus my job got split into 2 parts. Day-shift where I mostly talked and wrote anything but code. Then a night-shift, where I shapeshifted into a rogue programmer coding scripts nobody requested, but everyone missed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dlOxCUcaAh1ADXYF" /><figcaption>Wolff and Tom (Wolff&#39;s Revier)</figcaption></figure><p>What a joy really. Normally, this non-technical team would be drowning in an endless sea of automatable tasks, that nobody automates, just because nobody with coding capability sees them. But I did.</p><p>For a pleaser, coding for customers is great (especially the closer to them you are), but coding for your colleagues is orders of magnitudes better.</p><p>There was just 1 minor problem. I worked literally day and night, and that&#39;s not even remotely vegan.</p><h4>Solution? DeliveryOps</h4><p>During my evening routines I&#39;ve come to understand that what I was doing was <strong>delivery enablement</strong>. See, Global Services team is a team whose responsibility is to make sure Rossum does good in the real world — delivering Rossum.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*k9BG_aCWWsUg8wAY" /><figcaption>Rossum&#39;s early days illustration (no animals were hurt when copying this photo from Google)</figcaption></figure><p>As Rossum is not your classic username/password internet product, it requires some love being given to the implementation and optimisation. In order to streamline this, our infrastructure has to be highly automated and void of overhead.</p><p>For that objective — DeliveryOps Engineer is needed.</p><p>Thank you for listening to my story. Since you made it so far, consider checking DeliveryOps Engineer&#39;s job description :)</p><p>Perhaps the two of us could make a great team, just like Wolf and Tom.</p><p><a href="https://rossum.ai/career/deliveryops-engineer-with-python/">https://rossum.ai/career/deliveryops-engineer-with-python/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/1*h12tC_j2OIdoOc-xTFESyA.png" /></figure><p>Or check out other jobs at Rossum: <a href="https://rossum.ai/careers/">https://rossum.ai/careers</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5fa126a8b9bd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Giants, Tsunami and Consciousness Speed & Spacetime Interdependence in Terms of Structure]]></title>
            <link>https://albertnemec.medium.com/giants-tsunami-and-consciousness-speed-spacetime-interdependence-in-terms-of-structure-4796817640cf?source=rss-430239092e1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/4796817640cf</guid>
            <category><![CDATA[tsunami]]></category>
            <category><![CDATA[spacetime]]></category>
            <category><![CDATA[fantasy]]></category>
            <category><![CDATA[conciousness]]></category>
            <category><![CDATA[relativity]]></category>
            <dc:creator><![CDATA[Albert Nemec]]></dc:creator>
            <pubDate>Mon, 02 Nov 2020 15:10:32 GMT</pubDate>
            <atom:updated>2020-11-02T18:15:35.372Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>My mouse broke. While I could use the touchpad, I&#39;ve decided I&#39;ll take the memo and just start writing. It has been a while, has it not?</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/715/1*nGZyDn74HC-KS-TKdi6X9Q.jpeg" /><figcaption>Theory of Relativity + Tsunami + Lady having difficulties existing</figcaption></figure><p>Anyways, have you ever considered how slow the giants move? I mean the real big ones, for example 300 football fields (or 1200 pregnant whales) tall. I must admit, when a giant battles some kind of Godzilla it is impressive. With the music and all. Each step of the giant causes some way too eager volcano in Japan to join the conversation on how much greenhouse gases should there be in our atmosphere. How exciting.</p><p>But let&#39;s now consider the giant on a Tuesday, doing the mundane. Inspecting the fridge for example. It may take a good 10 seconds before the giant even touches the thing. By that time the fridge is open the giant may have changed his (or HERS! you pig) mind already.</p><p>Well, either the giant has significant advantage in overcoming it&#39;s lizard brain when it comes to midnight fridge raids, or alternatively the giant&#39;s consciousness operates on a different time scale.</p><blockquote>Did you know that each mammal species on Earth have about the same average number of heart beats per life?</blockquote><p>Imagine the mouse, going fast and furryous (&lt;- legitimate comedy) incredible forwardson. Have you ever seen a well centered, calm and patient mouse? Of course not!</p><p>Now that I think of it, there may be an evolutionary reason why mouses are small. Having &quot;faster&quot; consciousness (let&#39;s imagine it like seeing everything in slow motion) may be incredibly useful, especially when chased by a snake or multiple snakes even.</p><p>Question then would be if small people perceive time differently than big people. Children certainly do. Boredom is an illness of the youth, isn&#39;t it? Surely reflexes of children are much better. You can call it &quot;better brain&quot;, but I&#39;ll call it &quot;brains not yet optimised to the best thought/time ratio&quot;. School is a great help in that regard.</p><p>The trippy thought that&#39;s available is that some creatures could have the &quot;consciousness speed&quot; so distant from ours that we wouldn&#39;t even recognise it as a consciousness. From that perspective the division between organic matter and inorganic matter could be just a matter of a different time scale in which the inner transformation happens.</p><p>Temperature is exactly weird like that. Hot things are things where particles move fast. Cold things is where particles move slow. Relative to each other I presume, because who&#39;s there to measure the speeds.</p><p>I know, I&#39;m troubling you with the fluent disrespect to the distinction between matter and living matter. Well, you&#39;re troubling me with your respect to that distinction as well.</p><blockquote>And now, the final blow of this ideorgy (<em>Orgy of Ideas, hereby I do coin it</em>).</blockquote><p>Take a Tsunami speeding up towards Miami beach. It&#39;s tall, at least 5000 football fields or 20 000 pregnant Blue whales. What a view as the Tsunami clears the sand off all unnecessary accessories and humans. What a view. What a view.</p><blockquote>Do you see it? Close your eyes if you don’t.</blockquote><p>Now tell me, is the Tsunami in slow motion? You don&#39;t know, huh? You&#39;re saying that your watch still ticks the same old beat?</p><p>Alright, let me paint some more. You walk along an English riverside, the river is not important, just a decoration for the story. Now you see a puddle (not the dog!). Step above it, look at the puddle. If you need to, lay your face close to the edges of the puddle until you see a Miami beach (or at least a rough approximation of Miami beach).</p><p>Now kick the puddle (again not the dog, god damn it! (another level is that the dog is a god backwards (just by the way))). Do you see the Tsunami? It is pathetic. It is anti-slow motion and the whole thing is over before the brass section can deliver any goosebumps.</p><p>Compare the two Miami beach episodes. The first one is 100% slow motion.</p><p>To conclude, there seem to be direct proportion between scale and time. At least as far as information or structure is concerned.</p><p>At that my friends, is interesting.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4796817640cf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Errors versus Failures]]></title>
            <link>https://albertnemec.medium.com/errors-versus-failures-61880d15f98b?source=rss-430239092e1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/61880d15f98b</guid>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[error-handling]]></category>
            <category><![CDATA[functional-programming]]></category>
            <dc:creator><![CDATA[Albert Nemec]]></dc:creator>
            <pubDate>Tue, 28 Nov 2017 13:01:32 GMT</pubDate>
            <atom:updated>2017-11-28T13:01:32.674Z</atom:updated>
            <content:encoded><![CDATA[<p>Even though we dedicate the heart and soul to our applications, we have to accept the fact that some things are meant to fail.</p><p>Imagine you are a software. Quite a complex one, with a lot of functionality and duties. You have to feed yourself, keep your house in a habitable state, do the thing you do at work, maintain relationships with people, pay the bills etc.</p><p>On a typical Monday, you&#39;ve already done half of your daily tasks, when suddenly you realise you forgot the bills, you have to pay at post office, at home.</p><p>Paying the bills consists of several <strong>sub-steps</strong>.</p><ul><li>Sign the bill</li><li>Hand over the bill to the post lady</li><li>Pay for it</li><li>Take conformation paper</li></ul><p>As a computer program written imperatively — as a series of steps — you have very little information about how these tasks relate to each other. So you have to check along the process, if everything is alright and if you can proceed to another step.</p><pre><strong>function</strong> signTheBill(bill) {<br>    <strong>if</strong> (isPresent(bill)) {<br>        <strong>return</strong> sign(bill);<br>    } <strong>else</strong> {<br>        <strong>throw</strong> new Error(&#39;bill is missing&#39;);<br>    }<br>}</pre><blockquote>What is unfortunate about this code is that signTheBill function isn&#39;t concerned with just signing. It has to do some extra logic, that isn&#39;t presumed by the purpose of the operation. Error checking that is.</blockquote><p>Because the step “Hand over the bill” would make no sense if the bill is not there, instead of proceeding you throw an Error that will stop the execution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*BHn9PwsE96MtvDli-_4JuA.jpeg" /></figure><p>How would that look like in our human-machine analogy? You’d probably just freeze, waiting for the day to end so you can start the over.</p><p>That doesn’t seem very good, right? Surely there&#39;re better ways to spend your time, than standing mid-way to the post office, with expression of a dead fish on your face, getting all sentimental about your forgotten bill.</p><p>Better thing to do would probably be saying “fuck it”, ditching all the steps that are related to the bill business and move on to other tasks.</p><p>Right there is a difference between an error and failed computation. But what are those two things anyway?</p><h4>Error</h4><p>Good old error is just a way, how computer solves unsolvable problem. Program stops running and stays that way, unless it’s restarted by some parent process or person.</p><p>But just because you bumped your wrist, doesn’t mean you have to cut off your arm, right? It indeed is a slight overkill. You should try to minimise the impact of the fuck up and get on with your life, as soon as possible.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*W2eIY87sVrYVxnAlEiVcmw.jpeg" /></figure><h4>Failed Computation</h4><p>In functional environments, you don’t really need to throw errors. Your application is more of a complex system of roads and highways.</p><p>Each road is a function, that is usually chained on another function. No instructions, just one giant expression waiting to get evaluated (“waiting to be drove by your car”).</p><p>When one of your functions/roads breaks and it’s impossible to evaluate/drive it, you just close that road. Immediately all other roads that are leading from this closed one are inaccessible and we don’t have to worry about them.</p><h3>What would Jesus do?</h3><p>Which of those two approaches would Jesus pick? That is the question. And it&#39;s not that rhetorical as it sounds. Jesus already made his choice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*ZaQA8vJOGsGEy8CJPPgFaQ.jpeg" /></figure><p>To understand Jesus, let&#39;s peak into god&#39;s absolute programming language, and how failures are handled in there. What is this language, you ask? Well mathematics, obviously.</p><blockquote>Let&#39;s take a moment to talk about our lord and saviour algebra.</blockquote><p>Math is defined in expressions. It’s not imperative. There is no order to execution of for example multiplication operator.</p><p>To draw a parallel with how we program, we often use null value to describe a absence of value. (absence of a bill maybe?) Those non-values are what causes impossible scenarios, where we’re trying to operate on value that isn’t there.</p><h4>Another spook from Category Theory</h4><p>Category is defined by objects (in our simple example numbers) and arrows (aka morphisms, which define transition from object A to object B. Basically functions).</p><p>Formula A -&gt; B in example as 8 (*2) 16. (*2) being the arrow/function/operation which multiplies by two.</p><p>How does the category of numbers with corresponding multiplication arrows handle absence of value?</p><p>Well, the zero propagates further, having the resulting expression evaluated to zero.</p><p>And that is exactly the kind of behaviour we want for our functions. If one part of the pipeline fails to compute, whole expression is done for, no matter how many times we would operate on it later on (with our binary operation of * or actually any pure function).</p><h3>No Silent treatment</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jUtvQ6lX6FBvF8uaIJRitA.jpeg" /></figure><p>Beware tho! I&#39;m not encouraging you to let failures happen silently. Sure, you should have some mechanism to track your failures. It doesn&#39;t really matter, if you want to log your failures into the console, send request to some error tracking service or write to some log file. For us, it&#39;s just some side effect.</p><p>We know the pattern of Functor&#39;s fmap, and therefore question of “where should the side effects happen” is quite trivial for us. They should be hidden in the composition in a way, that no arrow/function has to be directly concerned with them.</p><pre><strong>const </strong>f = g = h<strong> = </strong>x =&gt; x + 1<strong><br>const</strong> compose = (...fns) =&gt; value =&gt;<br>    fns.<strong>reduce</strong>((acc, fn) =&gt; acc ? fn(acc) : acc, value)</pre><pre><strong>const</strong> pipeline = compose(f, g, h)<br>pipeline(4) <strong>// 7</strong></pre><p>So all the magic is hidden in the compose function, and that is the right place to do the failure logging.</p><h3>Concluding</h3><p>Obviously, if you&#39;re writing your code imperatively, you&#39;re not building your system of roads and you have no choice, but to construct these weird objects that&#39;ll stop your app.</p><p>But considering you are trying to go functional, this is the way you handle fuckups. The whole principal gets even more joyful, if you&#39;re decorating your roads with traffic signs, like type annotations.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61880d15f98b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tvoříme Funkcionální Podhoubí]]></title>
            <link>https://medium.com/blueberry-cz/tvo%C5%99%C3%ADme-funkcion%C3%A1ln%C3%AD-podhoub%C3%AD-7f7c70bccd8d?source=rss-430239092e1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f7c70bccd8d</guid>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[lambdup]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[meetup]]></category>
            <category><![CDATA[programming-languages]]></category>
            <dc:creator><![CDATA[Albert Nemec]]></dc:creator>
            <pubDate>Thu, 16 Nov 2017 15:57:09 GMT</pubDate>
            <atom:updated>2017-11-28T08:56:06.455Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Mohlo by se zdát, že téma funkcionálního programování je dávno uloženo v historických análech počítačové vědy a v dnešním dominiu Javy a jiných Objektově Orientovaných obrů nemá místo.</strong></p><p>Takové tvrzení však nemůže být dále od pravdy. Funkcionální programování je totiž postaveno na něčem, co nevyšlo z módy už několik tisíc let. Na matematice.</p><blockquote>Tvoření softwaru se tedy podobá spíše zápisu jedné velké rovnice než nekonečné sekvenci příkazů.</blockquote><p>Tento přístup má obrovskou výhodu, neboť již nejsme jako programátoři vedeni pouze svým odhadem, ale jasnými zákony, tak jako v matematice, které definují společný lingvistický základ, nehledě na syntax jazyku, či povahu aplikace.</p><p>Zní to příliš abstraktně a akademicky? Není! V posledních několika letech bylo předními vývojáři investováno neuvěřitelné množství úsilí do zboření předělu mezi světem akademiků a světem programátorů, díky čemuž je dnes funkcionílní programování jedním z nejdiskutovanějších a nejlukrativnějších témat v oboru.</p><p>V tomto duchu vzniká akce <a href="https://www.lambdup.io/">Lambdup</a> s ambicí stát se ústřední událostí funkcionílního světa, kde se každý rok sejdou přední vývojáři a propagátoři funkcionálního programování, aby společně posunuli hranice prozkoumaného a předali nové nápady, jak tyto mocné koncepty využít při řešení každodenních technologických problémů.</p><h4>A co nás čeká a nemine na letošním Lambdupu?</h4><p>Například rocková hvězda mezi programátory <a href="https://twitter.com/ericnormand"><strong>Eric Normand</strong></a>, který uvede celou událost nekompromisní náloží na téma Teorie za Funkcionálním Programováním.</p><p>V duchu překryvu mezi teorií a praxí však také uslyšíme o relativně novém jazyku Elixir, který kombinue lidovou praktičnost jazyku Ruby a neomylnou čistotu jazyka Erlang. O Elixiru bude mluvit <a href="https://twitter.com/cloud8421"><strong>Claudio Ortolina</strong></a>, který je jedním z autorů tohoto jazyku.</p><p>Mně osobně však nejvíce vzrušuje <a href="https://twitter.com/alesroubicek"><strong>Aleš Roubíček</strong></a> se svým talkem o Machine Learningu v jazyku Clojure. Clojure je konceptuálně extrémně minimalistickým jazykem a jeho užití ve strojovém učení je fascinující snad i pro lajka, jakým je Maruška z účtárny.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f7c70bccd8d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/blueberry-cz/tvo%C5%99%C3%ADme-funkcion%C3%A1ln%C3%AD-podhoub%C3%AD-7f7c70bccd8d">Tvoříme Funkcionální Podhoubí</a> was originally published in <a href="https://medium.com/blueberry-cz">Blueberry_cz</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Promising Future: Monadic Tantrum]]></title>
            <link>https://medium.com/blueberry/promising-future-monadic-tantrum-19232d21c642?source=rss-430239092e1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/19232d21c642</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[haskell]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[Albert Nemec]]></dc:creator>
            <pubDate>Wed, 11 Oct 2017 10:58:50 GMT</pubDate>
            <atom:updated>2017-10-12T21:38:35.656Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t97NjwhdveP_SL3aieOSow.jpeg" /></figure><p><strong>Time for science! Right now I’d like to tell you about an experiment I conducted that would prove whether Javascript Promises are indeed Monadic Values, like we know them from Haskell. Stick with me- we gonna get fancy as a fuk.</strong></p><h3>Motivations</h3><p>In functional realms, to talk about <strong>Monadic patterns</strong> being implementable in <strong>untyped</strong>, wild, and very <strong>impure</strong> languages like <strong>Javascript</strong>, is more of a rude joke.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qObABRh1dkCwrXWHN1EhQw.jpeg" /></figure><p>But let’s face it, at least one mad <strong>motherfucker</strong> like me has to try taking that path.</p><p>I’m convinced that <strong>React’s</strong> component composition is an environment pure enough to enable some promising future with <strong>Monads</strong>.</p><p>Oh yes. I’m about to deconstruct the shit out of <strong>Javascript</strong> <strong>Promises</strong>.</p><blockquote>Live example of the experiment is on <a href="https://codepen.io/Albert24/pen/LzbdEN?editors=0002">Codepen</a>.</blockquote><h3>Monads in Haskell</h3><p><strong>Monad</strong> is a <em>Typeclass</em> in Haskell. It is also a mathematical concept, and with this comes the great strength of monadic programming, <em>a.k.a.</em> monadic composition, as a way to write programs.</p><p><strong>In OOP languages, </strong>you use <em>Class</em>es to organise the code, and as you inherit from other <em>Class</em>es, your final instance grows in complexity.</p><blockquote>More methods, more state.</blockquote><p><strong><em>Type class</em>es — </strong>in functional languages with rich type system — provide more of an <strong>abstract definition</strong> of how type specific functions (like map is a type specific function for Array) should behave. It&#39;s just a set of <strong>type annotations</strong>, that now have to match your function.</p><p>These definitions are rarely used with specific types (primitive types that is), as more often, <strong>type variables</strong> are used. Like in this function, where we’re ensuring both arguments and result types are of the same type. Doesn’t matter if they are integers or strings, they just have to be all one type only.</p><pre><strong>type</strong> IntegerAddition = (a, a) =&gt; a</pre><p>Unfortunately, Javascript doesn’t have <em>Typeclass</em>es, so we have to make do with our plain old <strong>JS objects</strong> and <strong>Classes</strong>.</p><p>Instead of the type system, we could write series of <a href="https://codepen.io/Albert24/pen/NadjKN">tests like these</a> in our code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q5FR_tdzOeFXUziv6WQEZg.png" /></figure><p>We could do that. But it’s just runtime checking, not a static one, and also we would have to write a lot of <strong>awkward</strong> <strong>code</strong>.</p><p>But at least there is a way to achieve something like a dumb <strong>mocked-type system</strong>. If we create these rules and generalise them, maybe we could do it with just few of them.</p><p>So I created awkward <strong>unit tests </strong>that will runtime check if some class — in our case, Promise — behaves like a Monad.</p><h3>Mild Category Theory Harassment</h3><blockquote>Let’s get right into it. In order for something to qualify as a Monad, it has to pass few laws.</blockquote><p>Even our good old integers have to obey some <strong>behaviour</strong>. When divided, they shouldn’t perform like they do while subtracting, right?</p><p>If we wanted to test this with unit tests, their result could be determined upon a boolean of sorts.</p><pre>x - y !== x/y</pre><p>Surely this test would be pretty dumb and wouldn’t check all the possible scenarios- but if we wrote enough of them, we could be pretty sure if a type behaves like it should or not.</p><p>With <strong>integers</strong>, there is another rule that, when you add them together like this: y + xit should give you the same output as x + y. This is called associativity, and is provable with the following expression.</p><pre>x + y === y + x</pre><p>If you’ re interested in deeper elaboration, I believe Category Theory is your topic. Here is a nice <a href="https://www.youtube.com/watch?v=JMP6gI5mLHc">lecture from our guy Erik Meijer</a> on it. Even though most of the resources are written in presentations using Comic Sans — or academic papers — it is nonetheless quality reading.</p><p>My personal favourites are <a href="https://www.youtube.com/watch?v=z0N1aZ6SnBk">Erik Meijer</a> and <a href="https://www.youtube.com/watch?v=pHtk437yD1s">Simon Peyton Jones</a>. Watch them misfits <a href="https://www.youtube.com/watch?v=iSmkqocn0oQ">deconstruct nature of programming languages</a> in 6 minutes.</p><h3>The Experiment</h3><blockquote>So from <a href="https://wiki.haskell.org/Monad">Haskell Wiki</a> definitions of <strong>Monad Laws,</strong> we got 3 statement that we have to <strong>check </strong>to see whether they apply to Promises: Left identity, Right identity and Associativity.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*9E0RzKAiW-RrYVK5JffPAw.jpeg" /></figure><h4>Left identity test</h4><p>I started with a well known Haskell annotation of this test. It is more of a statement saying that when we wrap a value of a in a Monad (or Promise), and use bind (aka &gt;&gt;=, aka .then) to transform the inner value of the Monad with a function f, the value of both sides should be the same.</p><blockquote>Wrapping a value inside of a Promise must not change the value.</blockquote><blockquote><em>return a &gt;&gt;= f = f a</em></blockquote><p>Rewritten in Javascript it looks like this…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hl48BNa9rNO9Cgz-f_6qFQ.png" /></figure><p>Oh boy, that is a talkative test. I used monad and bind variables — instead of Promise directly— because I wanted to create a generic test with which you can test anything, <em>not </em>justPromises.</p><p>That code can be found on <a href="https://codepen.io/Albert24/pen/LzbdEN">Codepen</a>. Results of the test are in the console.</p><h3>Right Identity test</h3><blockquote><em>m &gt;&gt;= return = m</em></blockquote><blockquote>Rewrapping a Promise doesn’t change the inner value.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*NjYd821vebBnzG-Mnv9Q5Q.png" /></figure><p>This one is a simple test- checking if the return and bind functions work. In our case, thereturn function is aPromise constructor, and thebind (&gt;&gt;=) function implemented as athen method on the Promise.</p><h3>Associativity test</h3><p>Last of the monad laws is an associativity test. Like the integer story, we had a few lined up. This also is a rule that describes how the composition should work.</p><blockquote>You can either first transform the value and then wrap it in a Promise, or wrap the value in a Promise first and then transform it with a bind function. Either way, the result should be the same.</blockquote><p>Proof of this law written in Haskell is wilder than any previous proof written in Haskell.</p><blockquote><em>m &gt;&gt;= (\x -&gt; f x &gt;&gt;= g) = (m &gt;&gt;= f) &gt;&gt;= g</em></blockquote><p>On the left side, we transform contents x of monad m with f function. f in this case returns a new monad (since bind function is used on it) so we bind it onto g function.</p><p>On the right side, we use bind functions without the nesting. (It works very similarly with Promises). ‘Thens’ can be also nested, or chained.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IyxKHkNwhj9HJon2tdopjQ.png" /></figure><p><strong>A live example of the experiment is on </strong><a href="https://codepen.io/Albert24/pen/LzbdEN"><strong>Codepen</strong></a><strong>.</strong></p><h3>Counterpoints</h3><p>So, unless I missed something quite important, we’re done here, right? Not exactly..</p><h4>Dangling resolve function</h4><p>When we’re providing the constant to a newly created Promise, we pass is to a function r, which stands for resolve. This function has to be called to fulfil the Promise.</p><blockquote>Is this a problem? Does it bend the definition of Monad too much?</blockquote><p>I believe it’s more of a choice of API. It’d be very easy for us to create areturn function that would just take a value and call the resolve function for us, with the value provided.</p><pre>const return = x = new Promise(r =&gt; r(x))</pre><p>This, however, brings us to the second problem.</p><h4>Environment</h4><p>It does not matter that much whether the Promise is an apple or orange. What matters is whether we can <strong>easily work </strong>with it and <strong>help</strong> ourselves with everyday troubles.</p><p>The truth is, <strong>Javascript</strong> is very <strong>poorly equipped</strong> for proper Promise manipulation. How do you map it? How do you clone it in an immutable manner? Composition? do notation? Often you&#39;d get stuck trying to painfully reduce Promise.</p><blockquote>These questions need to be answered! I do believe it’s possible.</blockquote><h3>Conclusion</h3><p>So, the most objective statement that I can stand behind is that <strong>Promises do not fully match the Monad definition</strong> as we know it from Haskell. But since Javascript is a different language — with obviously different syntax — I believe that they do qualify as Monads, just implemented in a different way.</p><p><strong>Remember</strong>, <a href="https://codepen.io/Albert24/pen/ZXYKzL">Promises can be tweaked</a>, so there is great potential for creating the ecosystem Promises might need to become viable as <strong>state management</strong> solution and more.</p><h3>Tetta and Farewell</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/1*UPL0R9PnW_W-YDVLH9_vkQ.jpeg" /><figcaption>And as always, one hipster Nimoy for you.</figcaption></figure><p>My <strong>next steps</strong> are heading towards implementation of this pattern in the <strong>real world</strong>. I want to introduce some basic functions that are needed to work with Promises, like with Monads.</p><p>Also I’d like to describe a way how a Monad pattern can be used in <strong>React app</strong> as a state management solution.</p><blockquote><strong>Maybe these kind of articles aren’t for everyone, but if you know of someone mad enough to care, do share it.</strong></blockquote><blockquote><strong>Thanks</strong> ya’ll, tho. Since I started writing these.. writings, several people gave me their perspective on the structure of the articles. I hope it pays of for the readers as well. Namely I&#39;d like to thank <a href="https://medium.com/@_tomaass">Tomas</a>, <a href="https://medium.com/@DanielKrejci">Daniel</a> and <a href="http://penetratingprague.com/">David</a>.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19232d21c642" width="1" height="1" alt=""><hr><p><a href="https://medium.com/blueberry/promising-future-monadic-tantrum-19232d21c642">Promising Future: Monadic Tantrum</a> was originally published in <a href="https://medium.com/blueberry">Blueberry</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AJAX 2.0 — Composable Fetch]]></title>
            <link>https://medium.com/blueberry/ajax-2-0-composable-fetch-e640471f207a?source=rss-430239092e1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/e640471f207a</guid>
            <category><![CDATA[ajax]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Albert Nemec]]></dc:creator>
            <pubDate>Mon, 09 Oct 2017 12:45:15 GMT</pubDate>
            <atom:updated>2017-10-11T14:20:31.261Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>This article has 3 main points. To describe current situation of asynchronous <strong>fetching</strong> in Javascript. To talk about function <strong>composition</strong>. And to introduce you to a <strong>library</strong> that joins those two topic together in a truly functional feel.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*47ukn2XfcNvW6pjydUIlTA.jpeg" /></figure><h3>About the AJAX part</h3><p>Some time have passed since we used classic XMLHttpRequest with all the awkward onreadystatechange handling. When <em>Promises</em> came, most of us switched to fetch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/1*td-nPK11zIn68cX4ADEfMw.jpeg" /><figcaption>Is your API stronger than dirt?</figcaption></figure><p>Of course, some are still clinging towards jQuery, but let&#39;s face it, those guys aren&#39;t gonna make it to TechCrunch anytime soon.</p><p>Later we needed more functionality like cancellation of a pending <em>Promise</em>, so we started using things like Axios. Then we needed our fetch to work on server as well, mostly because of <em>server-side rendering</em>, thus we started using isomorphic-fetch and such.</p><p>Now we have decent tools to tackle the network and APIs of our backend friends. Yet all of fetch reincarnations introduced more of a API extension to the fetch, than an answer to notoriously humiliating question…</p><blockquote>How to sequence and delegate more complicated API calls without embarrassing heartbreaks.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*Y1Bv7QX12wI_VfRGjeaJQw.jpeg" /></figure><h3>This “composability” thing</h3><p>For something to be composable, it has to be made of building blocks that can be rearranged together to formulate different behaviour, in a predictable manner.</p><p>Since we&#39;re working with functions (as fetch is a function) the word composability refers to <a href="https://en.wikipedia.org/wiki/Function_composition_(computer_science)"><strong>Function composition</strong></a><strong>, </strong>which uses output of one function as input of another, our building blocks will therefore be functions.</p><blockquote><a href="https://codepen.io/Albert24/pen/VMrRpQ">If you haven’t seen function composition in action, peak in to this <strong>Codepen</strong>, I brewed for you</a></blockquote><p><em>Also notice the </em><strong><em>currying</em></strong><em> (function that returns function that can return another function and so on) it&#39;s convenient way to</em><strong><em> inject dependencies</em></strong><em> as parameters into the pipelines.</em></p><blockquote>In order for this to work, those functions need to be <strong>unary</strong> (taking one argument). Because function can have only one output it has to also take one input, if we want to chain them together.</blockquote><h4>Pipe Composition</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*O4EVUoHE2DpWwQ5RVwzY_w.jpeg" /></figure><p>The beauty of composition is in it’s atomic and reusable design. Just like in previous <a href="https://codepen.io/Albert24/pen/VMrRpQ"><strong>Codepen example</strong></a><strong> </strong>not only you can compose functions into pipelines, but since pipeline returns unary function, it’s very easy to pipe a pipeline into another pipeline, creating super pipelines.</p><h4>Side Effects</h4><p>Great advantage is, that we can pass as many <em>identity functions*</em> as we want anywhere into the pipeline to create <strong>side effects </strong>like <strong><em>console.log</em></strong><em>ging, </em><strong><em>redux</em></strong><em> action dispatching, </em><strong>rerouting</strong><em> </em>and such<em>.</em></p><p>In this way the pipe can behave like a middleware.</p><blockquote><strong>*identity function</strong> is a function that takes an argument and without any transformation returns it. Like this<em>x =&gt; x</em></blockquote><h4>Asynchronicity</h4><p>Next level is to have these pipeline abstract the async aspects of the fetching away, providing us with interface, into which we can just pass our beautiful <strong>pure functions</strong> without any regard with the fact, something is waiting to be executed.</p><p>Whenever you need to fetch something new during the pipeline execution, you just return a <em>Promise</em> in one of your functions and it’s going to by automagically waited for by default.</p><h3>The Library</h3><blockquote>Heavily inspired by monadic composition, well known from functional languages, <a href="https://github.com/honzabrecka/composable-fetch"><strong>composable-fetch</strong></a> features <strong>dynamic retries, timeouts, chaining, delays </strong>and even asynchronous <strong>branching. </strong>All in clean and convenient syntax.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q-9azr-mxlybpNN56P2c3A.png" /><figcaption>Example right from Readme</figcaption></figure><p>That is what the library provides, more important is though what this library enables. With pipeP you can restructure your awkward Promise recursion into elegant pipelines that are easy to read and reuse.</p><h4>Where it really helps</h4><p>If you&#39;re dealing with primeval API that forces you to perform samba of requests in order to get what you need, <a href="https://github.com/honzabrecka/composable-fetch"><strong>composable-fetch</strong></a><strong> </strong>can be<strong> </strong>your way out<strong>.</strong></p><blockquote>Basically, the shittier the API you’re trying to call gets, the more useful you’ll find the library to be.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*n2oOEio8UgJVLw_GuaZljw.jpeg" /></figure><h4>Tweakability</h4><p>What I like about this library the most, is that it&#39;s not creating any elaborate Classes, nor it hides too much logic under the hood.</p><p>It is simple. It&#39;s just Javascript.</p><p>And you can easily switch between your logic and the mechanics of the library, there is no strict line, behind which you&#39;re not allowed.</p><h3>Therefore</h3><p>I do encourage you to try <a href="https://github.com/honzabrecka/composable-fetch"><strong>composable-fetch</strong></a><strong> </strong>out. It&#39;s conveniently <strong>small</strong> and dependency-less package that may be the answer to the headache you&#39;re having from the fetching madness in your codebase, no one dares to refactor.</p><p>Also help out the creator of this library forking, commenting and issuing the <a href="https://github.com/honzabrecka/composable-fetch">Github repo</a>. It&#39;s the best way how you can help out the community, while being practical.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e640471f207a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/blueberry/ajax-2-0-composable-fetch-e640471f207a">AJAX 2.0 — Composable Fetch</a> was originally published in <a href="https://medium.com/blueberry">Blueberry</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Functional Realms vs Imperative Empires]]></title>
            <link>https://medium.com/blueberry/functional-realms-vs-imperative-empires-c22f11f6229?source=rss-430239092e1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/c22f11f6229</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[imperative-programming]]></category>
            <dc:creator><![CDATA[Albert Nemec]]></dc:creator>
            <pubDate>Mon, 14 Aug 2017 09:06:42 GMT</pubDate>
            <atom:updated>2017-08-14T09:06:42.474Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*hS2D9Lo9qW_C4EFhLn9snw.png" /></figure><p>Hello! It&#39;s seems like we ended up reading another chapter, didn&#39;t we? Good to hear that! Today, we&#39;ll be more practical. It&#39;s time for…</p><blockquote><strong>Side by Side</strong> (effect, lol) comparison of<strong> Imperative* </strong>and<strong> Functional code.</strong></blockquote><blockquote><strong>*Imperative</strong> code is a type that functions like a set of commands in which the compiler reads statement after statement, mutating a state in the scope that’s surrounding it.</blockquote><h3>Very Real Example</h3><p>Let’s presume, we need to display a phone number. It should always have 12 digits, however our customers sometimes provide a number including the country code, and other times they leave it out.</p><p>We need to somehow unify the format because our<em> server needs phone numbers equally long. So we place in front of them as many zeros as needed, until we’ll end up with same length strings, no matter if they have short country code, long country code or none.</em></p><pre>/* transformation magic (spaces are not really in those strings, just for more pleasurable readage) */</pre><pre>    &quot;112 211 432&quot; -&gt; &quot;000 112 211 432&quot;<br> &quot;21 333 412 234&quot; -&gt; &quot;021 333 412 234&quot;<br>&quot;244 131 783 114&quot; -&gt; &quot;244 131 783 114&quot;</pre><p>Sure it’s quite simple to write such function in both FP and Imperative manner, but let’s compare the two.</p><h4>Imperative Way</h4><pre>function formatPhoneNumber(number) {<br>  let result = number;<br>  while (result.length &lt; 12) {<br>    result = &#39;0&#39; + result;<br>  }<br>  return result;<br>}</pre><h4>Functional Way</h4><pre>const formatPhoneNumber = number =&gt;<br>  number.length &lt; 12<br>    ? formatPhoneNumber(&#39;0&#39; + number)<br>    : number</pre><p>While the imperative function is more of a description of steps, that need to take place, the functional is more like a statement, that just tells us, what is where, and where should it go.</p><h3>The Difference, really…</h3><p>Since the imperative example is more like a list of steps the poor computer has to follow, I’d call it middle-management programming. It’s much easier to tell a kid to stop hassling around that high voltage thing than making them truly appreciate, how fucked up their life could be otherwise. Therefore strict TELL-DO relationship is an easy way to go.</p><p>Functional programmer, on the other hand, is like a Zen master, that patiently builds connected corridors for the water to flow through, once the rain comes. He’s not out there, kicking asses. He observes and carefully sculptures the ways, for the asses to travel on. This one needs some dedication. It really is a path of quality, opposite to imperative code, that embraces quantity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*Emo8_p2et1ZSIw-wlFuqWg.jpeg" /></figure><h3>Less philosophical approach pls</h3><p>So the most obvious difference, aside from the stylisation of syntax, is the most juicy part of the function. The loops. Or actually, where is the loop in the functional one?</p><h4>Recursion</h4><p>That is recursion, which is heavily favoured amongst functional people. It’s just a function, that runs itself upon some condition. It is probably the more clear solution, at least for a mathematician. Nice thing is that everything that happens in the function, stays in the function. As it is of no use to a loop, to store computations inside it’s scope, it’s forced to mutate scopes outside it. That can be tricky…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/1*gf8AIbVbYUO_eqdX1rh_BA.jpeg" /></figure><h4>Scope Pollution</h4><p>Also the imperative function creates extra variable. This might not seem as a big deal, but imagine the function is bigger. Once there are more variables, each affected by different operations, it gets increasingly harder to know, what leads where, and in which part of it&#39;s life cycle the variable is.</p><p>This is not as much of a problem in functional world, where there’s no place for data that just floats around, going into magical functions, hoping it’ll do something wonderful in other galaxy. In functional world, it’s always simple exchange. I give you input, you give me output. Water is following the corridor.</p><h3>Unfortunately Side-effects</h3><p>It might almost seem like going all functional is a no-brainer. But real world has side effects. In fact, a program that has no side-effects, has no way of communicating with it’s users. It would be just a pointless CPU consumer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*5qej3KpAs51AlL9m_wL1zw.jpeg" /></figure><h4>What are they?</h4><p>Side effect is something that cannot be measured. It is something, that isn’t directly involved in neither processing input, nor composing output. In functional realms, this was a great problem. In our Zen analogy, side-effects are rogue cracks in the ground, in which the water ends up, or from which the underground water bursts later.</p><p>We can hardly really know, how much water will be lost in a crack, we don’t have enough information about the depth of the it.</p><p>In imperative programming, you already live with the uncertainty of what the data that you process really are, so you&#39;re pretty much used to it and you don&#39;t even care.</p><h4>How to fight them</h4><p>There are many ways, how to fight side-effects. In languages that are not as pure, like Javascript for example, here is where you&#39;ll switch back to imperative code for a second. But you also lose the advantages of the purity.</p><p>In more pure languages a pattern that&#39;d address this was desperately needed. Therefore Monads came. But let&#39;s stick with our Zen analogy and Javascript.</p><p>If you didn’t know, Javascript already implements a Monad. It’s the Promise object. This particular Monad handles one type of side-effect — Asynchronicity.</p><h4>Back to the Water</h4><p>Let’s talk about how Promises stand in our analogy. Async functions take some input and return output sometime later. So it’s a corridor that has a crack on it’s end. When the water ends up in this hole, it travels through underground tunnels, and later it bursts out of the soil somewhere else.</p><p>What Promise does is that it somehow wraps both holes (both input and output) in a single context, allowing us to write code, that isn’t at all concerned, with the fact that the data flow gets interrupted.</p><p>So in Zen master&#39;s mind, he notes that the two holes are related and when he builds his pipelines, he considers the two related corridors, as a single pipe.</p><h3>Using Monad pattern not only on Promises</h3><pre>const pipeline = new Promise(fetch_question).then(<br>  output =&gt;<br>    new Maybe(output).Just(<br>  question =&gt;<br>    new RenderQuestionWithButton(question).on(&#39;click&#39;,<br>  event =&gt;<br>    new Promise(send_answer(question, event.value).then(<br>  status =&gt;<br>    this.return([question, status])<br>)))))</pre><pre>// unwraps the value returned via .return() method<br>const [question, status] = pipeline.bind();</pre><p>The return()function takes output value of previous action, wraps it in default context (aka wrapping it inside FancySideEffectContainer), that is later unwrapped with the bind()fn. Why wouldn&#39;t we just return the status already with the return()method? Why wrapping it again?</p><p>Main reason is composeability. It is likely, we&#39;d have many of those pipelines, connected to each other, creating a tree of pipes, therefore ultimate pipeline, that is our application. All of it would be one statement. Isn&#39;t that cool?</p><p>If the behaviour of Promises was applied to solve other side-effects. This is the kind of code that we&#39;d have in Javascript. Note that output , question and event are all visible (in scope) to the code, that is under them because of closure.</p><p>There we have pure code, that can do side-effects. It looks like imperative code, but it isn&#39;t. Each statement is a distinct pure function, properly handled by the definition of the Monad we used bind function on.</p><blockquote>Bind function (do not confuse with the function on Array&#39;s prototype) is a function that has to be defined for every Monad. It is a function that takes a function, into which it&#39;ll pass internal value of the Monad (unwrapped) as a argument, returning new Monad instance, that can be further chained with other bind function. Because different Monads deal with different side-effects, bind functions can look very differently. For example then function is a bind function for the Promise Monad. Maybe Monad on the other hand implements it&#39;s bind function, so it propagates the null case, just like NaN does when you try to do arithmetic operations on it.</blockquote><pre>// the same behaviour<br>NaN + 3 === NaN</pre><pre>Maybe.Nothing.bind(fn) === Maybe.Nothing</pre><p>Here is how&#39;d the code we wrote earlier looks in Haskell. Beware that it&#39;s a pseudo-code for better readability.</p><pre>let pipeline = do<br>  output &lt;- fetch_question<br>  question &lt;- Just output<br>  event &lt;- render_question_with_button question<br>  status &lt;- send_answer question $ get_value event<br>  return (question, status)</pre><p>It&#39;s much nicer isn&#39;t it? That&#39;s just because of the do notation. It&#39;s just a syntactic sugar, under the hood it looks similar to that Javascript example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/1*UPL0R9PnW_W-YDVLH9_vkQ.jpeg" /><figcaption>One Hipster Nimoy for You</figcaption></figure><h3>Who won?</h3><p>Obviously I talked much more about functional programming than imperative. That&#39;s because I believe y&#39;all are very much familiar with the latter one.</p><p>The question here is more like “who won your heart?”. I can get behind Imperative&#39;s “do stuff now” attitude, because sometimes Zen is just too much effort for one stupid button. But again, knowing how stuff like currying or composition work, can add some spice into your code, making those code reviewers little less bored.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c22f11f6229" width="1" height="1" alt=""><hr><p><a href="https://medium.com/blueberry/functional-realms-vs-imperative-empires-c22f11f6229">Functional Realms vs Imperative Empires</a> was originally published in <a href="https://medium.com/blueberry">Blueberry</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript — The Puberty of Brendan’s Child]]></title>
            <link>https://medium.com/blueberry/javascript-the-puberty-of-brendons-child-6cff2fd3757?source=rss-430239092e1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/6cff2fd3757</guid>
            <category><![CDATA[devteam]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Albert Nemec]]></dc:creator>
            <pubDate>Mon, 17 Jul 2017 12:27:21 GMT</pubDate>
            <atom:updated>2017-07-24T14:40:42.704Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*VGloWsSKzeJ5DUtyaFBJRQ.jpeg" /></figure><p>There are probably thousands of articles about the history and/or future of JavaScript, so there’s no point writing any more of them.</p><p>Today I’d like to talk about the history and future of JavaScript.</p><p>…</p><p>You may say, “But dude! You just contradicted yourself like crazy,” and yes I did- just like JavaScript has been doing since it’s birth.</p><p>Don’t get me wrong, I like JavaScript. But to be honest, one has to be skeptical about a language that doesn’t even have any opinion on semicolons.</p><p>JavaScript is like a teenage kid that’s still looking for its identity, and even tho this process is very interesting to observe, it can also annoy the living shiet out of everybody… just like a teenager does.</p><h3>Moving on!</h3><p>Let’s cease with the foolishness for a sec.</p><p>JS was developed in about 2 weeks with it’s creator, Brendan Eich, given clear instruction: “Make it something like Java”. As Brendan is the king of trolls, god bless the guy, he made a language that kind of looked like another C clone, but under the hood is designed to destroy the souls of Java programmers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*sFv3Jfa-kfaeLaLswCIySQ.gif" /></figure><p>Because of this, I find the name “JavaScript” adorable.</p><p>This “Says one thing, does another” attitude is deeply rooted into the language. Let’s list some parts where it really hits the ding dong.</p><h4>Prototype bitch!</h4><p>As you probably know, the fabric of OOP are classes and inheritance. We were in the 90&#39;s, so Brendan couldn’t just smack OOP off the table. Instead he built JavaScript on prototype based inheritance, and classes were replaced by functions.</p><p>Sick move, Brendan! Now them Javists&#39;ll think that there is something nice for them in the language to guide them.</p><blockquote>But that gift of prototype felt like poison in the Javist&#39;s throat</blockquote><p>The fact that ‘class keyword’ was added to JavaScript in ES6, is a way of building on Brendan’s ‘Javist trolling’ heritage, providing those prototypes with a Trojan Horse they can hide in, only to betray you later on.</p><blockquote>Every time you extend a JavaScript class, a Java Programmer somewhere in the world sheds a sorrowful tear, and his dog dies.</blockquote><h4>Everyone&#39;s dead, Dave</h4><p>Now that we got rid of those Javist’s -those guys, are OK really- our guy Brendan was forced into some tech he wasn&#39;t into that much.</p><blockquote>Because… just like you wouldn&#39;t advise a surgeon about the tools he should use, nor you should do so to a programmer. They both are professionals, and your life is probably in their hands.</blockquote><h4>JavaScript — danger ahead</h4><p>It’s also worth noting that JavaScript is incredibly unsafe, as it doesn’t have a type system. Since over 80% (actual fake number) of your app is in libraries, your errors point to a rabbit hole, where the only thing you can find is the corpse of the aforementioned murdered Javist’s dog and some “babeled” code that causes cancer. (Babel is awesome btw, but this is the part of the article where I hate- later I also skate)</p><blockquote>There are probably more issues with the language, but alas, the story continues</blockquote><h3>Two Halves of Brendan&#39;s Brain</h3><p>So, as we established earlier, OOP wasn&#39;t quite ‘it’ in JavaScript and nobody cared, in my opinion. JavaScript was barely used back in the day. It was called “just a scripting language”. So what was it that Brendan meant the language to be used for?</p><blockquote>Let’s investigate him…</blockquote><p>Now for the part of the language that always tickled my brain in a good way. The language has functions as a “first class citizen”- meaning, you can pass functions around as a value. This more “statement — like” part of the language grew over previous ECMAscript(that&#39;s JavaScript) versions.</p><p>Methods like .filter .map .reduce weren’t in there until ES5. Nor were Arrow functions, spread operators, destructuring, (hopefully) incoming pipe operator, and much more sexy stuff.</p><p>So now there was a conflict over OOP vs Functional, I guess. Functional features weren’t really that supported until recently, but there was always some kind of “special” place for them in Java.script.</p><p>And here lies the ultimate contradiction. The place of dualism and confrontation. The place of fights like Angula vs Rect.</p><blockquote>Keep reading to be teleported to future.</blockquote><h3>The Future</h3><p>You have been teleported to future.</p><p>Now. Since you have been teleported to the future, let&#39;s talk.</p><p>In order to fully understand the current JavaScript identity, you have to go to the past.</p><h3>The Past</h3><p>Back to seriousness.</p><p>No doubt we can see several trends in how JavaScript grows.</p><p>It&#39;s…</p><h4>Very Community Driven</h4><p>This is probably the biggest strength JavaScript currently has. Sure it shall fade slightly as more interesting alternatives emerge(Web Assembly?). However, that doesn’t mean JavaScript will die. It simply means that it’ll reach its stable phase, where Java currently is.</p><h4>Heading Towards FP</h4><p>As we read new proposals for ES8, there certainly is some functional feel. For example the pipe operator (pls?). But from JavaScript&#39;s very nature, in a place where almost everything is a side effect, it can&#39;t reach, for example, Haskell in its pureness.</p><p>I believe some kind of sub-pattern is merging where functional meets with event driven environments, object oriented heritage, async nature and maybe even observables.</p><p>In this regard, JavaScript is one of those languages that pushes the border, propagates innovation and drives people mad.</p><h4>Browsers</h4><p>I&#39;ll make few very bold predictions. Feel free to disagree.</p><p>Browsers will get somehow more integrated into the system, allowing us to utilise their capabilities. Most applications are web apps or mobile apps, while desktop applications are deprecated.</p><p>Another potential direction, as broadband improves, is the possibility to share like 99% of our app with the cloud, and stream the users “desktop” in a similar way; Nvidia currently offers such a service for GPUs.</p><h3>The end of Brendan&#39;s Madness</h3><p>I’m not sure what JavaScript is supposed to be. I’m highly irritated, yet drawn in by what it is now. But the language is going to go its own way, consequently robbing other languages of ideas.</p><p>Somehow, we ended up tolerating the bad parts of the language. We don’t use them anyways. We embrace them, for the legacy of the ancient trollage back in the 90’s.</p><blockquote>What Brendan sowed, wasn&#39;t what he reaped. In the end I think he can be proud that his dualistic madness lives it&#39;s own life, both irritating and seducing yet more and more innocent young men (and women).</blockquote><p>To conclude, I&#39;d like to ask you to write down in the comments what features you love about other languages, and why it could be good in JavaScript.</p><p>Also, let me know if there’s another tale you’d prefer ruined by my interpretation next time.</p><p>Thanks for the readage you just delivered.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6cff2fd3757" width="1" height="1" alt=""><hr><p><a href="https://medium.com/blueberry/javascript-the-puberty-of-brendons-child-6cff2fd3757">JavaScript — The Puberty of Brendan’s Child</a> was originally published in <a href="https://medium.com/blueberry">Blueberry</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Invading Functional Realms — Functors]]></title>
            <link>https://medium.com/blueberry/invading-functional-realms-functors-92e8dc85c2c2?source=rss-430239092e1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/92e8dc85c2c2</guid>
            <category><![CDATA[haskell]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[functor]]></category>
            <dc:creator><![CDATA[Albert Nemec]]></dc:creator>
            <pubDate>Mon, 10 Jul 2017 13:37:04 GMT</pubDate>
            <atom:updated>2017-07-17T14:14:23.446Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*hS2D9Lo9qW_C4EFhLn9snw.png" /></figure><p><a href="http://www.crockford.com/">Douglas Crockford</a> once said that monads are cursed in the way that, “Once someone learns what monads are and how to use them, they lose the ability to explain it to other people.” Many have tried to break this curse and created resources that do a reasonably good job of explaining them to people that don’t know much about functional programming- the place from which the concept of monads came.</p><p>Honestly, knowing how monads work is almost useless, as you&#39;d still miss the context of the world behind it. Understanding problems of this “functional” world will allow you to understand how monads solve them.</p><p>So let&#39;s talk about <strong>functors, </strong>which are basically simpler form of monads.</p><p>It’s worth mentioning that I won’t be showing here much code, because we want to understand the concept. Specific implementations differ and are easier to grasp once you understand the basic ideas.</p><h3>What will be covered</h3><p>We will take a tiny glimpse into Haskell to see the place where functors and a great part of functional world we born. Don&#39;t worry, I&#39;ll try to keep Haskell on a leash so you&#39;re safe from it&#39;s superiority.</p><p>Then we&#39;ll talk about types, because after all, a functor is a type class in Haskell. Also, we&#39;ll investigate what functors are good for, and how are they implemented. At the end, I&#39;ll be the dick in the room and expose you to some theory of mathematical laws that apply to functors. However, I&#39;ll try to keep it light, on that end.</p><p>I should probably note that although I&#39;ll try to keep this series as language-neutral as possible comparing functional and nonfunctional approaches, I&#39;m a Javascript guy after all, thus I&#39;ll be probably view it from that perspective.</p><h3>Target Audience</h3><p>I mentioned that this article is even for forloopers- so who is a forlooper? As I see it, a forlooper is a unexperienced programmer that finds great joy in usage of for loops; ‘if’ statements and other cornerstones of many programming languages.</p><p>What’s wrong with loops, you may ask. Nothing, really, but I’ll refer you to an <a href="https://www.youtube.com/watch?v=o8NPllzkFhE">interview Linus Torvalds gave on TED</a> in which he tries to explain what he thinks elegant code is, and what isn’t. I don’t want to go too deep in this, but I think many can agree that methods like <em>map</em>,<em> reduce, filter </em>or even<em> list comprehensions </em>are more readable and elegant than having loops everywhere. And if you can remove the ‘if’ statement from a function, it is a win in terms of complexity.</p><p>You should know what a function is, recognise basic data types like arrays, lists, objects etc, and that’s pretty much it.</p><h3>Why should you care?</h3><p>Well, although functors sound like they are this very fancy and extremely complicated topic for academics only, I believe that they are actually quite simple, and knowing how the concept works can make you a better programmer- regardless of whether you code in Javascript, or Haskell itself.</p><h3>Let’s start basic</h3><p>In languages that natively support expressive data types, monads, functors, applicative functors, and more, are just a data type.</p><blockquote>If you already know what functors and monads are and have objections to what I just said, calm down please. I have a plan.</blockquote><p>Just like arrays, objects, maps and lists are bit fancier and more complicated than, for example, integers.</p><p>Integer’s are probably the most basic data type you can think of, so let’s start with them. There’s nothing too special about them, they pretty much just inform a computer that it should be possible to add, subtract, and multiply, and that they represent something. What do they represent? Well, one can’t know for sure. Say we have an integer with a value of 42. What does it mean? We don’t know. It could be the number of matches you played this season on Hearthstone. It could be the amount of lives you have in a game, or even the number of customers you have stored in your database.</p><p>The thing is that without a provided context, the computer doesn’t know. Only the programmer knows, and we have to rely on the fact that he had a coffee today, and will work with that information correctly.</p><p>In many cases, a single integer can say only so much. Let’s say we want to hold many integers, and note that there is some kind of logical connection between them. We need to group them so we don’t need to remember that variables <em>user_one</em>, <em>user_two</em> and <em>user_three </em>are related.</p><p>Thank God we have arrays (or lists, if you will). This “Master-Type” doesn’t add more data to those integers. It just informs us that we have more values, and that there is some specific meaning when they are together.</p><p>And mate, we’ve just got ourselves a <strong>functor</strong>.</p><h3>The funniest data type — Functors</h3><p>Just to provide some context, <strong>every monad is also a functor</strong> (but not every functor is a monad).</p><p>Functor’s aren’t exactly a data type. It’s more like a type class, because functor can have many forms. I don’t want to get too much into type classes as they are chapter unto themselves, and this article would get too Haskellish, but you can picture it like this…</p><blockquote><strong>Briefly about Type Classes</strong></blockquote><blockquote>In most languages we can express number in many ways. For example a double (like 21.3) and int (like 8) are both numbers, yet not every number is a for example a double. The fact that both doubles and Ints are numbers ensures us programmers that they support methods like addition and subtraction, yet in some cases they can behave differently. So here, “number” could be a type class, ensuring us we can use common operators and for example “int” is a data type, that is an instance of “number” class. So now we know, we can operate on these, but we can’t expect it to have decimal numbers.</blockquote><p>So you can see functor as a construct that “stores” data, and by the specific way it stores it, we can presume some additional information (context). Just like array informs us that it stores some data, and the data makes some sense while grouped together.</p><p>A common way to check if a structure is a functor is by asking ourselves if it makes sense to use <strong>map</strong> function on it. Ignoring the fact that <strong>map </strong>function does iterations (which applies only to functors that have more than one value in it), we can describe it as a function that grabs a value that is stored <strong>inside a container</strong>, does some transformations, and puts the transformed data back in the container.</p><p>This is an extremely important concept when it comes to functors, monads and applicative functors.</p><p><strong>The pulling a value from a functor</strong> (for example array), <strong>transforming it and returning it back into a container</strong> (you can replace the word container with a word context, because the container does nothing more than provide additional information about what it stores) is the key to the world of functors, and is often called “<strong>flatmapping</strong>”. In functional languages, people get confused about the difference between <strong>map</strong> and <strong>fmap</strong> functions. Although they perform a similar job, <strong>fmap </strong>is more generic, as you can use it on <strong>any functor, </strong>not just arrays.</p><h3>Some functors</h3><p>Okay, so we know that an array is a functor, and you might think that’s pretty much it. Well not at all! In functional languages like Haskell, we have much more, and the mind-blowing part is that these special and cool functors can be constructed in, for example, Javascript with the functionality that the language already provides.</p><blockquote>Fun fact : Actually, promises in Javascript behave very much like a functor. As the “then” part basically grabs a value from a container (the promise), does some transformations (in fetch, it often is .json func) and then returns the promise with a new value.</blockquote><p>Let’s list some common functors…</p><h3><strong>I said Maybeeeee</strong></h3><p>I can imagine that a maybe type sounds like a term borrowed from quantum mechanics, but it’s actually really simple. <em>Maybe </em>is very similar to<em> array</em>, just instead of storing many values, it stores just one, and the fact it is boxed inside a maybe wrapper informs us that there might be nothing, <strong>OR</strong> the value we expect.</p><p>For example, when we fetch some data over the Internet thing, we might get the JSON we wanted, but it might happen that we will fetch nothing, as no one really knows if the internet thing will actually work (the server might be down, or cosmic waves might strike and interrupt the transmission). By the fact we wrap this response data in the maybe structure, we are acknowledging that this possible failure can occur and prepare ourselves for the fact that we’ll have to handle something later.</p><p>If it’s still hard for you to imagine a maybe value, try to imagine it as an array that holds only one value, and that value can be undefined ( nil, null or whatever you want to call it).</p><p>The fact we are aware of this possible failure means we WILL handle both cases, because at the time you write your code, the computer doesn’t know which of those two cases is hidden inside your structure, so it will require you to handle both scenarios.</p><p>The question is tho, why is maybe a functor? Well, just like with array, we can use <strong>map </strong>function, because what <strong>map</strong> does is pull a value from a container, do some transformation and return the value back into the context. Maybe is just a container, nothing more. We just call it a maybe container so we later know that it could go bad.</p><p>Scenarios in which maybe can be useful are, for example, when we are getting some value from an object (or map, hashtable … depends on the language). It is theoretically possible to get a key value pair, that isn’t there (resulting in storing undefined or nil value instead of those juicy strings), so we acknowledge this fact by wrapping what we got from an object with a maybe container.</p><h3><strong>Either you understand or you don’t</strong></h3><p>Another common functor is ‘either’. It is this container that can contain two possible values. For example, either it contains true or false. By wrapping it inside an either box, we are preparing ourselves for both cases being possible, and thus we shouldn’t forget to handle both cases.</p><p>As you can see, it’s nothing too crazy; it just serves the purpose of documenting our data.</p><h3>Tuples and others</h3><p>As you can imagine, the tuple data type is also a functor as it’s a container for some other data.</p><p>Note that in languages like Haskell, you can create your own functors that can describe whatever context and contain whatever data.</p><p>You can create a functor that always contains, for example, an integer, and also some string that describes what operations were done to the integer. This behaves like a descriptive console.log (or print, or whatever).</p><p>Also, for these custom made functors you can define custom made functions like <strong>map</strong>, <strong>filter</strong> and <strong>reduce </strong>or even <strong>bind, </strong>which is the monad function.</p><h3>But why?</h3><p>Maybe it ain’t obvious, but the concept of providing additional information about your data is extremely powerful and useful.</p><p>Let’s say that every single operation that can go wrong returns a maybe value. Since the maybe value is both undefined and both some value (at least while you’re writing code, you see it that way), you are forced to handle both cases every time. So, as you eliminate every possibility for your operations going wrong, your code can’t have bugs :-)</p><p>Well not really.. one can never completely exterminate bugs, but it certainly helps as it’s making your code less error-prone and you’re providing documentation to your data as you work with it. And that’s just a type system, ladies and gents.</p><h3>The Law</h3><p>How do we know that a functor is a functor? Sure we gained some intuition, but we should be able to draw a clean line between functors and non-functors. The answer is yes, and for that we have functor laws. This is what they look like.</p><pre>Functor.map(identity) == Functor</pre><pre>Functor.map(x =&gt; func_2(func_1(x))) == Functor.map(func_1).map(func_2)</pre><p>Let’s talk about it. What is that identity variable we are passing as an argument in the first law? It’s nothing more than a function that takes 1 argument, and without any transformation, returns it.</p><p>Makes sense, because if you pass a non-functor like a integer into map, then the result won’t be the original number unchanged: it will break. So will the law, and thus it ain’t a functor.</p><p>So the first law states that if you pass a functor to map function accompanied by identity function, the original functor has to be returned.</p><p>What about the second law? It states that we can either transform a functor with 2 different functions twice, or transform it just once, but with the 2 functions combined into one.</p><h3>Wrapping up Functors</h3><p>So that’s pretty much it for functors.</p><p>The important part is that a functor is a type class that can have many manifestations (like array or maybe), and behaves like a container for inner data, providing additional information about the data.</p><p>So, with the knowledge you just gained, I’m pretty sure that functional languages just became at least 50% easier for you to grasp. Stay tuned for another sieges on Functional citadels.</p><p>PS: Please, if there&#39;s anything you think I got wrong or you&#39;re not quite sure what I meant by something, spam the shit out of the comments and I&#39;ll try to answer it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=92e8dc85c2c2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/blueberry/invading-functional-realms-functors-92e8dc85c2c2">Invading Functional Realms — Functors</a> was originally published in <a href="https://medium.com/blueberry">Blueberry</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>