Table of Contents

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
Inherited Members
Extension Methods

Constructors

Chain(Chain<T>)

Creates a new Chain<T> instance from another Chain<T> instance.

public Chain(Chain<T> other)

Parameters

other Chain<T>

Chain<T> instance to copy.

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 T

Single 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

bool

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

bool

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

Chain<T>

New Chain<T> instance.

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

Chain<T>

New Chain<T> instance.

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 T

Value to add.

Returns

Chain<T>

New Chain<T> instance.

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()

Returns

Chain<T>

This Chain<T> instance or its copy when it's not extendable.