Adding superpowers to a custom type

In modern Android and with the advent of Kotlin, functional programming is integrating into our everyday code bit by bit. Do we take full advantage of this paradigm though? In this article, I will explain, how a relative common nowadays type like Result<T> can be “powered up” to become a monad and help via composition, to solve different problems.

What is a monad ❓
To begin with, let us see what a monad is. Wikipedia, states as a definition:

In functional programming, a monad is an abstraction that allows structuring programs generically. Supporting languages…

Or how the Tell, Don’t Ask Principle can help us express intent

An ink pen
An ink pen
“Storytelling is the most powerful way to put ideas into the world.” - Robert McAfee Brown

Software development nowadays is a complex process that while entailing many scientific aspects, it can also be seen as a form of art. Even rules and best practices aside, a piece of code will always mirror the mind, soul and creativity of the developer that created it. As such a developer can always benefit from borrowing elements and studying great masters, not only of Computer Science, but of other arts too, such as the art of storytelling. After all, a craftsman must keep honing their skills.

Programming and storytelling are very similar in nature. For example, both are expressed via…

George Theocharis

Passion driven software engineer with the mission to constantly provide value, while crafting a unique story along the way. Android developer at heart.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store