using System;
using System.Collections.Immutable;
namespace Game.Extensions
{
///
/// Provides additional methods for the class.
///
public static class ImmutableArrayExtensions
{
///
/// Maps each element in an immutable array to a new value.
///
///
/// The type of elements in the source array.
///
///
/// The type of elements in the resulting array.
///
///
/// The source array.
///
///
/// Function which receives an element from the source array and its
/// index and returns the resulting element.
///
public static ImmutableArray Map(this ImmutableArray source, Func selector)
{
var builder = ImmutableArray.CreateBuilder(source.Length);
for (var i = 0; i < source.Length; ++i)
builder.Add(selector(source[i], i));
return builder.MoveToImmutable();
}
}
}