Skip to content

Commit

Permalink
Add docs for compareBy
Browse files Browse the repository at this point in the history
  • Loading branch information
passsy committed Dec 2, 2018
1 parent 47168f9 commit 25c03bc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/src/comparisons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ Comparator<T> reverse<T>(Comparator<T> comparator) {
return compareTo;
}

/**
* Creates a comparator using the function to transform value to a [Comparable] instance for comparison.
*/
Comparator<T> compareBy<T>(Comparable Function(T) selector) {
int compareTo(T a, T b) => selector(a).compareTo(selector(b));

return compareTo;
}

/**
* Creates a descending comparator using the function to transform value to a [Comparable] instance for comparison.
*/
Comparator<T> compareByDescending<T>(Comparable Function(T) selector) {
int compareTo(T a, T b) => selector(b).compareTo(selector(a));

return compareTo;
}

0 comments on commit 25c03bc

Please sign in to comment.