# ConvertingComparator<S, T>.withConverter constructor

ConvertingComparator<S, T>.withConverter(

1. Comparator<T> comparator,
2. ConversionService conversionService,
3. Class<T> targetType

)

A comparator that compares source values of type `S` by first converting them to another type `T` using a Converter, then applying a Comparator on `T`.

This is useful when you want to sort values based on a derived property or a type transformation.

### 🔧 Example: Compare strings by their lengths

    final comparator = ConvertingComparator<String, int>(
      Comparator.naturalOrder(),
      Converter<String, int>((s) => s.length),
    );

    final list = ['pear', 'banana', 'kiwi'];
    list.sort(comparator); // ['kiwi', 'pear', 'banana']

You can also use the factory constructors:

### 🔧 Using `withConverter` and a ConversionService:

    final service = DefaultConversionService();
    final comparator = ConvertingComparator.withConverter<String, int>(
      Comparator.naturalOrder(),
      service,
      Class<int>(),
    );

Constructs a comparator using a ConversionService and a target type.

## Implementation

    ConvertingComparator.withConverter(Comparator<T> comparator, ConversionService conversionService, Class<T> targetType)
      : this(comparator, ConversionServiceConverter(conversionService, targetType));