<?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 Fareed on Medium]]></title>
        <description><![CDATA[Stories by Fareed on Medium]]></description>
        <link>https://medium.com/@fareedmahar6?source=rss-8ec258d6d4e9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*UsIyLi6iguVjGb0c8K5gIA.jpeg</url>
            <title>Stories by Fareed on Medium</title>
            <link>https://medium.com/@fareedmahar6?source=rss-8ec258d6d4e9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 17:25:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fareedmahar6/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[Time-ticking bombs in FP Programming while working with streams.]]></title>
            <link>https://medium.com/@fareedmahar6/time-ticking-bombs-in-fp-programming-while-working-with-streams-504af783409a?source=rss-8ec258d6d4e9------2</link>
            <guid isPermaLink="false">https://medium.com/p/504af783409a</guid>
            <dc:creator><![CDATA[Fareed]]></dc:creator>
            <pubDate>Tue, 13 Dec 2022 00:28:42 GMT</pubDate>
            <atom:updated>2022-12-13T00:35:59.027Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RGCvVxnjhIiPw-nXuGWkYg.jpeg" /></figure><p>We Programmers seldom think about the consequences of writing a code snippet like this in a functional style and may not even notice if some race condition may occur.</p><p>Example 1:</p><pre>private List&lt;String&gt; performSomeImpureOperationOnName(List&lt;String&gt; names) {<br><br>        return names.stream()<br>                .map(this::performImpureOperation) //Bad Idea.<br>                .collect(Collectors.toList());    <br>    }</pre><p>Example 2:</p><pre>private List&lt;String&gt; getNamesWithSpecifiedLength(List&lt;String&gt; names) {<br>        List&lt;String&gt; namesWithLengthThree = new ArrayList&lt;&gt;();<br><br>        names.stream()<br>                .filter(name -&gt; name.length() == 3)<br>                .forEach(namesWithLengthThree::add); //Bad Idea and Good to have collect(Collectors.toList())<br><br>        return namesWithLengthThree;<br>    }</pre><p>Such types of snippets will be there lingering around for a very long time if we don’t have significant code reviews in practice and we may not even notice until a while that these are time-ticking bombs and when they can explode.</p><p>Still, wrinkling your nose what is so bad with the above snippets.?</p><blockquote><em>The problems with the above snippets</em></blockquote><ul><li>The functional pipeline is not pure.</li><li>We are doing shared mutability and the result may be unpredictable if we ever add <strong><em>names.stream().parallel()</em></strong></li></ul><p>So this is where we should carefully examine the functional style code and flag these things immediately, as it&#39;s very unpredictable that you run the code for a very long time and never see an error until one day it blows up in production and even you can not reproduce it easily even after running it several times.</p><p>So this is an Anti-Pattern that we should try to avoid, In a nutshell, a functional pipeline has to be extremely pure.</p><blockquote>Wondering? What this purity actually mean.?</blockquote><blockquote>What is pure function.?</blockquote><blockquote>A pure function is idempotent, it returns the same result for the same input, and does not have any <strong>side-effects</strong>.</blockquote><p>There are essentially two points that need to be kept in mind and are absolutely necessary.</p><ol><li>It does not change any state that is visible outside which is obvious.</li><li>It does not depend on anything that possibly may change.</li></ol><p><strong>Conclusion</strong></p><p>Purity is extremely important when it comes to dealing with such kinds of code snippets because it can be very treacherous if we are not careful about it, So always look for the mutation in your functional pipeline deep down being performed in some function.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=504af783409a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>