sorted method

Set<E> sorted([
  1. int compare(
    1. E a,
    2. E b
    )?
])

Returns a new set with elements sorted by the given compare function.

Example:

final set = {3, 1, 2};
print(set.sorted()); // {1, 2, 3}

Implementation

Set<E> sorted([int Function(E a, E b)? compare]) {
  final list = toList()..sort(compare);
  return Set.from(list);
}