using UnityEngine;
using System.Collections.Generic;

public static class ListExtensions 
{
	public static void RemoveNulls<T>(this List<T> list) where T : class
	{
		for(int i = list.Count - 1; i >= 0; i--)
		{
			if(list[i] == null)
			{
				list.RemoveAt(i);
			}
		}
	}

    public static T GetItemUnbounded<T>(this List<T> list, int index)
    {
        if (list.Count > index)
        {
            return list[index];
        }

        return default(T);
    }

    public static List<T> DeepCopy<T>(this List<T> list) where T : ISupportsDeepCopy<T>
    {
        if(list == null)
        {
            return null;
        }
        
        var result = new List<T>(list.Count);

        for (int i = 0; i < list.Count; i++)
        {
            result.Add(list[i].DeepCopy());
        }

        return result;
    }
}
