Skip to content

Commit

Permalink
improved IsEmpty
Browse files Browse the repository at this point in the history
  • Loading branch information
luithefirst committed Sep 30, 2024
1 parent d6bedf2 commit 4ad6690
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/Aardvark.Base/Extensions/IEnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -879,20 +879,20 @@ public static bool AllEqual<T>(this IEnumerable<T> elements)
/// Returns true if elements contains no items or if elements is null,
/// false otherwise.
/// </summary>
public static bool IsEmptyOrNull<T>(this T[] elements)
public static bool IsEmptyOrNull<T>(this Array self)
{
if (elements == null) return true;
return elements.Length == 0;
if (self == null) return true;
return self.Length == 0;
}

/// <summary>
/// Returns true if elements contains no items or if elements is null,
/// false otherwise.
/// </summary>
public static bool IsEmptyOrNull<T>(this ICollection<T> elements)
public static bool IsEmptyOrNull<T>(this ICollection<T> self)
{
if (elements == null) return true;
return elements.Count == 0;
if (self == null) return true;
return self.Count == 0;
}

/// <summary>
Expand Down Expand Up @@ -2282,11 +2282,28 @@ public static IEnumerable<T> Return<T>(this T item)
yield return item;
}

/// <summary>
/// Determines whether an array contains no elements.
/// </summary>
public static bool IsEmpty<T>(this Array self)
{
return self.Length == 0;
}

/// <summary>
/// Determines whether a sequence contains no elements.
/// </summary>
public static bool IsEmpty<T>(this ICollection<T> self)
{
return self.Count == 0;
}

/// <summary>
/// Determines whether a sequence contains no elements.
/// </summary>
public static bool IsEmpty<T>(this IEnumerable<T> self)
{
if (self is ICollection<T> col) return col.Count == 0;
return !self.Any();
}

Expand Down

0 comments on commit 4ad6690

Please sign in to comment.