No quantifier

Learn how to check if no items satisfy a condition.

This checks whether none of the elements in a collection satisfy a given condition.

Note that this quantifier always returns true for empty collections. This is known in logic as vacuous truth, meaning that the quantifier is satisfied because no elements in the collection do not satisfy the condition.

Croct's mascot neutral
Are none of the unicorns in the room shining?

Technically, yes. Since there are no unicorns in the room, there's no unicorn that isn't shining. Logic is fun, isn't it?

Syntax

This quantifier has the following syntax:

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

Either satisfy or satisfies can be used interchangeably:

no /*<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:

no /*<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 checks if a color is not present in a collection:

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

The following example is a bit more advanced, as it uses the indexed by clause to refer to the index of the element in the collection:

no item in cart indexed by index satisfies item's brand is "Apple" and index >= 1
Try in Playground

In the above example, the item variable refers to the element in the collection, while the index variable refers to the index of the element in the collection. The quantifiers then determine whether the user has added Apple products as the second or subsequent item in the cart.