There are two possible constructors:
new go.Set()
, for JavaScript
new go.Set<T>()
for TypeScript
In TypeScript, the optional generic argument describes the type of values that this Set may hold.
For example, the expression:
// TypeScript:
new go.Set<go.Point>()
Creates a new Set that may only contain Points.
Optional
coll: Iterable<T> | T[]an optional collection of items to add.
Read-only
count
This read-only property is the number of elements in the Set.
Read-only
iterator
Gets an object that you can use for iterating over the Set. The value will be a member of the Set. Typical usage:
var it = aSet.iterator;
while (it.next()) {
. . . " value: " + it.value . . .
}
Read-only
size
This read-only property is the number of elements in the Set.
Virtual
allThis is true if all invocations of the given predicate on items in the collection are true.
Call the given predicate on each item in the collection. As soon as a call returns false, this returns false. Otherwise this returns true. For an empty collection this returns true.
This function must not have any side-effects.
True if all predicate calls are true; false otherwise.
Virtual
anyThis is true if any invocation of the given predicate on items in the collection is true.
Call the given predicate on each item in the collection. As soon as a call returns true, this returns true. Otherwise this returns false. For an empty collection this returns false.
This function must not have any side-effects.
True if any predicate call is true; false otherwise.
Clears the Set. This sets the count to zero.
Be careful not to call this method while iterating over the collection.
Virtual
copyVirtual
each
NOTE: For 2.0 the constructor argument has changed. Set now optionally accepts a collection, and only checks types in TypeScript.
An unordered iterable collection that cannot contain two instances of the same value. In TypeScript it is a generic class that enforces at compile-time the type of elements that may be added to the Set.
An example usage:
You can iterate over the items in a Set:
Or:
Although not precisely implementing the features of the EcmaScript 6 Set class, this GoJS Set class has synonyms for the following methods and property:
The constructor now takes an optional Iterable or Array argument that provides the initial elements for the new Set.
Note that GoJS iteration is quite different than ES6 iteration, so that functionality has not been made somewhat compatible. These collection classes were defined in GoJS before the ES6 collection classes were proposed.
implements