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.
an optional collection of items to add.
This read-only property is the number of elements in the Set.
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 . . .
}
This read-only property is the number of elements in the Set.
Adds a given value to the Set, if not already present.
Be careful not to call this method while iterating over the collection.
The value to add to the Set; must not be null.
This modified Set.
This 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.
This 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.
Returns whether the given value is in this Set.
The value to check.
Whether or not the value is contained within the Set.
Returns true if all of the values of a given collection are in this Set.
the collection of items to check for.
Returns true if any of the values of a given collection are in this Set.
the collection of items to check for.
Makes a shallow copy of this Set. The values are not copied, so if they are objects they may continue to be shared with the original Set.
The new Set with the same elements.
Removes a value (if found) from the Set.
Be careful not to call this method while iterating over the collection.
The value to insert.
true if the value was found and removed, false otherwise.
Call the given function on each item in the collection.
This function must not modify the collection.
This Set itself.
Returns the first item in the collection, or null if there is none.
This returns null if there are no items in the collection.
Returns whether the given value is in this Set.
The value to check.
Whether or not the value is contained within the Set.
Removes a value (if found) from the Set.
Be careful not to call this method while iterating over the collection.
The value to remove.
true if the value was found and removed, false otherwise.
Produces a JavaScript Array from the contents of this Set.
A copy of the Set in Array form.
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.