<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Last Ent's Thoughts (Posts about programming)</title><link>https://last-ent.com/</link><description></description><atom:link href="https://last-ent.com/categories/programming.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><copyright>Contents © 2026 &lt;a href="mailto:blog@last-ent.com"&gt;Ent&lt;/a&gt; </copyright><lastBuildDate>Wed, 07 Jan 2026 16:10:23 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>FP for Sceptics: Intuitive guide to map/flatmap</title><link>https://last-ent.com/posts/intuitive-map-flatmap/</link><dc:creator>Ent</dc:creator><description>&lt;figure&gt;&lt;img src="https://last-ent.com/images/fmap/map.png"&gt;&lt;/figure&gt; &lt;div&gt;&lt;h2&gt;Backbone of Functional Programming&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;map&lt;/code&gt; &amp;amp; &lt;code&gt;flatmap&lt;/code&gt; form the backbone of Functional Progamming. It is very important be comfortable with these two concepts and this guide will help you develop an intuition for them.&lt;/p&gt;
&lt;p&gt;This guide is language agnostic but I expect you to be familiar with basic programming concepts like functions, types, data type/objects and list. &lt;/p&gt;
&lt;h3&gt;Nomenclature&lt;/h3&gt;
&lt;p&gt;Let me introduce you to some basic terms we will be using to talk about &lt;code&gt;map/flatmap&lt;/code&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Type&lt;/code&gt;s are data constructs and they can be &lt;code&gt;Basic Types&lt;/code&gt; like Int, String etc.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Container&lt;/code&gt; is a special &lt;code&gt;type&lt;/code&gt; which contains another &lt;code&gt;type&lt;/code&gt;. For example a List of Ints.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Function&lt;/code&gt; is a function whose input is of Type 1 and output is of Type 2. Type 1 &amp;amp; Type 2 can be same type.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Visualize&lt;/h3&gt;
&lt;p&gt;Though I have defined three terms it will be easier to think about them visually.&lt;/p&gt;
&lt;h4&gt;&lt;code&gt;Basic types&lt;/code&gt; (Int, String etc) will be represented by shapes&lt;/h4&gt;
&lt;p&gt;&lt;img alt="Basic Types" src="https://last-ent.com/images/fmap/basic-types.png"&gt;.&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;&lt;p&gt;&lt;a href="https://last-ent.com/posts/intuitive-map-flatmap/"&gt;Read more…&lt;/a&gt; (9 min remaining to read)&lt;/p&gt;&lt;/div&gt;</description><category>FP for sceptics</category><category>functional programming</category><category>programming</category><category>software design</category><guid>https://last-ent.com/posts/intuitive-map-flatmap/</guid><pubDate>Thu, 19 Nov 2020 18:03:25 GMT</pubDate></item><item><title>Visual guide to polling in Functional Programming (Scala)</title><link>https://last-ent.com/posts/polling-in-fp/</link><dc:creator>Ent</dc:creator><description>&lt;figure&gt;&lt;img src="https://last-ent.com/images/poll-st-3.png"&gt;&lt;/figure&gt; &lt;div&gt;&lt;p&gt;In this post, let's look at how to poll a system using a Stream.&lt;/p&gt;
&lt;p&gt;To make it easier/interesting, I will explain it using a visual approach.&lt;/p&gt;
&lt;p&gt;Let's use the following problem statement.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;We have API for a queue&lt;sup id="fnref:0"&gt;&lt;a class="footnote-ref" href="https://last-ent.com/posts/polling-in-fp/#fn:0"&gt;2&lt;/a&gt;&lt;/sup&gt; that can be queried using &lt;code&gt;pollFn&lt;/code&gt; function.&lt;/li&gt;
&lt;li&gt;We need to process data returned by queue using &lt;code&gt;process&lt;/code&gt; function.&lt;/li&gt;
&lt;li&gt;There may or may not be data at the time of querying.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="https://last-ent.com/posts/polling-in-fp/"&gt;Read more…&lt;/a&gt; (5 min remaining to read)&lt;/p&gt;&lt;/div&gt;</description><category>functional programming</category><category>programming</category><category>scala</category><category>software design</category><guid>https://last-ent.com/posts/polling-in-fp/</guid><pubDate>Sun, 26 Jul 2020 15:55:41 GMT</pubDate></item><item><title>FP for Sceptics: Option Type in Practice</title><link>https://last-ent.com/posts/option-type-in-practice/</link><dc:creator>Ent</dc:creator><description>&lt;div&gt;&lt;p&gt;In &lt;a href="https://last-ent.com/posts/introduction-to-option-type/"&gt;previous post&lt;/a&gt; we defined FP &amp;amp; error handling&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Functional Programming (FP) is based around mathematical concepts like &lt;strong&gt;Type Theory&lt;/strong&gt; - &lt;em&gt;We define our system in terms of ADTs, data flow &amp;amp; functions.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;FP promotes using types for error handling&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Option&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Either&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Monad&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;etc.&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;p&gt;Previous post also explained &lt;code&gt;Option&lt;/code&gt; type and how it works.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://last-ent.com/posts/adts-in-practice/"&gt;ADTs in Practice&lt;/a&gt; took a practical system&lt;sup id="fnref:1"&gt;&lt;a class="footnote-ref" href="https://last-ent.com/posts/option-type-in-practice/#fn:1"&gt;1&lt;/a&gt;&lt;/sup&gt; and designed ADTs for it.&lt;/p&gt;
&lt;p&gt;In this post, we will reuse the same system but try to figure out where &lt;code&gt;Option&lt;/code&gt; type makes most sense to use.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Option Type: Where to use it?" src="https://last-ent.com/images/option-practice-title.png"&gt;&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;&lt;p&gt;&lt;a href="https://last-ent.com/posts/option-type-in-practice/"&gt;Read more…&lt;/a&gt; (5 min remaining to read)&lt;/p&gt;&lt;/div&gt;</description><category>FP for sceptics</category><category>functional programming</category><category>programming</category><category>scala</category><category>software design</category><guid>https://last-ent.com/posts/option-type-in-practice/</guid><pubDate>Mon, 29 Jun 2020 16:00:00 GMT</pubDate></item><item><title>FP for Sceptics: Introduction to Option Type</title><link>https://last-ent.com/posts/introduction-to-option-type/</link><dc:creator>Ent</dc:creator><description>&lt;div&gt;&lt;p&gt;Functional Programming (FP) is based around mathematical concepts like &lt;strong&gt;Type Theory&lt;/strong&gt; - &lt;em&gt;We define our system in terms of ADTs, data flow &amp;amp; functions&lt;sup id="fnref:0"&gt;&lt;a class="footnote-ref" href="https://last-ent.com/posts/introduction-to-option-type/#fn:0"&gt;1&lt;/a&gt;&lt;/sup&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;We first implement "Happy Path" and then implement handlers for "Unhappy Path" (error handling). In &lt;a href="https://last-ent.com/posts/adts-in-practice"&gt;&lt;code&gt;ADTs in Practice&lt;/code&gt;&lt;/a&gt; we used "Exceptions" (&lt;code&gt;IO.raiseError&lt;/code&gt;) for error handling.&lt;/p&gt;
&lt;p&gt;However FP promotes using types for error handling, such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Option&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Either&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Monad&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;etc.&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In this post we will start by looking at the simplest of these:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;Option&lt;/code&gt; type denotes presence (&lt;code&gt;Some(value)&lt;/code&gt;) or absence (&lt;code&gt;None&lt;/code&gt;) of a value.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;img alt="Option has Some(value) &amp;amp; None. What are two ways of using it?" src="https://last-ent.com/images/option_title.png"&gt;

