Simplify StockMarket (C#) folder structure

This commit is contained in:
Zev Spitz
2022-01-17 11:56:20 +02:00
parent 66393f1235
commit e69a3d4b3f
14 changed files with 7 additions and 7 deletions

View File

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