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) {
  final Set<T> thisSet = Set.of(this);
  final Set<dynamic> otherSet = Set<dynamic>.of(ordering);

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

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