Sometimes you just need a subset of an object. In this lesson, we'll cover how you can accomplish this using Ramda's pick and omit functions, as well as the pickAll and pickBy variants of pick.

const R = require('ramda');

const {pick, prop, pickBy, pickAll, props, omit, compose, not, curry} = R;

const log = curry((desc, x) => R.tap(() => console.log(desc, JSON.stringify(x, null, )), x));

const product = {
name: 'widget',
price: ,
shippingWeight: ,
shippingMethod: 'UPS'
}; // get one single prop from a large object
const getByProp = pick(['name']); // { name: 'widget' } // different from R.prop
const getPropVal = prop('name'); // 'widget' const getByProps = pickAll(['name', 'price']); // { name: 'widget', price: 10 } const getPropsVals = props(['name', 'price']); // [ 'widget', 10 ] const getByPickBy = pickBy((val, key) => {
// Only get prop if
// val: is number
// key contains 'shipping'
return Number(val) && key.includes('shipping');
}); // { shippingWeight: 20 } const omitShippingProps = omit(['shippingWeight', 'shippingMethod']); // { name: 'widget', price: 10 } // another way to omit props by conditions
const notToPickByShippingProps = pickBy((val, key) => !key.includes('shipping')); // { name: 'widget', price: 10 } const result = notToPickByShippingProps(product);
console.log(result);

[Ramda] Pick and Omit Properties from Objects Using Ramda的更多相关文章

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

  2. [Ramda] Get Deeply Nested Properties Safely with Ramda's path and pathOr Functions

    In this lesson we'll see how Ramda's path and pathOr functions can be used to safely access a deeply ...

  3. [Ramda] Convert Object Methods into Composable Functions with Ramda

    In this lesson, we'll look at how we can use Ramda's invoker and constructNfunctions to take methods ...

  4. [Ramda] Refactor to a Point Free Function with Ramda's useWith Function

    Naming things is hard and arguments in generic utility functions are no exception. Making functions ...

  5. Appendix A. Common application properties

    Appendix A. Common application properties Prev  Part X. Appendices  Next URl链接:https://docs.spring.i ...

  6. JavaScript- The Good Parts Chapter 3 Objects

    Upon a homely object Love can wink.—William Shakespeare, The Two Gentlemen of Verona The simple type ...

  7. 【转】application.properties 常见配置

    Various properties can be specified inside your application.properties/application.yml file or as co ...

  8. Introspection in Python How to spy on your Python objects Guide to Python introspection

    Guide to Python introspection https://www.ibm.com/developerworks/library/l-pyint/ Guide to Python in ...

  9. JavaScript Objects in Detail

    JavaScript’s core—most often used and most fundamental—data type is the Object data type. JavaScript ...

随机推荐

  1. elasticsearch cluster 详解

    上一篇通过clusterservice对cluster做了一个简单的概述, 应该能够给大家一个初步认识.本篇将对cluster的代码组成进行详细分析,力求能够对cluster做一个更清晰的描述.clu ...

  2. mahout中KMeans算法

    本博文主要内容有   1.kmeans算法简介 2.kmeans执行过程  3.关于查看mahout中聚类结果的一些注意事项 4.kmeans算法图解      5.mahout的kmeans算法实现 ...

  3. 【JAVASE】Java同一时候抛出多个异常

    Java有异常抛出后.跳出程序.一般无法运行接下来的代码. 大家做登陆功能.常常会实username和password的登陆校验,username或者password错误.假设通常是提示usernam ...

  4. Android实践 -- Android蓝牙设置连接

    使用Android Bluetooth APIs将设备通过蓝牙连接并通信,设置蓝牙,查找蓝牙设备,配对蓝牙设备 连接并传输数据,以下是Android系统提供的蓝牙相关的类和接口 BluetoothAd ...

  5. 通过Rman catalog 创建及管理Oracle数据库备份

    基本环境信息target DB (需备份数据库) 192.168.199.67 ORACLE_SID=zgw HOSTNAME=Oracle11 catlog DB (备份管理数据库) 192.168 ...

  6. 【Codeforces Round #442 (Div. 2) A】Alex and broken contest

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 注意是所有的名字里面,只出现了其中某一个名字一次. [代码] #include <bits/stdc++.h> usin ...

  7. (7)Launcher3客制化之,改动单屏幕后,Fix在Hotseat拖动应用删除报错

    改动单屏幕后,在workspace里面拖动图标.到删除button上松开的时候,报错问题. 而且无法再次显示拖动的图标. 拖动松开手时候触发 public void onDropCompleted(f ...

  8. [D3] Select DOM Elements with D3 v4

    Before you can create dazzling data driven documents, you need to know how D3 accesses the DOM. This ...

  9. [Angular] Design API for show / hide components based on Auth

    Simple Auth service: import { Injectable } from '@angular/core'; import {HttpClient} from '@angular/ ...

  10. WebApi自定义返回类型和命名空间实现

    1.自定义ContentNegotiator /// <summary> /// 返回json的ContentNegotiator /// </summary> public ...