zoukankan      html  css  js  c++  java
  • [Ramda] Declaratively Map Data Transformations to Object Properties Using Ramda evolve

    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)
  • 相关阅读:
    Linux 实战
    bash 环境配置及脚本
    Linux vi/vim
    Linux 正则表达式
    001 KNN分类 最邻近算法
    测序名解
    流式细胞术
    CircRNA 环化RNA
    笔记总结
    Flume
  • 原文地址:https://www.cnblogs.com/Answer1215/p/6307207.html
Copyright © 2011-2022 走看看