Skip to content

Commit a472010

Browse files
committed
Add Nullable.equal, Nullable.compare
1 parent 90d7d47 commit a472010

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

src/Core__Nullable.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) {
@@ -10,6 +11,14 @@ function fromOption(option) {
1011

1112
}
1213

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

5665
export {
66+
equal ,
67+
compare ,
5768
fromOption ,
5869
getWithDefault ,
5970
getExn ,

src/Core__Nullable.res

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ let fromOption: option<'a> => t<'a> = option =>
1414
| None => undefined
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__Nullable.resi

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ switch asNullable->Nullable.toOption {
5555
*/
5656
external make: 'a => t<'a> = "%identity"
5757

58+
let equal: (t<'a>, t<'b>, ('a, 'b) => bool) => bool
59+
60+
let compare: (t<'a>, t<'b>, ('a, 'b) => int) => int
61+
5862
/**
5963
Converts a nullable value into an option, so it can be pattern matched on.
6064
Will convert both `null` and `undefined` to `None`, and a present value to `Some(value)`.

0 commit comments

Comments
 (0)