[Javascript] Functor law
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Javascript] Functor law相关的知识,希望对你有一定的参考价值。
Functor laws:
1. Identity:
map(id) == id
2. Composition:
compose(map(f), map(g)) == map(compose(f,g))
compose( map(toUpper), map(reverse), toArray )("bingo"); compose( map( compose(toUpper reverse), toArray ) )("bingo")
Natural Transformations:
"Takes one functor to another without knowing anything about the value".
maybeToArray(Maybe(2)) // [2] maybeToArray(Maybe(null)) // []
compose(nt, map(f)) == compose(map(f), nt) compose(maybeToArray, map(add(1)))(Maybe(5)) //[6] compose(map(add(1)), maybeToArray)(Maybe(5)) // [6]
以上是关于[Javascript] Functor law的主要内容,如果未能解决你的问题,请参考以下文章
[Javascript] Functor Basic Intro
Not a Functor/Functor/Applicative/Monad 的好例子?