&lt;/p&gt;&lt;p&gt;&lt;a href="https://last-ent.com/posts/introduction-to-option-type/"&gt;Read more…&lt;/a&gt; (4 min remaining to read)&lt;/p&gt;&lt;/div&gt;</description><category>FP for sceptics</category><category>functional programming</category><category>programming</category><category>scala</category><category>software design</category><guid>https://last-ent.com/posts/introduction-to-option-type/</guid><pubDate>Sun, 31 May 2020 22:38:34 GMT</pubDate></item><item><title>FP for Sceptics: ADTs in Practice</title><link>https://last-ent.com/posts/adts-in-practice/</link><dc:creator>Ent</dc:creator><description>&lt;div&gt;&lt;p&gt;In &lt;a href="https://last-ent.com/posts/introduction-to-adts"&gt;previous post&lt;/a&gt; we defined ADTs as&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Algebraic Data Types (or ADTs) model the flow of a program (or a system) in terms of data &amp;amp; functions that describe the complete behaviour and states the data can go through.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;In this post, we will work through defining ADTs for an API service.&lt;/p&gt;
&lt;p&gt;&lt;img alt="How to design ADT for a request-response flow?" src="https://last-ent.com/images/adt-server.png"&gt;&lt;/p&gt;
&lt;p&gt;API service will return User's Information by:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Extracting user id &amp;amp; password from the request&lt;/li&gt;
&lt;li&gt;Checks them against an authorization service&lt;/li&gt;
&lt;li&gt;Retrieves User's Information from database&lt;/li&gt;
&lt;li&gt;Returns User Information in response&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;/p&gt;&lt;p&gt;&lt;a href="https://last-ent.com/posts/adts-in-practice/"&gt;Read more…&lt;/a&gt; (3 min remaining to read)&lt;/p&gt;&lt;/div&gt;</description><category>FP for sceptics</category><category>functional programming</category><category>programming</category><category>scala</category><category>software design</category><guid>https://last-ent.com/posts/adts-in-practice/</guid><pubDate>Sun, 24 May 2020 15:50:02 GMT</pubDate></item><item><title>FP for Sceptics: Introduction to ADTs (Algebraic Data Types)</title><link>https://last-ent.com/posts/introduction-to-adts/</link><dc:creator>Ent</dc:creator><description>&lt;figure&gt;&lt;img src="https://last-ent.com/images/adt-flow.png"&gt;&lt;/figure&gt; &lt;div&gt;&lt;blockquote&gt;
&lt;p&gt;Algebraic Data Types (or ADTs) model the flow of a program (or a system) in terms of data &amp;amp; functions that describe the complete behaviour and states the data can go through.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Let's take an example to grok the concept better.&lt;/p&gt;
&lt;h2&gt;Example: Area of a rectangle&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;Calculate the area of a rectangle from a list of positive integers&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Here's a possible algorithm:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Take a list of integers (positive &amp;amp; negative)&lt;/li&gt;
&lt;li&gt;Filter for positive integers ie., remove negative integers&lt;/li&gt;
&lt;li&gt;Create pairs from the filtered list&lt;/li&gt;
&lt;li&gt;Apply equation for area of rectangle&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;/p&gt;&lt;p&gt;&lt;a href="https://last-ent.com/posts/introduction-to-adts/"&gt;Read more…&lt;/a&gt; (3 min remaining to read)&lt;/p&gt;&lt;/div&gt;</description><category>FP for sceptics</category><category>functional programming</category><category>programming</category><category>scala</category><category>software design</category><guid>https://last-ent.com/posts/introduction-to-adts/</guid><pubDate>Mon, 13 Apr 2020 22:31:05 GMT</pubDate></item><item><title>Elegance of Monadic Composition</title><link>https://last-ent.com/posts/elegance-of-monadic-composition/</link><dc:creator>Ent</dc:creator><description>&lt;figure&gt;&lt;img src="https://last-ent.com/images/donatron-io.png"&gt;&lt;/figure&gt; &lt;div&gt;&lt;p&gt;Functional programming has many interesting concepts but it can be hard to find practical applications for it in everyday work. In this post, I will explain how Monadic Composition can be used write elegant and easy to understand code.&lt;/p&gt;
&lt;p&gt;Consider an API &lt;code&gt;Donatron&lt;/code&gt; that accepts donations. The API's algorithm is as follows:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Accepts donations as list of strings&lt;/li&gt;
&lt;li&gt;Should have a few valid integer donations&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Else&lt;/strong&gt; goto &lt;code&gt;6&lt;/code&gt;. &lt;strong&gt;Response&lt;/strong&gt;: &lt;code&gt;No Valid Ints&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Should have a few donations of value 10 or above&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Else&lt;/strong&gt; goto &lt;code&gt;6&lt;/code&gt;. &lt;strong&gt;Response&lt;/strong&gt;: &lt;code&gt;No Acceptable Donations Found&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Valid donations to external service should succeed&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Else&lt;/strong&gt; &lt;code&gt;RuntimeException&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Log all accepted submissions&lt;/li&gt;
&lt;li&gt;Log Response&lt;/li&gt;
&lt;li&gt;Return Response&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;End goal is to be able to execute &lt;code&gt;Donatron.donate&lt;/code&gt; function and get correct response.&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;&lt;p&gt;&lt;a href="https://last-ent.com/posts/elegance-of-monadic-composition/"&gt;Read more…&lt;/a&gt; (5 min remaining to read)&lt;/p&gt;&lt;/div&gt;</description><category>functional programming</category><category>programming</category><category>scala</category><category>software design</category><category>type driven development</category><guid>https://last-ent.com/posts/elegance-of-monadic-composition/</guid><pubDate>Sat, 02 Nov 2019 03:19:08 GMT</pubDate></item><item><title>Elements of Coding Style</title><link>https://last-ent.com/posts/elements-of-coding-style/</link><dc:creator>Ent</dc:creator><description>&lt;div&gt;&lt;h2&gt;Rules of Software Engineering&lt;/h2&gt;
&lt;p&gt;There are three important rules in Software Engineering.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Rule 1: Easy to understand&lt;/strong&gt;. Anyone should be able to pick up the code and start working on it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Rule 2: Easy to debug&lt;/strong&gt;. If the code breaks, it should be easy to quickly investigate &amp;amp; identify where is the issue.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Rule 3: Shipping is the most important feature&lt;/strong&gt;. No matter how correct or elegant your code is, if you can't ship working code on time then why bother?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Having said that, &lt;code&gt;Rule 3&lt;/code&gt; should rarely be in opposition to &lt;code&gt;Rule 1 &amp;amp; 2&lt;/code&gt;. If you have to veto &lt;code&gt;Rule 1 &amp;amp; 2&lt;/code&gt; to ship your feature, then something's horribly wrong in your code &amp;amp; process. Complexity in code is a given and it is an engineer's responsibility to figure out how best to contain the damage and stop it from affecting the rest of the system.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Less elegant yet easy to understand &amp;amp; easier to debug should be the minimum expectation from all code shipped.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;
&lt;/p&gt;&lt;p&gt;&lt;a href="https://last-ent.com/posts/elements-of-coding-style/"&gt;Read more…&lt;/a&gt; (3 min remaining to read)&lt;/p&gt;&lt;/div&gt;</description><category>enterprise software development</category><category>musings</category><category>programming</category><category>software engineering</category><guid>https://last-ent.com/posts/elements-of-coding-style/</guid><pubDate>Sun, 15 Sep 2019 09:04:43 GMT</pubDate></item><item><title>Type Driven Development</title><link>https://last-ent.com/posts/type-driven-development/</link><dc:creator>Ent</dc:creator><description>&lt;figure&gt;&lt;img src="https://last-ent.com/images/shopping.png"&gt;&lt;/figure&gt; &lt;div&gt;&lt;h2&gt;Introduction&lt;/h2&gt;
&lt;p&gt;In our project workflow, we break down features to implement into tickets and developers pick them off one by one; Pretty standard &amp;amp; typical Agile/Kanban workflow. However while working on a feature recently, we came across on an interesting problem where our standard workflow didn't work out. Rather than trying to explain it in vague terms, I am going to start with a story.&lt;/p&gt;
&lt;h3&gt;TLDR&lt;/h3&gt;
&lt;p&gt;In case you don't want to dive in just yet, here is the idea we will cover in this post.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Think about the behaviour of your program in terms of data types &amp;amp; functions signatures. Next step is to &lt;code&gt;prove&lt;/code&gt; or &lt;code&gt;derive&lt;/code&gt; a function that composes all of the types &amp;amp; signatures to implement the feature. Then carry on to implement each of the individual functions with the guarantee that all functions will compose together.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;
&lt;/p&gt;&lt;p&gt;&lt;a href="https://last-ent.com/posts/type-driven-development/"&gt;Read more…&lt;/a&gt; (11 min remaining to read)&lt;/p&gt;&lt;/div&gt;</description><category>functional programming</category><category>programming</category><category>scala</category><category>software design</category><category>type driven development</category><guid>https://last-ent.com/posts/type-driven-development/</guid><pubDate>Sun, 08 Sep 2019 14:11:55 GMT</pubDate></item><item><title>Cats Effect's IO</title><link>https://last-ent.com/posts/cats-effects-io/</link><dc:creator>Ent</dc:creator><description>&lt;p&gt;Cats Effect's Fibers/IOs run on a thread pool created over VM. They are essentially Green Threads that are created over the thread pool. Unlike async frameworks, IO.flatmaps does not include _asynchronous boundary. This means that essentially all of nested flatmaps are run within a single fiber. IO has mechanism to introduce asynchronous boundary but this has to be done manually by the developer via IO.shift. Operations such as race, parMapN or parTraverse inherently introduce asynchronous boundary.&lt;/p&gt;
&lt;p&gt;~ 14th May, 22:11&lt;/p&gt;</description><category>programming</category><category>scala</category><guid>https://last-ent.com/posts/cats-effects-io/</guid><pubDate>Mon, 12 Aug 2019 18:44:38 GMT</pubDate></item></channel></rss>