使用者工具

網站工具


learn:functional-programming

**這是本文件的舊版!**

Functional Programming 筆記

Library

值 vs Functor

f g composition
pure pure compose(f, g)
effects pure(unary) f.map(g)
effects pure(n-ary) f1.map(g).ap(f2)
effects effects m.chain(f).chain(g)

Functor

Either

snippet.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

TODO

Identity

TODO

IO

Maybe

Reader

Tuple

TODO

State

* <https://ithelp.ithome.com.tw/articles/10280554>

Articles

learn/functional-programming.1655799689.txt.gz · 上一次變更: 2022/06/21 08:21 由 admin_wi1d5ky

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki