<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      [Javascript] Functor Basic Intro

      Well, this stuff will be a little bit strange if you deal with it first time.

       

      Container Object:

      •   Just a wrapper / contianer for values
      •   No Method
      •       No Nouns
      var _Container = function(val){
        this.val = val;
      }
      
      var Container = function(x){
        return new _Container(x);
      }
      
      console.log(Container(3)) // _Container( {val: 3})

      Every time we use Container, it will just add the value to the Container object and assign value to prop val.

       

      map function on Container:

      This map is not the map what you think it is.... 

      The map you think is the method on the Array.

      Here the map is the one get into the Container, grep the value, then apply function on this value. The return value is still Container.

      _Container.prototype.map = function(f){
        return Container(f(this.val))
      }
      var res = Container("flamethrower").map(function(s){ return _.capitalize(s) })
      console.log(res) //_Container( {val: "Flamethrower"} )

      So in the example, map function goes into the Container, get the value "flamethrower", and apply the function '_.capitialize' to the value and return the new value to the Container.

      Or you can write like this:

      var capitalize = _.capitalize;
      var res = Container("flamethrower").map(capitalize);

       

      More examples:

      Container([1,2,3]).map(reverse).map(first)
      //=> Container(3)
      
      
      Container("flamethrower").map(length).map(add(1))
      //=> Container(13)

       

      So "Container"... what you feel about it? It is nothing... you don't need to care about it. Just every time you call map on it, the return value will still inside the Container, so that you can chain map on it.

       

      Curry map:

      Define a global map function, which use Ramda curry method:

      var map = R.curry(function(f, obj) {
        return obj.map(f) 
      })

      Later we will pass Container as obj, and on our Container, we already defined map function, so we can use here as 'obj.map'.

      So, again, here 'obj.map' --> Means, goes into the obj, grep the value and apply function f.

       

      So now what we can do:

      Container(3).map(add(1)) // Container(4)
      
      map(add(1), Container(3)) // Container(4), or map(add(1))(Container(3)), since map is curry method

      More exmaples:

      map(R.compose(R.head, R.reverse), Container("dog"))
      //=> Container(“g”)

       

      So all what we have seen so far, we give a name call "Functor".

       

      Functor

      “An object or data structure you can map over”

       function: map

       

      // Exercise 1
      // ==========
      // Use _.add(x,y) and map(f,x) to make a function that increments a value inside a functor
      console.log("--------Start exercise 1--------")
      //map(): Go inside the object and run the function on the value of the object
      //map(): Here map is curry function, so take the function as first arguement and object as second arguement.
      //map(_.add(1), Identity(2)) --> Identity(3)
      var ex1 = map(_.add(1));
      
      
      assertDeepEqual(Identity(3), ex1(Identity(2)))
      console.log("exercise 1...ok!")
      
      
      
      
      
      // Exercise 2
      // ==========
      // Use _.head to get the first element of the list
      var xs = Identity(['do', 'ray', 'me', 'fa', 'so', 'la', 'ti', 'do'])
      console.log("--------Start exercise 2--------")
      
      
      var ex2 = map(_.head)
      
      
      assertDeepEqual(Identity('do'), ex2(xs))
      console.log("exercise 2...ok!")

       

      posted @ 2016-09-06 04:23  Zhentiw  閱讀(348)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 一二三四免费中文字幕| 综合激情网一区二区三区| 人人超人人超碰超国产| 亚洲国产天堂久久综合226114| 久久久久久久久久久免费精品| 国精品午夜福利视频| 最新中文字幕国产精品| 无遮高潮国产免费观看| 国产午夜亚洲精品不卡下载| 久久这里有精品国产电影网| 精品国产美女av久久久久| 精品无码黑人又粗又大又长 | 久久男人av资源站| 国产三级视频网站| 中文字幕亚洲人妻系列| 亚洲美女av一区二区| 国产亚欧女人天堂AV在线| 亚洲精品麻豆一二三区| 亚洲一级特黄大片在线观看| 日本亚洲色大成网站www久久| 国产精品麻豆成人av网| 中国女人高潮hd| 99精品久久久久久久婷婷| 干老熟女干老穴干老女人| 国产乱子伦农村xxxx| 亚洲色一区二区三区四区| 亚洲综合精品香蕉久久网| 毛片无码免费无码播放| 人人妻人人妻人人片色av| 97精品亚成在人线免视频| 精品九九人人做人人爱| 亚洲av成人区国产精品| 日日爽日日操| 91亚洲国产成人精品性色| 成人三级视频在线观看不卡| 免费a级黄毛片| 一本色道久久—综合亚洲| 国产激情无码一区二区三区| 国产偷国产偷亚洲高清午夜| 亚洲日韩久热中文字幕| 动漫av网站免费观看|