ListSet<T>.of constructor

ListSet<T>.of(
  1. Iterable<T> items, {
  2. bool sort = false,
  3. int compare(
    1. T a,
    2. T b
    )?,
})

Create a ListSet from the items iterable.

If sort is true, it will be sorted with compare, if provided, or with compareObject if not provided. If sort is false, compare will be ignored.

Implementation

ListSet.of(
  Iterable<T> items, {
  bool sort = false,
  int Function(T a, T b)? compare,
}) : assert(compare == null || sort == true) {
  _set = HashSet();
  _list = List.of(items.where((item) => _set.add(item)), growable: false);
  if (sort) _list.sort(compare ?? compareObject);
}