Some quantifier

Learn how to check that at least one item satisfies a condition.

This quantifier checks whether at least one element in a collection satisfies a given condition.

Note that the result is always false for empty collections. This is because there is not a single element in the collection that satisfies the condition.

Syntax

This quantifier has the following syntax:

some /*<item>*/ in /*<collection>*/ satisfies /*<condition>*/
Try in Playground

Either satisfy or satisfies can be used interchangeably:

some /*<item>*/ in /*<collection>*/ satisfy /*<condition>*/
Try in Playground

You can also specify a name to refer to the index of the element in the collection:

some /*<item>*/ in /*<collection>*/ indexed by /*<index>*/ satisfies /*<condition>*/
Try in Playground

You must replace the /*<item>*/ and /*<index>*/ placeholders with a valid identifier. These variables will refer to the element and its index in the collection, as exemplified in the following section.

Examples

Here is an example that check whether a color is present in a collection:

some color in ["red", "green", "blue"] satisfies color is "green" // true
Try in Playground

The following example shows how to use the index of the element in the condition:

some item in cart indexed by index satisfies item's brand is "Apple" and index < 3
Try in Playground

In the above example, it checks whether the user has added Apple products among the first three items in the cart.