sortedLike method

List<T> sortedLike(
  1. Iterable ordering
)

Returns a list, sorted according to the order specified by the ordering iterable. Items which don't appear in ordering will be included in the end, in their original order. Items of ordering which are not found in the original list are ignored.

Implementation

List<T> sortedLike(Iterable ordering) {
  Set<T> thisSet = Set.of(this);
  Set<dynamic> otherSet = Set<dynamic>.of(ordering);

  DiffAndIntersectResult<T, dynamic> result = thisSet.diffAndIntersect<dynamic>(
    otherSet,
    diffThisMinusOther: true,
    diffOtherMinusThis: false,
    intersectThisWithOther: false,
    intersectOtherWithThis: true,
  );

  List<T> intersectOtherWithThis = result.intersectOtherWithThis ?? [];
  List<T> diffThisMinusOther = result.diffThisMinusOther ?? [];
  return intersectOtherWithThis.followedBy(diffThisMinusOther).toList();
}