Skip to main content

Sets

A set keeps track of collection of unique values - a specific value can only be added to a set once. Sets are immutable by default Set<T>, and you can make them immutable using MutSet<T>.

main.w
// mutable set
let unqiueNumbers = MutSet<num>[1, 2, 3, 3, 3];
unqiueNumbers.add(4);
unqiueNumbers.delete(1);

// immutable set, will make values unique
let uniqueStrings = Set<str>["unique", "values", "values"];


log(Json.stringify(unqiueNumbers.toArray()));
log(Json.stringify(unqiueNumbers.size));

log(Json.stringify(uniqueStrings.toArray()));
Wing console output
# Run locally with wing console
wing it

[2,3,4]
3
["unique", "values"]