TupleExtensions
Namespace: SnowBank.Data.Tuples · class
Add extensions methods that deal with tuples on various types
Methods
Append
static IVarTuple Append<T1, T2>(IVarTuple tuple, T1 value1, T2 value2)
Appends two values at the end of a tuple
static IVarTuple Append<THead, T1, T2>(THead tuple, T1 value1, T2 value2)
Appends two values at the end of a tuple
static IVarTuple Append<T1, T2, T3>(IVarTuple tuple, T1 value1, T2 value2, T3 value3)
Appends three values at the end of a tuple
static IVarTuple Append<T1, T2, T3, T4>(IVarTuple tuple, T1 value1, T2 value2, T3 value3, T4 value4)
Appends four values at the end of a tuple
static IVarTuple Append<T1, T2, T3, T4, T5>(IVarTuple tuple, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5)
Appends four values at the end of a tuple
static IVarTuple Append<T1, T2, T3, T4, T5, T6>(IVarTuple tuple, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6)
Appends four values at the end of a tuple
static IVarTuple Append<T1, T2, T3, T4, T5, T6, T7>(IVarTuple tuple, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7)
Appends four values at the end of a tuple
static IVarTuple Append<T1, T2, T3, T4, T5, T6, T7, T8>(IVarTuple tuple, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7, T8 value8)
Appends four values at the end of a tuple
As
static (T1) As<T1>(IVarTuple tuple)
Returns a typed version of a tuple of size 1
tuple— Tuple that must be of size 1
Returns: Equivalent tuple, with its element converted to the specified type
static (T1, T2) As<T1, T2>(IVarTuple tuple)
Returns a typed version of a tuple of size 2
tuple— Tuple that must be of size 2
Returns: Equivalent tuple, with its elements converted to the specified types
static (T1, T2, T3) As<T1, T2, T3>(IVarTuple tuple)
Returns a typed version of a tuple of size 3
tuple— Tuple that must be of size 3
Returns: Equivalent tuple, with its elements converted to the specified types
static (T1, T2, T3, T4) As<T1, T2, T3, T4>(IVarTuple tuple)
Returns a typed version of a tuple of size 4
tuple— Tuple that must be of size 4
Returns: Equivalent tuple, with its elements converted to the specified types
static (T1, T2, T3, T4, T5) As<T1, T2, T3, T4, T5>(IVarTuple tuple)
Returns a typed version of a tuple of size 5
tuple— Tuple that must be of size 5
Returns: Equivalent tuple, with its elements converted to the specified types
static (T1, T2, T3, T4, T5, T6) As<T1, T2, T3, T4, T5, T6>(IVarTuple tuple)
Returns a typed version of a tuple of size 5
tuple— Tuple that must be of size 5
Returns: Equivalent tuple, with its elements converted to the specified types
Concat
static (T1, T2) Concat<T1, T2>((T1) t1, (T2) t2)
Returns a new tuple with the concatenation of this tuple and another tuple
static (T1, T2, T3) Concat<T1, T2, T3>((T1) t1, (T2, T3) t2)
Returns a new tuple with the concatenation of this tuple and another tuple
static (T1, T2, T3) Concat<T1, T2, T3>((T1, T2) t1, (T3) t2)
Returns a new tuple with the concatenation of this tuple and another tuple
static (T1, T2, T3, T4) Concat<T1, T2, T3, T4>((T1) t1, (T2, T3, T4) t2)
Returns a new tuple with the concatenation of this tuple and another tuple
static (T1, T2, T3, T4) Concat<T1, T2, T3, T4>((T1, T2) t1, (T3, T4) t2)
Returns a new tuple with the concatenation of this tuple and another tuple
static (T1, T2, T3, T4) Concat<T1, T2, T3, T4>((T1, T2, T3) t1, (T4) t2)
Returns a new tuple with the concatenation of this tuple and another tuple
Deconstruct
static void Deconstruct<T1>(IVarTuple value, out T1 item1)
Deconstructs this tuple into its individual elements
static void Deconstruct<T1, T2>(IVarTuple value, out T1 item1, out T2 item2)
Deconstructs this tuple into its individual elements
static void Deconstruct<T1, T2, T3>(IVarTuple value, out T1 item1, out T2 item2, out T3 item3)
Deconstructs this tuple into its individual elements
static void Deconstruct<T1, T2, T3, T4>(IVarTuple value, out T1 item1, out T2 item2, out T3 item3, out T4 item4)
Deconstructs this tuple into its individual elements
static void Deconstruct<T1, T2, T3, T4, T5>(IVarTuple value, out T1 item1, out T2 item2, out T3 item3, out T4 item4, out T5 item5)
Deconstructs this tuple into its individual elements
static void Deconstruct<T1, T2, T3, T4, T5, T6>(IVarTuple value, out T1 item1, out T2 item2, out T3 item3, out T4 item4, out T5 item5, out T6 item6)
Deconstructs this tuple into its individual elements
static void Deconstruct<T1, T2, T3, T4, T5, T6, T7>(IVarTuple value, out T1 item1, out T2 item2, out T3 item3, out T4 item4, out T5 item5, out T6 item6, out T7 item7)
Deconstructs this tuple into its individual elements
static void Deconstruct<T1, T2, T3, T4, T5, T6, T7, T8>(IVarTuple value, out T1 item1, out T2 item2, out T3 item3, out T4 item4, out T5 item5, out T6 item6, out T7 item7, out T8 item8)
Deconstructs this tuple into its individual elements
EndsWith
static bool EndsWith(IVarTuple left, IVarTuple right)
Test if the end of current tuple is equal to another tuple
left— Larger tupleright— Smaller tuple
Returns: True if the end of left is equal to right or if both tuples are identical
Explode
static IEnumerable<IVarTuple> Explode(IVarTuple tuple)
Transform a tuple of N elements into a list of N singletons
tuple— Tuple that contains any number of elements
Returns: Sequence of tuples that contains a single element
(123, ABC, false,).Explode() => [ (123,), (ABC,), (false,) ]
Get
static T Get<T>(IVarTuple tuple, Index index)
Returns the typed value of an item of the tuple, given its position
tuple— Tuple instanceindex— Position of the item, with0for the first element, and^1for the last element
Returns: Value of the item at position index, adapted into type T.
("Hello", "World", 123,).Get<string>(^3) => "Hello"
("Hello", "World", 123,).Get<string>(^2) => "World"
("Hello", "World", 123,).Get<int>(^1) => 123
("Hello", "World", 123,).Get<string>(^1) => "123"
IsNullOrEmpty
static bool IsNullOrEmpty(IVarTuple tuple)
Returns true if the tuple is either null or empty
OfSize
static TTuple OfSize<TTuple>(TTuple tuple, int size)
Ensures that the tuple has the expected size
tuple— Tuple which must be of a specific sizesize— Expected number of items in this tuple
Returns: The tuple itself, if it has the correct size; otherwise, an exception is thrown
static SpanTuple OfSize(SpanTuple tuple, int size)
Ensures that the tuple has the expected size
tuple— Tuple which must be of a specific sizesize— Expected number of items in this tuple
Returns: The tuple itself, if it has the correct size; otherwise, an exception is thrown
OfSizeAtLeast
static TTuple OfSizeAtLeast<TTuple>(TTuple tuple, int size)
Ensures that the tuple has at least a certain size
tuple— Tuple which must be of a specific sizesize— Expected minimum number of items in this tuple
Returns: The tuple itself, if it has the correct size; otherwise, an exception is thrown
static SpanTuple OfSizeAtLeast(SpanTuple tuple, int size)
Ensures that the tuple has at least a certain size
tuple— Tuple which must be of a specific sizesize— Expected minimum number of items in this tuple
Returns: The tuple itself, if it has the correct size; otherwise, an exception is thrown
OfSizeAtMost
static TTuple OfSizeAtMost<TTuple>(TTuple tuple, int size)
Ensures that the tuple has at most a certain size
tuple— Tuple which must be of a specific sizesize— Expected maximum number of items in this tuple
Returns: The tuple itself, if it has the correct size; otherwise, an exception is thrown
static SpanTuple OfSizeAtMost(SpanTuple tuple, int size)
Ensures that the tuple has at most a certain size
tuple— Tuple which must be of a specific sizesize— Expected maximum number of items in this tuple
Returns: The tuple itself, if it has the correct size; otherwise, an exception is thrown
StartsWith
static bool StartsWith(IVarTuple left, IVarTuple right)
Test if the start of current tuple is equal to another tuple
left— Larger tupleright— Smaller tuple
Returns: True if the beginning of left is equal to right or if both tuples are identical
Substring
static IVarTuple Substring<TTuple>(TTuple tuple, int offset)
Returns a substring of the current tuple
tuple— Current tupleoffset— Offset from the start of the current tuple (negative value means from the end)
Returns: Tuple that contains only the items past the first offset items of the current tuple
static IVarTuple Substring<TTuple>(TTuple tuple, int offset, int count)
Returns a substring of the current tuple
tuple— Current tupleoffset— Offset from the start of the current tuple (negative value means from the end)count— Number of items to keep
Returns: Tuple that contains only the selected items from the current tuple
ToArray
static object[] ToArray(IVarTuple tuple)
Returns an array containing all the objects of a tuple
static T[] ToArray<T>(IVarTuple tuple)
Returns a typed array containing all the items of a tuple
ToSTuple
static STuple ToSTuple(ValueTuple _)
Returns the equivalent STuple
static STuple<T1> ToSTuple<T1>((T1) tuple)
Returns the equivalent STuple
static STuple<T1, T2> ToSTuple<T1, T2>((T1, T2) tuple)
Returns the equivalent STuple
static STuple<T1, T2, T3> ToSTuple<T1, T2, T3>((T1, T2, T3) tuple)
Returns the equivalent STuple
static STuple<T1, T2, T3, T4> ToSTuple<T1, T2, T3, T4>((T1, T2, T3, T4) tuple)
Returns the equivalent STuple
static STuple<T1, T2, T3, T4, T5> ToSTuple<T1, T2, T3, T4, T5>((T1, T2, T3, T4, T5) tuple)
Returns the equivalent STuple
static STuple<T1, T2, T3, T4, T5, T6> ToSTuple<T1, T2, T3, T4, T5, T6>((T1, T2, T3, T4, T5, T6) tuple)
Returns the equivalent STuple
static STuple<T1, T2, T3, T4, T5, T6, T7> ToSTuple<T1, T2, T3, T4, T5, T6, T7>((T1, T2, T3, T4, T5, T6, T7) tuple)
Returns the equivalent STuple
static STuple<T1, T2, T3, T4, T5, T6, T7, T8> ToSTuple<T1, T2, T3, T4, T5, T6, T7, T8>((T1, T2, T3, T4, T5, T6, T7, (T8)) tuple)
Returns the equivalent STuple
Truncate
static IVarTuple Truncate<TTuple>(TTuple tuple, int count)
Returns a tuple with only the first (or last) items of this tuple
tuple— Tuple to truncatecount— Number of items to keep. If positive, items will be taken from the start of the tuple. If negative, items will be taken from the end of the tuple
Returns: New tuple of size |count|.
(a, b, c).Truncate(2) => (a, b) (a, b, c).Truncate(-2) => (b, c)
With
static void With<T1>(IVarTuple tuple, Action<T1> lambda)
Executes a lambda Action with the content of this tuple
tuple— Tuple of size 1lambda— Action that will be passed the content of this tuple as parameters
static void With<T1, T2>(IVarTuple tuple, Action<T1, T2> lambda)
Executes a lambda Action with the content of this tuple
tuple— Tuple of size 2lambda— Action that will be passed the content of this tuple as parameters
static void With<T1, T2, T3>(IVarTuple tuple, Action<T1, T2, T3> lambda)
Executes a lambda Action with the content of this tuple
tuple— Tuple of size 3lambda— Action that will be passed the content of this tuple as parameters
static void With<T1, T2, T3, T4>(IVarTuple tuple, Action<T1, T2, T3, T4> lambda)
Executes a lambda Action with the content of this tuple
tuple— Tuple of size 4lambda— Action that will be passed the content of this tuple as parameters
static void With<T1, T2, T3, T4, T5>(IVarTuple tuple, Action<T1, T2, T3, T4, T5> lambda)
Executes a lambda Action with the content of this tuple
tuple— Tuple of size 5lambda— Action that will be passed the content of this tuple as parameters
static void With<T1, T2, T3, T4, T5, T6>(IVarTuple tuple, Action<T1, T2, T3, T4, T5, T6> lambda)
Executes a lambda Action with the content of this tuple
tuple— Tuple of size 6lambda— Action that will be passed the content of this tuple as parameters
static void With<T1, T2, T3, T4, T5, T6, T7>(IVarTuple tuple, Action<T1, T2, T3, T4, T5, T6, T7> lambda)
Executes a lambda Action with the content of this tuple
tuple— Tuple of size 7lambda— Action that will be passed the content of this tuple as parameters
static void With<T1, T2, T3, T4, T5, T6, T7, T8>(IVarTuple tuple, Action<T1, T2, T3, T4, T5, T6, T7, T8> lambda)
Executes a lambda Action with the content of this tuple
tuple— Tuple of size 8lambda— Action that will be passed the content of this tuple as parameters
static TResult With<T1, TResult>(IVarTuple tuple, Func<T1, TResult> lambda)
Executes a lambda Function with the content of this tuple
tuple— Tuple of size 1lambda— Action that will be passed the content of this tuple as parameters
Returns: Result of calling lambda with the items of this tuple
static TResult With<T1, T2, TResult>(IVarTuple tuple, Func<T1, T2, TResult> lambda)
Executes a lambda Function with the content of this tuple
tuple— Tuple of size 2lambda— Function that will be passed the content of this tuple as parameters
Returns: Result of calling lambda with the items of this tuple
static TResult With<T1, T2, T3, TResult>(IVarTuple tuple, Func<T1, T2, T3, TResult> lambda)
Executes a lambda Function with the content of this tuple
tuple— Tuple of size 3lambda— Action that will be passed the content of this tuple as parameters
Returns: Result of calling lambda with the items of this tuple
static TResult With<T1, T2, T3, T4, TResult>(IVarTuple tuple, Func<T1, T2, T3, T4, TResult> lambda)
Executes a lambda Function with the content of this tuple
tuple— Tuple of size 4lambda— Function that will be passed the content of this tuple as parameters
Returns: Result of calling lambda with the items of this tuple
static TResult With<T1, T2, T3, T4, T5, TResult>(IVarTuple tuple, Func<T1, T2, T3, T4, T5, TResult> lambda)
Executes a lambda Function with the content of this tuple
tuple— Tuple of size 5lambda— Function that will be passed the content of this tuple as parameters
Returns: Result of calling lambda with the items of this tuple
static TResult With<T1, T2, T3, T4, T5, T6, TResult>(IVarTuple tuple, Func<T1, T2, T3, T4, T5, T6, TResult> lambda)
Executes a lambda Function with the content of this tuple
tuple— Tuple of size 6lambda— Function that will be passed the content of this tuple as parameters
Returns: Result of calling lambda with the items of this tuple
static TResult With<T1, T2, T3, T4, T5, T6, T7, TResult>(IVarTuple tuple, Func<T1, T2, T3, T4, T5, T6, T7, TResult> lambda)
Executes a lambda Function with the content of this tuple
tuple— Tuple of size 7lambda— Function that will be passed the content of this tuple as parameters
Returns: Result of calling lambda with the items of this tuple
static TResult With<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(IVarTuple tuple, Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult> lambda)
Executes a lambda Function with the content of this tuple
tuple— Tuple of size 8lambda— Function that will be passed the content of this tuple as parameters
Returns: Result of calling lambda with the items of this tuple