我有一段代码写的lodash象下面这样:使用ramda处理的承诺,并等待
const profit =
price -
_.sumBy(
await Promise.all(
map(uOrder => uOrder.invoice, await order.upstreamOrders),
),
'amount',
);
我想改变它ramda,后夫妇的思考和阅读一些文件我写下面的代码:
const resualt = R.compose(
R.pick(['amount']),
await Promise.all(),
R.map(await order.upstreamOrders, uOrder.invoice),
);
当然
其错误和不工作,但它的第一种方法,我想知道如何处理这样的使用ramda完美和功能方式的情况。我该如何执行此操作? 还下令对象是下面的示例的数组:
{
"_id" : ObjectId("59dce1f92d57920d3e62bdbc"),
"updatedAt" : ISODate("2017-10-10T15:06:34.111+0000"),
"createdAt" : ISODate("2017-10-10T15:06:33.996+0000"),
"_customer" : ObjectId("59dce1f92d57920d3e62bd44"),
"_distributor" : ObjectId("59dce1f92d57920d3e62bd39"),
"status" : "NEW",
"cart" : [
{
"count" : NumberInt(1),
"_item" : ObjectId("59dce1f92d57920d3e62bd57"),
"_id" : ObjectId("59dce1f92d57920d3e62bdc1")
},
{
"count" : NumberInt(1),
"_item" : ObjectId("59dce1f92d57920d3e62bd5c"),
"_id" : ObjectId("59dce1f92d57920d3e62bdc0")
},
{
"count" : NumberInt(1),
"_item" : ObjectId("59dce1f92d57920d3e62bd61"),
"_id" : ObjectId("59dce1f92d57920d3e62bdbf")
},
{
"count" : NumberInt(1),
"_item" : ObjectId("59dce1f92d57920d3e62bd66"),
"_id" : ObjectId("59dce1f92d57920d3e62bdbe")
},
{
"count" : NumberInt(1),
"_item" : ObjectId("59dce1f92d57920d3e62bd6b"),
"_id" : ObjectId("59dce1f92d57920d3e62bdbd")
}
],
"_upstreamOrders" : [
"4545643499"
],
"key" : "4592846350",
"__v" : NumberInt(1),
"_invoice" : "0811260909610702"
}
'几个音符await'是关键字,不是一个可以组成的函数。你需要把它解析成'then'并明确地处理这些承诺。最好你可以使用['composeP'](http://ramdajs.com/docs/#composeP)。 – Bergi
TBH,我不明白你为什么要使用'compose',没有什么需要改变表达式'await Promise.all(R.map(uOrder => uOrder.invoice,await order.upstreamOrders ))'。 – Bergi