-
Notifications
You must be signed in to change notification settings - Fork 0
/
Arrays.cs
36 lines (32 loc) · 1.78 KB
/
Arrays.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// —————————————————————————————————————————————
//?
//!? 📜 Arrays.cs
//!? 🖋️ Galacticai 📅 2022
//! ⚖️ GPL-3.0-or-later
//? 🔗 Dependencies: No special dependencies
//?
// —————————————————————————————————————————————
namespace GalacticLib;
/// <summary> Various tools for arrays </summary>
public static class Arrays {
/// <summary> Add an <paramref name="element"/> item to the end of <paramref name="array"/></summary>
/// <typeparam name="T">Type of the array to be used</typeparam>
/// <param name="array">Array to manipulate</param>
/// <param name="element">Element to add to <paramref name="array"/></param>
/// <returns>Array {<paramref name="array"/>, <paramref name="element"/>} as <typeparamref name="type"/>[]</returns>
public static T[] AddArrays<T>(this T[] array, T element)
=> [.. array, element];
/// <summary> Add an <paramref name="expansion"/> array to the end of <paramref name="array"/></summary>
/// <typeparam name="T">Type of the array to be used</typeparam>
/// <param name="array">Array to manipulate</param>
/// <param name="expansion">Element to add to <paramref name="array"/></param>
/// <returns>Array {<paramref name="array"/>, <paramref name="expansion"/>} as <typeparamref name="type"/>[]</returns>
public static T[] AddArrays<T>(this T[] array, T[] expansion)
=> [.. array, .. expansion];
public static bool ContainsSubType<T, TTarget>(this T[] values) where TTarget : T {
foreach (var value in values)
if (value?.GetType() is TTarget)
return true;
return false;
}
}