This commit is contained in:
Infi
2024-11-13 04:13:18 +01:00
parent 9597218319
commit 45fdac0dd6
21 changed files with 341 additions and 339 deletions
+16 -1
View File
@@ -1,4 +1,5 @@
using ChatTwo.Resources;
using System.Runtime.CompilerServices;
using ChatTwo.Resources;
using Dalamud.Interface.ImGuiNotification;
namespace ChatTwo.Util;
@@ -26,4 +27,18 @@ public static class WrapperUtil
public static IEnumerable<(T Value, int Index)> WithIndex<T>(this IEnumerable<T> list)
=> list.Select((x, i) => (x, i));
/// <summary> Return the first object fulfilling the predicate or null for structs. </summary>
/// <param name="values"> The enumerable. </param>
/// <param name="predicate"> The predicate. </param>
/// <returns> The first object fulfilling the predicate, or a null-optional. </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static T? FirstOrNull<T>(this IEnumerable<T> values, Func<T, bool> predicate) where T : struct
{
foreach(var val in values)
if (predicate(val))
return val;
return null;
}
}