This commit is contained in:
Alexander Navarro 2024-10-20 22:20:02 -03:00
parent c620e6b14a
commit 76c7956d21
5 changed files with 67 additions and 7 deletions

Binary file not shown.

View file

@ -1,22 +1,25 @@
# Monad Is Actually Easy.
# 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.
- 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]]
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
@ -35,6 +38,5 @@ the Left Unit Law. When there's a certain value and a function,  the rule is th
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. 
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))

40
notes/error-handling.md Normal file
View file

@ -0,0 +1,40 @@
---
title: "Error Handling"
tags:
- #coding
- #design-patterns
- #errors
created: 2024-10-20 16:45
---
# Error Handling
Different ways to handle errors in code
## Errors as Exceptions - Try Catch
### Try Catch
## Errors as Values
### `Result<T, Err>` - `Option<T>`
The `Result<T, Err>` type (sometimes also called `Option<T>`, `Maybe<T>`, or others)
is a custom data type that may or may not have a value, but like the
Schrödinger's box, we won't know until we peak inside of it, forcing the code
to handle both cases.
This data type can be use to solve 2 common pitfals:
- `Result<T, Err>`: this data can have a value (sometimes called `Ok(T)`), or can hold an error.
- `Option<T>`: this data can have a value (sometimes called `Some(T)`) or can not have a value (sometimes called `None()`).
This data type is often used with [[pattern matching]], allowing to handle each possible variation of the type.
Resources:
- [[Readwise/Monad Is Actually Easy.|This data type is a monad]]
- Rust [`Option<T>`](https://doc.rust-lang.org/book/ch06-01-defining-an-enum.html#the-option-enum-and-its-advantages-over-null-values) and [`Result<T, E>`](https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html) types.
- Gleam [`Option(a)`](https://hexdocs.pm/gleam_stdlib/gleam/option.html) type.
### Return touples

9
notes/none.md Normal file
View file

@ -0,0 +1,9 @@
---
title: "None"
tags:
created: 2024-10-20 17:02
---
# None

9
notes/untitled.md Normal file
View file

@ -0,0 +1,9 @@
---
title: "Untitled"
tags:
created: 2024-10-20 16:44
---
# Untitled