Exemplo n.º 1
0
        /// <summary>
        /// Returns the minimum element in sequence using custom user 'comparer'
        /// </summary>
        /// <typeparam name="TSource">The type of the elements</typeparam>
        /// <param name="source">A sequence of values</param>
        /// <param name="comparer">Comparer to compare elements from sequence</param>
        /// <returns>The minimum value in the sequence</returns>
        internal static TSource Min <TSource>(this IEnumerable <TSource> source, IComparer <TSource> comparer)
        {
            if (comparer == null)
            {
                return(Enumerable.Min(source));
            }

            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            using (var enumerator = source.GetEnumerator())
            {
                if (!enumerator.MoveNext())
                {
                    throw new InvalidOperationException("Sequence contains no elements");
                }

                var min = enumerator.Current;
                while (enumerator.MoveNext())
                {
                    var current = enumerator.Current;
                    if (comparer.Compare(current, min) < 0)
                    {
                        min = current;
                    }
                }

                return(min);
            }
        }
Exemplo n.º 2
0
    public void BlinqShouldEqualLinqNativeArrayMinComparableSelector([ArrayValues] int[] sourceArr)
    {
        var arr            = Linq.ToArray(Linq.Select(sourceArr, (i) => (Comparable)i));
        var srcNativeArray = new NativeArray <Comparable>(arr, Allocator.Persistent);
        var expected       = ExceptionAndValue(() => Linq.Min(srcNativeArray, SelectSelf <Comparable>().Invoke));
        var actual         = ExceptionAndValue(() => Blinq.Min(srcNativeArray, SelectSelf <Comparable>()));

        srcNativeArray.Dispose();
    }
Exemplo n.º 3
0
    public void BlinqShouldEqualLinqNativeArrayMinSelector_int(
        [ValueSource(typeof(Values_int), nameof(Values_int.Values))] int[] sourceArr
        )
    {
        var srcNativeArray = new NativeArray <int>(sourceArr, Allocator.Persistent);
        var expected       = ExceptionAndValue(() => Linq.Min(srcNativeArray, SelectSelf <int>().Invoke));
        var actual         = ExceptionAndValue(() => Blinq.Min(srcNativeArray, SelectSelf <int>()));

        srcNativeArray.Dispose();
    }
Exemplo n.º 4
0
    public void BlinqShouldEqualLinqNativeArrayMin_double(
        [ValueSource(typeof(Values_double), nameof(Values_double.Values))] double[] sourceArr
        )
    {
        var srcNativeArray = new NativeArray <double>(sourceArr, Allocator.Persistent);
        var expected       = ExceptionAndValue(() => Linq.Min(srcNativeArray));
        var actual         = ExceptionAndValue(() => Blinq.Min(srcNativeArray));

        srcNativeArray.Dispose();
    }
Exemplo n.º 5
0
 public static long Min(this IEnumerable <long> source) =>
 LinqEnumerable.Min(source);
Exemplo n.º 6
0
 public static double Min <TSource>(this IEnumerable <TSource> source, Func <TSource, double> selector) =>
 LinqEnumerable.Min(source, selector);
Exemplo n.º 7
0
 public static TSource Min <TSource>(this IEnumerable <TSource> source) =>
 LinqEnumerable.Min(source);
Exemplo n.º 8
0
 public static int?Min <TSource>(this IEnumerable <TSource> source, Func <TSource, int?> selector) =>
 LinqEnumerable.Min(source, selector);
Exemplo n.º 9
0
 public static long?Min(this IEnumerable <long?> source)
 => Enumerable.Min(source);
Exemplo n.º 10
0
 public static decimal Min(this IEnumerable <decimal> source) =>
 LinqEnumerable.Min(source);
Exemplo n.º 11
0
 public static long Min <TSource>(this IEnumerable <TSource> source, Func <TSource, long> selector) =>
 LinqEnumerable.Min(source, selector);
Exemplo n.º 12
0
 public static decimal?Min(this IEnumerable <decimal?> source)
 => Enumerable.Min(source);
Exemplo n.º 13
0
 public static float?Min(this IEnumerable <float?> source)
 => Enumerable.Min(source);
Exemplo n.º 14
0
 public static double?Min(this IEnumerable <double?> source)
 => Enumerable.Min(source);
Exemplo n.º 15
0
 public static int Min(this IEnumerable <int> source) =>
 LinqEnumerable.Min(source);
Exemplo n.º 16
0
 public static double Min(this IEnumerable <double> source) =>
 LinqEnumerable.Min(source);
Exemplo n.º 17
0
 public static decimal?Min <TSource>(this IEnumerable <TSource> source, Func <TSource, decimal?> selector) =>
 LinqEnumerable.Min(source, selector);
Exemplo n.º 18
0
 public static float Min(this IEnumerable <float> source) =>
 LinqEnumerable.Min(source);
Exemplo n.º 19
0
 public static TResult Min <TSource, TResult>(this IEnumerable <TSource> source, Func <TSource, TResult> selector) =>
 LinqEnumerable.Min(source, selector);
Exemplo n.º 20
0
 public static float Min <TSource>(this IEnumerable <TSource> source, Func <TSource, float> selector) =>
 LinqEnumerable.Min(source, selector);
Exemplo n.º 21
0
 public static int?Min(this IEnumerable <int?> source)
 => Enumerable.Min(source);