ixfx
    Preparing search index...

    Class SetStringImmutable<V>

    A Set which stores unique items determined by their value, rather than object reference (unlike the default JS Set). Create with Sets.mutable. Immutable.

    By default the JSON.stringify() representation is considered the 'key' for an object. Pass in a function to setMutable to define your own way of creating keys for values. The principle should be that objects that you consider identical should have the same string key value.

    The Sets.ISetMutable alternative also has events for monitoring changes.

    const s = Sets.mutable();
    s.add(item); // Add one or more items. Items with same key are overriden.
    s.has(item); // Returns true if item value is present
    s.clear(); // Remove everything
    s.delete(item); // Delete item by value
    s.toArray(); // Returns values as an array
    s.values(); // Returns an iterator over values
    s.size; // Returns number of items in set
    // Data to add
    const people = [
    {name: `Barry`, city: `London`}
    {name: `Sally`, city: `Bristol`}
    ];

    // Create a set, defining how keys will be generated
    let s = Sets.mutable(person => {
    // Key person objects by name and city.
    // ie. Generated keys will be: `Barry-London`, `Sally-Bristol`
    return `${person.name}-${person.city}`
    });

    // Add list - since it's immutable, a changed copy is returned
    s = s.add(...people);

    // Accessing: has/get
    s.has({name:`Barry`, city:`Manchester`})); // False, key is different (Barry-Manchester)
    s.has({name:`Barry`, city:`London`})); // True, we have Barry-London as a key
    s.has(people[1]); // True, key of object is found (Sally-Bristol)

    // Deleting (returns changed copy)
    s = s.delete({name:`Barry`, city:`London`});

    Type Parameters

    • V

      Type of data stored

    Implements

    Constructors

    Accessors

    Methods

    Constructors

    Accessors

    • get size(): number

      Returns number

    Methods

    • Returns Generator<V, void, unknown>