Most of the functions offered by the ramda library are curried by default. Functions you've created or that you've pulled in from another library may not be curried. Ramda's curry and curryN functions allow you to take a non-curried function and use it as a curried functions. In the case where you have a manually curried function and you want to just call it like a normal function, you can use uncurryN to get back a function that accepts all of the arguments at once.

What is manully curry?

const add =  a => b => a + b;

When we call it, we should do:

add()();

or

const inc = add();
const res = inc();

What is R.curry?

const add = R.curry((a, b) => a + b);

when we all this, we can do:

const inc = add();
const res = inc();

or:

add(,)

So the main difference between R.curry and manully curry function is R.curry allow user pass all the params necessary at once. But manully curry, you have to invoke the function twice.


R.curryN:

Actually R.curryN is basiclly the same as R.curry. Just it tells how many params the curry function should expect.

var sumArgs = (...args) => R.sum(args);

var curriedAddFourNumbers = R.curryN(4, sumArgs);
var f = curriedAddFourNumbers(, );
var g = f();
g(); //=> 10

So in the example, it has 4 params.


R.uncurryN:

It is used for manully curry, so that we don't need to invoke function multi times, just pass all the params which necessary at once.

const add = a => b => c => a + b+ c; // manually curry

// if we call normally
add()()(); // if we uncurry it
const sum = R.uncurryN(, add);
const res = sum(,,); //

[Ramda] Curry and Uncurry Functions with Ramda的更多相关文章

  1. [Ramda] Convert Object Methods into Composable Functions with Ramda

    In this lesson, we'll look at how we can use Ramda's invoker and constructNfunctions to take methods ...

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

  3. [Ramda] Curry, Compose and Pipe examples

    const curry = R.curry((fns, ary) => R.ap(fns, ary)); ), R.add()]); ,,]); console.log(res); //[2, ...

  4. 从函数式编程到Ramda函数库(二)

    Ramda 基本的数据结构都是原生 JavaScript 对象,我们常用的集合是 JavaScript 的数组.Ramda 还保留了许多其他原生 JavaScript 特性,例如,函数是具有属性的对象 ...

  5. [Javascript] Monads

    Monads allow you to nest computations. They are a pointed functor that adds mjoin and chain function ...

  6. [Javascript] Functor Basic Intro

    Well, this stuff will be a little bit strange if you deal with it first time. Container Object: Just ...

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

  8. 如何编写高质量的 JS 函数(4) --函数式编程[实战篇]

    本文首发于 vivo互联网技术 微信公众号 链接:https://mp.weixin.qq.com/s/ZoXYbjuezOWgNyJKmSQmTw作者:杨昆 [编写高质量函数系列],往期精彩内容: ...

  9. programming-languages学习笔记--第3部分

    programming-languages学习笔记–第3部分 */--> pre.src {background-color: #292b2e; color: #b2b2b2;} pre.src ...

随机推荐

  1. sql server向表里添加字段

    ADD mcTypeE VARCHAR(20) NULL,mcGoodsE VARCHAR(20) NULL, mcTypeF VARCHAR(20) NULL,mcGoodsF VARCHAR(20 ...

  2. 文档翻译第003篇:Process Monitor帮助文档(Part 3,附Process Monitor的简单演示)

    [导入与导出配置] 一旦您配置了一个筛选器,您能够使用"工具(Tools)"菜单中的"保存筛选器(SaveFilters)"菜单项将其保存.Process Mo ...

  3. Log4j.properties 属性详解以及 LOG4J日志级别详解

    转自:https://blog.csdn.net/lovely0903jpp/article/details/82261607 假如项目的生产环境上增加请求以及响应信息的打印,这个时候,对于新手来说, ...

  4. VUE笔记 - 列表过渡动画 v-enter, v-leave-to | v-enter-active, v-leave-active | v-move

    本例要结合过渡动画四个过程的示意图一起理解. https://cn.vuejs.org/v2/guide/transitions.html 疑问: v-for="(item,i) in li ...

  5. python,寻找班级里面名字最长的人

    寻找班级里面名字最长的人 我有一串字符串人名:names=(' Kunpen Ji, Li XIAO, Caron Li,' ' Dongjian SHI, Ji ZHAO, Fia YUAN Y,' ...

  6. CodeVs——T 3304 水果姐逛水果街Ⅰ

    http://codevs.cn/problem/3304/ 时间限制: 2 s  空间限制: 256000 KB  题目等级 : 钻石 Diamond 题解  查看运行结果     题目描述 Des ...

  7. hbase单机安装和简单使用

    电脑太卡了,使用不了hadoop和hdfs了,所以今天安装了一个伪分布式,数据存储在本地磁盘,也没有向HDFS中存,也没有使用自己的zookeeper,安装过程中还出了点小问题,总结一下,免得忘了. ...

  8. JS中的发布订阅模式

    一. 你是如何理解发布订阅模式的 JS中的设计模式: 单例模式:处理业务逻辑 构造原型模式:封装类库,组件,框架,插件等 类库:jQuery 只是提供了一些常用的方法,可以应用到任何的项目中,不具备业 ...

  9. CSS笔记 - fgm练习 2-9 - 播放列表收缩展开

    练习地址: http://www.fgm.cc/learn/lesson2/09.html <style> *{ margin: 0;padding: 0;font-size: 12px; ...

  10. [Angular] Component architecture and Reactive Forms

    It it recommeded that when deals with form component, we can create a container component to hold st ...