Sometimes you need to filter an array of objects or perform other conditional logic based on a combination of factors. Ramda's where function gives you a concise way to declaratively map individual predicates to object properties, that when combined, cover the various facets of your conditions. In this lesson, we'll look at how this powerful function can be used for scenarios requiring a complex predicate function.

const products = [
{name: 'Jeans', price:, category: 'clothes', stock: },
{name: 'Hoodie', price:, category: 'clothes', stock: },
{name: 'Sneakers', price:, category: 'clothes', stock: },
{name: 'Cards', price: , category: 'games', stock: },
{name: 'iPhone', price: , category: 'electronics', stock: },
{name: 'Sauce Pan', price: , category: 'housewares', stock: }
] const predicate = R.where({
category: R.complement(R.equals('clothes')), // category is not clothes
stock: R.lt(R.__, ), // less than 50
price: R.gte(R.__, ) // greater or equal than 100
}) const getResults = R.pipe(R.filter(predicate), R.pluck('name'))
const result = getResults(products)
console.log(result) document.getElementById('output').innerHTML = `${JSON.stringify(result)}`

[Ramda] Declaratively Map Predicates to Object Properties Using Ramda where的更多相关文章

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

  2. [Ramda] Change Object Properties with Ramda Lenses

    In this lesson we'll learn the basics of using lenses in Ramda and see how they enable you to focus ...

  3. [Spring学习笔记 2 ]装配各种类型的属性 map,list,array,null,properties

    一.spring Ioc容器补充(1) Spring Ioc容器 DI(依赖注入): 注入的方式:设值方法注入setter(属性注入)/构造子注入(构造函数传入依赖的对象)/字段注入field(注解) ...

  4. ES6 Map vs ES5 Object

    ES6 Map vs ES5 Object Map vs Object https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenc ...

  5. [Javascript Crocks] Safely Access Object Properties with `prop`

    In this lesson, we’ll use a Maybe to safely operate on properties of an object that could be undefin ...

  6. [ES6] When should use Map instead of Object

    Use Maps when keys are unknown until runtime: Map: let recentPosts = new Map(); createPost( newPost, ...

  7. list中依据map<String,Object>的某个值排序

    private void sort(List<Map<String, Object>> list) { Collections.sort(list, new Comparato ...

  8. Map、HashMap、Properties、TreeMap

    1.掌握Map接口中常用方法. 2.遍历Map集合的两种方式都要精通. 第一种:获取所有key,遍历每个key,通过key获取value. 第二种:获取Set<Map.Entry>即可,遍 ...

  9. [Javascript Crocks] Safely Access Nested Object Properties with `propPath`

    In this lesson, we’ll look at the propPath utility function. We’ll ask for a property multiple level ...

随机推荐

  1. Kinect 开发 —— 硬件设备解剖

    Kinect for Xbox: 360 不支持“近景模式” 三只眼睛 —— 红外投影机,RGB摄像头,红外深度投影头  —— 色彩影像中的每个像素分别与深度影像中的一个像素对应 四只耳朵 —— L形 ...

  2. 商业模式(二):P2P网贷平台,利差和服务费为主的金融玩法

    2014~2015,先后在2家P2P平台工作过,还了解过其它若干武汉P2P平台. 结合自己的工作经历和理财经历,说几句~ 1.P2P网贷这种金融类的创业项目和经营风险,远高于制造业和服务业~      ...

  3. ANSI-X99MAC算法和PBOC的3DES MAC算法

    仅仅要有标准的DES加密和解密算法.类似ANSI-X99MAC算法和PBOC3DES算法就非常好实现.他们都是用DES算法再经过一层算法实现的.实现原理看图就能看明确.3DES算法实现就更简单了.就是 ...

  4. Android 给图片加边框

    图片处理时,有时需要为图片加一些边框,下面介绍一种为图片添加简单边框的方法. 基本思路是:将边框图片裁剪成八张小图片(图片大小最好一致,不然后面处理会很麻烦),分别对应左上角,左边,左下角,下边,右下 ...

  5. JSP中使用EL表达式

    EL表达式 :EL 全名为Expression Language,就是为了替代<%= %>脚本表达式. EL主要作用: 获取数据: EL表达式主要用于替换JSP页面中的脚本表达式,以从各种 ...

  6. 暴力破解FTP服务器技术探讨与防范措施

    暴力破解FTP服务器技术探讨与防范措施 随着Internet的发展出现了由于大量傻瓜化黑客工具任何一种黑客攻击手段的门槛都降低了很多但是暴力破解法的工具制作都已经非常容易大家通常会认为暴力破解攻击只是 ...

  7. 【习题 7-8 UVA-12107】Digit Puzzle

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 迭代加深搜索. 枚举最大层数.(也即改变的数字个数 然后枚举第一个改哪个数字,第二个改哪个数字.. 一定要注意字典序问题. 每次优先 ...

  8. 安卓手机运行WINDOWS

    http://www.pcdiy.com.tw/detail/1974 我的ZenFone 2手机可以跑Windows啦! 就在台风来袭,有人正准备去泛舟的那天,国外的XDA论坛神人则是选择让自己的Z ...

  9. 5.decltype类型拷贝

    #include <iostream> using namespace std; template <class T> void show(T *p) { //初始化 decl ...

  10. 文件上传流式处理commons-fileupload

    1. 从请求中获取MultipartFile @RequestMapping(value="/upload", method=RequestMethod.POST) public ...