Skip to content

Commit 90d7d47

Browse files
committed
Add Null.equal, Null.compare
1 parent 184323c commit 90d7d47

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

src/Core__Null.mjs

+11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import * as Curry from "rescript/lib/es6/curry.js";
44
import * as Caml_option from "rescript/lib/es6/caml_option.js";
5+
import * as Core__Option from "./Core__Option.mjs";
56

67
function fromOption(option) {
78
if (option !== undefined) {
@@ -11,6 +12,14 @@ function fromOption(option) {
1112
}
1213
}
1314

15+
function equal(a, b, eq) {
16+
return Core__Option.equal(a === null ? undefined : Caml_option.some(a), b === null ? undefined : Caml_option.some(b), eq);
17+
}
18+
19+
function compare(a, b, cmp) {
20+
return Core__Option.compare(a === null ? undefined : Caml_option.some(a), b === null ? undefined : Caml_option.some(b), cmp);
21+
}
22+
1423
function getWithDefault(value, $$default) {
1524
if (value !== null) {
1625
return value;
@@ -55,6 +64,8 @@ function flatMap(value, f) {
5564
}
5665

5766
export {
67+
equal ,
68+
compare ,
5869
fromOption ,
5970
getWithDefault ,
6071
getExn ,

src/Core__Null.res

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ let fromOption: option<'a> => t<'a> = option =>
1414
| None => null
1515
}
1616

17+
let equal = (a, b, eq) => Core__Option.equal(a->toOption, b->toOption, eq)
18+
19+
let compare = (a, b, cmp) => Core__Option.compare(a->toOption, b->toOption, cmp)
20+
1721
let getWithDefault = (value, default) =>
1822
switch value->toOption {
1923
| Some(x) => x

src/Core__Null.resi

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ let asNullValue = myStr->Null.make // The compiler now thinks this can be `strin
4444
*/
4545
external make: 'a => t<'a> = "%identity"
4646

47+
let equal: (t<'a>, t<'b>, ('a, 'b) => bool) => bool
48+
49+
let compare: (t<'a>, t<'b>, ('a, 'b) => int) => int
50+
4751
/**
4852
Converts a nullable value into an option, so it can be pattern matched on.
4953
Will convert `null` to `None`, and a present value to `Some(value)`.

0 commit comments

Comments
 (0)