Contact Us 1-800-596-4880

some

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 ]
     }
   ]
 }

some(Null, (Nothing) -> Boolean): Boolean

Helper function that enables some to work with a null value.

Introduced in DataWeave 2.3.0. Supported by Mule 4.3 and later.