Sets
This example uses sets to represent the members of two teams. It shows how duplicate names are removed, how to check membership, and how to find everyone on either team, on both teams, or only on the backend team.
backend = Set.from_list(["Sam", "Lee", "Sam"]) frontend = Set.from_list(["Lee", "Jo"]) expect backend.len() == 2 expect backend.contains("Sam") expect backend.union(frontend) == Set.from_list(["Sam", "Lee", "Jo"]) expect backend.intersection(frontend) == Set.from_list(["Lee"]) expect backend.difference(frontend) == Set.from_list(["Sam"]) unique : Set(U64) unique = [3, 1, 3].iter().collect() expect unique.len() == 2
The final example collects an iterator into a Set(U64), removing duplicate numbers along the way.
Set elements need to support equality and hashing, which strings and integers already do. For your own types, see Custom Equality and Hashing.
A set’s iteration order is not guaranteed, so the tests compare membership rather than expecting a particular order.
Output
Run this from the directory that has main.roc in it:
$ roc test main.roc All (6) tests passed in 32.6 ms.
Validated with Roc nightly-2026-10-29-a0a9fc2.