From 3170ad704ab0bdd07c1cc86fbb7188d50372c8e1 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Thu, 2 Mar 2023 20:28:16 +0100 Subject: [PATCH 01/12] eq -> equal, cmp -> compare --- src/Core__List.mjs | 12 ++++++------ src/Core__List.res | 16 ++++++++-------- src/Core__List.resi | 36 ++++++++++++++++++------------------ src/Core__Option.mjs | 8 ++++---- src/Core__Option.res | 8 ++++---- src/Core__Option.resi | 28 ++++++++++++++-------------- src/Core__Result.mjs | 8 ++++---- src/Core__Result.res | 8 ++++---- src/Core__Result.resi | 26 +++++++++++++------------- 9 files changed, 75 insertions(+), 75 deletions(-) diff --git a/src/Core__List.mjs b/src/Core__List.mjs index 88b2cc9d..74afbabf 100644 --- a/src/Core__List.mjs +++ b/src/Core__List.mjs @@ -969,7 +969,7 @@ function every2(l1, l2, p) { }; } -function cmpByLength(_l1, _l2) { +function compareLength(_l1, _l2) { while(true) { var l2 = _l2; var l1 = _l1; @@ -989,7 +989,7 @@ function cmpByLength(_l1, _l2) { }; } -function cmp(l1, l2, f) { +function compare(l1, l2, f) { var _l1 = l1; var _l2 = l2; var p = Curry.__2(f); @@ -1016,7 +1016,7 @@ function cmp(l1, l2, f) { }; } -function eq(l1, l2, f) { +function equal(l1, l2, f) { var _l1 = l1; var _l2 = l2; var p = Curry.__2(f); @@ -1386,9 +1386,9 @@ export { some , every2 , some2 , - cmpByLength , - cmp , - eq , + compareLength , + compare , + equal , has , getBy , filter , diff --git a/src/Core__List.res b/src/Core__List.res index 5506f64b..d82347ae 100644 --- a/src/Core__List.res +++ b/src/Core__List.res @@ -680,15 +680,15 @@ let rec every2U = (l1, l2, p) => let every2 = (l1, l2, p) => every2U(l1, l2, (. a, b) => p(a, b)) -let rec cmpByLength = (l1, l2) => +let rec compareLength = (l1, l2) => switch (l1, l2) { | (list{}, list{}) => 0 | (_, list{}) => 1 | (list{}, _) => -1 - | (list{_, ...l1s}, list{_, ...l2s}) => cmpByLength(l1s, l2s) + | (list{_, ...l1s}, list{_, ...l2s}) => compareLength(l1s, l2s) } -let rec cmpU = (l1, l2, p) => +let rec compareU = (l1, l2, p) => switch (l1, l2) { | (list{}, list{}) => 0 | (_, list{}) => 1 @@ -696,27 +696,27 @@ let rec cmpU = (l1, l2, p) => | (list{a1, ...l1}, list{a2, ...l2}) => let c = p(. a1, a2) if c == 0 { - cmpU(l1, l2, p) + compareU(l1, l2, p) } else { c } } -let cmp = (l1, l2, f) => cmpU(l1, l2, (. x, y) => f(x, y)) +let compare = (l1, l2, f) => compareU(l1, l2, (. x, y) => f(x, y)) -let rec eqU = (l1, l2, p) => +let rec equalU = (l1, l2, p) => switch (l1, l2) { | (list{}, list{}) => true | (_, list{}) | (list{}, _) => false | (list{a1, ...l1}, list{a2, ...l2}) => if p(. a1, a2) { - eqU(l1, l2, p) + equalU(l1, l2, p) } else { false } } -let eq = (l1, l2, f) => eqU(l1, l2, (. x, y) => f(x, y)) +let equal = (l1, l2, f) => equalU(l1, l2, (. x, y) => f(x, y)) let rec some2U = (l1, l2, p) => switch (l1, l2) { diff --git a/src/Core__List.resi b/src/Core__List.resi index 5c3a1718..d12659ed 100644 --- a/src/Core__List.resi +++ b/src/Core__List.resi @@ -615,24 +615,24 @@ List.some2(list{0, 1}, list{5, 0}, (a, b) => a > b) // true let some2: (t<'a>, t<'b>, ('a, 'b) => bool) => bool /** -`cmpByLength(list1, list2)` compare two lists solely by length. Returns `-1` if +`compareLength(list1, list2)` compare two lists solely by length. Returns `-1` if `length(list1)` is less than `length(list2)`, `0` if `length(list1)` equals `length(list2)`, and `1` if `length(list1)` is greater than `length(list2)`. ## Examples ```rescript -List.cmpByLength(list{1, 2}, list{3, 4, 5, 6}) // -1 +List.compareLength(list{1, 2}, list{3, 4, 5, 6}) // -1 -List.cmpByLength(list{1, 2, 3}, list{4, 5, 6}) // 0 +List.compareLength(list{1, 2, 3}, list{4, 5, 6}) // 0 -List.cmpByLength(list{1, 2, 3, 4}, list{5, 6}) // 1 +List.compareLength(list{1, 2, 3, 4}, list{5, 6}) // 1 ``` */ -let cmpByLength: (t<'a>, t<'a>) => int +let compareLength: (t<'a>, t<'a>) => int /** -`cmp(list1, list2, f)` compare elements one by one `f`. `f` returns a negative +`compare(list1, list2, f)` compare elements one by one `f`. `f` returns a negative number if `list1` is "less than" `list2`, zero if `list1` is "equal to" `list2`, a positive number if `list1` is "greater than" `list2`. @@ -645,40 +645,40 @@ zero for all `list1` and `list2`. ## Examples ```rescript -List.cmp(list{3}, list{3, 7}, (a, b) => compare(a, b)) /* (-1) */ +List.compare(list{3}, list{3, 7}, (a, b) => compare(a, b)) /* (-1) */ -List.cmp(list{5, 3}, list{5}, (a, b) => compare(a, b)) /* 1 */ +List.compare(list{5, 3}, list{5}, (a, b) => compare(a, b)) /* 1 */ -List.cmp(list{1, 3, 5}, list{1, 4, 2}, (a, b) => compare(a, b)) /* (-1) */ +List.compare(list{1, 3, 5}, list{1, 4, 2}, (a, b) => compare(a, b)) /* (-1) */ -List.cmp(list{1, 3, 5}, list{1, 2, 3}, (a, b) => compare(a, b)) /* 1 */ +List.compare(list{1, 3, 5}, list{1, 2, 3}, (a, b) => compare(a, b)) /* 1 */ -List.cmp(list{1, 3, 5}, list{1, 3, 5}, (a, b) => compare(a, b)) /* 0 */ +List.compare(list{1, 3, 5}, list{1, 3, 5}, (a, b) => compare(a, b)) /* 0 */ ``` **Please note:** The total ordering of List is different from Array, for Array, we compare the length first and, only if the lengths are equal, elements one by one. For lists, we just compare elements one by one. */ -let cmp: (t<'a>, t<'a>, ('a, 'a) => int) => int +let compare: (t<'a>, t<'a>, ('a, 'a) => int) => int /** -`eq(list1, list2, f)` check equality of `list2` and `list2` using `f` for +`equal(list1, list2, f)` check equality of `list2` and `list2` using `f` for equality on elements, where `f` is a function that returns `true` if items `x` and -`y` meet some criterion for equality, `false` otherwise. eq `false` if length +`y` meet some criterion for equality, `false` otherwise. equal `false` if length of `list1` and `list2` are not the same. ## Examples ```rescript -List.eq(list{1, 2, 3}, list{1, 2}, (a, b) => a == b) // false +List.equal(list{1, 2, 3}, list{1, 2}, (a, b) => a == b) // false -List.eq(list{1, 2}, list{1, 2}, (a, b) => a == b) // true +List.equal(list{1, 2}, list{1, 2}, (a, b) => a == b) // true -List.eq(list{1, 2, 3}, list{(-1), (-2), (-3)}, (a, b) => abs(a) == abs(b)) // true +List.equal(list{1, 2, 3}, list{(-1), (-2), (-3)}, (a, b) => abs(a) == abs(b)) // true ``` */ -let eq: (t<'a>, t<'a>, ('a, 'a) => bool) => bool +let equal: (t<'a>, t<'a>, ('a, 'a) => bool) => bool /** `has(list, element, f)` returns `true` if the list contains at least one diff --git a/src/Core__Option.mjs b/src/Core__Option.mjs index 29ad429b..eae7113b 100644 --- a/src/Core__Option.mjs +++ b/src/Core__Option.mjs @@ -78,7 +78,7 @@ function isNone(x) { return x === undefined; } -function eq(a, b, f) { +function equal(a, b, f) { var f$1 = Curry.__2(f); if (a !== undefined) { if (b !== undefined) { @@ -91,7 +91,7 @@ function eq(a, b, f) { } } -function cmp(a, b, f) { +function compare(a, b, f) { var f$1 = Curry.__2(f); if (a !== undefined) { if (b !== undefined) { @@ -117,7 +117,7 @@ export { orElse , isSome , isNone , - eq , - cmp , + equal , + compare , } /* No side effect */ diff --git a/src/Core__Option.res b/src/Core__Option.res index 9b688647..998d421f 100644 --- a/src/Core__Option.res +++ b/src/Core__Option.res @@ -90,7 +90,7 @@ let isSome = x => let isNone = x => x == None -let eqU = (a, b, f) => +let equalU = (a, b, f) => switch a { | Some(a) => switch b { @@ -100,9 +100,9 @@ let eqU = (a, b, f) => | None => b == None } -let eq = (a, b, f) => eqU(a, b, (. x, y) => f(x, y)) +let equal = (a, b, f) => equalU(a, b, (. x, y) => f(x, y)) -let cmpU = (a, b, f) => +let compareU = (a, b, f) => switch (a, b) { | (Some(a), Some(b)) => f(. a, b) | (None, Some(_)) => -1 @@ -110,4 +110,4 @@ let cmpU = (a, b, f) => | (None, None) => 0 } -let cmp = (a, b, f) => cmpU(a, b, (. x, y) => f(x, y)) +let compare = (a, b, f) => compareU(a, b, (. x, y) => f(x, y)) diff --git a/src/Core__Option.resi b/src/Core__Option.resi index fbcf89c1..28cabcfd 100644 --- a/src/Core__Option.resi +++ b/src/Core__Option.resi @@ -198,7 +198,7 @@ Option.isNone(Some(1)) // false let isNone: option<'a> => bool /** -`eq(opt1, opt2, f)` evaluates two optional values for equality with respect to a predicate function `f`. If both `opt1` and `opt2` are `None`, returns `true`. +`equal(opt1, opt2, f)` evaluates two optional values for equality with respect to a predicate function `f`. If both `opt1` and `opt2` are `None`, returns `true`. If one of the arguments is `Some(value)` and the other is `None`, returns `false`. If arguments are `Some(value1)` and `Some(value2)`, returns the result of @@ -211,16 +211,16 @@ let clockEqual = (a, b) => mod(a, 12) == mod(b, 12) open Option -eq(Some(3), Some(15), clockEqual) // true -eq(Some(3), None, clockEqual) // false -eq(None, Some(3), clockEqual) // false -eq(None, None, clockEqual) // true +equal(Some(3), Some(15), clockEqual) // true +equal(Some(3), None, clockEqual) // false +equal(None, Some(3), clockEqual) // false +equal(None, None, clockEqual) // true ``` */ -let eq: (option<'a>, option<'b>, ('a, 'b) => bool) => bool +let equal: (option<'a>, option<'b>, ('a, 'b) => bool) => bool /** -`cmp(opt1, opt2, f)` compares two optional values with respect to given `f`. +`compare(opt1, opt2, f)` compares two optional values with respect to given `f`. If both `opt1` and `opt2` are `None`, it returns `0`. If the first argument is `Some(value1)` and the second is `None`, returns `1` (something is greater than nothing). @@ -239,12 +239,12 @@ let clockCompare = (a, b) => compare(mod(a, 12), mod(b, 12)) open Option -cmp(Some(3), Some(15), clockCompare) // 0 -cmp(Some(3), Some(14), clockCompare) // 1 -cmp(Some(2), Some(15), clockCompare) // (-1) -cmp(None, Some(15), clockCompare) // (-1) -cmp(Some(14), None, clockCompare) // 1 -cmp(None, None, clockCompare) // 0 +compare(Some(3), Some(15), clockCompare) // 0 +compare(Some(3), Some(14), clockCompare) // 1 +compare(Some(2), Some(15), clockCompare) // (-1) +compare(None, Some(15), clockCompare) // (-1) +compare(Some(14), None, clockCompare) // 1 +compare(None, None, clockCompare) // 0 ``` */ -let cmp: (option<'a>, option<'b>, ('a, 'b) => int) => int +let compare: (option<'a>, option<'b>, ('a, 'b) => int) => int diff --git a/src/Core__Result.mjs b/src/Core__Result.mjs index fd9e5ffb..f0fcfbc4 100644 --- a/src/Core__Result.mjs +++ b/src/Core__Result.mjs @@ -72,7 +72,7 @@ function isError(x) { } } -function eq(a, b, f) { +function equal(a, b, f) { var f$1 = Curry.__2(f); if (a.TAG === /* Ok */0) { if (b.TAG === /* Ok */0) { @@ -87,7 +87,7 @@ function eq(a, b, f) { } } -function cmp(a, b, f) { +function compare(a, b, f) { var f$1 = Curry.__2(f); if (a.TAG === /* Ok */0) { if (b.TAG === /* Ok */0) { @@ -117,8 +117,8 @@ export { getWithDefault , isOk , isError , - eq , - cmp , + equal , + compare , forEach , } /* No side effect */ diff --git a/src/Core__Result.res b/src/Core__Result.res index 423ae5a1..d629cff5 100644 --- a/src/Core__Result.res +++ b/src/Core__Result.res @@ -72,7 +72,7 @@ let isError = x => | Error(_) => true } -let eqU = (a, b, f) => +let equalU = (a, b, f) => switch (a, b) { | (Ok(a), Ok(b)) => f(. a, b) | (Error(_), Ok(_)) @@ -80,9 +80,9 @@ let eqU = (a, b, f) => | (Error(_), Error(_)) => true } -let eq = (a, b, f) => eqU(a, b, (. x, y) => f(x, y)) +let equal = (a, b, f) => equalU(a, b, (. x, y) => f(x, y)) -let cmpU = (a, b, f) => +let compareU = (a, b, f) => switch (a, b) { | (Ok(a), Ok(b)) => f(. a, b) | (Error(_), Ok(_)) => -1 @@ -90,7 +90,7 @@ let cmpU = (a, b, f) => | (Error(_), Error(_)) => 0 } -let cmp = (a, b, f) => cmpU(a, b, (. x, y) => f(x, y)) +let compare = (a, b, f) => compareU(a, b, (. x, y) => f(x, y)) let forEach = (r, f) => switch r { diff --git a/src/Core__Result.resi b/src/Core__Result.resi index 3f03b7bd..0a6bc37c 100644 --- a/src/Core__Result.resi +++ b/src/Core__Result.resi @@ -134,7 +134,7 @@ let isOk: t<'a, 'b> => bool let isError: t<'a, 'b> => bool /** - `eq(res1, res2, f)`: Determine if two `Result` variables are equal with + `equal(res1, res2, f)`: Determine if two `Result` variables are equal with respect to an equality function. If `res1` and `res2` are of the form `Ok(n)` and `Ok(m)`, return the result of `f(n, m)`. If one of `res1` and `res2` are of the form `Error(e)`, return false If both `res1` and `res2` are of the form @@ -151,19 +151,19 @@ let isError: t<'a, 'b> => bool let mod10equal = (a, b) => mod(a, 10) === mod(b, 10) - Result.eq(good1, good2, mod10equal) == true + Result.equal(good1, good2, mod10equal) == true - Result.eq(good1, bad1, mod10equal) == false + Result.equal(good1, bad1, mod10equal) == false - Result.eq(bad2, good2, mod10equal) == false + Result.equal(bad2, good2, mod10equal) == false - Result.eq(bad1, bad2, mod10equal) == true + Result.equal(bad1, bad2, mod10equal) == true ``` */ -let eq: (t<'a, 'c>, t<'b, 'd>, ('a, 'b) => bool) => bool +let equal: (t<'a, 'c>, t<'b, 'd>, ('a, 'b) => bool) => bool /** - `cmp(res1, res2, f)`: Compare two `Result` variables with respect to a + `compare(res1, res2, f)`: Compare two `Result` variables with respect to a comparison function. The comparison function returns -1 if the first variable is "less than" the second, 0 if the two variables are equal, and 1 if the first is "greater than" the second. @@ -185,18 +185,18 @@ let eq: (t<'a, 'c>, t<'b, 'd>, ('a, 'b) => bool) => bool let mod10cmp = (a, b) => Pervasives.compare(mod(a, 10), mod(b, 10)) - Result.cmp(Ok(39), Ok(57), mod10cmp) == 1 + Result.compare(Ok(39), Ok(57), mod10cmp) == 1 - Result.cmp(Ok(57), Ok(39), mod10cmp) == (-1) + Result.compare(Ok(57), Ok(39), mod10cmp) == (-1) - Result.cmp(Ok(39), Error("y"), mod10cmp) == 1 + Result.compare(Ok(39), Error("y"), mod10cmp) == 1 - Result.cmp(Error("x"), Ok(57), mod10cmp) == (-1) + Result.compare(Error("x"), Ok(57), mod10cmp) == (-1) - Result.cmp(Error("x"), Error("y"), mod10cmp) == 0 + Result.compare(Error("x"), Error("y"), mod10cmp) == 0 ``` */ -let cmp: (t<'a, 'c>, t<'b, 'd>, ('a, 'b) => int) => int +let compare: (t<'a, 'c>, t<'b, 'd>, ('a, 'b) => int) => int /** `forEach(res, f)` runs the provided function `f` on the `Ok` value. If `res` is `Error`, nothing happens. From 0a52e1cac7151e68d068dc35ea2ad402cd586876 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Thu, 2 Mar 2023 20:36:14 +0100 Subject: [PATCH 02/12] Fix typo --- src/Core__String.resi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core__String.resi b/src/Core__String.resi index 56486294..52158cf4 100644 --- a/src/Core__String.resi +++ b/src/Core__String.resi @@ -961,7 +961,7 @@ external padEnd: (string, int, string) => string = "padEnd" /** `localeCompare(referenceStr, compareStr)` returns a float than indicatings -whether a reference string comes before or fater, or is the same as the given +whether a reference string comes before or after, or is the same as the given string in sort order. If `referenceStr` occurs before `compareStr` positive if the `referenceStr` occurs after `compareStr`, `0` if they are equivalent. Do not rely on exact return values of `-1` or `1` From b534e28241a8f1a0f44ac232d5ae4b0f942d7190 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Thu, 2 Mar 2023 20:36:37 +0100 Subject: [PATCH 03/12] Add String.equal, String.compare --- src/Core__String.mjs | 16 ++++++++++++++++ src/Core__String.res | 11 +++++++++++ src/Core__String.resi | 4 ++++ 3 files changed, 31 insertions(+) diff --git a/src/Core__String.mjs b/src/Core__String.mjs index 1b8a0b9f..fb79fae4 100644 --- a/src/Core__String.mjs +++ b/src/Core__String.mjs @@ -1,6 +1,20 @@ // Generated by ReScript, PLEASE EDIT WITH CARE +function equal(a, b) { + return a === b; +} + +function compare(a, b) { + if (a === b) { + return 0; + } else if (a > b) { + return 1; + } else { + return -1; + } +} + function indexOfOpt(s, search) { var index = s.indexOf(search); if (index !== -1) { @@ -26,6 +40,8 @@ function searchOpt(s, re) { } export { + equal , + compare , indexOfOpt , lastIndexOfOpt , searchOpt , diff --git a/src/Core__String.res b/src/Core__String.res index dac72645..dee4498a 100644 --- a/src/Core__String.res +++ b/src/Core__String.res @@ -6,6 +6,17 @@ @val external fromCodePoint: int => string = "String.fromCodePoint" @variadic @val external fromCodePointMany: array => string = "String.fromCodePoint" +let equal = (a: string, b: string) => a === b + +let compare = (a: string, b: string) => + if a === b { + 0 + } else if a > b { + 1 + } else { + -1 + } + @get external length: string => int = "length" @get_index external get: (string, int) => option = "" @send external charAt: (string, int) => string = "charAt" diff --git a/src/Core__String.resi b/src/Core__String.resi index 52158cf4..cb0a5593 100644 --- a/src/Core__String.resi +++ b/src/Core__String.resi @@ -118,6 +118,10 @@ String.fromCodePointMany([0xd55c, 0xae00, 0x1f63a]) == `한글😺` @val external fromCodePointMany: array => string = "String.fromCodePoint" +let equal: (string, string) => bool + +let compare: (string, string) => int + /** `length(str)` returns the length of the given `string`. See [`String.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length) on MDN. From 50ea8d5845d6de71d9a56712b46379a9e871ef9f Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Thu, 2 Mar 2023 20:39:30 +0100 Subject: [PATCH 04/12] Add Int.equal, Int.compare --- src/Core__Int.mjs | 10 ++++++++++ src/Core__Int.res | 4 ++++ src/Core__Int.resi | 4 ++++ 3 files changed, 18 insertions(+) diff --git a/src/Core__Int.mjs b/src/Core__Int.mjs index 1ad4aea3..a701942e 100644 --- a/src/Core__Int.mjs +++ b/src/Core__Int.mjs @@ -3,6 +3,14 @@ import * as Pervasives from "rescript/lib/es6/pervasives.js"; import * as Core__Array from "./Core__Array.mjs"; +function equal(a, b) { + return a === b; +} + +function compare(a, b) { + return a - b | 0; +} + function fromString(radix, x) { var maybeInt = radix !== undefined ? parseInt(x, radix) : parseInt(x); if (isNaN(maybeInt) || maybeInt > 2147483647 || maybeInt < -2147483648) { @@ -54,6 +62,8 @@ var Constants = { export { Constants , + equal , + compare , fromString , range , rangeWithOptions , diff --git a/src/Core__Int.res b/src/Core__Int.res index a4f0e42e..1fb3943a 100644 --- a/src/Core__Int.res +++ b/src/Core__Int.res @@ -3,6 +3,10 @@ module Constants = { @inline let maxValue = 2147483647 } +let equal = (a: int, b: int) => a === b + +let compare = (a, b) => a - b + @send external toExponential: int => string = "toExponential" @send external toExponentialWithPrecision: (int, ~digits: int) => string = "toExponential" diff --git a/src/Core__Int.resi b/src/Core__Int.resi index d1a8bcfb..e34dc9ac 100644 --- a/src/Core__Int.resi +++ b/src/Core__Int.resi @@ -56,6 +56,10 @@ module Constants: { let maxValue: int } +let equal: (int, int) => bool + +let compare: (int, int) => int + /** `toExponential(n)` return a `string` representing the given value in exponential notation. From 4bb5902f13090e37b47868ddaa6b32b201597a26 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Thu, 2 Mar 2023 20:42:09 +0100 Subject: [PATCH 05/12] Add Float.equal, Float.compare --- src/Core__Float.mjs | 16 ++++++++++++++++ src/Core__Float.res | 11 +++++++++++ src/Core__Float.resi | 4 ++++ 3 files changed, 31 insertions(+) diff --git a/src/Core__Float.mjs b/src/Core__Float.mjs index 2d9f7f0b..eb76ff31 100644 --- a/src/Core__Float.mjs +++ b/src/Core__Float.mjs @@ -3,6 +3,20 @@ var Constants = {}; +function equal(a, b) { + return a === b; +} + +function compare(a, b) { + if (a === b) { + return 0; + } else if (a > b) { + return 1; + } else { + return -1; + } +} + function fromString(i) { var i$1 = parseFloat(i); if (isNaN(i$1)) { @@ -14,6 +28,8 @@ function fromString(i) { export { Constants , + equal , + compare , fromString , } /* No side effect */ diff --git a/src/Core__Float.res b/src/Core__Float.res index 8781324d..81d30b1f 100644 --- a/src/Core__Float.res +++ b/src/Core__Float.res @@ -7,6 +7,17 @@ module Constants = { @val external maxValue: float = "Number.MAX_VALUE" } +let equal = (a: float, b: float) => a === b + +let compare = (a: float, b: float) => + if a === b { + 0 + } else if a > b { + 1 + } else { + -1 + } + @val external isNaN: float => bool = "isNaN" @val external isFinite: float => bool = "isFinite" @val external parseFloat: 'a => float = "parseFloat" diff --git a/src/Core__Float.resi b/src/Core__Float.resi index cb3e835b..5109f8f0 100644 --- a/src/Core__Float.resi +++ b/src/Core__Float.resi @@ -109,6 +109,10 @@ module Constants: { external maxValue: float = "Number.MAX_VALUE" } +let equal: (float, float) => bool + +let compare: (float, float) => int + /** `isNaN(v)` tests if the given `v` is `NaN`. See [`NaN`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN) on MDN. From f35ba39b8fa5c3d180cab604f419c17f3e7a45b1 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Thu, 2 Mar 2023 20:45:12 +0100 Subject: [PATCH 06/12] Add Date.equal, Date.compare --- src/Core__Date.mjs | 11 +++++++++++ src/Core__Date.res | 4 ++++ src/Core__Date.resi | 4 ++++ 3 files changed, 19 insertions(+) diff --git a/src/Core__Date.mjs b/src/Core__Date.mjs index f73ca00a..bb84ed38 100644 --- a/src/Core__Date.mjs +++ b/src/Core__Date.mjs @@ -1,9 +1,20 @@ // Generated by ReScript, PLEASE EDIT WITH CARE +import * as Core__Float from "./Core__Float.mjs"; var UTC = {}; +function equal(a, b) { + return a.getTime() === b.getTime(); +} + +function compare(a, b) { + return Core__Float.compare(a.getTime(), b.getTime()); +} + export { UTC , + equal , + compare , } /* No side effect */ diff --git a/src/Core__Date.res b/src/Core__Date.res index 02f639b9..f3b98fdf 100644 --- a/src/Core__Date.res +++ b/src/Core__Date.res @@ -86,6 +86,10 @@ module UTC = { @send external getTime: t => msSinceEpoch = "getTime" @send external getTimezoneOffset: t => int = "getTimezoneOffset" +let equal = (a, b) => a->getTime === b->getTime + +let compare = (a, b) => Core__Float.compare(a->getTime, b->getTime) + // Locale @send external getFullYear: t => int = "getFullYear" @send external getMonth: t => int = "getMonth" diff --git a/src/Core__Date.resi b/src/Core__Date.resi index b97a16f2..38145e6e 100644 --- a/src/Core__Date.resi +++ b/src/Core__Date.resi @@ -432,6 +432,10 @@ Returns the time, in milliseconds, between UNIX epoch (January 1, 1970 00:00:00 @val external now: unit => msSinceEpoch = "Date.now" +let equal: (t, t) => bool + +let compare: (t, t) => int + /** `getTime(date)` From 92c42aca5bfacf5eac5194b7a56312d7c76218a8 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Thu, 2 Mar 2023 20:59:58 +0100 Subject: [PATCH 07/12] Add Array.equal, Array.compare --- src/Core__Array.mjs | 48 ++++++++++++++++++++++++++++++++++++++++++++ src/Core__Array.res | 46 ++++++++++++++++++++++++++++++++++++++++++ src/Core__Array.resi | 4 ++++ 3 files changed, 98 insertions(+) diff --git a/src/Core__Array.mjs b/src/Core__Array.mjs index 74183c35..99cea411 100644 --- a/src/Core__Array.mjs +++ b/src/Core__Array.mjs @@ -24,6 +24,52 @@ function fromInitializer(length, f) { return arr; } +function equal(a, b, eq) { + var eq$1 = Curry.__2(eq); + var len = a.length; + if (len === b.length) { + var _i = 0; + while(true) { + var i = _i; + if (i === len) { + return true; + } + if (!eq$1(a[i], b[i])) { + return false; + } + _i = i + 1 | 0; + continue ; + }; + } else { + return false; + } +} + +function compare(a, b, cmp) { + var cmp$1 = Curry.__2(cmp); + var lenA = a.length; + var lenB = b.length; + if (lenA > lenB) { + return 1; + } else if (lenA < lenB) { + return -1; + } else { + var _i = 0; + while(true) { + var i = _i; + if (i === lenA) { + return 0; + } + var c = cmp$1(a[i], b[i]); + if (c !== 0) { + return c; + } + _i = i + 1 | 0; + continue ; + }; + } +} + function indexOfOpt(arr, item) { var index = arr.indexOf(item); if (index !== -1) { @@ -126,6 +172,8 @@ function findMap(arr, f) { export { make , fromInitializer , + equal , + compare , indexOfOpt , lastIndexOfOpt , reduce , diff --git a/src/Core__Array.res b/src/Core__Array.res index e0d6cd5a..ec05df53 100644 --- a/src/Core__Array.res +++ b/src/Core__Array.res @@ -37,6 +37,52 @@ let fromInitializer = (~length, f) => @get external length: array<'a> => int = "length" +let rec equalFromIndexU = (a, b, i, eq, len) => + if i === len { + true + } else if eq(. a->getUnsafe(i), b->getUnsafe(i)) { + equalFromIndexU(a, b, i + 1, eq, len) + } else { + false + } + +let equalU = (a, b, eq) => { + let len = a->length + if len === b->length { + equalFromIndexU(a, b, 0, eq, len) + } else { + false + } +} + +let equal = (a, b, eq) => equalU(a, b, (. a, b) => eq(a, b)) + +let rec compareFromIndexU = (a, b, i, cmp, len) => + if i === len { + 0 + } else { + let c = cmp(. a->getUnsafe(i), b->getUnsafe(i)) + if c === 0 { + compareFromIndexU(a, b, i + 1, cmp, len) + } else { + c + } + } + +let compareU = (a, b, cmp) => { + let lenA = a->length + let lenB = b->length + if lenA > lenB { + 1 + } else if lenA < lenB { + -1 + } else { + compareFromIndexU(a, b, 0, cmp, lenA) + } +} + +let compare = (a, b, cmp) => compareU(a, b, (. a, b) => cmp(a, b)) + @send external copyAllWithin: (array<'a>, ~target: int) => array<'a> = "copyWithin" @send diff --git a/src/Core__Array.resi b/src/Core__Array.resi index ccbb4e1d..0984fe1e 100644 --- a/src/Core__Array.resi +++ b/src/Core__Array.resi @@ -27,6 +27,10 @@ let make: (~length: int, 'a) => array<'a> */ let fromInitializer: (~length: int, int => 'a) => array<'a> +let equal: (array<'a>, array<'a>, ('a, 'a) => bool) => bool + +let compare: (array<'a>, array<'a>, ('a, 'a) => int) => int + @val external isArray: 'a => bool = "Array.isArray" /** From d7c683494fae5f74a84ae293ecb95deb74f5b321 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Fri, 3 Mar 2023 07:33:05 +0100 Subject: [PATCH 08/12] Simplify Option.equal, Option.compare --- src/Core__Option.mjs | 10 ++++------ src/Core__Option.res | 21 +++++++-------------- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/Core__Option.mjs b/src/Core__Option.mjs index eae7113b..455655f8 100644 --- a/src/Core__Option.mjs +++ b/src/Core__Option.mjs @@ -78,11 +78,10 @@ function isNone(x) { return x === undefined; } -function equal(a, b, f) { - var f$1 = Curry.__2(f); +function equal(a, b, eq) { if (a !== undefined) { if (b !== undefined) { - return f$1(Caml_option.valFromOption(a), Caml_option.valFromOption(b)); + return Curry._2(eq, Caml_option.valFromOption(a), Caml_option.valFromOption(b)); } else { return false; } @@ -91,11 +90,10 @@ function equal(a, b, f) { } } -function compare(a, b, f) { - var f$1 = Curry.__2(f); +function compare(a, b, cmp) { if (a !== undefined) { if (b !== undefined) { - return f$1(Caml_option.valFromOption(a), Caml_option.valFromOption(b)); + return Curry._2(cmp, Caml_option.valFromOption(a), Caml_option.valFromOption(b)); } else { return 1; } diff --git a/src/Core__Option.res b/src/Core__Option.res index 998d421f..64171450 100644 --- a/src/Core__Option.res +++ b/src/Core__Option.res @@ -90,24 +90,17 @@ let isSome = x => let isNone = x => x == None -let equalU = (a, b, f) => - switch a { - | Some(a) => - switch b { - | None => false - | Some(b) => f(. a, b) - } - | None => b == None +let equal = (a, b, eq) => + switch (a, b) { + | (Some(a), Some(b)) => eq(a, b) + | (None, None) => true + | (None, Some(_)) | (Some(_), None) => false } -let equal = (a, b, f) => equalU(a, b, (. x, y) => f(x, y)) - -let compareU = (a, b, f) => +let compare = (a, b, cmp) => switch (a, b) { - | (Some(a), Some(b)) => f(. a, b) + | (Some(a), Some(b)) => cmp(a, b) | (None, Some(_)) => -1 | (Some(_), None) => 1 | (None, None) => 0 } - -let compare = (a, b, f) => compareU(a, b, (. x, y) => f(x, y)) From a9acdecd5f5219b2369eb15bde44538393fe0b06 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Fri, 3 Mar 2023 07:37:30 +0100 Subject: [PATCH 09/12] Add Null.equal, Null.compare --- src/Core__Null.mjs | 11 +++++++++++ src/Core__Null.res | 4 ++++ src/Core__Null.resi | 4 ++++ 3 files changed, 19 insertions(+) diff --git a/src/Core__Null.mjs b/src/Core__Null.mjs index 18551f8f..d6c6e83b 100644 --- a/src/Core__Null.mjs +++ b/src/Core__Null.mjs @@ -2,6 +2,7 @@ import * as Curry from "rescript/lib/es6/curry.js"; import * as Caml_option from "rescript/lib/es6/caml_option.js"; +import * as Core__Option from "./Core__Option.mjs"; function fromOption(option) { if (option !== undefined) { @@ -11,6 +12,14 @@ function fromOption(option) { } } +function equal(a, b, eq) { + return Core__Option.equal(a === null ? undefined : Caml_option.some(a), b === null ? undefined : Caml_option.some(b), eq); +} + +function compare(a, b, cmp) { + return Core__Option.compare(a === null ? undefined : Caml_option.some(a), b === null ? undefined : Caml_option.some(b), cmp); +} + function getWithDefault(value, $$default) { if (value !== null) { return value; @@ -55,6 +64,8 @@ function flatMap(value, f) { } export { + equal , + compare , fromOption , getWithDefault , getExn , diff --git a/src/Core__Null.res b/src/Core__Null.res index 3fca7268..023ad78c 100644 --- a/src/Core__Null.res +++ b/src/Core__Null.res @@ -14,6 +14,10 @@ let fromOption: option<'a> => t<'a> = option => | None => null } +let equal = (a, b, eq) => Core__Option.equal(a->toOption, b->toOption, eq) + +let compare = (a, b, cmp) => Core__Option.compare(a->toOption, b->toOption, cmp) + let getWithDefault = (value, default) => switch value->toOption { | Some(x) => x diff --git a/src/Core__Null.resi b/src/Core__Null.resi index f6d2bd51..50b1e79f 100644 --- a/src/Core__Null.resi +++ b/src/Core__Null.resi @@ -44,6 +44,10 @@ let asNullValue = myStr->Null.make // The compiler now thinks this can be `strin */ external make: 'a => t<'a> = "%identity" +let equal: (t<'a>, t<'b>, ('a, 'b) => bool) => bool + +let compare: (t<'a>, t<'b>, ('a, 'b) => int) => int + /** Converts a nullable value into an option, so it can be pattern matched on. Will convert `null` to `None`, and a present value to `Some(value)`. From 3941592a036d7e5515e49a8cc55aa72591d8b02f Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Fri, 3 Mar 2023 07:37:48 +0100 Subject: [PATCH 10/12] Add Nullable.equal, Nullable.compare --- src/Core__Nullable.mjs | 11 +++++++++++ src/Core__Nullable.res | 4 ++++ src/Core__Nullable.resi | 4 ++++ 3 files changed, 19 insertions(+) diff --git a/src/Core__Nullable.mjs b/src/Core__Nullable.mjs index 1a7b1ff3..00606cb3 100644 --- a/src/Core__Nullable.mjs +++ b/src/Core__Nullable.mjs @@ -2,6 +2,7 @@ import * as Curry from "rescript/lib/es6/curry.js"; import * as Caml_option from "rescript/lib/es6/caml_option.js"; +import * as Core__Option from "./Core__Option.mjs"; function fromOption(option) { if (option !== undefined) { @@ -10,6 +11,14 @@ function fromOption(option) { } +function equal(a, b, eq) { + return Core__Option.equal((a == null) ? undefined : Caml_option.some(a), (b == null) ? undefined : Caml_option.some(b), eq); +} + +function compare(a, b, cmp) { + return Core__Option.compare((a == null) ? undefined : Caml_option.some(a), (b == null) ? undefined : Caml_option.some(b), cmp); +} + function getWithDefault(value, $$default) { if (value == null) { return $$default; @@ -54,6 +63,8 @@ function flatMap(value, f) { } export { + equal , + compare , fromOption , getWithDefault , getExn , diff --git a/src/Core__Nullable.res b/src/Core__Nullable.res index 0d74399a..51849685 100644 --- a/src/Core__Nullable.res +++ b/src/Core__Nullable.res @@ -14,6 +14,10 @@ let fromOption: option<'a> => t<'a> = option => | None => undefined } +let equal = (a, b, eq) => Core__Option.equal(a->toOption, b->toOption, eq) + +let compare = (a, b, cmp) => Core__Option.compare(a->toOption, b->toOption, cmp) + let getWithDefault = (value, default) => switch value->toOption { | Some(x) => x diff --git a/src/Core__Nullable.resi b/src/Core__Nullable.resi index 8df01762..821554d1 100644 --- a/src/Core__Nullable.resi +++ b/src/Core__Nullable.resi @@ -55,6 +55,10 @@ switch asNullable->Nullable.toOption { */ external make: 'a => t<'a> = "%identity" +let equal: (t<'a>, t<'b>, ('a, 'b) => bool) => bool + +let compare: (t<'a>, t<'b>, ('a, 'b) => int) => int + /** Converts a nullable value into an option, so it can be pattern matched on. Will convert both `null` and `undefined` to `None`, and a present value to `Some(value)`. From 3c2b3d2f6c6f6ec8531f54f9624ae1b1799668b7 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sun, 11 Jun 2023 12:02:54 +0200 Subject: [PATCH 11/12] Handle Infinity, NaN correctly for Int compare --- src/Core__Float.mjs | 8 ++++---- src/Core__Float.res | 8 ++++---- src/Core__Int.mjs | 8 +++++++- src/Core__Int.res | 9 ++++++++- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/Core__Float.mjs b/src/Core__Float.mjs index eb76ff31..88c808e0 100644 --- a/src/Core__Float.mjs +++ b/src/Core__Float.mjs @@ -8,12 +8,12 @@ function equal(a, b) { } function compare(a, b) { - if (a === b) { + if (a < b) { + return -1; + } else if (a === b) { return 0; - } else if (a > b) { - return 1; } else { - return -1; + return 1; } } diff --git a/src/Core__Float.res b/src/Core__Float.res index 81d30b1f..dd04ddf7 100644 --- a/src/Core__Float.res +++ b/src/Core__Float.res @@ -10,12 +10,12 @@ module Constants = { let equal = (a: float, b: float) => a === b let compare = (a: float, b: float) => - if a === b { + if a < b { + -1 + } else if a === b { 0 - } else if a > b { - 1 } else { - -1 + 1 } @val external isNaN: float => bool = "isNaN" diff --git a/src/Core__Int.mjs b/src/Core__Int.mjs index a701942e..1b8538ba 100644 --- a/src/Core__Int.mjs +++ b/src/Core__Int.mjs @@ -8,7 +8,13 @@ function equal(a, b) { } function compare(a, b) { - return a - b | 0; + if (a < b) { + return -1; + } else if (a === b) { + return 0; + } else { + return 1; + } } function fromString(radix, x) { diff --git a/src/Core__Int.res b/src/Core__Int.res index 1fb3943a..e2162ba2 100644 --- a/src/Core__Int.res +++ b/src/Core__Int.res @@ -5,7 +5,14 @@ module Constants = { let equal = (a: int, b: int) => a === b -let compare = (a, b) => a - b +let compare = (a: int, b: int) => + if a < b { + -1 + } else if a === b { + 0 + } else { + 1 + } @send external toExponential: int => string = "toExponential" @send external toExponentialWithPrecision: (int, ~digits: int) => string = "toExponential" From b72eb84f3542a0f4f2dd580ff5ed7cdecccbc100 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sun, 11 Jun 2023 12:06:59 +0200 Subject: [PATCH 12/12] Remove xxxU functions --- src/Core__Array.mjs | 6 ++---- src/Core__Array.res | 24 ++++++++++-------------- src/Core__List.mjs | 42 ++++++++++++++++++------------------------ src/Core__List.res | 15 ++++++--------- src/Core__Result.mjs | 6 ++---- src/Core__Result.res | 12 ++++-------- 6 files changed, 42 insertions(+), 63 deletions(-) diff --git a/src/Core__Array.mjs b/src/Core__Array.mjs index 99cea411..cbe561c4 100644 --- a/src/Core__Array.mjs +++ b/src/Core__Array.mjs @@ -25,7 +25,6 @@ function fromInitializer(length, f) { } function equal(a, b, eq) { - var eq$1 = Curry.__2(eq); var len = a.length; if (len === b.length) { var _i = 0; @@ -34,7 +33,7 @@ function equal(a, b, eq) { if (i === len) { return true; } - if (!eq$1(a[i], b[i])) { + if (!Curry._2(eq, a[i], b[i])) { return false; } _i = i + 1 | 0; @@ -46,7 +45,6 @@ function equal(a, b, eq) { } function compare(a, b, cmp) { - var cmp$1 = Curry.__2(cmp); var lenA = a.length; var lenB = b.length; if (lenA > lenB) { @@ -60,7 +58,7 @@ function compare(a, b, cmp) { if (i === lenA) { return 0; } - var c = cmp$1(a[i], b[i]); + var c = Curry._2(cmp, a[i], b[i]); if (c !== 0) { return c; } diff --git a/src/Core__Array.res b/src/Core__Array.res index ec05df53..5c45b83b 100644 --- a/src/Core__Array.res +++ b/src/Core__Array.res @@ -37,39 +37,37 @@ let fromInitializer = (~length, f) => @get external length: array<'a> => int = "length" -let rec equalFromIndexU = (a, b, i, eq, len) => +let rec equalFromIndex = (a, b, i, eq, len) => if i === len { true - } else if eq(. a->getUnsafe(i), b->getUnsafe(i)) { - equalFromIndexU(a, b, i + 1, eq, len) + } else if eq(a->getUnsafe(i), b->getUnsafe(i)) { + equalFromIndex(a, b, i + 1, eq, len) } else { false } -let equalU = (a, b, eq) => { +let equal = (a, b, eq) => { let len = a->length if len === b->length { - equalFromIndexU(a, b, 0, eq, len) + equalFromIndex(a, b, 0, eq, len) } else { false } } -let equal = (a, b, eq) => equalU(a, b, (. a, b) => eq(a, b)) - -let rec compareFromIndexU = (a, b, i, cmp, len) => +let rec compareFromIndex = (a, b, i, cmp, len) => if i === len { 0 } else { - let c = cmp(. a->getUnsafe(i), b->getUnsafe(i)) + let c = cmp(a->getUnsafe(i), b->getUnsafe(i)) if c === 0 { - compareFromIndexU(a, b, i + 1, cmp, len) + compareFromIndex(a, b, i + 1, cmp, len) } else { c } } -let compareU = (a, b, cmp) => { +let compare = (a, b, cmp) => { let lenA = a->length let lenB = b->length if lenA > lenB { @@ -77,12 +75,10 @@ let compareU = (a, b, cmp) => { } else if lenA < lenB { -1 } else { - compareFromIndexU(a, b, 0, cmp, lenA) + compareFromIndex(a, b, 0, cmp, lenA) } } -let compare = (a, b, cmp) => compareU(a, b, (. a, b) => cmp(a, b)) - @send external copyAllWithin: (array<'a>, ~target: int) => array<'a> = "copyWithin" @send diff --git a/src/Core__List.mjs b/src/Core__List.mjs index 74afbabf..2f23f3d0 100644 --- a/src/Core__List.mjs +++ b/src/Core__List.mjs @@ -989,55 +989,49 @@ function compareLength(_l1, _l2) { }; } -function compare(l1, l2, f) { - var _l1 = l1; - var _l2 = l2; - var p = Curry.__2(f); +function compare(_l1, _l2, p) { while(true) { - var l2$1 = _l2; - var l1$1 = _l1; - if (!l1$1) { - if (l2$1) { + var l2 = _l2; + var l1 = _l1; + if (!l1) { + if (l2) { return -1; } else { return 0; } } - if (!l2$1) { + if (!l2) { return 1; } - var c = p(l1$1.hd, l2$1.hd); + var c = Curry._2(p, l1.hd, l2.hd); if (c !== 0) { return c; } - _l2 = l2$1.tl; - _l1 = l1$1.tl; + _l2 = l2.tl; + _l1 = l1.tl; continue ; }; } -function equal(l1, l2, f) { - var _l1 = l1; - var _l2 = l2; - var p = Curry.__2(f); +function equal(_l1, _l2, p) { while(true) { - var l2$1 = _l2; - var l1$1 = _l1; - if (!l1$1) { - if (l2$1) { + var l2 = _l2; + var l1 = _l1; + if (!l1) { + if (l2) { return false; } else { return true; } } - if (!l2$1) { + if (!l2) { return false; } - if (!p(l1$1.hd, l2$1.hd)) { + if (!Curry._2(p, l1.hd, l2.hd)) { return false; } - _l2 = l2$1.tl; - _l1 = l1$1.tl; + _l2 = l2.tl; + _l1 = l1.tl; continue ; }; } diff --git a/src/Core__List.res b/src/Core__List.res index d82347ae..2e720bef 100644 --- a/src/Core__List.res +++ b/src/Core__List.res @@ -688,35 +688,32 @@ let rec compareLength = (l1, l2) => | (list{_, ...l1s}, list{_, ...l2s}) => compareLength(l1s, l2s) } -let rec compareU = (l1, l2, p) => +let rec compare = (l1, l2, p) => switch (l1, l2) { | (list{}, list{}) => 0 | (_, list{}) => 1 | (list{}, _) => -1 | (list{a1, ...l1}, list{a2, ...l2}) => - let c = p(. a1, a2) + let c = p(a1, a2) if c == 0 { - compareU(l1, l2, p) + compare(l1, l2, p) } else { c } } -let compare = (l1, l2, f) => compareU(l1, l2, (. x, y) => f(x, y)) - -let rec equalU = (l1, l2, p) => +let rec equal = (l1, l2, p) => switch (l1, l2) { | (list{}, list{}) => true | (_, list{}) | (list{}, _) => false | (list{a1, ...l1}, list{a2, ...l2}) => - if p(. a1, a2) { - equalU(l1, l2, p) + if p(a1, a2) { + equal(l1, l2, p) } else { false } } -let equal = (l1, l2, f) => equalU(l1, l2, (. x, y) => f(x, y)) let rec some2U = (l1, l2, p) => switch (l1, l2) { diff --git a/src/Core__Result.mjs b/src/Core__Result.mjs index f0fcfbc4..b54c7671 100644 --- a/src/Core__Result.mjs +++ b/src/Core__Result.mjs @@ -73,10 +73,9 @@ function isError(x) { } function equal(a, b, f) { - var f$1 = Curry.__2(f); if (a.TAG === /* Ok */0) { if (b.TAG === /* Ok */0) { - return f$1(a._0, b._0); + return Curry._2(f, a._0, b._0); } else { return false; } @@ -88,10 +87,9 @@ function equal(a, b, f) { } function compare(a, b, f) { - var f$1 = Curry.__2(f); if (a.TAG === /* Ok */0) { if (b.TAG === /* Ok */0) { - return f$1(a._0, b._0); + return Curry._2(f, a._0, b._0); } else { return 1; } diff --git a/src/Core__Result.res b/src/Core__Result.res index d629cff5..681729c8 100644 --- a/src/Core__Result.res +++ b/src/Core__Result.res @@ -72,26 +72,22 @@ let isError = x => | Error(_) => true } -let equalU = (a, b, f) => +let equal = (a, b, f) => switch (a, b) { - | (Ok(a), Ok(b)) => f(. a, b) + | (Ok(a), Ok(b)) => f(a, b) | (Error(_), Ok(_)) | (Ok(_), Error(_)) => false | (Error(_), Error(_)) => true } -let equal = (a, b, f) => equalU(a, b, (. x, y) => f(x, y)) - -let compareU = (a, b, f) => +let compare = (a, b, f) => switch (a, b) { - | (Ok(a), Ok(b)) => f(. a, b) + | (Ok(a), Ok(b)) => f(a, b) | (Error(_), Ok(_)) => -1 | (Ok(_), Error(_)) => 1 | (Error(_), Error(_)) => 0 } -let compare = (a, b, f) => compareU(a, b, (. x, y) => f(x, y)) - let forEach = (r, f) => switch r { | Ok(ok) => f(ok)