STuple<T1, T2>

Namespace: SnowBank.Data.Tuples · struct

Implements: IVarTuple, IEquatable<IVarTuple>, IComparable<IVarTuple>, IReadOnlyList<object>, IEnumerable<object>, IEnumerable, IReadOnlyCollection<object>, IStructuralEquatable, IStructuralComparable, ITuple, IFormattable, IEquatable<STuple<T1, T2>>, IComparable<STuple<T1, T2>>, IEquatable<(T1, T2)>, IComparable<(T1, T2)>, IComparable, ITupleSpanPackable, ITuplePackable, ITupleFormattable, ISpanFormattable, ISpanEncodable

Tuple that holds a pair of items

Constructors

STuple<T1, T2>

STuple<T1, T2>(T1 item1, T2 item2)

Constructs a STuple

Properties

Count

int Count { get; }

Item

object Item { get; }

IVarTuple Item { get; }

IVarTuple Item { get; }

Last

T2 Last { get; }

Returns the value of the last item in the tuple

Tail

STuple<T2> Tail { get; }

Returns a tuple without the first item

Methods

Append

STuple<T1, T2, T3> Append<T3>(T3 value)

Appends a single new item at the end of the current tuple.

  • value — Value that will be added as an embedded item

Returns: New tuple with one extra item

If is a tuple, and you want to append the items of this tuple, and not the tuple itself, please call !

STuple<T1, T2, T3, T4> Append<T3, T4>(T3 value1, T4 value2)

Appends two new items at the end of the current tuple.

  • value1 — First item that will be added as an embedded item
  • value2 — Second item that will be added as an embedded item

Returns: New tuple with two extra item

If any of or is a tuple, and you want to append the items of this tuple, and not the tuple itself, please call !

CompareTo

int CompareTo(STuple<T1, T2> other)

int CompareTo((T1, T2) other)

int CompareTo(IVarTuple other)

Concat

IVarTuple Concat(IVarTuple tuple)

Appends the items of a tuple at the end of the current tuple.

  • tuple — Tuple whose items are to be appended at the end

Returns: New tuple composed of the current tuple's items, followed by tuple's items

STuple<T1, T2, T3> Concat<T3>(STuple<T3> tuple)

STuple<T1, T2, T3, T4> Concat<T3, T4>(STuple<T3, T4> tuple)

STuple<T1, T2, T3> Concat<T3>((T3) tuple)

Appends the items of a tuple at the end of the current tuple.

  • tuple — Tuple whose items are to be appended at the end

Returns: New tuple composed of the current tuple's items, followed by tuple's items

STuple<T1, T2, T3, T4> Concat<T3, T4>((T3, T4) tuple)

Appends the items of a tuple at the end of the current tuple.

  • tuple — Tuple whose items are to be appended at the end

Returns: New tuple composed of the current tuple's items, followed by tuple's items

STuple<T1, T2, T3, T4, T5> Concat<T3, T4, T5>((T3, T4, T5) tuple)

Appends the items of a tuple at the end of the current tuple.

  • tuple — Tuple whose items are to be appended at the end

Returns: New tuple composed of the current tuple's items, followed by tuple's items

STuple<T1, T2, T3, T4, T5, T6> Concat<T3, T4, T5, T6>((T3, T4, T5, T6) tuple)

Appends the items of a tuple at the end of the current tuple.

  • tuple — Tuple whose items are to be appended at the end

Returns: New tuple composed of the current tuple's items, followed by tuple's items

STuple<T1, T2, T3, T4, T5, T6, T7> Concat<T3, T4, T5, T6, T7>((T3, T4, T5, T6, T7) tuple)

Appends the items of a tuple at the end of the current tuple.

  • tuple — Tuple whose items are to be appended at the end

Returns: New tuple composed of the current tuple's items, followed by tuple's items

STuple<T1, T2, T3, T4, T5, T6, T7, T8> Concat<T3, T4, T5, T6, T7, T8>((T3, T4, T5, T6, T7, T8) tuple)

Appends the items of a tuple at the end of the current tuple.

  • tuple — Tuple whose items are to be appended at the end

Returns: New tuple composed of the current tuple's items, followed by tuple's items

CopyTo

void CopyTo(object[] array, int offset)

Copy both items of this pair into an array at the specified offset

Deconstruct

void Deconstruct(out T1 item1, out T2 item2)

Equals

bool Equals(object obj)

bool Equals(IVarTuple other)

bool Equals(STuple<T1, T2> other)

bool Equals((T1, T2) other)

Fill

void Fill(ref (T1, T2) t)

Get

TItem Get<TItem>(int index)

Returns the typed value of an item of the tuple, given its position

  • index — Position of the item

Returns: Value of the item at position index, adapted into type TItem.

STuple.Create("Hello", "World", 123,).Get<string>(0) => "Hello"STuple.Create("Hello", "World", 123,).Get<int>(2) => 123STuple.Create("Hello", "World", 123,).Get<string>(2) => "123"

TItem Get<TItem>(Index index)

Returns the typed value of an item of the tuple, given its position

  • index — Position of the item

Returns: Value of the item at position index, adapted into type TItem.

STuple.Create("Hello", "World", 123,).Get<string>(0) => "Hello"STuple.Create("Hello", "World", 123,).Get<int>(^1) => 123STuple.Create("Hello", "World", 123,).Get<string>(^1) => "123"

GetEnumerator

IEnumerator<object> GetEnumerator()

GetHashCode

int GetHashCode()

ToString

string ToString()

string ToString(string format, IFormatProvider provider = null)

ToValueTuple

(T1, T2) ToValueTuple()

TryFormat

bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = null, IFormatProvider provider = null)

With

void With(Action<T1, T2> lambda)

Execute a lambda Action with the content of this tuple

  • lambda — Action that will be passed the content of this tuple as parameters

TItem With<TItem>(Func<T1, T2, TItem> lambda)

Execute a lambda Function with the content of this tuple

  • lambda — Action that will be passed the content of this tuple as parameters

Returns: Result of calling lambda with the items of this tuple

Fields

Item1

readonly T1 Item1

First element of the pair

Item2

readonly T2 Item2

Second element of the pair