Contains test

Learn how to check if a collection contains a certain element.

This test checks whether a collection contains a certain element. It works the same way as the in test, but with the operands reversed.

You can use any collection type, including lists and maps. Keys are ignored when checking whether a map contains an element.

When comparing elements, this test uses the same equivalence rules as the equal operation to ensure consistency in how it determines whether two items are equal.

Syntax

This test has the following syntax:

/*<collection>*/ contains /*<element>*/
Try in Playground

You can alternatively use the following syntax:

/*<collection>*/ includes /*<element>*/
Try in Playground

Both forms have the same semantics. You can use whichever makes your query more expressive and easier to read.

You can negate the test to verify the contrary:

/*<collection>*/ does not contain /*<element>*/
Try in Playground

The same applies to the alternative syntax:

/*<collection>*/ does not include /*<element>*/
Try in Playground

Parameters

These are the supported parameters:

collection

The collection to check.

element
any

The element to search for in the collection.

Examples

Here is a simple example that checks whether a list contains a certain element:

["a", "b", "c"] contains "b" // true
Try in Playground

To negate the test, you can write:

["a", "b", "c"] does not contain "b" // false
Try in Playground