For the complete documentation index, see llms.txt. This page is also available as Markdown.

ObjectToSet

Convert a collection into a Set, deduplicating automatically.

Accepts an Array, a list-delimited String, an existing Set, a QueryColumn, an XML node, a bounded Range, or any value castable to a Set. When the value is already of the requested variant it is returned as-is; otherwise a new Set of the specified variant is created and populated.

Method Signature

ObjectToSet(value=[any], type=[string], delimiter=[string])

Arguments

Argument
Type
Required
Description
Default

value

any

true

The value to convert. Accepts Array, Set, list-delimited String, QueryColumn, XML, Range, etc.

type

string

false

The backing variant: "default" / "hash" (HashSet), "linked" / "ordered" (LinkedHashSet), or "sorted" / "tree" (TreeSet). When omitted, the caster defaults to LINKED for ordered collections like Arrays.

delimiter

string

false

When {@code value} is a String, the list delimiter to split on. Defaults to {@code ","}.

,

Examples

Convert an Array to a Set

Calling .toSet() on an Array deduplicates its elements and returns a BoxSet.

s = [ 1, 2, 2, 3 ].toSet();
writeOutput( s.size() );

Result: 3

Convert an Array to a linked (insertion-ordered) Set

Pass a type argument to control the backing implementation.

Result: [c, a, b]

Convert an Array to a sorted Set

Result: [1, 3, 5, 9]

Split a comma-delimited string into a Set

listToSet() splits the string on the default delimiter and deduplicates.

Result: 3

Split a string with a custom delimiter

Result: 3

Split with a custom delimiter and preserve insertion order

Result: [a, b, c]

Convert a Query to a Set of row structs

Each row becomes a Struct element in the Set.

Result: 2

Get distinct column values as a Set

Use .columnData() to extract a column as an Array first, then call .toSet() to deduplicate.

Result: 2

Last updated

Was this helpful?