我有一段代碼寫的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