// MIT License - Copyright (c) 2023 wallstop
// Full license text: https://github.com/wallstop/unity-helpers/blob/main/LICENSE
namespace WallstopStudios.UnityHelpers.Core.Helper
{
using System.Collections.Generic;
///
/// Provides utility methods for creating IEnumerable instances from elements.
///
///
/// Thread Safety: All methods are thread-safe.
/// Performance: O(1) operations that wrap arrays.
/// Allocations: Allocates array for single element overload, returns params array for multi-element overload.
///
public static class Enumerables
{
///
/// Creates an IEnumerable containing a single element.
///
/// The type of the element.
/// The single element to wrap in an enumerable.
/// An IEnumerable containing only the specified element.
///
/// Null handling: Element can be null for reference types.
/// Thread-safe: Yes.
/// Performance: O(1).
/// Allocations: Allocates a single-element array.
/// Edge cases: Works with null elements for reference types.
///
public static IEnumerable Of(T element)
{
return new[] { element };
}
///
/// Creates an IEnumerable containing multiple elements.
///
/// The type of the elements.
/// The elements to wrap in an enumerable.
/// An IEnumerable containing all the specified elements.
///
/// Null handling: Elements can contain nulls for reference types. If elements itself is null, returns null.
/// Thread-safe: Yes.
/// Performance: O(1) - directly returns the params array.
/// Allocations: Params array is allocated by the compiler if not already an array.
/// Edge cases: Empty params returns empty array. Can be called with explicit array to avoid allocation.
///
public static IEnumerable Of(params T[] elements)
{
return elements;
}
}
}