Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ComparatorUtils #17

Open
AndreTheHunter opened this issue Apr 7, 2022 · 0 comments
Open

Add ComparatorUtils #17

AndreTheHunter opened this issue Apr 7, 2022 · 0 comments

Comments

@AndreTheHunter
Copy link
Contributor

class ComparatorUtils {
  ComparatorUtils._();

  static Comparator<T> compareBy<T, C extends Comparable<C>>(
    C Function(T) selector,
  ) {
    //based on https://pub.dev/documentation/kt_dart/latest/kt_collection/compareBy.html
    return (T a, T b) => selector(a).compareTo(selector(b));
  }

  static Comparator<T> compareByDescending<T, C extends Comparable<C>>(
    C Function(T) selector,
  ) {
    //based on https://pub.dev/documentation/kt_dart/latest/kt_collection/compareByDescending.html
    return (T a, T b) => selector(b).compareTo(selector(a));
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant