-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListExtensAlias.cs
237 lines (220 loc) · 7.33 KB
/
ListExtensAlias.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
using System;
using System.Linq;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace Godot.CollectionsExtens.List.Alias;
/// <summary>
/// We recommend using this library if you need to convert gdscript code to C# quickly.
/// </summary>
public static partial class ListExtensAlias
{
/// <summary>
/// Appends another array at the end of this array.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="p_arr"></param>
/// <param name="p_item"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void AppendArray<T>(this List<T> p_arr, List<T> p_item)
{
p_arr.AddRange(p_item);
}
/// <summary>
/// Removes the first occurrence of a specific object from the List<T>
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="p_arr"></param>
/// <param name="p_item"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Erase<T>(this List<T> p_arr, T p_item)
{
p_arr.Remove(p_item);
}
/// <summary>
/// Filters a sequence of values based on a predicate.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="p_arr"></param>
/// <param name="p_predicate"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static List<T> Filter<T>(
this List<T> p_arr, Func<T, bool> p_predicate)
{
return (List<T>)p_arr.Where(p_predicate);
}
/// <summary>
/// Filters a sequence of values based on a predicate.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="p_arr"></param>
/// <param name="p_predicate"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static List<T> Filter<T>(
this List<T> p_arr, Func<T, int, bool> p_predicate)
{
return (List<T>)p_arr.Where(p_predicate);
}
/// <summary>
/// Returns the zero-based index of the first occurrence of a value in the Array<T> or in a portion of it.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="p_arr"></param>
/// <param name="item"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Find<T>(this List<T> p_arr, T item)
{
return p_arr.IndexOf(item);
}
/// <summary>
/// Returns the zero-based index of the first occurrence of a value in the Array<T> or in a portion of it.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="p_arr"></param>
/// <param name="item"></param>
/// <param name="index"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Find<T>(this List<T> p_arr, T item, int index)
{
return p_arr.IndexOf(item, index);
}
/// <summary>
/// Determines whether an element is in the List<T>.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="p_arr"></param>
/// <param name="item"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool Has<T>(this List<T> p_arr, T item)
{
return p_arr.Contains(item);
}
/// <summary>
/// Returns a hashed 32-bit integer value representing the array and its contents.
/// Note: Arrays with equal hash values are not guaranteed to be the same,
/// as a result of hash collisions. On the countrary, arrays with different hash values are guaranteed to be different.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="p_arr"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Hash<T>(this List<T> p_arr)
{
return GD.Hash(Variant.From(p_arr));
}
/// <summary>
/// Returns true if the list is empty ([]).
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="p_arr"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsEmpty<T>(this List<T> p_arr)
{
return p_arr.Count == 0;
}
/// <summary>
/// Projects each element of a sequence into a new form.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="TResult"></typeparam>
/// <param name="p_arr"></param>
/// <param name="p_selector"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static List<TResult> Map<T, TResult>(
this List<T> p_arr, Func<T, TResult> p_selector)
{
return (List<TResult>)p_arr.Select(p_selector);
}
/// <summary>
/// Projects each element of a sequence into a new form.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="TResult"></typeparam>
/// <param name="p_arr"></param>
/// <param name="p_selector"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static List<TResult> Map<T, TResult>(
this List<T> p_arr, Func<T, int, TResult> p_selector)
{
return (List<TResult>)p_arr.Select(p_selector);
}
/// <summary>
///
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="p_arr"></param>
/// <param name="p_func"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T Reduce<T>(this List<T> p_arr, Func<T, T, T> p_func)
{
return p_arr.Aggregate(p_func);
}
/// <summary>
/// Applies an accumulator function over a sequence.
/// The specified seed value is used as the initial accumulator value,
/// and the specified function is used to select the result value.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="TAccumulate"></typeparam>
/// <param name="p_arr"></param>
/// <param name="seed"></param>
/// <param name="p_func"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static TAccumulate Reduce<T, TAccumulate>(
this List<T> p_arr, TAccumulate seed, Func<TAccumulate, T, TAccumulate> p_func)
{
return p_arr.Aggregate(seed, p_func);
}
/// <summary>
/// Applies an accumulator function over a sequence.
/// The specified seed value is used as the initial accumulator value,
/// and the specified function is used to select the result value.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="TAccumulate"></typeparam>
/// <typeparam name="TResult"></typeparam>
/// <param name="p_arr"></param>
/// <param name="seed"></param>
/// <param name="p_func"></param>
/// <param name="resultSelector"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static TResult Reduce<T, TAccumulate, TResult>(
this List<T> p_arr, TAccumulate seed, Func<TAccumulate, T, TAccumulate> p_func, Func<TAccumulate, TResult> resultSelector)
{
return p_arr.Aggregate(seed, p_func, resultSelector);
}
/// <summary>
/// Returns the zero-based index of the last occurrence of a value in the List<T> or in a portion of it.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="p_arr"></param>
/// <param name="item"></param>
/// <param name="index"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int RFind<T>(this List<T> p_arr, T item, int index)
{
return p_arr.LastIndexOf(item, index);
}
/// <summary>
/// Gets the number of elements contained in the List<T>.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="p_arr"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Size<T>(this List<T> p_arr)
{
return p_arr.Count;
}
}