Naming things is hard and arguments in generic utility functions are no exception. Making functions "tacit" or "point free" removes the need for the extra parameter names and can make your code cleaner and more succinct. In this lesson, we'll create a normal, "pointed" function and then use ramda's useWith function to refactor our way to point-free bliss.

const R = require('ramda');

const { find, useWith, identity, propEq } = R;

const countries = [
{flag: 'GB', cc: 'GB'},
{flag: 'US', cc: 'US'},
{flag: 'CA', cc: 'CA'},
{flag: 'FR', cc: 'FR'}
]; // Normally when you see there are multi args, you can think to use 'R.useWith'
// to make it point free style
//const getCountry = (cc, list) => find(propEq('cc'), list); /*
* Refactor the getCountry function to make it as point-free function
* */
const getCountry = useWith(
find,
[
propEq('cc'),
identity
]
); const result = getCountry('US', countries); console.log(result);

[Ramda] Refactor to a Point Free Function with Ramda's useWith Function的更多相关文章

  1. [Ramda] Refactor to Point Free Functions with Ramda using compose and converge

    In this lesson we'll take some existing code and refactor it using some functions from the Ramda lib ...

  2. 在JS中关于堆与栈的认识function abc(a){ a=100; } function abc2(arr){ arr[0]=0; }

    平常我们的印象中堆与栈就是两种数据结构,栈就是先进后出:堆就是先进先出.下面我就常见的例子做分析: main.cpp int a = 0; 全局初始化区 char *p1; 全局未初始化区 main( ...

  3. Adding New Functions to MySQL(User-Defined Function Interface UDF、Native Function)

    catalog . How to Add New Functions to MySQL . Features of the User-Defined Function Interface . User ...

  4. JavaScript中函数function fun(){}和 var fun=function(){}的区别

    function fun(){} 和 var fun=function(){}的区别 标题有点长···· 废话少说,其实他们的主要区别就是"函数声明的提前行为". var fun= ...

  5. Mysql drop function xxxx ERROR 1305 (42000): FUNCTION (UDF) xxxx does not exist

    mysql> drop function GetEmployeeInformationByID;ERROR 1305 (42000): FUNCTION (UDF) GetEmployeeInf ...

  6. Javascript 链式作用域 function fn(){}和var fn=function(){}区别

    其实对于Javascript链式作用域的描述,包括,JS权威指南,都有些太冗长了--但是很准确:JavaScript中的函数运行在他们被定义的作用域里,而不是他们被执行的作用域里. 这句话有点难懂,但 ...

  7. js页面加载的几种方式的速度: window.onload、 $(window).load、 $(function(){})、 $(document).ready(function () {})、onload=‘asd()’

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  8. JavaScript自学笔记(2)---function a(){} 和 var a = function(){}的区别(javascript)

    function a(){} 和 var a = function(){}的区别: 学习做浮窗,看到别人的代码里有: window.onresize = function(){ chroX = doc ...

  9. 洛谷P1464 Function  HDU P1579 Function Run Fun

    洛谷P1464 Function HDU P1579 Function Run Fun 题目描述 对于一个递归函数w(a,b,c) 如果a≤0 or b≤0 or c≤0就返回值11. 如果a> ...

随机推荐

  1. ubuntu14中 memcached安装与使用

    第一步,先安装lib-event 下载lib-event  的包http://libevent.org/ 下载完之后,解压安装 ./configure –prefix=/usr (或 ./config ...

  2. 【iOS开发-29】解决方式:TabBar的图片不显示,仅仅显示灰色的正方形

    (1)现象 tabbar上的图片变成一块正方形的灰色块块,原先的图片没有了. (2)原因 tabbar上的图片本质上不是一个图片.而是一个形状图片.系统对我们使用的图片也仅仅是把当中的形状" ...

  3. 国内计算机类期刊 SCI收录:

    国内计算机类期刊 SCI收录: JOURNAL OF COMPUTER SCIENCE AND TECHNOLOGY,计算机科学与技术,英文,双月刊, SCIE 国内计算机类期刊 EI收录: 核心类 ...

  4. android--显式跳转和隐式跳转的差别使用方法

    #创建第二个activity * 新创建的activity.必须在清单文件里做配置,否则系统找不到,在显示时会直接报错 <activity android:name="com.ithe ...

  5. js中#代表什么

    js中#代表什么 一.总结 1.#号:代表id选择器  2. $('#div1'). : 常用用法,前面也有$符号 二."#"在js中代表什么 js里我不曾看到用到‘#’的代码端, ...

  6. Mybatis的使用中的一些不太注意的技巧

    以下就总结一下Mybatis的使用中的一些不太注意的技巧,算是Mybatis的总结笔 1.插入时主键返回 我们向数据库插入一条记录是,使用Mybatis的<insert>是无法返回插入的主 ...

  7. Android新控件RecyclerView剖析

    传智·没羽箭(传智播客北京校区Java学院高级讲师) 个人简单介绍:APKBUS专家之中的一个,黑马技术沙龙会长,在移动领域有多年的实际开发和研究经验.精通HTML5.Oracle.J2EE .Jav ...

  8. ANSCII码和BCD码互转

    bool AtoBCD(unsigned char* Asc,unsigned char* BCD,int len) { int i; unsigned char ch; //高位 unsigned ...

  9. [Angular2 Form] Validation message for Reactive form

    <div class="form-field"> <label>Confirm Password: </label> <input typ ...

  10. 最简单的基于FFmpeg的移动端样例:IOS HelloWorld

    ===================================================== 最简单的基于FFmpeg的移动端样例系列文章列表: 最简单的基于FFmpeg的移动端样例:A ...