This commit is contained in:
melekhin
2026-05-29 16:45:24 +07:00
parent 7ebbeb7855
commit ba77411c4a
31 changed files with 2544 additions and 345 deletions

View File

@@ -49,18 +49,18 @@ public static partial class Extensions
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static double QuickPow(this double baseValue, int exp)
internal static double QuickPow(this double base_Value, int exp)
{
switch (exp)
{
case 0: return 1.0;
case 1: return baseValue;
case 2: return baseValue * baseValue;
case 3: return baseValue * baseValue * baseValue;
case 4: { double x2 = baseValue * baseValue; return x2 * x2; }
case -1: return 1.0 / baseValue;
case -2: return 1.0 / (baseValue * baseValue);
default: return Math.Pow(baseValue, exp);
case 1: return base_Value;
case 2: return base_Value * base_Value;
case 3: return base_Value * base_Value * base_Value;
case 4: { double x2 = base_Value * base_Value; return x2 * x2; }
case -1: return 1.0 / base_Value;
case -2: return 1.0 / (base_Value * base_Value);
default: return Math.Pow(base_Value, exp);
}
}
@@ -71,261 +71,267 @@ public static partial class Extensions
//internal static U Protect<U>(this U? metric) where U : class, IMetric<U>, new() => metric ?? new();
//internal static C Protect<C, U>(this C? collection)
// where C : IMetricCollection<U>, new() where U : class, IMetric<U>, new() => collection ?? new();
//public static C MetricSelect<C, U>(this C? collection, Func<U, U>? selector)
// where C : IMetricCollection<U>, new() where U : class, IMetric<U>, new()
//{
// var source = (collection ??= new());
// var nColl = (C)source.CreateByInstanceU(source.Count);
// if (selector is not null)
// {
// for (int i = 0; i < nColl.Count; i++)
// nColl[i] = selector(source[i]);
// return nColl;
// }
// return new();
//}
//public static IEnumerable<double> MetricSelect<U>(this IMetricCollection<U> collection, Func<U, double> selector)
// where U : class, IMetric<U>, new()
//{
// if (collection is not null)
// {
// if (selector is not null)
// return collection.Select(selector);
// return collection.Select(u => double.NaN);
// }
// else return [];
//}
//public static IMetricCollection<Uz> MetricSelect<Ux, Uz>(this IMetricCollection<Ux>? collection, Func<Ux, Uz>? selector)
// where Ux : class, IMetric<Ux>, new() where Uz : class, IMetric<Uz>, new()
//{
// if (collection is not null && selector is not null)
// {
// var destCollection = collection.CreateByInstance<Uz>(collection.Count);
// for (int i = 0; i < collection.Count; i++)
// destCollection[i] = selector(collection[i]);
// return destCollection;
// }
// return null!;
//}
//public static MetricCollection<Uz> MetricSelect<Ux, Uz>(this MetricCollection<Ux>? collection, Func<Ux, Uz>? selector)
// where Ux : class, IMetric<Ux>, new() where Uz : class, IMetric<Uz>, new()
//{
// if (collection is not null && selector is not null)
// {
// var destCollection = collection.CreateByInstance<Uz>(collection.Count());
// for (int i = 0; i < collection.Count(); i++)
// destCollection[i] = selector(collection[i]);
// return destCollection;
// }
// return null!;
//}
//public static MetricArray<Uz> MetricSelect<Ux, Uz>(this MetricArray<Ux>? collection, Func<Ux, Uz>? selector)
// where Ux : class, IMetric<Ux>, new() where Uz : class, IMetric<Uz>, new()
//{
// var coll = collection?.ToArray();
// if (coll is not null && selector is not null)
// {
// var destCollection = new MetricArray<Uz>(coll.Length);
// for (int i = 0; i < coll.Length; i++)
// destCollection[i] = selector(coll[i]);
// return destCollection;
// }
// return null!;
//}
//public static MetricList<Uz> MetricSelect<Ux, Uz>(this MetricList<Ux>? collection, Func<Ux, Uz>? selector)
// where Ux : class, IMetric<Ux>, new() where Uz : class, IMetric<Uz>, new()
//{
// if (collection is not null && selector is not null)
// {
// var destCollection = new MetricList<Uz>(collection.Count);
// for (int i = 0; i < collection.Count; i++)
// destCollection[i] = selector(collection[i]);
// return destCollection;
// }
// return null!;
//}
//public static MetricObservableCollection<Uz> MetricSelect<Ux, Uz>(this MetricObservableCollection<Ux>? collection, Func<Ux, Uz>? selector)
// where Ux : class, IMetric<Ux>, new() where Uz : class, IMetric<Uz>, new()
//{
// if (collection is not null && selector is not null)
// {
// var destCollection = new MetricObservableCollection<Uz>(collection.Count);
// for (int i = 0; i < collection.Count; i++)
// destCollection[i] = selector(collection[i]);
// return destCollection;
// }
// return null!;
//}
//public static double[] MetricSelect<U>(this MetricArray<U> collection, Func<U, double> selector)
// where U : class, IMetric<U>, new()
//{
// var coll = collection ?? [];
// var arr = new double[coll.Length];
// if (selector is not null)
// for (int i = 0; i < arr.Length; i++)
// arr[i] = selector(coll[i]);
// return arr;
//}
//public static List<double> MetricSelect<U>(this MetricList<U> collection, Func<U, double> selector)
// where U : class, IMetric<U>, new()
//{
// var coll = collection ?? [];
// var list = new List<double>(coll.Count);
// if (selector is not null)
// for (int i = 0; i < list.Count; i++)
// list[i] = selector(coll[i]);
// return list;
//}
//public static ObservableCollection<double> MetricSelect<U>(this MetricObservableCollection<U> collection, Func<U, double> selector)
// where U : class, IMetric<U>, new()
//{
// var coll = collection ?? [];
// var list = new List<double>(coll.Count);
// if (selector is not null)
// for (int i = 0; i < list.Count; i++)
// list[i] = selector(coll[i]);
// return new(list);
//}
//internal static C ForEachC<C, U>(this C? collection, Func<U, U>? Set)
// where C : IMetricCollection<U>, new() where U : class, IMetric<U>, new()
//{
// var nColl = (C)(collection ??= new()).CreateByInstanceU(collection.Count);
// if (Set is not null)
// for (int i = 0; i < nColl.Count; i++)
// nColl[i] = Set(nColl[i]);
// return nColl;
//}
//internal static double ProtectValue(this IMetric? metric) => metric is null ? 0d : metric.Value;
//public static U Min<U>(this U? T1, U? T2) where U : class, IMetric<U>, new() => (T1.ProtectValue() < T2.ProtectValue() ? T1 : T2).Protect();
//public static U Min<U>(this U T1, IEnumerable<U> units) where U : class, IMetric<U>, new() => (T1 ?? new()).Min((units ?? []).MaxBy(u => u.ProtectValue()));
//public static U Max<U>(this U? T1, U? T2) where U : class, IMetric<U>, new() => (T1.ProtectValue() > T2.ProtectValue() ? T1 : T2).Protect();
//public static U Max<U>(this U T1, IEnumerable<U> units) where U : class, IMetric<U>, new() => (T1 ?? new()).Max((units ?? []).MaxBy(u => u.ProtectValue()));
//internal static U Protect<U>(this U? metric) where U : class, IMetric<U>, new() => metric ?? new();
//internal static C Protect<C, U>(this C? collection)
// where C : IMetricCollection<U>, new() where U : class, IMetric<U>, new() => collection ?? new();
////internal static double ToDouble(this double number) => number;
////internal static double ToDouble(this double? number) => number ?? 0d;
////internal static double ToDouble<N>(this N number) where N : INumber<N> => Convert.ToDouble(number);
////internal static double ToDouble<N>(this N? number) where N : struct, INumber<N> => number is not null ? Convert.ToDouble(number) : 0d;
//internal static IEnumerable<U> MetricSelect<U>(this double[] nums, Func<double, U> selector) where U : class, IMetric<U>, new() => nums.Select(selector);
//internal static IEnumerable<U> MetricSelect<U>(this double?[] nums, Func<double, U> selector) where U : class, IMetric<U>, new() => nums.Select(num => selector(num.ToDouble()));
//internal static IEnumerable<U> MetricSelect<U, N>(this N[] nums, Func<double, U> selector) where N : INumber<N> where U : class, IMetric<U>, new() => nums.Select(num => selector(num.ToDouble()));
//internal static IEnumerable<U> MetricSelect<U, N>(this N?[] nums, Func<double, U> selector) where N : struct, INumber<N> where U : class, IMetric<U>, new() => nums.Select(num => selector(num.ToDouble()));
//internal static IEnumerable<U> MetricSelect<U>(this IEnumerable<double> nums, Func<double, U> selector) where U : class, IMetric<U>, new() => nums.Select(selector);
//internal static IEnumerable<U> MetricSelect<U>(this IEnumerable<double?> nums, Func<double, U> selector) where U : class, IMetric<U>, new() => nums.Select(num => selector(num.ToDouble()));
//internal static IEnumerable<U> MetricSelect<U, N>(this IEnumerable<N> nums, Func<double, U> selector) where N : INumber<N> where U : class, IMetric<U>, new() => nums.Select(num => selector(num.ToDouble()));
//internal static IEnumerable<U> MetricSelect<U, N>(this IEnumerable<N?> nums, Func<double, U> selector) where N : struct, INumber<N> where U : class, IMetric<U>, new() => nums.Select(num => selector(num.ToDouble()));
//public static C MetricSelect<C, U>(this C? collection, Func<U, U>? selector)
// where C : IMetricCollection<U>, new() where U : class, IMetric<U>, new()
//{
// var source = (collection ??= new());
// var nColl = (C)source.CreateByInstanceU(source.Count);
// if (selector is not null)
// {
// for (int i = 0; i < nColl.Count; i++)
// nColl[i] = selector(source[i]);
// return nColl;
// }
// return new();
//}
//public static IEnumerable<double> MetricSelect<U>(this IMetricCollection<U> collection, Func<U, double> selector)
// where U : class, IMetric<U>, new()
//{
// if (collection is not null)
// {
// if (selector is not null)
// return collection.Select(selector);
// return collection.Select(u => double.NaN);
// }
// else return [];
//}
//public static U Clone<U>(this U? metric) where U : class, IMetric<U>, new() => new() { Value = metric.ProtectValue() };
//public static U Abs<U>(this U? metric) where U : class, IMetric<U>, new() => new() { Value = Math.Abs(metric.ProtectValue()) };
///// <summary>C^2 = A^2 + B^2</summary>
///// <returns>C = (A^2 + B^2).Sqrt(2)</returns>
//public static U Hypotenuse<U>(this U? A, U? B) where U : class, IMetric<U>, new()
//{
// var a = A.ProtectValue();
// var b = B.ProtectValue();
// return new U() { Value = Math.Sqrt(a * a + b * b) };
//}
///// <summary>C^2 = A^2 + B^2</summary>
///// <returns>B = (C^2 - A^2).Sqrt(2)</returns>
//public static U KatetFromHyp<U>(this U? A, U? C) where U : class, IMetric<U>, new()
//{
// var a = A.ProtectValue();
// var c = C.ProtectValue();
// return new U() { Value = Math.Sqrt(c * c - a * a) };
//}
///// <summary>C^2 = A^2 + B^2</summary>
///// <returns>B = (C^2 - A^2).Sqrt(2)</returns>
//public static U KatetFromKatet<U>(this U? C, U? A) where U : class, IMetric<U>, new()
//{
// var a = A.ProtectValue();
// var c = C.ProtectValue();
// return new U() { Value = Math.Sqrt(c * c - a * a) };
//}
//public static Area Pow(this Length? metric, double? val = 2) => new() { Value = Math.Pow(metric.ProtectValue(), val ?? 2) };
//public static Length Sqrt(this Area? metric) => new() { Value = Math.Sqrt(metric.ProtectValue()) };
//public static IMetricCollection<Uz> MetricSelect<Ux, Uz>(this IMetricCollection<Ux>? collection, Func<Ux, Uz>? selector)
// where Ux : class, IMetric<Ux>, new() where Uz : class, IMetric<Uz>, new()
//{
// if (collection is not null && selector is not null)
// {
// var destCollection = collection.CreateByInstance<Uz>(collection.Count);
// for (int i = 0; i < collection.Count; i++)
// destCollection[i] = selector(collection[i]);
// return destCollection;
// }
// return null!;
//}
//public static MetricCollection<Uz> MetricSelect<Ux, Uz>(this MetricCollection<Ux>? collection, Func<Ux, Uz>? selector)
// where Ux : class, IMetric<Ux>, new() where Uz : class, IMetric<Uz>, new()
//{
// if (collection is not null && selector is not null)
// {
// var destCollection = collection.CreateByInstance<Uz>(collection.Count());
// for (int i = 0; i < collection.Count(); i++)
// destCollection[i] = selector(collection[i]);
// return destCollection;
// }
// return null!;
//}
//public static MetricArray<Uz> MetricSelect<Ux, Uz>(this MetricArray<Ux>? collection, Func<Ux, Uz>? selector)
// where Ux : class, IMetric<Ux>, new() where Uz : class, IMetric<Uz>, new()
//{
// var coll = collection?.ToArray();
// if (coll is not null && selector is not null)
// {
// var destCollection = new MetricArray<Uz>(coll.Length);
// for (int i = 0; i < coll.Length; i++)
// destCollection[i] = selector(coll[i]);
// return destCollection;
// }
// return null!;
//}
//public static MetricList<Uz> MetricSelect<Ux, Uz>(this MetricList<Ux>? collection, Func<Ux, Uz>? selector)
// where Ux : class, IMetric<Ux>, new() where Uz : class, IMetric<Uz>, new()
//{
// if (collection is not null && selector is not null)
// {
// var destCollection = new MetricList<Uz>(collection.Count);
// for (int i = 0; i < collection.Count; i++)
// destCollection[i] = selector(collection[i]);
// return destCollection;
// }
// return null!;
//}
//public static MetricObservableCollection<Uz> MetricSelect<Ux, Uz>(this MetricObservableCollection<Ux>? collection, Func<Ux, Uz>? selector)
// where Ux : class, IMetric<Ux>, new() where Uz : class, IMetric<Uz>, new()
//{
// if (collection is not null && selector is not null)
// {
// var destCollection = new MetricObservableCollection<Uz>(collection.Count);
// for (int i = 0; i < collection.Count; i++)
// destCollection[i] = selector(collection[i]);
// return destCollection;
// }
// return null!;
//}
//public static U MetricSum<U>(this IEnumerable<U> args) where U : IMetric, new() => new() { Value = args?.Where(t => t is not null).Sum(m => m.ProtectValue()) ?? 0d };
//public static U MetricAverage<U>(this IEnumerable<U> args) where U : IMetric, new() => new() { Value = args?.Average(m => m.ProtectValue()) ?? double.NaN };
//public static U MetricMax<U>(this IEnumerable<U> args) where U : IMetric, new() => new() { Value = args.Max(m => m.ProtectValue()) };
//public static U MetricMin<U>(this IEnumerable<U> args) where U : IMetric, new() => new() { Value = args.Min(m => m.ProtectValue()) };
//public static double[] MetricSelect<U>(this MetricArray<U> collection, Func<U, double> selector)
// where U : class, IMetric<U>, new()
//{
// var coll = collection ?? [];
// var arr = new double[coll.Length];
// if (selector is not null)
// for (int i = 0; i < arr.Length; i++)
// arr[i] = selector(coll[i]);
// return arr;
//}
//public static List<double> MetricSelect<U>(this MetricList<U> collection, Func<U, double> selector)
// where U : class, IMetric<U>, new()
//{
// var coll = collection ?? [];
// var list = new List<double>(coll.Count);
// if (selector is not null)
// for (int i = 0; i < list.Count; i++)
// list[i] = selector(coll[i]);
// return list;
//}
//public static ObservableCollection<double> MetricSelect<U>(this MetricObservableCollection<U> collection, Func<U, double> selector)
// where U : class, IMetric<U>, new()
//{
// var coll = collection ?? [];
// var list = new List<double>(coll.Count);
// if (selector is not null)
// for (int i = 0; i < list.Count; i++)
// list[i] = selector(coll[i]);
// return new(list);
//}
//internal static C ForEachC<C, U>(this C? collection, Func<U, U>? Set)
// where C : IMetricCollection<U>, new() where U : class, IMetric<U>, new()
//{
// var nColl = (C)(collection ??= new()).CreateByInstanceU(collection.Count);
// if (Set is not null)
// for (int i = 0; i < nColl.Count; i++)
// nColl[i] = Set(nColl[i]);
// return nColl;
//}
//internal static double Protect_Value(this IMetric? metric) => metric is null ? 0d : metric._Value;
//public static U Min<U>(this U? T1, U? T2) where U : class, IMetric<U>, new() => (T1.Protect_Value() < T2.Protect_Value() ? T1 : T2).Protect();
//public static U Min<U>(this U T1, IEnumerable<U> units) where U : class, IMetric<U>, new() => (T1 ?? new()).Min((units ?? []).MaxBy(u => u.Protect_Value()));
//public static U Max<U>(this U? T1, U? T2) where U : class, IMetric<U>, new() => (T1.Protect_Value() > T2.Protect_Value() ? T1 : T2).Protect();
//public static U Max<U>(this U T1, IEnumerable<U> units) where U : class, IMetric<U>, new() => (T1 ?? new()).Max((units ?? []).MaxBy(u => u.Protect_Value()));
////internal static double ToDouble(this double number) => number;
////internal static double ToDouble(this double? number) => number ?? 0d;
////internal static double ToDouble<N>(this N number) where N : INumber<N> => Convert.ToDouble(number);
////internal static double ToDouble<N>(this N? number) where N : struct, INumber<N> => number is not null ? Convert.ToDouble(number) : 0d;
//internal static IEnumerable<U> MetricSelect<U>(this double[] nums, Func<double, U> selector) where U : class, IMetric<U>, new() => nums.Select(selector);
//internal static IEnumerable<U> MetricSelect<U>(this double?[] nums, Func<double, U> selector) where U : class, IMetric<U>, new() => nums.Select(num => selector(num.ToDouble()));
//internal static IEnumerable<U> MetricSelect<U, N>(this N[] nums, Func<double, U> selector) where N : INumber<N> where U : class, IMetric<U>, new() => nums.Select(num => selector(num.ToDouble()));
//internal static IEnumerable<U> MetricSelect<U, N>(this N?[] nums, Func<double, U> selector) where N : struct, INumber<N> where U : class, IMetric<U>, new() => nums.Select(num => selector(num.ToDouble()));
//internal static IEnumerable<U> MetricSelect<U>(this IEnumerable<double> nums, Func<double, U> selector) where U : class, IMetric<U>, new() => nums.Select(selector);
//internal static IEnumerable<U> MetricSelect<U>(this IEnumerable<double?> nums, Func<double, U> selector) where U : class, IMetric<U>, new() => nums.Select(num => selector(num.ToDouble()));
//internal static IEnumerable<U> MetricSelect<U, N>(this IEnumerable<N> nums, Func<double, U> selector) where N : INumber<N> where U : class, IMetric<U>, new() => nums.Select(num => selector(num.ToDouble()));
//internal static IEnumerable<U> MetricSelect<U, N>(this IEnumerable<N?> nums, Func<double, U> selector) where N : struct, INumber<N> where U : class, IMetric<U>, new() => nums.Select(num => selector(num.ToDouble()));
//public static C MetricSum<C, U>(this IEnumerable<MetricCollection<C, U>> collections)
// where C : MetricCollection<C, U>, ICreateByCapacity, new() where U : class, IMetric<U>, new()
//{
// var cArr = collections.ToArray();
// C accumulator = (C)cArr.FirstOrDefault(new C());
// for (int i = 1; i < cArr.Length; i++)
// accumulator = accumulator.FuncByPairOrOneToMany(cArr[i], (a, b) => a + b, out C _);
// return accumulator;
//}
//public static C MetricAverage<C, U>(this IEnumerable<MetricCollection<C, U>> collections)
// where C : MetricCollection<C, U>, ICreateByCapacity, new() where U : class, IMetric<U>, new()
// => collections.MetricSum() / collections.Count();
//public static U Clone<U>(this U? metric) where U : class, IMetric<U>, new() => new() { _Value = metric.Protect_Value() };
//public static U Abs<U>(this U? metric) where U : class, IMetric<U>, new() => new() { _Value = Math.Abs(metric.Protect_Value()) };
///// <summary>C^2 = A^2 + B^2</summary>
///// <returns>C = (A^2 + B^2).Sqrt(2)</returns>
//public static U Hypotenuse<U>(this U? A, U? B) where U : class, IMetric<U>, new()
//{
// var a = A.Protect_Value();
// var b = B.Protect_Value();
// return new U() { _Value = Math.Sqrt(a * a + b * b) };
//}
///// <summary>C^2 = A^2 + B^2</summary>
///// <returns>B = (C^2 - A^2).Sqrt(2)</returns>
//public static U KatetFromHyp<U>(this U? A, U? C) where U : class, IMetric<U>, new()
//{
// var a = A.Protect_Value();
// var c = C.Protect_Value();
// return new U() { _Value = Math.Sqrt(c * c - a * a) };
//}
///// <summary>C^2 = A^2 + B^2</summary>
///// <returns>B = (C^2 - A^2).Sqrt(2)</returns>
//public static U KatetFromKatet<U>(this U? C, U? A) where U : class, IMetric<U>, new()
//{
// var a = A.Protect_Value();
// var c = C.Protect_Value();
// return new U() { _Value = Math.Sqrt(c * c - a * a) };
//}
//public static Area Pow(this Length? metric, double? val = 2) => new() { _Value = Math.Pow(metric.Protect_Value(), val ?? 2) };
//public static Length Sqrt(this Area? metric) => new() { _Value = Math.Sqrt(metric.Protect_Value()) };
//public static U MetricSum<U>(this IEnumerable<U> args) where U : IMetric, new() => new() { _Value = args?.Where(t => t is not null).Sum(m => m.Protect_Value()) ?? 0d };
//public static U MetricAverage<U>(this IEnumerable<U> args) where U : IMetric, new() => new() { _Value = args?.Average(m => m.Protect_Value()) ?? double.NaN };
//public static U MetricMax<U>(this IEnumerable<U> args) where U : IMetric, new() => new() { _Value = args.Max(m => m.Protect_Value()) };
//public static U MetricMin<U>(this IEnumerable<U> args) where U : IMetric, new() => new() { _Value = args.Min(m => m.Protect_Value()) };
//public static U MetricSumBy<TSource, U>(this IEnumerable<TSource> source, Func<TSource, U> selector)
// where U : class, IMetric<U>, new()
//{
// if (source is null) return new();
// if (selector is null) throw new ArgumentNullException("selector is null");
// return new() { Value = source.Select(selector).Where(t => t is not null).Sum(t => t.ProtectValue()) };
//}
//public static U MetricAverageBy<TSource, U>(this IEnumerable<TSource> source, Func<TSource, U> selector)
// where U : class, IMetric<U>, new()
//{
// if (source is null) return new();
// if (selector is null) throw new ArgumentNullException("selector is null");
// return new() { Value = source.Select(selector).Average(t => t.ProtectValue()) };
//}
//public static C MetricSumBy<TSource, C, U>(this IEnumerable<TSource> source, Func<TSource, MetricCollection<C, U>> selector)
// where C : MetricCollection<C, U>, ICreateByCapacity, new() where U : class, IMetric<U>, new()
//{
// if (source is null) return new();
// if (selector is null) throw new ArgumentNullException("selector is null");
// return source.Select(selector).MetricSum();
//}
//public static C MetricAverageBy<TSource, C, U>(this IEnumerable<TSource> source, Func<TSource, MetricCollection<C, U>> selector)
// where C : MetricCollection<C, U>, ICreateByCapacity, new() where U : class, IMetric<U>, new()
//{
// if (source is null) return new();
// if (selector is null) throw new ArgumentNullException("selector is null");
// return source.Select(selector).MetricAverage();
//}
//public static C MetricSum<C, U>(this IEnumerable<MetricCollection<C, U>> collections)
// where C : MetricCollection<C, U>, ICreateByCapacity, new() where U : class, IMetric<U>, new()
//{
// var cArr = collections.ToArray();
// C accumulator = (C)cArr.FirstOrDefault(new C());
// for (int i = 1; i < cArr.Length; i++)
// accumulator = accumulator.FuncByPairOrOneToMany(cArr[i], (a, b) => a + b, out C _);
// return accumulator;
//}
//public static C MetricAverage<C, U>(this IEnumerable<MetricCollection<C, U>> collections)
// where C : MetricCollection<C, U>, ICreateByCapacity, new() where U : class, IMetric<U>, new()
// => collections.MetricSum() / collections.Count();
//public static MetricArray<U> ToMetricArray<U>(this IEnumerable<U> source) where U : class, IMetric<U>, new() => new(source);
//public static MetricList<U> ToMetricList<U>(this IEnumerable<U> source) where U : class, IMetric<U>, new() => new(source);
//public static U MetricSumBy<TSource, U>(this IEnumerable<TSource> source, Func<TSource, U> selector)
// where U : class, IMetric<U>, new()
//{
// if (source is null) return new();
// if (selector is null) throw new ArgumentNullException("selector is null");
// return new() { _Value = source.Select(selector).Where(t => t is not null).Sum(t => t.Protect_Value()) };
//}
//public static U MetricAverageBy<TSource, U>(this IEnumerable<TSource> source, Func<TSource, U> selector)
// where U : class, IMetric<U>, new()
//{
// if (source is null) return new();
// if (selector is null) throw new ArgumentNullException("selector is null");
// return new() { _Value = source.Select(selector).Average(t => t.Protect_Value()) };
//}
//public static C MetricSumBy<TSource, C, U>(this IEnumerable<TSource> source, Func<TSource, MetricCollection<C, U>> selector)
// where C : MetricCollection<C, U>, ICreateByCapacity, new() where U : class, IMetric<U>, new()
//{
// if (source is null) return new();
// if (selector is null) throw new ArgumentNullException("selector is null");
// return source.Select(selector).MetricSum();
//}
//public static C MetricAverageBy<TSource, C, U>(this IEnumerable<TSource> source, Func<TSource, MetricCollection<C, U>> selector)
// where C : MetricCollection<C, U>, ICreateByCapacity, new() where U : class, IMetric<U>, new()
//{
// if (source is null) return new();
// if (selector is null) throw new ArgumentNullException("selector is null");
// return source.Select(selector).MetricAverage();
//}
//public static MetricArray<U> ToMetricArray<U>(this IEnumerable<U> source) where U : class, IMetric<U>, new() => new(source);
//public static MetricList<U> ToMetricList<U>(this IEnumerable<U> source) where U : class, IMetric<U>, new() => new(source);
}