Dal*_*ale 3 dataweave mulesoft
%dw 2.0
import * from dw::core::Arrays
output application/json
var arr = [0,1,2,4,3]
---
arr filter $ <= 2
Run Code Online (Sandbox Code Playgroud)
和
%dw 2.0
import * from dw::core::Arrays
output application/json
var arr = [0,1,2,4,3]
---
arr takeWhile $ <= 2
Run Code Online (Sandbox Code Playgroud)
它们都给出相同的结果。有什么区别吗?
嗨 Dale 有一个区别 takeWhile 将停止使用第一个元素不满足条件的元素,这不是过滤器的情况,因此对于此示例 [0,2,4,3,1]
随着 TakeWhile
%dw 2.0
import * from dw::core::Arrays
output application/json
var arr = [0,2,4,3,1]
---
arr takeWhile $ <= 2
Run Code Online (Sandbox Code Playgroud)
返回:
[
0,
2
]
Run Code Online (Sandbox Code Playgroud)
带过滤器
%dw 2.0
import * from dw::core::Arrays
output application/json
var arr = [0,2,4,3,1]
---
arr filter $ <= 2
Run Code Online (Sandbox Code Playgroud)
返回:
[
0,
2,
1
]
Run Code Online (Sandbox Code Playgroud)