using System; using System.Collections.Generic; using UnityEngine; using Object = UnityEngine.Object; namespace Unity.UIWidgets.foundation { public delegate void ValueChanged(T value); public delegate IEnumerable EnumerableFilter(IEnumerable input); public static class ObjectUtils { public static T SafeDestroy(T obj) where T : Object { if (Application.isEditor) { Object.DestroyImmediate(obj); } else { Object.Destroy(obj); } return null; } } public static class CollectionUtils { public static V putIfAbsent(this IDictionary it, K key, Func ifAbsent) { V value; if (it.TryGetValue(key, out value)) { return value; } value = ifAbsent(); it[key] = value; return value; } public static bool isEmpty(this ICollection it) { return it.Count == 0; } public static bool isNotEmpty(this ICollection it) { return it.Count != 0; } public static bool isEmpty(this Queue it) { return it.Count == 0; } public static bool isNotEmpty(this Queue it) { return it.Count != 0; } public static bool isEmpty(this IDictionary it) { return it.Count == 0; } public static bool isNotEmpty(this IDictionary it) { return it.Count != 0; } public static bool isEmpty(this string it) { return string.IsNullOrEmpty(it); } public static bool isNotEmpty(this string it) { return !string.IsNullOrEmpty(it); } public static TValue getOrDefault(this IDictionary it, TKey key) { TValue v; it.TryGetValue(key, out v); return v; } public static T first(this IList it) { return it[0]; } public static T last(this IList it) { return it[it.Count - 1]; } public static T removeLast(this IList it) { var lastIndex = it.Count - 1; var result = it[lastIndex]; it.RemoveAt(lastIndex); return result; } } }