// MIT License - Copyright (c) 2025 wallstop
// Full license text: https://github.com/wallstop/unity-helpers/blob/main/LICENSE
namespace WallstopStudios.UnityHelpers.Core.Helper
{
using System.Collections.Generic;
///
/// Wraps an existing comparer and reverses its ordering (descending if original was ascending).
///
public sealed class ReverseComparer : IComparer
{
///
/// A default instance that uses .
///
public static readonly ReverseComparer Instance = new();
private readonly IComparer _baseComparer;
///
/// Creates a reversed comparer from a base comparer.
///
public ReverseComparer(IComparer baseComparer = null)
{
_baseComparer = baseComparer ?? Comparer.Default;
}
///
/// Compares two values with reversed ordering.
///
public int Compare(TElement x, TElement y)
{
return _baseComparer.Compare(y, x);
}
}
}