使用者工具

網站工具


learn:functional-programming

差異處

這裏顯示兩個版本的差異處。

連向這個比對檢視

兩邊的前次修訂版前次修改
下次修改
前次修改
下次修改兩邊的下次修訂版
learn:functional-programming [2022/06/21 08:19] admin_wi1d5kylearn:functional-programming [2022/06/21 08:21] – [Either] admin_wi1d5ky
行 16: 行 16:
  
 ## Functor ## Functor
- 
  
 ### Either ### Either
行 24: 行 23:
   * `Either.Right` 會繼續跑,而 `Either.Left` 則會忽略後續運算,執意將手上的值傳下去   * `Either.Right` 會繼續跑,而 `Either.Left` 則會忽略後續運算,執意將手上的值傳下去
   * <https://ithelp.ithome.com.tw/articles/10279389>   * <https://ithelp.ithome.com.tw/articles/10279389>
 +
 +```javascript
 +const addOne = num => Right(R.add(1));
 +const error = () => Left(new Error('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 ### Future
  
 > TODO > TODO
 +
  
 ### Identity ### Identity
  
 > TODO > TODO
 +
  
 ### IO ### IO
行 50: 行 67:
  
 > TODO > TODO
 +
  
 ### State ### State
learn/functional-programming.txt · 上一次變更: 2022/06/21 08:47 由 admin_wi1d5ky

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki