首页 > 代码库 > [Javascript] Functor law

[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