jjzjj

ramda长度深

我有一系列的数组,一个深度,需要计算嵌套阵列的长度之和,IE。长度深.试图找出一种很好的惯用方式来与Ramda一起做。我当前的解决方案感觉还不够简短。可能我缺少一些东西。你能提出更好的建议吗?constarr=[[1],[2,3],[4,5,6]]constlengthDeep=R.pipe(R.map(R.prop('length')),R.sum)console.log(lengthDeep(arr))//6PS:我通过尝试将其应用于日常编码来学习RAMDA。看答案首先,您可以使用R.length代替R.prop('length')。您也可以考虑将阵列变平,之后所需的结果是:R.pipe(

javascript - 在 ramda 中使用 fetch api

我正在学习Ramda并尝试实现无点编程。为了做到这一点,我尝试在这里和那里重构,但卡在了这一点上。我显然认为这行不通,因为调用是异步的,但我找不到这段代码有什么问题。//WhyisthisconsttoJSONRamda=R.pipe(R.prop('json'),//gettingthe'json'functionR.call//andcallingit)//differentfromthisconsttoJSON=response=>response.json()//Worksfetch('https://jsonplaceholder.typicode.com/todos/1')

javascript - 如何访问 Ramda.map 中的迭代索引

我曾经写过类似的东西_.map(items,(item,index)=>{});用lodash。通常我不需要index但有时它很有用。我现在正在迁移到Ramda:R.map((item,index)=>{},items);index是undefined。当然,我可以在上层范围内创建变量index并在map主体中每次递增它,但从Ramda所代表的FPAngular来看,这是有点错误的。那么有什么方法可以获取迭代索引吗? 最佳答案 查看addIndex:Createsanewlistiterationfunctionfromanexis

javascript - 使用 Ramda 处理异步编程

我正在研究处理返回带有Ramda函数而不是pipeP的Promise的函数。我正在尝试将函数(其中一个返回promise)与equals进行比较,如下所示:getSectionFromDb::obj->promisegetSectionFromData::obj->numberR.equals(getSectionFromDb,getSectionFromData)这里有两个因素在起作用。首先R.equals不会评估函数,但更大的问题是我将promise与数字进行比较。有没有一种功能性的方法来做这种事情(我知道这些函数不是引用透明的,但必须有一种处理io的方法)?有Ramda的方法吗?

关于 ramda.js:如何将 R.pick 与 TypeScript 一起使用

HowtouseR.pickwithTypeScript我正在尝试类似的东西123456789101112131415161718192021importRfrom'ramda'importfsfrom'fs'importpathfrom'path'import{promisify}from'util'constreadFile=promisify(fs.readFile)exportasyncfunctiondiscoverPackageInfo():Promise name:string, version:string description:string}>{ returnreadFil

关于 ramda.js:如何将 R.pick 与 TypeScript 一起使用

HowtouseR.pickwithTypeScript我正在尝试类似的东西123456789101112131415161718192021importRfrom'ramda'importfsfrom'fs'importpathfrom'path'import{promisify}from'util'constreadFile=promisify(fs.readFile)exportasyncfunctiondiscoverPackageInfo():Promise name:string, version:string description:string}>{ returnreadFil