javascript - __ 应该只适用于柯里化(Currying)函数吗?为什么它在这里工作?

标签 javascript node.js functional-programming ramda.js

我试图理解为什么 __在这段代码中工作正常:

function editAddress (id, addressId, model) {
    return BusinessService
      .getById(id)
      .then(unless(
        () => checkUrlValue(addressId, model.id),
        rejectWithError(InvalidData.error('Invalid address data: Address id is different from request'))
      ))
      .then(pipe(
        updateModel(__, 'addresses', model, 'id', addressId),
        juxt([ always(id), identity ]),
        apply(BusinessService.editById)
      ))
      .then(pipe(
        prop('addresses'),
        find(propEq('id', addressId))
      ))
  }
function updateModel (entity, property, model, attr, id) {
  return evolve({
    [property]: pipe(
      juxt([
        findIndex(propEq(attr, id)),
        pipe(
          find(propEq(attr, id)),
          mergeLeft(model)
        ),
        identity
      ]),
      apply(update)
    )
  })(entity)
}

既然调用的函数 ( updateModel ) 没有柯里化(Currying),为什么 __ 在这种情况下仍然有效?

最佳答案

updateModel 未进行柯里化(Currying)处理,但它返回一个名为 evolve 的柯里化(Currying)函数的结果。第一个调用传入:

{
    [property]: pipe(
      juxt([
        findIndex(propEq(attr, id)),
        pipe(
          find(propEq(attr, id)),
          mergeLeft(model)
        ),
        identity
      ]),
      apply(update)
    )
}

然后使用 entity 调用进化调用的结果,在您的情况下将是 __。如果不了解 evolve 的内部结构,就不可能进一步理解代码。

关于javascript - __ 应该只适用于柯里化(Currying)函数吗?为什么它在这里工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57891579/

相关文章:

javascript - 如何在 angular.js 中使用可靠的 ddl

javascript - 模块构建失败,Vue js 中的 vue-router.esm.js

node.js - solve() 函数在 promise 中返回未定义

node.js - 如何正确格式化此 EJS 三元条件?

functional-programming - 如何将数据传递到撰写管道的后续阶段

javascript - 如何限制javascript中函数创建的动态元素的数量?

javascript - 如何更改react.js redux中另一个reducer的状态?

node.js - 吞噬错误产生EN0ENT

programming-languages - CLR 上的功能开发

javascript - 为什么我的 Ramda dropRepeats 函数在这里不起作用?