public static T Max <T>([NotNull] this IComparer <T> comparer, T x, T y) { comparer.CheckArgumentNull(nameof(comparer)); int cmp = comparer.Compare(x, y); return(cmp >= 0 ? x : y); }
public static TSource Min <TSource>( [NotNull] this IEnumerable <TSource> source, [NotNull] IComparer <TSource> comparer) { source.CheckArgumentNull(nameof(source)); comparer.CheckArgumentNull(nameof(comparer)); return(source.Extreme(comparer, -1)); }
public static IComparer <T> ThenBy <T, TKey>( [NotNull] this IComparer <T> comparer, [NotNull] Func <T, TKey> keySelector, IComparer <TKey>?keyComparer = null) { comparer.CheckArgumentNull(nameof(comparer)); return(comparer.ChainWith(By(keySelector, keyComparer))); }
public static IComparer <T> ChainWith <T>( [NotNull] this IComparer <T> comparer, [NotNull] IComparer <T> nextComparer) { comparer.CheckArgumentNull(nameof(comparer)); nextComparer.CheckArgumentNull(nameof(nextComparer)); var comparers = GetComparers(comparer); var nextComparers = GetComparers(nextComparer); return(new ChainedComparer <T>(comparers.Concat(nextComparers).ToArray())); }
public static IComparer <T> Reverse <T>([NotNull] this IComparer <T> comparer) { comparer.CheckArgumentNull(nameof(comparer)); return(new ReverseComparer <T>(comparer)); }