We can compose lenses to get value:

const addrs = [{street: '99 Walnut Dr.', zip: '04821'}, {street: '2321 Crane Way', zip: '08082'}]
const user = {id: 3, name: 'Charles Bronson', addresses: addrs} const addresses = R.lensProp('addresses')
const street = R.lensProp('street')
const first = R.lensIndex(0) const firstStreet = R.compose(addresses, first, street)
const res = R.view(firstStreet, user) console.log(res) // '99 Walnut Dr.'

[Ramda] Compose lenses的更多相关文章

  1. [Ramda] Compose and Curry

    Curry: The idea of Curry is to spreate the data from the function. Using Curry to define the functio ...

  2. [React] Update Component State in React With Ramda Lenses

    In this lesson, we'll refactor a React component to use Ramda lenses to update our component state. ...

  3. [Ramda] Refactor to Point Free Functions with Ramda using compose and converge

    In this lesson we'll take some existing code and refactor it using some functions from the Ramda lib ...

  4. [Ramda] Change Object Properties with Ramda Lenses

    In this lesson we'll learn the basics of using lenses in Ramda and see how they enable you to focus ...

  5. [Ramda] Simple log function for debugging Compose function

    const log = function(x){ console.log(x); return x; } const get = R.curry(function(prop, obj){ return ...

  6. [Ramda] Simple log function for debugging Compose function / Using R.tap for logging

    const log = function(x){ console.log(x); return x; } const get = R.curry(function(prop, obj){ return ...

  7. [Ramda] Curry, Compose and Pipe examples

    const curry = R.curry((fns, ary) => R.ap(fns, ary)); ), R.add()]); ,,]); console.log(res); //[2, ...

  8. 函数式编程-compose与pipe

    函数式编程中有一种模式是通过组合多个函数的功能来实现一个组合函数.一般支持函数式编程的工具库都实现了这种模式,这种模式一般被称作compose与pipe.以函数式著称的Ramda工具库为例. cons ...

  9. [转] Ramda 函数库参考教程

    学习函数式编程的过程中,我接触到了 Ramda.js. 我发现,这是一个很重要的库,提供了许多有用的方法,每个 JavaScript 程序员都应该掌握这个工具. 你可能会问,Underscore 和  ...

随机推荐

  1. 36.intellij idea 如何一键清除所有断点

    转自:https://www.cnblogs.com/austinspark-jessylu/p/7799212.html 1.在idea左下方找到"View Breakpoints&quo ...

  2. 深入了解Linux远程桌面

    本文转载于:http://www.linux521.com/2009/system/201004/11001.html 已发表在<网管员世界>2010年3月杂志             本 ...

  3. Java学习笔记三.2

    5.继承 //Java中所有对象都显式/隐式的继承子Object类 class fu{ fu(){ System.out.println("fu..."+getNum()); sh ...

  4. 百度地图API 添加标签

    1.手动创建数据,实际项目则是接受GPS信息 /建立坐标点: // lng:经度 lat:纬度 var points = [ {"lng":112.58,"lat&quo ...

  5. js无缝滚动原理及详解[转自刹那芳华]

    刚刚接触JS,网上找了一些关于无缝滚动的教程,但都大同小异,对我这种新手来说也只是会用,不知道什么意思,想要自己写个更是一头雾水.于是找了一些资料,详细说明一下JS无缝滚动的原理,相信看过这篇文章之后 ...

  6. JS截取字符串 charAt(),slice(),substring(),substr()

    1. charAt(i)输出指定下标的字母,长度为1,适用于把字符串切割成单个字符串. 2. slice() 和 substring() 都支持1-2个参数,第一个参数是开始位置,第二个参数是结束位置 ...

  7. JS概述

             从Asp.NET跨越到JavaScript.这既是一个新的领域也是一个非常熟悉的地方,新是由于不知道什么是JavaScript,首先来了解一下什么是JavaScript.       ...

  8. 计算机系统—CPU结构和内部工作

    一.计算机系统硬件组成 计算机系统的基本组成由:计算器.控制器.存储器.输入和输出设备这5大核心部件组成. 运算器和控制器等继承在一起成为CPU.以下通过这张图能够非常清楚的表达计算机系统.先从全局上 ...

  9. Android ServiceManager启动

    许久就想写篇关于servicemanager的文章,之前对服务启动顺序诸如zygote,systemserver.等启动顺序理解有点混乱,现做例如以下理解分析: 事实上init进程启动后,Servic ...

  10. php实现运气模型(命运随机,克服困难)

    php实现运气模型(命运随机,克服困难) 一.总结 1.应该用表格来布局的,这种多列的用表格布局比div和span布局方便很多 2.span标签设置宽度:变成行内快元素:display:inline- ...