orderBy method

Iterable<T> orderBy(
  1. num order(
    1. T item
    ), {
  2. bool desc = false,
})

Sort items

Implementation

Iterable<T> orderBy(
  num Function(T item) order, {
  bool desc = false,
}) sync* {
  final sorted = toList();
  if (desc) {
    sorted.sort(
      (a, b) => order(b) > order(a)
          ? 1
          : order(b) < order(a)
              ? -1
              : 0,
    );
  } else {
    sorted.sort(
      (a, b) => order(b) < order(a)
          ? 1
          : order(b) > order(a)
              ? -1
              : 0,
    );
  }
  for (final item in sorted) {
    yield item;
  }
}