From:

const onSeachClick = (searchTerm) => {
if(searchTerm !== '') {
searchForMovies(searchTerm)
} else {
console.log('a search term should be provided')
}
}

To:

// Utils

const inNotEmpty = R.compose(
R.not,
R.isEmpty
); const onSearchClick = () => {
R.ifElse(
isNotEmpty, // logic to check
searchForMovices, // do it if true
log('a search term should be provided') // do it if false
)
}

Example2:

/*
Example2:
*/
function processSearchResponse(response) {
// check total_results prop from response,
// it shuold greater than 0
const searchHasResult = R.compose(
R.lt(),
R.prop('total_results')
);
// get results props from response,
// then createMoviesElements called
const createElementFromResults = R.compose(
createMovicesElements,
R.prop('results')
);
//always return empty
const createArrayWithNotFound = R.always([
createMoviceNotFoundElement({})
]); const elements = R.ifElse(
searchHasResult,
createElementFromResults,
createArrayWithNotFound
)(response);
}

[Ramda] Rewrite if..else with Ramda ifElse的更多相关文章

  1. [Ramda] Handle Branching Logic with Ramda's Conditional Functions

    When you want to build your logic with small, composable functions you need a functional way to hand ...

  2. [Ramda] Sort, SortBy, SortWith in Ramda

    The difference between sort, sortBy, sortWith is that: 1. sort: take function as args. 2. sortBy: ta ...

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

  4. [Ramda] Getter and Setter in Ramda & lens

    Getter on Object: 1. prop: R.prop(}); //=> 100 R.prop('x', {}); //=> undefined 2. props: R.pro ...

  5. 前端笔记之React(六)ES6的Set和Map&immutable和Ramda和lodash&redux-thunk

    一.ES6的Set.Map数据结构 Map.Set都是ES6新的数据结构,都是新的内置构造函数,也就是说typeof的结果,多了两个: Set 是不能重复的数组 Map 是可以任何东西当做键的对象 E ...

  6. [转]如何在 JS 代码中消灭 for 循环

    一,用好 filter,map,和其它 ES6 新增的高阶遍历函数 二,理解和熟练使用 reduce 三,用递归代替循环(可以break!) 四,使用高阶函数遍历数组时可能遇到的陷阱 五,死磕到底,T ...

  7. 翻译连载 | 附录 C:函数式编程函数库-《JavaScript轻量级函数式编程》 |《你不知道的JS》姊妹篇

    原文地址:Functional-Light-JS 原文作者:Kyle Simpson-<You-Dont-Know-JS>作者 关于译者:这是一个流淌着沪江血液的纯粹工程:认真,是 HTM ...

  8. 给 JavaScript 开发者讲讲函数式编程

    本文译自:Functional Programming for JavaScript People 和大多数人一样,我在几个月前听到了很多关于函数式编程的东西,不过并没有更深入的了解.于我而言,可能只 ...

  9. [Ramda] Filter, Reject and Partition

    We'll learn how to get a subset of an array by specifying items to include with filter, or items to ...

随机推荐

  1. 10. ZooKeeper之搭建伪集群模式。

    转自:https://blog.csdn.net/en_joker/article/details/78673456 在集群和单机两种模式下,我们基本完成了分别针对生产环境和开发环境ZooKeeper ...

  2. ASP.NET MVC案例教程(基于ASP.NET MVC beta)——第五篇:MVC整合Ajax

    摘要      本文将从完成“输入数据验证”这个功能出发,逐渐展开ASP.NET MVC与Ajax结合的方法.首先,本文将使用ASP.NET MVC提供的同步方式完成数据验证.而后,将分别结合ASP. ...

  3. React render return 空行问题

    Uncaught Invariant Violation: App.render(): A valid React element (or null) must be returned. You ma ...

  4. C语言库函数,头文件

    参看:https://zhidao.baidu.com/question/328173842.html 该文件包含了的C语言标准库函数的定义 stdlib.h里面定义了五种类型.一些宏和通用工具函数. ...

  5. 【习题 6-3 UVA - 536】 Tree Recovery

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 递归题 [代码] #include <bits/stdc++.h> using namespace std; const ...

  6. 【河南省多校脸萌第六场 E】LLM找对象

    [链接]点击打开链接 [题意] 在这里写题意 [题解] 把n个时间离散化一下. 对于不是相邻的点,在两者之间再加一个空格就好. 这样最多会有1000个位置. 则定义dp[i][k][j] 表示前i个数 ...

  7. iCarousel——在iOS和Mac OS应用中实现3D CoverFlow旋转木马效果的开源类库

    前言 iCarousel一个简单.可高度定制的3D CoverFlow开源类库,旨在简化在 iPhone, iPad和Mac OS中生成各种类型的cover flow(视图切换)效果(分页.滚动视图) ...

  8. php中嵌套html代码和html代码中嵌套php方式

    php中嵌套html代码和html代码中嵌套php方式 一.总结 拷贝的话直接html代码是极好的方式 1.php中嵌套html代码(本质是原生php):a.原生嵌套<?php .....?&g ...

  9. Redis笔记---set

    1.redis set的介绍 集合中的数据是不重复且没有顺序,集合类型和列表类型的对比. 集合类型:存储的是的是最多2的32次方减一个字符串,数据是没有顺序的,但是数据是唯一的 列表类型:最多存储内容 ...

  10. 6.3 Android硬件访问服务APP代码

    以下步骤是操作MainActivity类 1.导入包 import android.os.ILedService 2.添加成员变量 private ILedService iLedService = ...