deepSort method

List<E> deepSort()

Returns new instance of List, which is recursively sorted by values. It sorts by values nested List, Set or Map (primitive collections), nested primitive collections inside nested primitive collections and so on.

it gets rid of incomparable values like:

If there are more List, Set or Map, it groups them, sorts by length and puts in the following order:

  1. int and double values
  2. String values
  3. All List sorted by length
  4. All Set sorted by length
  5. All Map sorted by length

Implementation

List<E> deepSort() {
  var intDoubleValues = <dynamic>[...whereType<int>(), ...whereType<double>()]
    ..sort();
  var stringValues = <String>[...whereType<String>()]..sort();

  var lists = <List>[
    for (var list in whereType<List>()) ...{
      list.deepSort(),
    }
  ]..sort(_sortByLengthRecipe);

  var sets = <Set>[
    for (var set in whereType<Set>()) ...{
      set.deepSort(),
    }
  ]..sort(_sortByLengthRecipe);

  var maps = <Map>[
    for (var map in whereType<Map>()) ...{
      map.deepSortByValue(),
    }
  ]..sort(_sortByLengthRecipe);

  return <E>[
    ...intDoubleValues.cast<E>(),
    ...stringValues.cast<E>(),
    ...lists.cast<E>(),
    ...sets.cast<E>(),
    ...maps.cast<E>(),
  ];
}