Skip to content

Commit 184323c

Browse files
committed
Simplify Option.equal, Option.compare
1 parent c3df5aa commit 184323c

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

src/Core__Option.mjs

+4-6
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,10 @@ function isNone(x) {
7878
return x === undefined;
7979
}
8080

81-
function equal(a, b, f) {
82-
var f$1 = Curry.__2(f);
81+
function equal(a, b, eq) {
8382
if (a !== undefined) {
8483
if (b !== undefined) {
85-
return f$1(Caml_option.valFromOption(a), Caml_option.valFromOption(b));
84+
return Curry._2(eq, Caml_option.valFromOption(a), Caml_option.valFromOption(b));
8685
} else {
8786
return false;
8887
}
@@ -91,11 +90,10 @@ function equal(a, b, f) {
9190
}
9291
}
9392

94-
function compare(a, b, f) {
95-
var f$1 = Curry.__2(f);
93+
function compare(a, b, cmp) {
9694
if (a !== undefined) {
9795
if (b !== undefined) {
98-
return f$1(Caml_option.valFromOption(a), Caml_option.valFromOption(b));
96+
return Curry._2(cmp, Caml_option.valFromOption(a), Caml_option.valFromOption(b));
9997
} else {
10098
return 1;
10199
}

src/Core__Option.res

+7-14
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,17 @@ let isSome = x =>
9090

9191
let isNone = x => x == None
9292

93-
let equalU = (a, b, f) =>
94-
switch a {
95-
| Some(a) =>
96-
switch b {
97-
| None => false
98-
| Some(b) => f(. a, b)
99-
}
100-
| None => b == None
93+
let equal = (a, b, eq) =>
94+
switch (a, b) {
95+
| (Some(a), Some(b)) => eq(a, b)
96+
| (None, None) => true
97+
| (None, Some(_)) | (Some(_), None) => false
10198
}
10299

103-
let equal = (a, b, f) => equalU(a, b, (. x, y) => f(x, y))
104-
105-
let compareU = (a, b, f) =>
100+
let compare = (a, b, cmp) =>
106101
switch (a, b) {
107-
| (Some(a), Some(b)) => f(. a, b)
102+
| (Some(a), Some(b)) => cmp(a, b)
108103
| (None, Some(_)) => -1
109104
| (Some(_), None) => 1
110105
| (None, None) => 0
111106
}
112-
113-
let compare = (a, b, f) => compareU(a, b, (. x, y) => f(x, y))

0 commit comments

Comments
 (0)