learn:functional-programming
差異處
這裏顯示兩個版本的差異處。
兩邊的前次修訂版前次修改 下次修改 | 前次修改 | ||
learn:functional-programming [2022/06/21 13:34] – admin_wi1d5ky | learn:functional-programming [2024/12/22 21:17] (目前版本) – 外部編輯 127.0.0.1 | ||
---|---|---|---|
行 1: | 行 1: | ||
# Functional Programming 筆記 | # Functional Programming 筆記 | ||
- | |||
## Library | ## Library | ||
- | - <https:// | + | - [Ramda](https:// |
- | - <https:// | + | - [fp-ts](https:// |
行 18: | 行 17: | ||
## Functor | ## Functor | ||
- | | + | |
- | * Future | + | ^ ADT ^ Effect ^ |
- | * Identity | + | | Either | 處理錯誤情境 | |
- | * IO | + | | Future | # |
- | * Maybe: 專門處理無值( null || undefined ) 情境 | + | | Identity | # |
- | * Reader | + | | IO | 處理永不失敗的同步計算 | |
- | * Tuple | + | | Maybe | 處理無值情境 | |
- | * State | + | | Reader | # |
+ | | Tuple | # | ||
+ | | State | # | ||
+ | |||
+ | |||
+ | ### Either | ||
+ | |||
+ | | ||
+ | * 分成 `Either.Right` 和 `Either.Left` | ||
+ | * `Either.Right` 會繼續跑,而 `Either.Left` 則會忽略後續運算,執意將手上的值傳下去 | ||
+ | * < | ||
+ | |||
+ | ```javascript | ||
+ | const addOne = num => Right(R.add(1)); | ||
+ | const error = () => Left(new Error(' | ||
+ | |||
+ | Right(10) | ||
+ | .chain(addOne) | ||
+ | .map(R.add(2)) | ||
+ | .inspect() // Right(13) | ||
+ | |||
+ | Right(10) | ||
+ | .chain(error) | ||
+ | .map(R.add(2)) | ||
+ | .inspect() // Left(Error: error) | ||
+ | |||
+ | ``` | ||
+ | |||
+ | ### Future | ||
+ | |||
+ | > TODO | ||
+ | |||
+ | |||
+ | ### Identity | ||
+ | |||
+ | > TODO | ||
+ | |||
+ | |||
+ | ### IO | ||
+ | |||
+ | * 處理永不失敗的同步計算 | ||
+ | * <https:// | ||
+ | |||
+ | ### Maybe | ||
+ | |||
+ | * 處理無值情境 | ||
+ | * < | ||
+ | |||
+ | ### Reader | ||
+ | * 用來避免中間傳送無用的 `dep` | ||
+ | * < | ||
+ | |||
+ | ### Tuple | ||
+ | |||
+ | > TODO | ||
+ | |||
+ | |||
+ | ### State | ||
+ | |||
+ | * < | ||
learn/functional-programming.1655789641.txt.gz · 上一次變更: 2024/12/22 21:17 (外部編輯)