Contact Us 1-800-596-4880

some

DataWeave 2.2 is compatible and bundled with Mule 4.2. This version of Mule reached its End of Life on May 2, 2023, when Extended Support ended.

Deployments of new applications to CloudHub that use this version of Mule are no longer allowed. Only in-place updates to applications are permitted.

MuleSoft recommends that you upgrade to the latest version of Mule 4 that is in Standard Support so that your applications run with the latest fixes and security enhancements.

some(Array<T>, (T) -> Boolean): Boolean

Returns true if at least one element in the array matches the specified condition.

The function stops iterating after the first element that matches the condition is found.

Parameters

Name Description

list

The input array.

condition

A condition (or expression) used to match elements in the array.

Example

This example applies a variety of expressions to elements of several input arrays. The $ in the condition is the default parameter for the current element of the array that the condition evaluates. Note that you can replace the default $ parameter with a lambda expression that contains a named parameter for the current array element.

Source

 %dw 2.0
 import * from dw::core::Arrays
 output application/json
 ---
 { "results" : [
     "ok" : [
       [1,2,3] some (($ mod 2) == 0),
       [1,2,3] some ((nextNum) -> (nextNum mod 2) == 0),
       [1,2,3] some (($ mod 2) == 1),
       [1,2,3,4,5,6,7,8] some (log('should stop at 2 ==', $) == 2),
       [1,2,3] some ($ == 1),
       [1,1,1] some ($ == 1),
       [1] some ($ == 1)
     ],
     "err" : [
       [1,2,3] some ($ == 100),
       [1] some ($ == 2)
     ]
   ]
}

Output

{
   "results": [
     {
       "ok": [ true, true, true, true, true, true, true ]
     },
     {
       "err": [ false, false ]
     }
   ]
 }