aboutsummaryrefslogtreecommitdiff
path: root/src/std/order.gleam
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2019-05-29 21:02:55 +0100
committerLouis Pilfold <louis@lpil.uk>2019-06-02 21:12:59 +0100
commit5a1f3494eb9517a7b7a332cb74dd10a6a7d32d31 (patch)
tree5d0d281c66cf71c6e3ca880e6621138a71b95e7b /src/std/order.gleam
parentee03f5a0465e176e220060164a5ffc408f73ed0d (diff)
downloadgleam_stdlib-5a1f3494eb9517a7b7a332cb74dd10a6a7d32d31.tar.gz
gleam_stdlib-5a1f3494eb9517a7b7a332cb74dd10a6a7d32d31.zip
Enable namespaced modules
Diffstat (limited to 'src/std/order.gleam')
-rw-r--r--src/std/order.gleam48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/std/order.gleam b/src/std/order.gleam
new file mode 100644
index 0000000..4d39705
--- /dev/null
+++ b/src/std/order.gleam
@@ -0,0 +1,48 @@
+pub enum Order =
+ | Lt
+ | Eq
+ | Gt
+;
+
+pub fn reverse(order) {
+ case order {
+ | Lt -> Gt
+ | Eq -> Eq
+ | Gt -> Lt
+ }
+}
+
+pub fn to_int(order) {
+ case order {
+ | Lt -> -1
+ | Eq -> 0
+ | Gt -> 1
+ }
+}
+
+pub fn compare(a, b) {
+ case {a, b} {
+ | {Lt, Lt} -> Eq
+ | {Lt, _} -> Lt
+ | {Eq, Eq} -> Eq
+ | {Gt, Gt} -> Eq
+ | {Eq, Gt} -> Lt
+ | _ -> Gt
+ }
+}
+
+pub fn max(a, b) {
+ case {a, b} {
+ | {Gt, _} -> Gt
+ | {Eq, Lt} -> Eq
+ | _ -> b
+ }
+}
+
+pub fn min(a, b) {
+ case {a, b} {
+ | {Lt, _} -> Lt
+ | {Eq, Gt} -> Eq
+ | _ -> b
+ }
+}