【发布时间】:2020-01-13 10:31:01
【问题描述】:
我试图理解为什么__ 在这段代码中可以正常工作:
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)没有被柯里化,为什么__在这种情况下仍然有效?
【问题讨论】:
-
有趣的问题。我从未见过这种行为,我是 Ramda 的创始人之一。 Will Jenkins 的回答解释了这一点,我的评论对此进行了扩展。但很高兴知道这会奏效。
标签: javascript node.js functional-programming ramda.js