Ramda 之 pickAll()

栏目: 编程语言 · 发布时间: 5年前

内容简介:除了WebStorm 2018.3.3Quokka 1.0.136

除了 pick() 外,Ramda 另外提供了 pickAll() ,若該 property 並不存在於 object,則顯示 undefined

Version

WebStorm 2018.3.3

Quokka 1.0.136

Ramda 0.26.1

pick()

import { map, pick } from 'ramda';

const data = [
  { id: 1, title: 'Functional Programming in JavaScript' },
  { id: 2, title: 'RxJS in Action' },
  { id: 3, title: 'Speaking JavaScript' },
];

const getBooks = map(pick(['title', 'price']));
console.dir(getBooks(data));

pick() 可用來擷取 object 的部分 property,倘若 pick() 包含 object 所沒有的 property,則會自動不顯示。

Ramda 之 pickAll()

pickAll()

import { map, pickAll } from 'ramda';

const data = [
  { id: 1, title: 'Functional Programming in JavaScript' },
  { id: 2, title: 'RxJS in Action' },
  { id: 3, title: 'Speaking JavaScript' },
];

const getBooks = map(pickAll(['title', 'price']));
console.dir(getBooks(data));

若 object 沒有的 property 也要顯示 undefined ,則要使用 pickAll()

pickAll()

[k] -> {k: v} -> {k: v}

pick() 功能相同,唯若 property 不存在,則顯示 undefined

[k] :要抽取的 property

{k: v} :data 為 object

{k: v} : 回傳新的 object

Ramda 之 pickAll()

Conclusion

  • pick()pickAll() 的差異只在於若 object 沒有的 property 是否要顯示, pick() 會安靜地不顯示,而 pickAll() 則會顯示 undefined

Reference

Ramda , pick()

Ramda , pickAll()


以上所述就是小编给大家介绍的《Ramda 之 pickAll()》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Twenty Lectures on Algorithmic Game Theory

Twenty Lectures on Algorithmic Game Theory

Tim Roughgarden / Cambridge University Press / 2016-8-31 / USD 34.99

Computer science and economics have engaged in a lively interaction over the past fifteen years, resulting in the new field of algorithmic game theory. Many problems that are central to modern compute......一起来看看 《Twenty Lectures on Algorithmic Game Theory》 这本书的介绍吧!

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具