Set
The Set collection in Tish.
Overview
Set is a collection of unique values. It works identically across every Tish backend — the
interpreter, the bytecode VM, and native (AOT) compiled binaries. Membership uses SameValueZero
equality: NaN is equal to NaN, +0 and -0 are the same value, primitives compare by value, and
objects compare by identity. Insertion order is preserved.
let s = new Set([1, 2, 2, 3]) // {1, 2, 3}
s.size // 3Constructor
Properties & methods
Iteration
.values(), .keys(), and .entries() return real iterators (objects with a
.next() yielding { value, done }), so they work directly, in for...of, and with spread:
let s = new Set([2, 3, 4])
let total = 0
for (let v of s.values()) {
total = total + v
}
total // 9
s.values().next() // { value: 2, done: false }
[...s.values()] // [2, 3, 4]Examples
let seen = new Set()
seen.add("a")
seen.add("b")
seen.add("a") // duplicate — ignored
seen.size // 2
seen.has("b") // true
seen.delete("a") // true
seen.size // 1
// SameValueZero: NaN is a single member.
let n = new Set([NaN, NaN])
n.size // 1
n.has(NaN) // trueCompatibility notes (v1)
forEachis not available yet, and.add()does not return the set (no method chaining). Iterate withfor...ofover.values().- Direct
for (x of set)and[...set]are not wired yet — iterate via.values()/.keys()/.entries(). Those now return iterators, so[...set.values()]andset.values().next()work like JavaScript. console.log(set)prints the underlying object rather thanSet(n) {…}. Log[...set.values()]style output for a clean view (set.values()).