[Ramda] Curry and Uncurry Functions with Ramda
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(1)(2);
or
const inc = add(1); const res = inc(2);
What is R.curry?
const add = R.curry((a, b) => a + b);
when we all this, we can do:
const inc = add(1); const res = inc(2);
or:
add(1,2)
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(1, 2); var g = f(3); g(4); //=> 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(1)(2)(3); // if we uncurry it const sum = R.uncurryN(3, add); const res = sum(1,2,3); // 6
相关文章
- From Docker to Kubernetes(一)- Image And Container
- MOB LEC10 LIDAR, Point Cloud and Iterative Closest Points
- SpringBoot+SpringDataJpa @Query之 JPQL使用书写模板(模糊查询and条件查询)
- 【Android】开发Android应用时对于Handler消息传递与缓存问题深入运用and理解
- ORA-23487: object groups “string”.”string” and “string”.”string” do not have the same connection qualifier ORACLE 报错 故障修复 远程处理
- ORA-24940: invalid combination of string namespace, string presentation and string receive protocol ORACLE 报错 故障修复 远程处理
- ORA-26815: Error from Apply Network Receiver for Apply “string” and Capture “string”. ORACLE 报错 故障修复 远程处理
- ORA-31498: description and remove_description cannot both be specified ORACLE 报错 故障修复 远程处理
- ORA-39192: table mode jobs with transportable=always and partition filters only allow objects from one table ORACLE 报错 故障修复 远程处理
- MySQL Error number: MY-010345; Symbol: ER_INVALID_CHARSET_AND_DEFAULT_IS_MB; SQLSTATE: HY000 报错 故障修复 远程处理
- ORA-01295: DB_ID mismatch between dictionary string and logfiles ORACLE 报错 故障修复 远程处理
- ORA-13904: The file has been dropped and recreated during the procedure call. ORACLE 报错 故障修复 远程处理
- ORA-18170: FTST0011 FTWindow and FTDistance restriction ORACLE 报错 故障修复 远程处理
- Create a nice looking chart with CL_GUI_CHART_ENGINE – Part 3 – Chart Data and render详解编程语言
- Leading the Next Level of Applications with Redis and AMQP(redisamqp)
- order Managing Data with C and MySQL(cmysqlin)
- Swo Linux File Management: How to Navigate Save and Share Files with Ease(swolinux文件)
- Mastering Regex on Linux: Tips and Tricks for Efficient Pattern Matching(regexlinux)
- Mastering Network Troubleshooting with Linux Ping and C: A Comprehensive Guide(linuxpingc)
- Exploring the Benefits and Functionality of Linux SPI Communication(linuxspi)
- Boost Your Web Performance with Linux and Xcache: A Comprehensive Guide(linuxxcache)
- Exploring the Power of MySQL for Storing and Manipulating 16bit Hexadecimal Data(mysql存储16进制)
- Effortlessly Learn Linux with Engaging and Insightful PPT Presentations(linux教学ppt)
- Boost Your Efficiency and Performance with Linux CPU St Optimizations(linuxcpust)
- Exploring the Benefits and Challenges of Implementing a MySQL Multidatabase Architecture with Multiple Data Centers.(mysql多数据中心)
- Redis: Managing Files with Efficiency and Ease(redis文件)
- How to Optimize MySQL for High Frequency Read and Write Operations(mysql频繁读写)
- Oracle数据库中的AND查询(oracle and查询)
- 语句Oracle中简洁的With语句(oracle 中with)
- MySQL中的AND和OR使用逻辑运算符优化查询语句(mysql中and与or)
- Oracle中使用除了And的其他查询关键字(oracle中除了and)
- 分析学习Oracle深入理解使用With 分析(oracle使用with)