sortPinnedFirst<T> function

List<T> sortPinnedFirst<T>(
  1. List<T> items,
  2. bool isPinned(
    1. T
    )
)

Stable (List.sort is not): pinned items first, relative order kept.

Implementation

List<T> sortPinnedFirst<T>(List<T> items, bool Function(T) isPinned) {
  final List<T> pinned = <T>[];
  final List<T> others = <T>[];
  for (final T item in items) {
    (isPinned(item) ? pinned : others).add(item);
  }
  return <T>[...pinned, ...others];
}