博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Ramda] Declaratively Map Data Transformations to Object Properties Using Ramda evolve
阅读量:6916 次
发布时间:2019-06-27

本文共 864 字,大约阅读时间需要 2 分钟。

We don't always control the data we need in our applications, and that means we often find ourselves massaging and transforming our data. In this lesson, we'll learn how to transform objects in a declarative way using ramda's evolve function.

 

Assume we have this object:

const product = {    name: 'cog',    price: 100,    details: {      shippingInfo: {        weight: 7,        method: 'ups'      }    }  }

 

Let's say we have to do 

  • Uppcase for name
  • Double price
  • Change weight to 8

Using Ramda's evolve:

const product = {    name: 'cog',    price: 100,    details: {      shippingInfo: {        weight: 7,        method: 'ups'      }    }  }const transformation = {    name: R.toUpper,    price: R.multiply(2),    details: {      shippingInfo: {        weight: R.inc      }    }};const adjustProduct = R.evolve(transformation);const result = adjustProduct(product)

 

转载地址:http://jmxcl.baihongyu.com/

你可能感兴趣的文章
VirtualBox修改现有VDI虚拟磁盘大小
查看>>
mac 10.12 sierra 机械键盘+ratm可编程鼠标记录
查看>>
jmeter用beanshell调用自己写的jar进行MD5加密
查看>>
调用系统相机相冊
查看>>
最简单的视音频播放演示样例7:SDL2播放RGB/YUV
查看>>
vector draw 试用期结束的 激活方法
查看>>
Oracle数据库软件标准版的一个限制:仅仅能用一个rman channel
查看>>
docker官方文档中的dns,link,expose,publish
查看>>
使用 redis “捕捉” “用户登录过期” 事件
查看>>
MyEclipse 8.5安装Aptana
查看>>
C#动态对象(dynamic)示例(实现方法和属性的动态)
查看>>
Objective-C之成魔之路【8-訪问成员变量和属性】
查看>>
支付宝支付-常用支付API详解(查询、退款、提现等)
查看>>
windows下查看特定端口被什么程序占用
查看>>
JSON.parse()与JSON.stringify()的区别
查看>>
1032. Sharing (25)
查看>>
JSP的隐藏对象
查看>>
2014秋C++ 第8周项目 分支程序设计
查看>>
[pig] pig 基础使用
查看>>
java中的线程同步
查看>>