From 3334a9220898091a7a292777fc877cbbde27fdda Mon Sep 17 00:00:00 2001 From: Jonas Wanke Date: Thu, 12 Dec 2024 11:53:06 +0100 Subject: [PATCH] impl Ordering: Compare --- packages_v5/example.candy | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/packages_v5/example.candy b/packages_v5/example.candy index 36d88c949..27be9e7cd 100644 --- a/packages_v5/example.candy +++ b/packages_v5/example.candy @@ -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 {