GoJS API
/ to search
    Preparing search index...

    Class Set<T>

    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:

      const set = new go.Set();  // In TypeScript: new go.Set<string>();
    set.add("orange");
    set.add("apple");
    set.add("orange");
    // now set.size === 2
    // and set.has("orange") === true
    // and set.has("banana") === false

    You can iterate over the items in a Set:

      const it = aSet.iterator;
    while (it.next()) {
    . . . it.value . . .
    }

    Or:

      aSet.each(val => {
    . . . val . . .
    });

    For compatibility with versions of GoJS before version 3.0, the following synonyms are defined:

    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 ECMAScript iteration, so that functionality has not been made somewhat compatible. These collection classes were defined in GoJS before the ECMAScript collection classes were proposed.

    Type Parameters

    • T

    Implements

    Index

    Constructors

    • 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.

      Type Parameters

      • T

      Parameters

      • Optionalcoll: Iterable<T> | Iterable<T, any, any>

        an optional collection of items to add; it can be either a GoJS Iterable or a JavaScript Iterable, including an Array

      Returns Set<T>

    Accessors

    • get count(): number

      This read-only property is the number of elements in the Set.

      Returns number

    • get iterator(): Iterator<T>

      Gets an object that you can use for iterating over the Set. The value will be a member of the Set. Typical usage:

        const it = aSet.iterator;
      while (it.next()) {
      . . . " value: " + it.value . . .
      }

      Returns Iterator<T>

    • get size(): number

      This read-only property is the number of elements in the Set.

      Returns number

    Methods

    • This class implements the JavaScript Symbol.iterator, and can be used with spread syntax or for ... of statements.

      Returns IterableIterator<T>

      since

      3.0

    • Adds a given value to the Set, if not already present.

      Be careful not to call this method while iterating over the collection.

      Parameters

      • val: T

        The value to add to the Set; must not be null.

      Returns this

      This modified Set.

    • Adds all of the values of a collection to this Set.

      Be careful not to call this method while iterating over the collection.

      Parameters

      • coll: Iterable<T> | Iterable<T, any, any>

        the collection of items to add -- it can be either a GoJS Iterable or a JavaScript Iterable, including an Array

      Returns this

      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.

      Parameters

      • pred: (a: T) => boolean

        This function must not have any side-effects.

      Returns boolean

      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.

      Parameters

      • pred: (a: T) => boolean

        This function must not have any side-effects.

      Returns boolean

      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 void

    • Returns whether the given value is in this Set. A synonym for has.

      Parameters

      • val: T

        The value to check.

      Returns boolean

      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.

      Parameters

      • coll: Iterable<T> | Iterable<T, any, any>

        the collection of items to check for.

      Returns boolean

    • Returns true if any of the values of a given collection are in this Set.

      Parameters

      • coll: Iterable<T> | Iterable<T, any, any>

        the collection of items to check for.

      Returns boolean

    • 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.

      Returns Set<T>

      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.

      Parameters

      • val: T

        The value to remove.

      Returns boolean

      true if the value was found and removed, false otherwise.

    • Call the given function on each item in the collection.

      Parameters

      • func: (a: T) => void

        This function must not modify the collection.

      Returns this

      This Set itself.

    • Returns the first item in the collection, or null if there is none.

      Returns T | null

      This returns null if there are no items in the collection.

    • Call a provided function once per each key/value pair in this Set.

      Parameters

      • callbackFunc: (value1: T, value2: T, map: Set<T>) => void

        a function to call for each value in the Set

      • thisArg: any

        a value to use as this when executing callbackFunc

      Returns void

      since

      3.0

    • Returns whether the given value is in this Set.

      Parameters

      • val: T

        The value to check.

      Returns boolean

      Whether or not the value is contained within the Set.

    • Removes a value (if found) from the Set. A synonym for delete.

      Be careful not to call this method while iterating over the collection.

      Parameters

      • val: T

        The value to insert.

      Returns boolean

      true if the value was found and removed, false otherwise.

    • Removes all of the values of a collection from this Set.

      Be careful not to call this method while iterating over the collection.

      Parameters

      • coll: Iterable<T> | Iterable<T, any, any>

        the collection of items to remove.

      Returns this

      This modified Set.

    • Removes from this Set all items that are not in the given collection.

      Be careful not to call this method while iterating over the collection.

      Parameters

      • coll: Iterable<T> | Iterable<T, any, any>

        the collection of items that should be kept in this Set.

      Returns this

      This modified Set.

    • Produces a JavaScript Array from the contents of this Set.

      Returns T[]

      A copy of the Set in Array form.

    • Converts the Set to a List. Because there is no ordering within a Set, the values in the List may be in any order.

      Returns List<T>

      A copy of the contents of this Set in List form.

    • Return a JavaScript iterator that produces the values in this Set. This does not produce the old GoJS style Iterator -- use the iterator property if you want that.

      Returns IterableIterator<T>

      since

      3.0