码迷,mamicode.com
首页 > 编程语言 > 详细

[Javascript] Functor law

时间:2016-09-12 06:11:56      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

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

标签:

原文地址:http://www.cnblogs.com/Answer1215/p/5863415.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!