The Magic of Monads[Math Mondays]
A very useful concept. Don't worry no category theory required.
To learn more about the newsletter, check our detailed About Page + FAQs
To help me understand you better, please fill out this anonymous, 2-min survey. If you liked this post, make sure you hit the heart icon in this email.
Recommend this publication to Substack over here
Take the next step by subscribing here
Here comes an idea that gives a lot of people headaches,
But is extremely important if you want to write clean and readable code.
In this post/email, I will cover Monads. I won’t (can’t) give you a complete mathematical understanding of the term, since Monads are a term from category theory (also philosophy to those interested) and will thus require a lot of prior knowledge. I will teach you enough about Monads to use them in your programming journeys.
In category theory, a branch of mathematics, a monad (also triple, triad, standard construction and fundamental construction)[1] is a monoid in the category of endofunctors. An endofunctor is a functor mapping a category to itself, and a monad is an endofunctor together with two natural transformations required to fulfill certain coherence conditions. Monads are used in the theory of pairs of adjoint functors, and they generalize closure operators on partially ordered sets to arbitrary categories.
This is the Wikipedia Definition of a monad. Show this to anyone that wants to pursue a Math Major to show them what waits for them.
Warning. This can be a very theoretical discussion. I have linked two fantastic videos to give you a more ‘visual’ explanation. The first is more comprehensive, going over some of the details. The second is a lot shorter (lesser than 3 mins) and covers how you as a software dev can use Monads. I would suggest watching them if you have no experience with the concept.
Key Highlights
What… even- From a coding perspective, monads are simply a software engineering pattern. They are written for reusability, code reusability, and writing pipelines at scale.
Why do monads help- Before we talk about the details, I think always helps to understand why something exists in the first place. This helps contextualize the solutions better. Monads are amazing when you want to chain a lot of functions together. Typically you’d have to do a lot of error checking/input handling to make sure the output of one function can be usable as the input of another. This can lead to long and messy code. Monads help you by abstracting away the implementation details in one place, letting you write very clear chains of functions.
When to use monads- If you have a group of objects that behave in similar ways, then Monads become your best buds. Take inputs for a login form. You want them all to not be null, have certain lengths (length per input type can vary), come from a certain alphabet, etc. You can chain all the different behaviors into a monad, and reuse it whenever you have to authenticate a form.
The deets of Monads (101)- A monad is a type that wraps an object of another type (think of our input form monad which wraps individual input). Monads are capable of returning something wrapped in another monad, which allows you to chain a whole bunch of them together. This is a pretty great guide that covers a couple of examples to really help you master the monad implementation side.
If you struggle with this idea, don’t worry. This is a very hard idea to articulate. Fortunately, learning how to use this idea is not too hard. Just work through a few common examples and you will have a great understanding of how you can use these effectively.
This is the second, shorter one that is great for coders.
I created Technology Made Simple using new techniques discovered through tutoring multiple people into top tech firms. The newsletter is designed to help you succeed, saving you from hours wasted on the Leetcode grind. I have a 100% satisfaction policy, so you can try it out at no risk to you. You can read the FAQs and find out more here. Use the button below to get 20% off for upto a whole year.
Before proceeding, if you have enjoyed this post so far, please make sure you like it (the little heart button in the email/post). I also have a special request for you.
***Special Request***
This newsletter has received a lot of love. If you haven’t already, I would really appreciate it if you could take 5 seconds to let Substack know that they should feature this publication on their pages. This will allow more people to see the newsletter.
There is a simple form in Substack that you can fill up for it. Here it is. Thank you.
https://docs.google.com/forms/d/e/1FAIpQLScs-yyToUvWUXIUuIfxz17dmZfzpNp5g7Gw7JUgzbFEhSxsvw/viewform
To get your Substack URL, follow the following steps-
Open - https://substack.com/
If you haven’t already, log in with your email.
In the top right corner, you will see your icon. Click on it. You will see the drop-down. Click on your name/profile. That will show you the link.
You will be redirected to your URL. Please put that in to the survey. Appreciate your help.
In the comments below, share what topic you want to focus on. I’d be interested in learning and will cover them. To learn more about the newsletter, check our detailed About Page + FAQs
If you liked this post, make sure you fill out this survey. It’s anonymous and will take 2 minutes of your time. It will help me understand you better, allowing for better content.
https://forms.gle/XfTXSjnC8W2wR9qT9
I see you living the dream.
Go kill all and Stay Woke,
Devansh <3
To make sure you get the most out of Math Mondays, make sure you’re checking in the rest of the days as well. Leverage all the techniques I have discovered through my successful tutoring to easily succeed in your interviews and save your time and energy by joining the premium subscribers down below. Get a discount (for a whole year) using the button below
Reach out to me on:
Instagram: https://www.instagram.com/iseethings404/
Message me on Twitter: https://twitter.com/Machine01776819
My LinkedIn: https://www.linkedin.com/in/devansh-devansh-516004168/
My content:
Read my articles: https://rb.gy/zn1aiu
My YouTube: https://rb.gy/88iwdd
Get a free stock on Robinhood. No risk to you, so not using the link is losing free money: https://join.robinhood.com/fnud75