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. RTSP、HTTP、HTTPS、SDP四种协议详解

    我们将主要讲解RTSP,HTTP,HTTPS, SDP四种协议.  一:RTSP协议简介 实时流协议RTSP是一个应用层协议,用于控制具有实时特性的数据(例如多媒体流)的传送. RTSP协议一般与RT ...

  2. Redhat Linux下如何使用KVM虚拟机(视频)

    KVM(kernel-basedVirtualMachine)是一个开源的系统虚拟化模块,自Linux2.6.20之后集成在Linux的各个主要发行版本中.它使用Linux自身的调度器进行管理,所以相 ...

  3. Kinect 开发 —— 骨骼追踪(下)

    Kinect 连线游戏 在纸上将一些列数字(用一个圆点表示)从小到大用线连起来.游戏逻辑很简单,只不过我们在这里要实现的是动动手将这些点连起来,而不是用笔或者鼠标. 在开始写代码之前,需要明确定义我们 ...

  4. eclipse工作空间配置导出

    由于工作与学习的需求,需要使用不同的工作空间.而eclipse的新建工作空间其他以前的配置都没有继承过来,那么就得重新配置一遍. 经过学习其他前辈们的经验与自己的摸索总结一下3种方法: 方法一:使用e ...

  5. 【Henu ACM Round #12 D】 Longest Subsequence

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 记录每个数字出现的次数cnt[x]; (大于1e6的直接忽略) 另外用一个数组z[1e6] 然后for枚举x 第二层for枚举x的倍 ...

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

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

  7. 65.十一级指针实现百万qq号的增删查改以及排序写入

    运行结果: 内存使用情况: 写入文件排序好的数据: 创建文件地址以及创建十一级指针 char *path = "QQ.txt"; char *sortpath = "QQ ...

  8. C#异步编程的实现方式(4)——Task任务

    最基本的是知道怎么启动一个Task. 1.Task类构造函数 使用Task类的构造函数.实例化Task对象时,任务不会立即运行,而是指定Created状态.接着调用Task类的Start()方法来启动 ...

  9. js-YDUI 移动端解决方案

    /** * YDUI 可伸缩布局方案 * rem计算方式:设计图尺寸px / 100 = 实际rem 例: 100px = 1rem */ !function (window) { /* 设计图文档宽 ...

  10. JavaScript 进度条重复加载

    <!DOCTYPE HTML> <html> <head> <meta charset ="utf-8"> <title> ...