FP for Sceptics: Intuitive guide to map/flatmap

Backbone of Functional Programming

map & flatmap 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.

This guide is language agnostic but I expect you to be familiar with basic programming concepts like functions, types, data type/objects and list.


Let me introduce you to some basic terms we will be using to talk about map/flatmap.

  • Types are data constructs and they can be Basic Types like Int, String etc.
  • Container is a special type which contains another type. For example a List of Ints.
  • Function is a function whose input is of Type 1 and output is of Type 2. Type 1 & Type 2 can be same type.


Though I have defined three terms it will be easier to think about them visually.

Basic types (Int, String etc) will be represented by shapes

Basic Types.

Read more…

My Favourite Evening Snack

I know what you are thinking

I thought this was a programming blog, wtc is this? But hear me out!

Few weeks ago I saw a video by Matt D'Avella where he was talking a quick healthy snack and the part showed him putting a few dried corn kernels into a small vessel and after a few minutes, popcorn ready.

That intrigued me, to say the least.

I gave it a try and Yes, it's that simple.

Popcorn I made

A few things to keep in mind of course, so read on if it interests you.

Salted Popcorn

  1. Take a small iron pot. (Preferably with thich bottom)
  2. Add in some oil. (I used Olive Oil)
  3. Drop the kernels into the oil.
  4. Partially cover it with a lid.
  5. Wait for em to pop!
  6. Add in a bit salt (not too much!) and shake em around.

Movie Popcorn

Do you yearn for the popcorn we get at movies without the unhealthy side of it? Yes, you can make it at home.

  1. Take a small iron pot. (Preferably with thich bottom)
  2. Add in clarified butter. (Not normal butter) 3-6. Same as before.

Things to know

Why to partially cover the lid?

The kernels have some amount of moisture in them. By partially opening the lid, you let the water vapour out getting them crunchy.

Also the reason the kernels pop is because the moisture inside the kernels get super heated and need to vent out.

Why not normal butter?

If you heat normal butter for long, it starts burning. This is because of milk residue in the butter.

Also it has moisture in it causing popcorn to get soggy.

Don't use too much Oil!

If you add in too much oil, there is a chance the popcorn will get soggy (that was my experience).

Also the popcorn will smell & taste lot more of the oil used. While I love me some Olive Oil, too much on my popcorn feels weird.

Variation on Cooking Style

One variation I read online is to wait until the oil heats up sufficiently before putting in the kernels.

How do you know when the oil is ready? Put in a kernel or two at the start and wait for both of them to pop before you put in the rest.


So there you have it folks!

That's how I am now addicted to my evening popcorn.

Ent's snappy guide to Emacs


I have used many editors over time and one "System" that I really enjoyed was Emacs. However I did not understand how it worked under the hood and it led to some fun times. This post is an attempt to log my experience with learning and understanding the "missing bits" in a single place.

This guide is consolidation of knowledge & experience of 2-3 days of intense focus learning & modifying Emacs.


The aim of this guide is to quickly:

  • Bootstrap your understanding to a level where you can start thinking in terms Emacs' terminology and use that knowledge to searching the internet for new questions you might have.
  • Develop a rudimentary understanding of how to customize Emacs.
  • Setup an aesthically pleasing UI with usable setup.

This guide IS NOT about the basics of text editors like:

  • What are text editors? What is Emacs or Vim?
  • Which editor should I use?
  • How to navigate using either editor?
  • How to read/write elisp. I have a basic understanding of lisp/clojure but otherwise I haven't bothered with learning it for this.

Read more…

Second Static Website

Static Website Hosting

I really like the low footprint and utility of Static Websites. This website is built using Nikola.

In this post I will talk about some issues I faced with deploying a second static website and how I eventually solved it.

Github Pages

I have long enjoyed the awesomeness of User Github Pages and am quite happy with it.

However as soon as I tried to create a second independent static website with custom domain, Github was having nothing of it.

After spending lot of time scouring the web for how to make it work between Github & Namecheap, my DNS provider, I had nothing to show for it.

Read more…

Dependency Mock Server & Black Friday Preparation

Last year while preparing for Black Friday our team had an interesting challenge:

Some of our downstream services1 had proper setup to provide environments/APIs to load test.

This meant will have to configure our systems based on hopeful estimates based on last minute estimates and until then, we would could only sit idle. This wasn't appealing for obvious reasons of doing a hackjob and having a firefighting mode during Black Friday/Cyber Week.

Proposed Solution: Dependency Mock Server

The solution I came up with and which we used was to have a Mock Server that served endpoints similar to our dependencies and return dynamic responses based on request payload.

Server with Three Dependencies

Read more…

OT: Mapping thoughts, Memex & Zettelkasten.

Off Topic are posts where I talk about the human side of things.

Vannevar Bush, As We May Think

Have you read Vannevar Bush's article As We May Think? In that article he discusses an interesting concept:

"A System becoming an extension of human knowledge and memory which may be consulted with exceeding speed and flexibility."

Now this might not seem groundbreaking to us for we have Computers, Internet and Search Engines (Google, DDG, etc.). However it's important to know that Hypertext, which is the backbone of internet, was created thanks to the inspiration taken from Memex, which is the name of the system Bush proposed.

Read more…

Introducing Off Topic

I miss the days of yore,
where blogs had focus broad.
A mix of hobbies or talents varied,
a window into a person's psyche.

A journal of sorts where they write,
of things that spark their interests and delights.
Then came the internet of modern times,
that asked of everything, to be commercialized.

I protest, I detest,
this utilitarian web.
`Off Topic` is where,
I break this thread.

Visual guide to polling in Functional Programming (Scala)

In this post, let's look at how to poll a system using a Stream.

To make it easier/interesting, I will explain it using a visual approach.

Let's use the following problem statement.

  • We have API for a queue1 that can be queried using pollFn function.
  • We need to process data returned by queue using process function.
  • There may or may not be data at the time of querying.

    Read more…

FP for Sceptics: Option Type in Practice

In previous post we defined FP & error handling

Functional Programming (FP) is based around mathematical concepts like Type Theory - We define our system in terms of ADTs, data flow & functions.

FP promotes using types for error handling

  • Option
  • Either
  • Monad
  • etc.

Previous post also explained Option type and how it works.

ADTs in Practice took a practical system1 and designed ADTs for it.

In this post, we will reuse the same system but try to figure out where Option type makes most sense to use.

Option Type: Where to use it?

Read more…

FP for Sceptics: Introduction to Option Type

Functional Programming (FP) is based around mathematical concepts like Type Theory - We define our system in terms of ADTs, data flow & functions1.

We first implement "Happy Path" and then implement handlers for "Unhappy Path" (error handling). In ADTs in Practice we used "Exceptions" (IO.raiseError) for error handling.

However FP promotes using types for error handling, such as:

  • Option
  • Either
  • Monad
  • etc.

In this post we will start by looking at the simplest of these:

Option type denotes presence (Some(value)) or absence (None) of a value.

Option has Some(value) & None. What are two ways of using it?

Read more…