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: ,
details: {
shippingInfo: {
weight: ,
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: ,
details: {
shippingInfo: {
weight: ,
method: 'ups'
}
}
} const transformation = {
name: R.toUpper,
price: R.multiply(),
details: {
shippingInfo: {
weight: R.inc
}
}
};
const adjustProduct = R.evolve(transformation);
const result = adjustProduct(product)

[Ramda] Declaratively Map Data Transformations to Object Properties Using Ramda evolve的更多相关文章

  1. [Ramda] Declaratively Map Predicates to Object Properties Using Ramda where

    Sometimes you need to filter an array of objects or perform other conditional logic based on a combi ...

  2. [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 ...

  3. [Ramda] R.project -- Select a Subset of Properties from a Collection of Objects in Ramda

    In this lesson we'll take an array of objects and map it to a new array where each object is a subse ...

  4. Manipulating Data from Oracle Object Storage to ADW with Oracle Data Integrator (ODI)

    0. Introduction and Prerequisites This article presents an overview on how to use Oracle Data Integr ...

  5. [Javascript Crocks] Safely Access Object Properties with `prop`

    In this lesson, we’ll use a Maybe to safely operate on properties of an object that could be undefin ...

  6. [Ramda] Convert a QueryString to an Object using Function Composition in Ramda

    In this lesson we'll use a handful of Ramda's utility functions to take a queryString full of name/v ...

  7. [Angular 2] Passing data to components with 'properties'

    Besides @Input(), we can also use properties on the @Component, to pass the data. import {Component, ...

  8. 重构改善既有代码设计--重构手法19:Replace Data Value with Object (以对象取代数据值)

    你有一笔数据项(data item),需要额外的数据和行为. 将这笔数据项变成一个对象. class Order... private string customer; ==> class Or ...

  9. html5 嵌入元素 img map areaiframe embed meter object meter

    <img src="路径">            src 路径可以是img.jpg 也可以是 绝对和相对路径+img.jpg <img src="路径 ...

随机推荐

  1. POJ 2427 Smith's Problem Pell方程

    题目链接 :  http://poj.org/problem?id=2427 PELL方程几个学习的网址: http://mathworld.wolfram.com/PellEquation.html ...

  2. 使用Microsoft.Office.Interop.Excel时,64位问题

    前不久,碰到一个问题. 曾经用的好好的Microsoft.Office.Interop.Excel实现的导出Excel,迁移至64位server后,就出现: 检索 COM 类工厂中 CLSID 为 { ...

  3. 计算两个String 类型的时间相关几个月

    /** * 返回两个时间段相隔几个月 * @param date1 * @param date2 * @return * @throws ParseException * @throws ParseE ...

  4. Cocos2d-x学习笔记(三)CCNode分析

    原创文章.转载请注明出处:http://blog.csdn.net/sfh366958228/article/details/38706483 通过前两份学习笔记,我们不难发现CCScene.CCLa ...

  5. 让人难过的 openssl_pkcs7_encrypt

    让人难过的 openssl_pkcs7_encrypt 用PHP.NET的范例,没有加密结果,也没有报错信息,而openssl_pkcs7_sign()函数则返回 error opening inpu ...

  6. ubuntu-系统密匙

    1.安装虚拟机xp,需要密匙,网上搜了一个,验证能用 MRX3F-47B9T-2487J-KWKMF-RPWBY 2.安装vm也需要密匙,如下可用 HC6JC-FPJ4M-RZM61-48852-2A ...

  7. matlab 局部特征检测与提取(问题与特征)

    物体识别:SIFT 特征: 人脸识别:LBP 特征: 行人检测:HOG 特征: 0. 常见手工设计的低级别特征 manually designed low-level features 语音:高斯混合 ...

  8. 使用差分VHD启动Win7

    平台:windows 8.1 目的:在VHD里装个Win7 介绍:建立VHD装系统姑且不表,比较有意思的是用差分VHD备份系统这点. 差分硬盘这个概念在虚拟机里常用,类似VM中的快照,不过差分硬盘更灵 ...

  9. django 简单会议室预约(1)

    django 是python的一个web框架,为什么要用django,作者之前用过另一个框架flask,虽然flask比较简单很容易让人学,但是flask没有整体感,会让初学着茫然. 这里我们用dja ...

  10. [Node.js] Node Util Promisify - How to Convert Callback Based APIs to Promise-based

    Since Node.js V8.0+, it introduces a 'util' libaray, which has a 'promisfy' function. It can conver ...