STuple

Namespace: SnowBank.Data.Tuples · struct

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

Factory class for Tuples

Properties

Count

int Count { get; }

Methods

Append

IVarTuple Append<T1>(T1 value)

Returns a new Tuple by that contains the element of this tuple, with an extra item at the end

  • value — Value of the item that will be appended at the end

Returns: New tuple with the extra item

If TItem is an IVarTuple, then it will be appended as a single element. If you need to append the items of a tuple, you must call Concat

Example: STuple.Create("Hello").Append("World") => ("Hello", "World")

CompareTo

int CompareTo(IVarTuple other)

int CompareTo(object other)

Concat

IVarTuple Concat(IVarTuple tuple)

Returns a new Tuple by appending the items of another tuple at the end of this tuple

  • tuple — Tuple whose items must be appended at the end of the current tuple

Returns: New tuple, or the same instance if tuple is empty.

static IVarTuple Concat(IVarTuple head, IVarTuple tail)

Concatenates two tuples together

static IVarTuple Concat<THead, TTail>(in THead head, in TTail tail)

Concatenates two tuples together

static IVarTuple Concat(IVarTuple head, IVarTuple middle, IVarTuple tail)

Concatenates two tuples together

CopyTo

void CopyTo(object[] array, int offset)

Copies all items of the tuple into an array at a specific location.

  • array — The destination array, which must be large enough to contain all the items.
  • offset — The offset at which to start copying items.
var tmp = new object[3];
("Hello", "World", 123).CopyTo(tmp, 0);

Create

static STuple Create()

Create a new empty tuple with 0 elements

static STuple<T1> Create<T1>(T1 item1)

Create a new 1-tuple, holding only one item

static IVarTuple Create(object[] items)

Create a new N-tuple, from N items

  • items — Items to wrap in a tuple

If you already have an array of items, you should call instead. Mutating the array, would also mutate the tuple!

static IVarTuple Create(ReadOnlySpan<object> items)

Create a new N-tuple, from N items

  • items — Items to wrap in a tuple

If you already have an array of items, you should call instead. Mutating the array, would also mutate the tuple!

static STuple<T1> Create<T1>((T1) tuple)

Converts a ValueTuple into the equivalent STuple of the same size

static STuple<T1> Create<T1>(ref (T1) tuple)

Converts a ValueTuple into the equivalent STuple of the same size

static STuple<T1, T2> Create<T1, T2>((T1, T2) tuple)

Converts a ValueTuple into the equivalent STuple of the same size

static STuple<T1, T2> Create<T1, T2>(ref (T1, T2) tuple)

Converts a ValueTuple into the equivalent STuple of the same size

static STuple<T1, T2, T3> Create<T1, T2, T3>((T1, T2, T3) tuple)

Converts a ValueTuple into the equivalent STuple of the same size

static STuple<T1, T2, T3> Create<T1, T2, T3>(ref (T1, T2, T3) tuple)

Converts a ValueTuple into the equivalent STuple of the same size

static STuple<T1, T2, T3, T4> Create<T1, T2, T3, T4>((T1, T2, T3, T4) tuple)

Converts a ValueTuple into the equivalent STuple of the same size

static STuple<T1, T2, T3, T4> Create<T1, T2, T3, T4>(ref (T1, T2, T3, T4) tuple)

Converts a ValueTuple into the equivalent STuple of the same size

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

Converts a ValueTuple into the equivalent STuple of the same size

static STuple<T1, T2, T3, T4, T5> Create<T1, T2, T3, T4, T5>(ref (T1, T2, T3, T4, T5) tuple)

Converts a ValueTuple into the equivalent STuple of the same size

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

Converts a ValueTuple into the equivalent STuple of the same size

static STuple<T1, T2, T3, T4, T5, T6> Create<T1, T2, T3, T4, T5, T6>(ref (T1, T2, T3, T4, T5, T6) tuple)

Converts a ValueTuple into the equivalent STuple of the same size

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

Converts a ValueTuple into the equivalent STuple of the same size

static STuple<T1, T2, T3, T4, T5, T6, T7> Create<T1, T2, T3, T4, T5, T6, T7>(ref (T1, T2, T3, T4, T5, T6, T7) tuple)

Converts a ValueTuple into the equivalent STuple of the same size

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

Converts a ValueTuple into the equivalent STuple of the same size

static STuple<T1, T2, T3, T4, T5, T6, T7, T8> Create<T1, T2, T3, T4, T5, T6, T7, T8>(ref (T1, T2, T3, T4, T5, T6, T7, (T8)) tuple)

