[Ramda] Pick and Omit Properties from Objects Using Ramda
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的更多相关文章
- [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 ...
- [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 ...
- [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 ...
- [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 ...
- Appendix A. Common application properties
Appendix A. Common application properties Prev Part X. Appendices Next URl链接:https://docs.spring.i ...
- JavaScript- The Good Parts Chapter 3 Objects
Upon a homely object Love can wink.—William Shakespeare, The Two Gentlemen of Verona The simple type ...
- 【转】application.properties 常见配置
Various properties can be specified inside your application.properties/application.yml file or as co ...
- 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 ...
- JavaScript Objects in Detail
JavaScript’s core—most often used and most fundamental—data type is the Object data type. JavaScript ...
随机推荐
- 13.constexpr
#include <iostream> using namespace std; //声明返回值为常量表达式 constexpr int get() { ; return num; } v ...
- springMVC视图解析器——InternalResourceViewResolver(转)
springmvc在处理器方法中通常返回的是逻辑视图,如何定位到真正的页面,就需要通过视图解析器. springmvc里提供了多个视图解析器,InternalResourceViewResolver就 ...
- 洛谷 P1230 智力大冲浪
洛谷 P1230 智力大冲浪 题目描述 小伟报名参加中央电视台的智力大冲浪节目.本次挑战赛吸引了众多参赛者,主持人为了表彰大家的勇气,先奖励每个参赛者m元.先不要太高兴!因为这些钱还不一定都是你的?! ...
- (转)kvm虚拟机中,如何给子系统更换光盘
转自:http://www.cnblogs.com/york-hust/archive/2012/06/12/2546334.html 启动kvm后,在kvm窗口中,按下CTRL+ALT+2,切换至q ...
- python3 购物车小程序,余额写入文件保存
python3 购物车小程序,余额写入文件保存 #!/usr/bin/env python # -*- coding:utf-8 -*- # Author:Hiuhung Wan goods = ( ...
- 3、C++快速入门
参考书籍: C++程序设计教程_第二版_钱能 //篇幅较少,适合快速学习 C++ Primer Plus 第六版 中文版 //篇幅较大,讲的非常详细 C++一般必须包含的头文件是#inc ...
- Netty原理和使用
性能主题 Netty原理和使用 Netty是一个高性能 事件驱动的异步的非堵塞的IO(NIO)框架,用于建立TCP等底层的连接,基于Netty可以建立高性能的Http服务器.支持HTTP. WebSo ...
- WCF REST 基础教程
概述 Representational State Transfer(REST)是Roy Fielding博士在2000年他的博士论文中提出来的一种软件架构风格. 因此REST是设计风格而不是标准,R ...
- 一个例子讲解wav头文件 stm32声音程序 录音和播放 wav
下面我们一wav头文件来分析一下: 下面是双声道的,16位,48000采样录的wav文件: 打开属性,能看到的有用信息只有比特率了: 上图的比特率就是 wav头文件里的bitrate: 1536kbp ...
- 一次修复IncrediBuild Coordinator服务的经历
作者:朱金灿 来源:http://blog.csdn.net/clever101 早上发现部门的分布式编译服务的服务端崩溃了,原来是IncrediBuild Coordinator服务启动不了.启动该 ...