Skip to content

Commit

Permalink
impl Ordering: Compare
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasWanke committed Dec 12, 2024
1 parent 0b7a1a4 commit 3334a92
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages_v5/example.candy
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,27 @@ fun isAtLeast[T: Compare](left: T, right: T) Bool {
}
}
enum Ordering { less, equal, greater }
impl Ordering: Compare {
fun compareTo(self: Ordering, other: Ordering) Ordering {
switch self {
less => switch other {
less => Ordering.equal(),
equal => Ordering.less(),
greater => Ordering.less(),
},
equal => switch other {
less => Ordering.greater(),
equal => Ordering.equal(),
greater => Ordering.less(),
},
greater => switch other {
less => Ordering.greater(),
equal => Ordering.greater(),
greater => Ordering.equal(),
},
}
}
}
impl Ordering: ToText {
fun toText(self: Ordering) Text {
switch self {
Expand Down

0 comments on commit 3334a92

Please sign in to comment.