Deduplicate modifier

Learn how to remove duplicate items from a collection.

This modifier removes duplicate elements from a collection. This is useful when you want your collection to behave like a set, where each element only appears once.

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

For maps, there are a few things to keep in mind:

  • Keys are not considered for deduplication.
  • The order and keys are preserved in the resulting map.
  • The first key encountered is retained for duplicate values.

Syntax

This modifier has the following syntax:

/*<collection>*/ without duplicates
Try in Playground

Parameters

These are the supported parameters:

collection
collection

The collection to deduplicate.

Examples

Here is a basic example of using this modifier with a list:

["a", "b", "a", "c"] without duplicates // ["a", "b", "c"]
Try in Playground

You can also use it to deduplicate a map:

["a": 1, "b": 2, "c": 1] without duplicates // ["a": 1, "b": 2]
Try in Playground