Dataweave替换为do

我有一种情况,我试图从有效负载中删除空对象和空对象,并发现以下功能,但是我知道用“ do”代替了“ using”。我可以知道它的样子吗:

这是代码

%dw 2.0
fun filterValue(value) = value match {
    case is Object -> filterKeyValuePairs(value)
    case is Array -> $ map filterValue($) filter (not (isEmpty($)))
    else -> value
}
fun filterKeyValuePairs(value) = value mapObject (value, key, index) ->
using (filteredValue = filterValue(value)){
    ((key): filteredValue) if (not isEmpty(filteredValue))
}

---
filterValue(payload)
评论
laut
laut

Same code with do; do basically gives you header --- body

%dw 2.0
fun filterValue(value) = value match {
    case is Object -> filterKeyValuePairs(value)
    case is Array -> $ map filterValue($) filter (not (isEmpty($)))
    else -> value
}
fun filterKeyValuePairs(value) = value mapObject (value, key, index) -> do {
    var filteredValue = filterValue(value)
    ---
    ((key): filteredValue) if (not isEmpty(filteredValue))
}
---
filterValue(payload)

如果您想在没有第二个功能的情况下进行操作:

%dw 2.0
fun filterValue(value) = value match {
    case is Object -> $ mapObject do {
        var filteredVal = filterValue($)
        ---
        (($$): filteredVal) if (not (isEmpty(filteredVal)))
    }
    case is Array -> $ map filterValue($) filter (not (isEmpty($)))
    else -> value
}
---
filterValue(payload)
点赞
评论