Skip to content

Commit 4559103

Browse files
committed
Introduce Ordered
1 parent 53746a7 commit 4559103

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

packages/core/lib/src/order.dart

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'package:ribs_core/src/function.dart';
1+
import 'package:ribs_core/ribs_core.dart';
22

33
/// Defines a total ordering for elements of type `A`.
44
///
@@ -12,6 +12,9 @@ abstract class Order<A> {
1212
static Order<A> fromComparable<A extends Comparable<dynamic>>() =>
1313
Order.from((A a, A b) => a.compareTo(b));
1414

15+
static Order<A> fromOrdered<A extends Ordered<dynamic>>() =>
16+
Order.from((A a, A b) => a.compareTo(b));
17+
1518
/// Creates a new [Order] that compares 2 elements using [f].
1619
factory Order.from(Function2<A, A, int> f) => _OrderF(f);
1720

packages/core/lib/src/ordered.dart

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
abstract class Ordered<A> implements Comparable<A> {
2+
const Ordered();
3+
4+
@override
5+
int compareTo(A other);
6+
7+
bool operator <(A that) => compareTo(that) < 0;
8+
9+
bool operator <=(A that) => compareTo(that) <= 0;
10+
11+
bool operator >(A that) => compareTo(that) > 0;
12+
13+
bool operator >=(A that) => compareTo(that) >= 0;
14+
}

0 commit comments

Comments
 (0)