Skip to content

Set Methods

Sets store unique script values through the same ValueKey policy used by map keys. Immutable leaf values such as unit, booleans, finite numbers, chars, strings, and bytes compare by value. Script heap objects and host refs compare by identity, while transient values such as PathProxy are rejected before mutation.

Use set::from_array to build a set from an array. Duplicate values are deduplicated according to ValueKey equality, so aliases of the same script object collapse while separate objects with identical fields remain distinct.

fn main() {
let tags = set::from_array(["daily", "quest", "daily"]);
if tags.has("quest") && tags.len() == 2 {
return "ok";
}
return "missing";
}

values and iter produce iterators over set values. If stable display order matters, collect and sort before joining.

fn main() {
let tags = set::from_array(["raid", "daily", "quest"]);
return tags.values().collect_array().sort().join(",");
}

add returns true when a value was inserted and false when it was already present. remove returns whether a value was removed.

fn main() {
let tags = set::from_array(["daily"]);
let added = tags.add("quest");
let removed = tags.remove("missing");
tags.extend(set::from_array(["raid", "daily"]));
return added && !removed && tags.len() == 3;
}

clear removes all values and returns ().

union, intersection, difference, and symmetric_difference return new sets. Relation helpers return booleans.

fn main() {
let owned = set::from_array(["daily", "quest", "raid"]);
let required = set::from_array(["daily", "quest"]);
let event = set::from_array(["quest", "bonus"]);
let shared = owned.intersection(event);
return required.is_subset(owned)
&& owned.is_superset(required)
&& shared.has("quest");
}

Callback helpers map, filter, find, any, all, and count mirror the array callback model.