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. 5.Zookeeper的两种安装和配置(Windows):单机模式与集群模式

    转自:https://blog.csdn.net/a906998248/article/details/50815031

  2. 哈夫曼树的介绍 ---java实现

    一.     什么是哈夫曼树 是一种带权路径长度最短的二叉树,也称最优二叉树 带权路径长度:WPL=(W1*L1+W2*L2+W3*L3+...+ Wn*Ln) N个权值Wi(i=1,2,...n)构 ...

  3. 并发控制MsSql

    Isolation   阅读目录(Content) 1 并发控制理论 1.1 悲观并发控制 1.2 乐观并发控制 2 隔离级别 2.1 隔离级别说明 2.2 Read Commmitted Snaps ...

  4. HTTP网络协议(四)

    确保Web安全的HTTPS HTTP存在三个比较明显的缺点: 通信使用明文(不加密),内容可能会被窃听. 不验证通信方的身份,因此有可能遭遇伪装. 无法证明报文的完整性,所以可能已遭篡改.  尽管HT ...

  5. UVA 11090 Going in Cycle!!(Bellman-Ford推断负圈)

    题意:给定一个n个点m条边的加权有向图,求平均权值最小的回路. 思路:使用二分法求解.对于每个枚举值mid,推断每条边权值减去mid后有无负圈就可以. #include<cstdio> # ...

  6. SpringMVC实战(三种控制器方式)

    1.前言 上篇博客着重说了一下SpringMVC中几种处理映射的方式,这篇博客来说一下SpringMVC中几种经常使用的控制器.  2.经常使用控制器 2.1 ParameterizableViewC ...

  7. c++11 多线程 -- 基本使用

    c++11 多线程 – 基本使用 前言:这篇文章仅针对没有使用过c++11线程库的童鞋来高速入门,也是自己的一个简单记录,内容比較基础. 1.线程的基本使用 2.相互排斥量 3.条件变量 4.原子变量 ...

  8. MongoDb 查询时常用方法

    Query.All("name", "a", "b");//通过多个元素来匹配数组Query.And(Query.EQ("name ...

  9. Java 接口中定义抽象方法有什么意义

    接口方法声明只能是public abstract的,所以不管你在声明的时候加不加abstract,都是可以的.Java 8开始,接口还引入了默认方法,也就是可以给接口的方法提供默认的实现,默认方法应当 ...

  10. UVA Bandwidth

    题目例如以下: Bandwidth  Given a graph (V,E) where V is a set of nodes and E is a set of arcsin VxV, and a ...