3.7 KiB
Monad Is Actually Easy
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) resources
Note
This example can be usefull to replicate the behavior of Option of Rust in other languages
There are these three essentials in a monad. Unit, map, and flat map. View Highlight)
In other words, this 'Maybe' monad can make a box with a value with 'just', or an empty box with 'nothing' View Highlight)
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)
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)
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)
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)
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)
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)
