-
Notifications
You must be signed in to change notification settings - Fork 1
API.Util.Extensions
JuDelCo edited this page Oct 11, 2021
·
16 revisions
Namespace: Ju.Extensions
// Information
bool All<TSource>(Func<TSource, bool> predicate); // all elements satisfies the predicate?
bool Any<TSource>(Func<TSource, bool> predicate); // any element satisfies the predicate?
bool Contains<TSource>(TSource value);
int Count<TSource>();
bool IsNullOrEmpty<TSource>();
bool Some<TSource>(Func<TSource, bool> predicate); // equivalent to .Any()
// Filtering
TSource ElementAt<TSource>(int index);
IEnumerable<TSource> Filter<TSource>(Func<TSource, bool> predicate);
TSource Find<TSource>(Func<TSource, bool> predicate); // throws error if not found
TSource Find<TSource>(TSource defaultValue, Func<TSource, bool> predicate); // returns default value if not found
TSource FindUnique<TSource>(Func<TSource, bool> predicate); // throws error if not found or more than one element found
TSource FindUnique<TSource>(TSource defaultValue, Func<TSource, bool> predicate); // throws error if more than one element found
TSource First<TSource>();
TSource Last<TSource>();
// Iteration
void ForEach<TSource>(Action<TSource> action);
void ForEach<TSource>(Func<TSource, bool> action); // return false to break the loop
void ForEachReverse<TSource>(Action<TSource> action); // allows to remove the item in the loop
void ForEachReverse<TSource>(Func<TSource, bool> action); // allows to remove the item in the loop, return false to break the loop
// Transformation
IEnumerable<TResult> Cast<TResult>();
IEnumerable<TSource> Concatenate<TSource>(params IEnumerable<TSource>[] others);
IEnumerable<TResult> Flatten<TSource, TResult>(Func<TSource, IEnumerable<TResult>> selector);
IEnumerable<TResult> Map<TSource, TResult>(Func<TSource, TResult> selector); // new enumerator of another type
IEnumerable<TSource> OrderBy<TSource, TKey>(Func<TSource, TKey> keySelector);
TSource Reduce<TSource>(Func<TSource, TSource, TSource> function); // collapses the entire enumerator to a single object
TResult Reduce<TSource, TResult>(TResult startValue, Func<TResult, TSource, TResult> function);
IEnumerable<TSource> Reverse<TSource>();
// Casting
TSource[] ToArray<TSource>();
IEnumerable<TSource> ToEnumerable<TSource>();
List<TSource> ToList<TSource>();
void RemoveIf<TSource>(Func<TSource, bool> condition);
TValue GetOrDefault<TKey, TValue>(TKey key, TValue defaultValue = default(TValue));
TValue GetOrInsertDefault<TKey, TValue>(TKey key, TValue defaultValue = default(TValue));
TValue GetOrInsertNew<TKey, TValue>(TKey key) where TValue : new();
void ForEachKey<TKey, TValue>(Action<TKey> action);
void ForEachKeyReverse<TKey, TValue>(Action<TKey> action);
void ForEachValue<TKey, TValue>(Action<TValue> action);
void ForEachValueReverse<TKey, TValue>(Action<TValue> action);
bool ContainsCaseInsensitive(string value);
string Truncate(int maxLength);
string SanitizePath();
string RemoveInvisibleCharacters();
int ToInt();
uint ToUInt();
bool IsWithin(float min, float max); // including min and max
bool IsBetween(float min, float max); // excluding min and max
bool IsWithin(float min, float max); // including min and max
bool IsBetween(float min, float max); // excluding min and max
string GetFriendlyName(bool aliasNullable = true, bool includeSpaceAfterComma = true);
string AsString(string format = "yyyyMMdd_HHmmss");
double AsUnixTimeStamp();
string AsUnixTimeStampString();
Return to [Home]
- Home
- Install
- Manual
-
Core API
- Services:
- Util:
-
Unity API
- Services:
- Integrations: