Contains all test

Learn how to check if a collection contains all specified elements.

This test checks whether one collection contains all elements of another. It is the opposite of the contains none test.

This operation corresponds to the mathematical concepts of superset and subset. Specifically, it checks whether the collection 𝐴 is a superset of 𝐵 (𝐴 ⊇ 𝐵) or, conversely, whether 𝐵 is a subset of 𝐴 (𝐵 ⊆ 𝐴).

Note that the result is always true if the second collection is empty, because the empty set is a subset of every set.

Croct's mascot neutral
Is every unicorn in the room shining?

This might sound funny, but since there are no unicorns in the room, there's no unicorn that isn't shining. So, technically, they all are!

Also, keep in mind that neither the order nor duplicate elements affect the result since collections are treated as sets.

Syntax

This test has the following syntax:

/*<collection>*/ contains all of /*<collection>*/
Try in Playground

Alternatively, you can use the following syntax:

/*<collection>*/ includes all of /*<collection>*/
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 all of /*<collection>*/
Try in Playground

The same applies to the alternative syntax:

/*<collection>*/ does not include all of /*<collection>*/
Try in Playground

However, consider using the contains none test instead of negating, as it is more expressive and easier to understand.

Parameters

These are the supported parameters:

collection

The collection to check.

subset

The collection whose elements must be contained in the other collection.

Examples

Here is an example of a collection that contains all the elements of another collection:

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

And here is a counterexample:

["a", "b"] contains all of ["a", "b", "c"] // false
Try in Playground

To negate the test, you can write:

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

If the second collection is empty, the result is always true:

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