AtomsStack<T> class
Namespace: Arlecchino.Atoms.Collections · Assembly: Arlecchino.Core
A stack held as one piece of application state, put on and taken off the top. AtomsStack.Value reads from the top down, so Value[0] is what AtomsStack.Peek answers.
public abstract class AtomsStack<T> : IReadableAtom<IReadOnlyList<T>>
Implements IReadableAtom<IReadOnlyList<T><T>>
Constructors
| Member | Summary |
|---|---|
AtomsStack(IReadOnlyList<T>) | Creates the stack. |
Properties
| Member | Summary |
|---|---|
Count | How many are on it. |
IsEmpty | Whether nothing is on it. |
RecordsHistory | Whether changes of this stack enter the undo history. |
Value | What is on the stack now, top first, 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
| Member | Summary |
|---|---|
Clear() | Takes everything off. An empty stack changes nothing. |
GetEnumerator() | Walks the stack from the top down, so foreach over it reads the way it does over a Stack<T>. Reach for AtomsStack.Value where a sequence is what is wanted, LINQ included. |
Peek() | Reads the one on top without taking it, and throws when the stack is empty. |
Pop() | Takes the one on top, and throws when the stack is empty. |
Push(T) | Puts something on top. |
Push(IReadOnlyList<T>) | Puts several on at once, the last of them ending up on top — what a loop of AtomsStack.Push would leave, in one notification and one undo step. |
Reset(IReadOnlyList<T>) | Replaces what is on the stack in one go, for a stack that is rebuilt rather than unwound. Contents equal to what is already there change nothing. |
Subscribe(Action) | Calls back whenever what is on the stack changes. |
TryPeek(out T) | Reads the one on top without taking it or throwing. |
TryPop(out T) | Takes the one on top without throwing when the stack is empty. |
Constructors in detail
AtomsStack(IReadOnlyList<T>)
public AtomsStack(IReadOnlyList<T> initial);
Creates the stack.
Parameters
| Name | Type | Description |
|---|---|---|
initial | IReadOnlyList<T><T> | What is already on it, top first; empty when omitted. It is copied, not held. |
Properties in detail
Count
public int Count { get; }
How many are on it.
Type int
IsEmpty
public bool IsEmpty { get; }
Whether nothing is on it.
Type bool
RecordsHistory
public abstract bool RecordsHistory { get; }
Whether changes of this stack enter the undo history.
Type bool
Value
public IReadOnlyList<T> Value { get; }
What is on the stack now, top first, 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 IReadOnlyList<T><T>
Methods in detail
Clear()
public void Clear();
Takes everything off. An empty stack changes nothing.
GetEnumerator()
public List<T> GetEnumerator();
Walks the stack from the top down, so foreach over it reads the way it does over a Stack<T>. Reach for AtomsStack.Value where a sequence is what is wanted, LINQ included.
Returns Enumerator<T><T> — The enumerator, which throws when the stack changes while it is being walked.
Peek()
public T Peek();
Reads the one on top without taking it, and throws when the stack is empty.
Returns T — What is on top.
Pop()
public T Pop();
Takes the one on top, and throws when the stack is empty.
Returns T — What was on top.
Push(T)
public void Push(T item);
Puts something on top.
Parameters
| Name | Type | Description |
|---|---|---|
item | T | What to put on. |
Push(IReadOnlyList<T>)
public void Push(IReadOnlyList<T> items);
Puts several on at once, the last of them ending up on top — what a loop of AtomsStack.Push would leave, in one notification and one undo step.
Parameters
| Name | Type | Description |
|---|---|---|
items | IReadOnlyList<T><T> | What to put on. Putting none on changes nothing. |
Reset(IReadOnlyList<T>)
public void Reset(IReadOnlyList<T> items);
Replaces what is on the stack in one go, for a stack that is rebuilt rather than unwound. Contents equal to what is already there change nothing.
Parameters
| Name | Type | Description |
|---|---|---|
items | IReadOnlyList<T><T> | What should be on it instead, top first. |
Subscribe(Action)
public IDisposable Subscribe(Action listener);
Calls back whenever what is on the stack changes.
Parameters
| Name | Type | Description |
|---|---|---|
listener | Action | What to run on change. |
Returns IDisposable — Dispose it to stop listening.
TryPeek(out T)
public bool TryPeek(out T item);
Reads the one on top without taking it or throwing.
Parameters
| Name | Type | Description |
|---|---|---|
item | T | What is on top, when there is one. |
Returns bool — true when there was one.
TryPop(out T)
public bool TryPop(out T item);
Takes the one on top without throwing when the stack is empty.
Parameters
| Name | Type | Description |
|---|---|---|
item | T | What was on top, when there was one. |
Returns bool — true when something was taken.