void/Readwise/Monad Is Actually Easy..md
2024-10-13 17:51:49 -03:00

40 lines
3.7 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Monad Is Actually Easy.
![rw-book-cover](https://i.ytimg.com/vi/8hYUthfmSRM/maxresdefault.jpg)
## Metadata
- Author: [[Coding with Yalco]]
- Full Title: Monad Is Actually Easy.
- Category: #articles
- Document Tags: [[dev]] [[dev/design-patterns]]
- URL: https://www.youtube.com/watch?v=8hYUthfmSRM
- Archive: https://web-archive.alecodes.page/bookmarks?bf=1&search=&title=Monad%20Is%20Actually%20Easy.
> [!tldr]
> #Functional #Programming #Coding
This video explains one of the concepts of functional programming, Monad. A monad can be understood as a box that creates a new box filled with values by applying a function to a value. The basic functions of a monad include Unit, Map, and FlatMap. The unit is a function that wraps a given value in a monad, Map is a function that sends out the result of the executed function back into the box, and FlatMap is a function that processes values already contained in the box. Thanks to these functions, monads make it convenient to process values in programming and help simplify difficult problems. Therefore, understanding and being able to use it is a great help in improving programming skills. Through this video, I hope you have helped understand the basic concepts and operating principles of Monad, and understand Monad through a simple example.
## Highlights
'Maybe' is like Schrödinger's box.  In other words, it is used to hold a value that  may or may not exist, just like the types called   Option, Optional, Nullable in other languages. Such monads allow for the safe and convenient  
handling of operations when a  valid value has not been returned [View Highlight](https://read.readwise.io/read/01j9xkp05a5hvjysk36jj8qt2x)) [[resources]]
> [!note]
> This example can be usefull to replicate the behavior of Option<T> of Rust in other languages
There are these three essentials in  a monad. Unit, map, and flat map. [View Highlight](https://read.readwise.io/read/01j9xks9yx76p1gnsrxh1kz6qn))
In other words, this 'Maybe' monad can make   a box with a value with 'just',  or an empty box with 'nothing' [View Highlight](https://read.readwise.io/read/01j9xktwhss9pwc2y7yt09t6x2))
the 'Functor' function,  commonly referred to as the 'map' method.  It carries out the given function and  then puts the result back into a box. [View Highlight](https://read.readwise.io/read/01j9xkw0a68fr05fytfenqczj3))
the flat map,   also known as 'bind'. It's the same as the above map,   but you can see that it doesn't wrap  the value in a box when sending it out. [View Highlight](https://read.readwise.io/read/01j9xkwy1tgn917kczbarkdxcr))
we can summarize monads like this:  
They are magic boxes that have the  ability to hold a given value and   later process the subsequent functions given  by map or flat map, returning other boxes. [View Highlight](https://read.readwise.io/read/01j9xk4qrbj6bft0t9vwx8pgk0))
the Left Unit Law. When there's a certain value and a function,  the rule is that the result of wrapping this  value in a monad and applying a function,  should be the same as simply  giving that value to the function. [View Highlight](https://read.readwise.io/read/01j9xk6jbj6rjagtgqvfzp4kjs))
the Right  Unit Law which stipulates that,  the result of applying a function that  simply returns the same value to the monad  should be identical to the original monad. [View Highlight](https://read.readwise.io/read/01j9xk7rpfgzvd8ba29cx9qj44))
he law of associativity. 
When applying two functions  'f' and 'g' to a certain monad,  Applying 'g' to the result of first applying 'f', Should yield the same result as applying a single   function that is a combination  of 'f' and 'g' sequentially. [View Highlight](https://read.readwise.io/read/01j9xk96vz0xb9wm1vkmke4ser))