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. 全面了解Linux下Proc文件系统

    全面了解Linux下Proc文件系统   Proc是一个虚拟文件系统,在Linux系统中它被挂载于/proc目录之上.Proc有多个功能 ,这其中包括用户可以通过它访问内核信息或用于排错,这其中一个非 ...

  2. 【基础篇】DatePickerDialog日期控件的基本使用(一)

    项目步骤: 1.首先在Main.xml布局文件中添加一个Button标签,用来点击显示日期控件,Main.xml内容如下: <RelativeLayout xmlns:android=" ...

  3. API集合开发文档

    百度翻译api https://www.cnblogs.com/DevilX5/p/7079470.html 实现QQ第三方登录.网站接入 http://blog.csdn.net/u01067894 ...

  4. C++ 补课(一)

    1,在C语言中,全局变量必须声明在所有的函数之前,局部变量必须声明在所有可执行语句之前: C++ 允许在代码块的任何位置对局部变量进行声明 2,常量定义方面,C语言 #define 可能因计算的优先级 ...

  5. C# 返回分页查询的总页数

    /// <summary> /// 返回分页查询操作的的总页数 /// </summary> /// <param name="count">总 ...

  6. nginx学习十一 nginx启动流程

    今天用了一天的时间看nginx的启动流程,流程还是非常复杂.基本的函数调用有十几个之多.通过看源代码和上网查资料,弄懂了一些函数.有些函数还在学习中,有些函数还待日后学习,这里记录一下今天所学.加油! ...

  7. SQlite-数据库的访问实例(转)

    1.DBAdapter类: 1 package com.cnzcom.android.quickdial; import android.content.ContentValues; import a ...

  8. [LuoguU41039]PION后缀自动机 树链剖分+动态开点线段树

    链接 刚开始看出题人题解都吓蒙掉了,还以为是什么难题,结果就一板子题 思路:对每一个文件名开一棵线段树,然后树剖即可 #include<bits/stdc++.h> #define REP ...

  9. 一句话解决Ping问题(主机,开发板,虚拟机)

    PC机使用网卡A连接开发板,VMWare就要使用同一个网卡A作为桥接网卡 步骤: 1.确定网卡A 2.VMWare选择网卡A作为桥接网卡 3.设置三者IP在同一网段 a.Windows网卡A的IP b ...

  10. 蚂蚁金服入股36Kr给我的一点警示:应该相信自己的理性分析,不能盲目迷信权威

    最近3年,关注互联网和创业投资比较多,每周都会关注下本周发生的创业投融资大事件. 我注意到,一些自媒体作者经常会发布一些有"前瞻性"的文章,比如"美团大众要合并了&quo ...