Converts a ValueTuple into the equivalent STuple of the same size

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

Create a new 2-tuple, holding two items

static STuple<T1, T2, T3> Create<T1, T2, T3>(T1 item1, T2 item2, T3 item3)

Create a new 3-tuple, holding three items

static STuple<T1, T2, T3, T4> Create<T1, T2, T3, T4>(T1 item1, T2 item2, T3 item3, T4 item4)

Create a new 4-tuple, holding four items

static STuple<T1, T2, T3, T4, T5> Create<T1, T2, T3, T4, T5>(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5)

Create a new 5-tuple, holding five items

static STuple<T1, T2, T3, T4, T5, T6> Create<T1, T2, T3, T4, T5, T6>(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6)

Create a new 6-tuple, holding six items

static STuple<T1, T2, T3, T4, T5, T6, T7> Create<T1, T2, T3, T4, T5, T6, T7>(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7)

Create a new 7-tuple, holding seven items

static STuple<T1, T2, T3, T4, T5, T6, T7, T8> Create<T1, T2, T3, T4, T5, T6, T7, T8>(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, T8 item8)

Create a new 8-tuple, holding eight items

CreateBoxed

static IVarTuple CreateBoxed(object item)

Create a new 1-tuple, holding only one item

This is the non-generic equivalent of STuple.Create(item)

Equals

bool Equals(IVarTuple value)

bool Equals(object obj)

static bool Equals(IVarTuple left, IVarTuple right)

Determines whether the specified tuple instances are considered equal

  • left — Left tuple
  • right — Right tuple

Returns: True if the tuples are considered equal; otherwise, false. If both left and right are null, the methods returns true;

This method is equivalent of calling left.Equals(right),

Equivalent

static bool Equivalent(IVarTuple left, IVarTuple right)

Determines whether the specified tuple instances are considered similar

  • left — Left tuple
  • right — Right tuple

Returns: True if the tuples are considered similar; otherwise, false. If both left and right are null, the methods returns true;

FromArray

static IVarTuple FromArray<T>(T[] items)

Creates a new tuple, from an array of typed items

  • items — Array of items

Returns: Tuple with the same size as items and where all the items are of type T

static IVarTuple FromArray<T>(ReadOnlySpan<T> items)

Creates a new tuple, from a section of an array of typed items

static IVarTuple FromArray<T>(T[] items, int offset, int count)

Creates a new tuple, from a section of an array of typed items

FromEnumerable

static IVarTuple FromEnumerable<T>(IEnumerable<T> items)

Creates a new tuple from a sequence of typed items

FromObjects

static IVarTuple FromObjects(ReadOnlyMemory<object> items)

Create a new N-tuple by copying the content of an array of untyped items

static IVarTuple FromObjects(ReadOnlySpan<object> items)

Create a new N-tuple by copying the content of an array of untyped items

static IVarTuple FromObjects(object[] items)

Create a new N-tuple by copying the content of an array of untyped items

static IVarTuple FromObjects(ReadOnlyMemory<object> items, bool copy)

Create a new N-tuple that wraps a section of an array of untyped items

If is true, and the original array is mutated, the tuple will reflect the changes!

static IVarTuple FromObjects(object[] items, int offset, int count)

Create a new N-tuple by copying a section of an array of untyped items

GetEnumerator

IEnumerator<object> GetEnumerator()

GetHashCode

int GetHashCode()

ToString

string ToString()

string ToString(string format, IFormatProvider provider = null)

TryFormat

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

Wrap

static IVarTuple Wrap(ReadOnlyMemory<object> items)

Create a new N-tuple that wraps a sequence of untyped items

If the original sequence is mutated, the tuple will reflect the changes!

static IVarTuple Wrap(object[] items)

Create a new N-tuple that wraps an array of untyped items

If the original array is mutated, the tuple will reflect the changes!

static IVarTuple Wrap(object[] items, int offset, int count)

Create a new N-tuple that wraps a section of an array of untyped items

If the original array is mutated, the tuple will reflect the changes!

WrapArray

static IVarTuple WrapArray<T>(T[] items)

Wraps an array into a tuple with the same items

Changing the array will impact the tuple, which may break the expectations of some consumers, who assume that a tuple is immutable.

static IVarTuple WrapArray<T>(ReadOnlyMemory<T> items)

Wraps an array into a tuple with the same items

Changing the array will impact the tuple, which may break the expectations of some consumers, who assume that a tuple is immutable.

Fields

Empty

static readonly IVarTuple Empty

Empty tuple

Not to be mistaken with a 1-tuple containing 'null' !