# ConvertingComparator<S, T>.converter constructor

ConvertingComparator<S, T>.converter(

1. Converter<S, T> converter

)

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>(),
    );

Uses Comparator.naturalOrder as the default comparator for `T`.

## Implementation

    ConvertingComparator.converter(Converter<S, T> converter) : this(Comparator.naturalOrder(), converter);