rj-action-library/Runtime/Tools/Arrays.cs

51 lines
1.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.Text;
using System;
namespace Rokojori
{
public class Arrays
{
public static int IndexOf<T>( T[] values, T other )
{
return Array.IndexOf( values, other );
}
public static int FindIndex<T>( T[] values, Func<T,bool> predicate )
{
for ( int i = 0; i < values.Length; i++ )
{
if ( predicate( values[ i ] ) )
{
return i;
}
}
return -1;
}
public static bool Contains <T>( T[] values, T other )
{
return Array.IndexOf( values, other ) != -1;
}
public static T[] Add<T>( T[] values, T other )
{
var newValues = new T[ values.Length + 1 ];
Array.Copy( values, newValues, values.Length );
newValues[ values.Length ] = other;
return newValues;
}
public static void ForEach<T>( T[] values, Action<T> callback )
{
foreach ( var it in values )
{
callback( it );
}
}
}
}