Struct Chain<T>
- Namespace
- LfrlAnvil
- Assembly
- LfrlAnvil.Core.dll
A lightweight representation of a sequence of linked nodes with values.
public readonly struct Chain<T> : IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable
Type Parameters
T
Value type.
- Implements
-
IEnumerable<T>
- Inherited Members
- Extension Methods
Constructors
Chain(Chain<T>)
public Chain(Chain<T> other)
Parameters
Chain(IEnumerable<T>)
Creates a new Chain<T> instance from a collection of values.
public Chain(IEnumerable<T> values)
Parameters
values
IEnumerable<T>Collection of values.
Chain(T)
Creates a new Chain<T> instance from a single value.
public Chain(T value)
Parameters
value
TSingle value.
Fields
Empty
Represents an empty sequence.
public static readonly Chain<T> Empty
Field Value
- Chain<T>
Properties
Count
Gets the number of elements in the collection.
public int Count { get; }
Property Value
- int
The number of elements in the collection.
IsAttached
Specifies whether or not this sequence has been attached to the end of another sequence.
public bool IsAttached { get; }
Property Value
IsExtendable
Specifies whether or not new values can be appended to this sequence. Chain<T> is considered extendable when it hasn't been attached to the end of another sequence and no value has been added after its last node.
public bool IsExtendable { get; }
Property Value
Methods
Extend(Chain<T>)
Attaches the provided other
to the end of this sequence.
[Pure]
public Chain<T> Extend(Chain<T> other)
Parameters
other
Chain<T>Sequence to attach.
Returns
Remarks
This method does not allocate memory.
Exceptions
- InvalidOperationException
When this sequence is not extendable.
Extend(IEnumerable<T>)
Adds the provided collection of values
to the end of this sequence.
[Pure]
public Chain<T> Extend(IEnumerable<T> values)
Parameters
values
IEnumerable<T>Collection of values to add.
Returns
Exceptions
- InvalidOperationException
When this sequence is not extendable.
Extend(T)
Adds the provided value
to the end of this sequence.
[Pure]
public Chain<T> Extend(T value)
Parameters
value
TValue to add.
Returns
Exceptions
- InvalidOperationException
When this sequence is not extendable.
GetEnumerator()
Creates a new Chain<T>.Enumerator instance for this sequence.
[Pure]
public Chain<T>.Enumerator GetEnumerator()
Returns
- Chain<T>.Enumerator
New Chain<T>.Enumerator instance.
ToExtendable()
Returns an extendable version of this Chain<T> instance.
[Pure]
public Chain<T> ToExtendable()