diff --git a/.zk/notebook.db b/.zk/notebook.db index 7a84cce..3fc9fd3 100644 Binary files a/.zk/notebook.db and b/.zk/notebook.db differ diff --git a/Readwise/Monad Is Actually Easy..md b/Readwise/Monad Is Actually Easy..md index 3d0b762..2cfa039 100644 --- a/Readwise/Monad Is Actually Easy..md +++ b/Readwise/Monad Is Actually Easy..md @@ -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: +- Archive: . + > [!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 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)) - diff --git a/notes/error-handling.md b/notes/error-handling.md new file mode 100644 index 0000000..8ec4cd5 --- /dev/null +++ b/notes/error-handling.md @@ -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` - `Option` + +The `Result` type (sometimes also called `Option`, `Maybe`, 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`: this data can have a value (sometimes called `Ok(T)`), or can hold an error. +- `Option`: 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`](https://doc.rust-lang.org/book/ch06-01-defining-an-enum.html#the-option-enum-and-its-advantages-over-null-values) and [`Result`](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 diff --git a/notes/none.md b/notes/none.md new file mode 100644 index 0000000..4723365 --- /dev/null +++ b/notes/none.md @@ -0,0 +1,9 @@ +--- +title: "None" +tags: +created: 2024-10-20 17:02 +--- + +# None + + diff --git a/notes/untitled.md b/notes/untitled.md new file mode 100644 index 0000000..d977a38 --- /dev/null +++ b/notes/untitled.md @@ -0,0 +1,9 @@ +--- +title: "Untitled" +tags: +created: 2024-10-20 16:44 +--- + +# Untitled + +