zoukankan      html  css  js  c++  java
  • [Ramda] Getter and Setter in Ramda & lens

    Getter on Object:

    1. prop:

    R.prop('x', {x: 100}); //=> 100
    R.prop('x', {}); //=> undefined

    2. props: 

    R.props(['x', 'y'], {x: 1, y: 2}); //=> [1, 2]
    R.props(['c', 'a', 'b'], {b: 2, a: 1}); //=> [undefined, 1, 2]

    Setter ob Object:

    R.assoc('c', 3, {a: 1, b: 2}); //=> {a: 1, b: 2, c: 3}

    Another way to use Lens:

    var xLens = R.lens(R.prop('x'), R.assoc('x'));
    
    R.view(xLens, {x: 1, y: 2});            //=> 1
    R.set(xLens, 4, {x: 1, y: 2});          //=> {x: 4, y: 2}
  • 相关阅读:
    100——第9例
    100——第8例
    100——第7例
    POJ
    POJ
    POJ
    Egyptian Collegiate Programming Contest 2017 (ACM ECPC 2017)
    SCUT
    SCUT
    SCUT
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5947316.html
Copyright © 2011-2022 走看看