Skip to main content

AtomsSet<T> class

Namespace: Arlecchino.Atoms.Collections · Assembly: Arlecchino.Core

A set held as one piece of application state, behaving as a HashSet<T> does: adding what is already there changes nothing. A walk of it is in no order, so sort it where the reader sees the order.

public abstract class AtomsSet<T> : IReadableAtom<IReadOnlySet<T>>

Implements IReadableAtom<IReadOnlySet<T><T>>

Constructors

MemberSummary
AtomsSet(IReadOnlyList<T>, IEqualityComparer<T>)Creates the set.

Properties

MemberSummary
CountHow many it holds.
IsEmptyWhether it holds nothing.
RecordsHistoryWhether changes of this set enter the undo history.
ValueWhat the set holds now, as a live view rather than a copy. It is read-only all the way down, so every change goes through the members below.

Methods

MemberSummary
Add(T)Puts something in. Putting in what is already there changes nothing.
Add(IReadOnlyList<T>)Puts several in at once. One notification, one frame and one undo step for however many of them were not there already.
Clear()Takes everything out. An empty set changes nothing.
Contains(T)Whether the set holds something.
GetEnumerator()Walks what the set holds, in no order it promises, so foreach over the set itself reads the way it does over a HashSet<T>. Reach for AtomsSet.Value where a sequence is what is wanted, LINQ included.
Remove(T)Takes something out, and does nothing when it is not there.
Reset(IReadOnlyList<T>)Replaces the contents in one go, for the set that is worked out again rather than edited — what a new listing marks, what a filter leaves. Contents equal to what is already there change nothing.
Subscribe(Action)Calls back whenever the contents change.
TryAdd(T)Puts something in and says whether it was new.
TryRemove(T)Takes something out and says whether it was there.

Constructors in detail

AtomsSet(IReadOnlyList<T>, IEqualityComparer<T>)

public AtomsSet(IReadOnlyList<T> initial, IEqualityComparer<T> comparer);

Creates the set.

Parameters

NameTypeDescription
initialIReadOnlyList<T><T>What it starts with; empty when omitted. It is copied, not held.
comparerIEqualityComparer<T><T>How items are compared; the default comparer for T is used when omitted.

Properties in detail

Count

public int Count { get; }

How many it holds.

Type int

IsEmpty

public bool IsEmpty { get; }

Whether it holds nothing.

Type bool

RecordsHistory

public abstract bool RecordsHistory { get; }

Whether changes of this set enter the undo history.

Type bool

Value

public IReadOnlySet<T> Value { get; }

What the set holds now, as a live view rather than a copy. It is read-only all the way down, so every change goes through the members below.

Type IReadOnlySet<T><T>

Methods in detail

Add(T)

public void Add(T item);

Puts something in. Putting in what is already there changes nothing.

Parameters

NameTypeDescription
itemTWhat to put in.

Add(IReadOnlyList<T>)

public void Add(IReadOnlyList<T> items);

Puts several in at once. One notification, one frame and one undo step for however many of them were not there already.

Parameters

NameTypeDescription
itemsIReadOnlyList<T><T>What to put in. Adding none, or only what is there, changes nothing.

Clear()

public void Clear();

Takes everything out. An empty set changes nothing.

Contains(T)

public bool Contains(T item);

Whether the set holds something.

Parameters

NameTypeDescription
itemTWhat to look for.

Returns booltrue when it is there.

GetEnumerator()

public HashSet<T> GetEnumerator();

Walks what the set holds, in no order it promises, so foreach over the set itself reads the way it does over a HashSet<T>. Reach for AtomsSet.Value where a sequence is what is wanted, LINQ included.

Returns Enumerator<T><T> — The enumerator, which throws when the set changes while it is being walked.

Remove(T)

public void Remove(T item);

Takes something out, and does nothing when it is not there.

Parameters

NameTypeDescription
itemTWhat to take out.

Reset(IReadOnlyList<T>)

public void Reset(IReadOnlyList<T> items);

Replaces the contents in one go, for the set that is worked out again rather than edited — what a new listing marks, what a filter leaves. Contents equal to what is already there change nothing.

Parameters

NameTypeDescription
itemsIReadOnlyList<T><T>What the set should hold instead.

Subscribe(Action)

public IDisposable Subscribe(Action listener);

Calls back whenever the contents change.

Parameters

NameTypeDescription
listenerActionWhat to run on change.

Returns IDisposable — Dispose it to stop listening.

TryAdd(T)

public bool TryAdd(T item);

Puts something in and says whether it was new.

Parameters

NameTypeDescription
itemTWhat to put in.

Returns booltrue when it went in, false when it was already there.

TryRemove(T)

public bool TryRemove(T item);

Takes something out and says whether it was there.

Parameters

NameTypeDescription
itemTWhat to take out.

Returns booltrue when something was taken out.