From 4459254b5be4713f82cf93081d74d4939fbbb778 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Thu, 10 Jul 2025 10:12:42 +0200 Subject: [PATCH 01/16] format docstrings with the new format tools command --- runtime/Belt_Array.resi | 171 ++++++++------- runtime/Belt_Float.resi | 16 +- runtime/Belt_HashMap.resi | 28 +-- runtime/Belt_HashSet.resi | 14 +- runtime/Belt_Int.resi | 8 +- runtime/Belt_List.resi | 251 ++++++++++------------ runtime/Belt_Map.resi | 68 +++--- runtime/Belt_MapDict.resi | 6 +- runtime/Belt_MapInt.resi | 4 +- runtime/Belt_MapString.resi | 4 +- runtime/Belt_MutableSet.resi | 84 ++++---- runtime/Belt_Option.resi | 80 +++---- runtime/Belt_Range.resi | 18 +- runtime/Belt_Result.resi | 50 ++--- runtime/Belt_Set.resi | 115 +++++----- runtime/Belt_SetDict.resi | 95 ++++----- runtime/Belt_SortArray.resi | 12 +- runtime/Js_array2.res | 12 +- runtime/Js_date.res | 8 +- runtime/Js_dict.resi | 2 +- runtime/Js_float.res | 16 +- runtime/Js_global.res | 7 +- runtime/Js_math.res | 10 +- runtime/Js_null.resi | 4 +- runtime/Js_null_undefined.resi | 4 +- runtime/Js_option.res | 10 +- runtime/Js_re.res | 10 +- runtime/Js_undefined.resi | 4 +- runtime/Pervasives.res | 2 +- runtime/Stdlib_Array.resi | 53 +++-- runtime/Stdlib_AsyncIterator.resi | 23 +- runtime/Stdlib_BigInt.resi | 4 +- runtime/Stdlib_Bool.resi | 2 +- runtime/Stdlib_Console.resi | 39 ++-- runtime/Stdlib_Date.resi | 199 ++++++++++++------ runtime/Stdlib_Dict.resi | 1 - runtime/Stdlib_Float.resi | 30 +-- runtime/Stdlib_Int.resi | 24 +-- runtime/Stdlib_Iterator.resi | 21 +- runtime/Stdlib_JSON.resi | 83 ++++---- runtime/Stdlib_JsError.resi | 8 +- runtime/Stdlib_List.resi | 220 +++++++++----------- runtime/Stdlib_Math.resi | 334 +++++++++++++++--------------- runtime/Stdlib_Null.resi | 9 +- runtime/Stdlib_Nullable.resi | 11 +- runtime/Stdlib_Object.res | 22 +- runtime/Stdlib_Option.resi | 7 +- runtime/Stdlib_Promise.resi | 43 ++-- runtime/Stdlib_RegExp.resi | 9 +- runtime/Stdlib_Result.resi | 14 +- runtime/Stdlib_Set.resi | 2 +- runtime/Stdlib_String.resi | 88 ++++---- 52 files changed, 1181 insertions(+), 1178 deletions(-) diff --git a/runtime/Belt_Array.resi b/runtime/Belt_Array.resi index 2f35453d70..ffa41799bc 100644 --- a/runtime/Belt_Array.resi +++ b/runtime/Belt_Array.resi @@ -24,7 +24,7 @@ Return the size of the array ## Examples ```rescript -assertEqual(Belt.Array.length(["test"]), 1) +Belt.Array.length(["test"]) == 1 ``` */ external length: t<'a> => int = "%array_length" @@ -39,9 +39,9 @@ If `i` is out of range returns `None`. ## Examples ```rescript -assertEqual(Belt.Array.get(["a", "b", "c"], 0), Some("a")) -assertEqual(Belt.Array.get(["a", "b", "c"], 3), None) -assertEqual(Belt.Array.get(["a", "b", "c"], -1), None) +Belt.Array.get(["a", "b", "c"], 0) == Some("a") +Belt.Array.get(["a", "b", "c"], 3) == None +Belt.Array.get(["a", "b", "c"], -1) == None ``` */ let get: (t<'a>, int) => option<'a> @@ -112,7 +112,7 @@ let arr = [10, 11, 12, 13, 14] let () = Belt.Array.reverseInPlace(arr) -assertEqual(arr, [14, 13, 12, 11, 10]) +arr == [14, 13, 12, 11, 10] ``` */ let reverseInPlace: t<'a> => unit @@ -123,7 +123,7 @@ let reverseInPlace: t<'a> => unit ## Examples ```rescript -assertEqual(Belt.Array.reverse([10, 11, 12, 13, 14]), [14, 13, 12, 11, 10]) +Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] ``` */ let reverse: t<'a> => t<'a> @@ -137,7 +137,7 @@ value. You must specify the type of data that will eventually fill the array. ```rescript let arr: array> = Belt.Array.makeUninitialized(5) -assertEqual(Belt.Array.getExn(arr, 0), Js.undefined) +Belt.Array.getExn(arr, 0) == Js.undefined ``` */ @new @@ -155,7 +155,7 @@ Js.log(Belt.Array.getExn(arr, 0)) // undefined Belt.Array.setExn(arr, 0, "example") -assertEqual(Belt.Array.getExn(arr, 0), "example") +Belt.Array.getExn(arr, 0) == "example" ``` */ @new @@ -173,11 +173,11 @@ let make: (int, 'a) => t<'a> ## Examples ```rescript -assertEqual(Belt.Array.range(0, 3), [0, 1, 2, 3]) +Belt.Array.range(0, 3) == [0, 1, 2, 3] -assertEqual(Belt.Array.range(3, 0), []) +Belt.Array.range(3, 0) == [] -assertEqual(Belt.Array.range(3, 3), [3]) +Belt.Array.range(3, 3) == [3] ``` */ let range: (int, int) => array @@ -189,19 +189,19 @@ It also return an empty array when `start > finish`. ## Examples ```rescript -assertEqual(Belt.Array.rangeBy(0, 10, ~step=3), [0, 3, 6, 9]) +Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] -assertEqual(Belt.Array.rangeBy(0, 12, ~step=3), [0, 3, 6, 9, 12]) +Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] -assertEqual(Belt.Array.rangeBy(33, 0, ~step=1), []) +Belt.Array.rangeBy(33, 0, ~step=1) == [] -assertEqual(Belt.Array.rangeBy(33, 0, ~step=-1), []) +Belt.Array.rangeBy(33, 0, ~step=-1) == [] -assertEqual(Belt.Array.rangeBy(3, 12, ~step=-1), []) +Belt.Array.rangeBy(3, 12, ~step=-1) == [] -assertEqual(Belt.Array.rangeBy(3, 3, ~step=0), []) +Belt.Array.rangeBy(3, 3, ~step=0) == [] -assertEqual(Belt.Array.rangeBy(3, 3, ~step=1), [3]) +Belt.Array.rangeBy(3, 3, ~step=1) == [3] ``` */ let rangeBy: (int, int, ~step: int) => array @@ -215,9 +215,9 @@ n populated by `f(i)` start from `0` to `n - 1`. ## Examples ```rescript -assertEqual(Belt.Array.makeBy(5, (i) => i), [0, 1, 2, 3, 4]) +Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] -assertEqual(Belt.Array.makeBy(5, (i) => i * i), [0, 1, 4, 9, 16]) +Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] ``` */ let makeBy: (int, int => 'a) => t<'a> @@ -236,7 +236,7 @@ Stop with the shorter array. ## Examples ```rescript -assertEqual(Belt.Array.zip([1, 2], [3, 4, 5]), [(1, 3), (2, 4)]) +Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] ``` */ let zip: (t<'a>, array<'b>) => array<('a, 'b)> @@ -252,7 +252,7 @@ Equivalent to `map(zip(xs, ys), ((a, b)) => f(a, b))` ## Examples ```rescript -assertEqual(Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b), [6, 9]) +Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] ``` */ let zipBy: (t<'a>, array<'b>, ('a, 'b) => 'c) => array<'c> @@ -265,9 +265,9 @@ second items. ## Examples ```rescript -assertEqual(Belt.Array.unzip([(1, 2), (3, 4)]), ([1, 3], [2, 4])) +Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) -assertEqual(Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]), ([1, 3, 5, 7], [2, 4, 6, 8])) +Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) ``` */ let unzip: array<('a, 'b)> => (t<'a>, array<'b>) @@ -279,9 +279,9 @@ let unzip: array<('a, 'b)> => (t<'a>, array<'b>) ## Examples ```rescript -assertEqual(Belt.Array.concat([1, 2, 3], [4, 5]), [1, 2, 3, 4, 5]) +Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] -assertEqual(Belt.Array.concat([], ["a", "b", "c"]), ["a", "b", "c"]) +Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] ``` */ let concat: (t<'a>, t<'a>) => t<'a> @@ -292,7 +292,7 @@ let concat: (t<'a>, t<'a>) => t<'a> ## Examples ```rescript -assertEqual(Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]), [1, 2, 3, 4, 5, 6, 7, 8]) +Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] ``` */ let concatMany: array> => t<'a> @@ -309,11 +309,11 @@ if `len` is negative; returns the empty array. ## Examples ```rescript -assertEqual(Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3), [12, 13, 14]) +Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] -assertEqual(Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3), [13, 14, 15]) +Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] -assertEqual(Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9), [14, 15, 16]) +Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] ``` */ let slice: (t<'a>, ~offset: int, ~len: int) => t<'a> @@ -330,9 +330,9 @@ means get the last element as a singleton array ## Examples ```rescript -assertEqual(Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2), [12, 13, 14, 15, 16]) +Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] -assertEqual(Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4), [13, 14, 15, 16]) +Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] ``` */ let sliceToEnd: (t<'a>, int) => t<'a> @@ -354,15 +354,15 @@ as `length(arr - offset)`. ## Examples ```rescript -let arr = Belt.Array.makeBy(5, (i) => i) +let arr = Belt.Array.makeBy(5, i => i) Belt.Array.fill(arr, ~offset=2, ~len=2, 9) -assertEqual(arr, [0, 1, 9, 9, 4]) +arr == [0, 1, 9, 9, 4] Belt.Array.fill(arr, ~offset=7, ~len=2, 8) -assertEqual(arr, [0, 1, 9, 9, 4]) +arr == [0, 1, 9, 9, 4] ``` */ let fill: (t<'a>, ~offset: int, ~len: int, 'a) => unit @@ -384,10 +384,10 @@ let v1 = [10, 11, 12, 13, 14, 15, 16, 17] let v2 = [20, 21, 22, 23, 24, 25, 26, 27] Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) -assertEqual(v2, [20, 21, 14, 15, 16, 25, 26, 27]) +v2 == [20, 21, 14, 15, 16, 25, 26, 27] Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) -assertEqual(v1, [10, 11, 14, 15, 16, 15, 16, 17]) +v1 == [10, 11, 14, 15, 16, 15, 16, 17] ``` */ let blit: (~src: t<'a>, ~srcOffset: int, ~dst: t<'a>, ~dstOffset: int, ~len: int) => unit @@ -421,7 +421,7 @@ let total = ref(0) Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) -assertEqual(total.contents, 1 + 2 + 3 + 4) +total.contents == 1 + 2 + 3 + 4 ``` */ let forEach: (t<'a>, 'a => unit) => unit @@ -435,7 +435,7 @@ the beginning to end. ## Examples ```rescript -assertEqual(Belt.Array.map([1, 2], (x) => x + 1), [2, 3]) +Belt.Array.map([1, 2], x => x + 1) == [2, 3] ``` */ let map: (t<'a>, 'a => 'b) => array<'b> @@ -449,7 +449,7 @@ the beginning to end, concatenating the results. ## Examples ```rescript -assertEqual(Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]), [11, 21, 12, 22]) +Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] ``` */ let flatMap: (t<'a>, 'a => array<'b>) => array<'b> @@ -463,8 +463,8 @@ the predicate function `p`; returns `None` if no element satisifies the function ## Examples ```rescript -assertEqual(Belt.Array.getBy([1, 4, 3, 2], (x) => mod(x, 2) == 0), Some(4)) -assertEqual(Belt.Array.getBy([15, 13, 11], (x) => mod(x, 2) == 0), None) +Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) +Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None ``` */ let getBy: (t<'a>, 'a => bool) => option<'a> @@ -479,8 +479,8 @@ the function. ## Examples ```rescript -assertEqual(Belt.Array.getIndexBy([1, 4, 3, 2], (x) => mod(x, 2) == 0), Some(1)) -assertEqual(Belt.Array.getIndexBy([15, 13, 11], (x) => mod(x, 2) == 0), None) +Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) +Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None ``` */ let getIndexBy: (t<'a>, 'a => bool) => option @@ -500,7 +500,7 @@ let keepWithIndexU: (t<'a>, ('a, int) => bool) => t<'a> ## Examples ```rescript -assertEqual(Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1), [2]) +Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] ``` */ let keepWithIndex: (t<'a>, ('a, int) => bool) => t<'a> @@ -514,16 +514,13 @@ None applied `p`. ## Examples ```rescript -assertEqual( - Belt.Array.keepMap([1, 2, 3], x => - if mod(x, 2) == 0 { - Some(x) - } else { - None - } - ), - [2] -) +Belt.Array.keepMap([1, 2, 3], x => + if mod(x, 2) == 0 { + Some(x) + } else { + None + } +) == [2] ``` */ let keepMap: (t<'a>, 'a => option<'b>) => array<'b> @@ -537,7 +534,9 @@ supplied two arguments: the index starting from 0 and the element from `xs`. ## Examples ```rescript -Belt.Array.forEachWithIndex(["a", "b", "c"], (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x)) +Belt.Array.forEachWithIndex(["a", "b", "c"], (i, x) => + Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x) +) /* prints: @@ -549,7 +548,7 @@ let total = ref(0) Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) -assertEqual(total.contents, 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13) +total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 ``` */ let forEachWithIndex: (t<'a>, (int, 'a) => unit) => unit @@ -563,7 +562,7 @@ two arguments: the index starting from 0 and the element from `xs`. ## Examples ```rescript -assertEqual(Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x), [0 + 1, 1 + 2, 2 + 3]) +Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] ``` */ let mapWithIndex: (t<'a>, (int, 'a) => 'b) => array<'b> @@ -577,9 +576,9 @@ first of tuple where predicate cause true, second where predicate cause false ## Examples ```rescript -assertEqual(Belt.Array.partition([1, 2, 3, 4, 5], (x) => mod(x, 2) == 0), ([2, 4], [1, 3, 5])) +Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) -assertEqual(Belt.Array.partition([1, 2, 3, 4, 5], (x) => mod(x, 2) != 0), ([1, 3, 5], [2, 4])) +Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) ``` */ let partition: (t<'a>, 'a => bool) => (t<'a>, t<'a>) @@ -595,9 +594,9 @@ accumulator. ## Examples ```rescript -assertEqual(Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b), 10) +Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 -assertEqual(Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b), "abcd") +Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" ``` */ let reduce: (array<'b>, 'a, ('a, 'b) => 'a) => 'a @@ -611,7 +610,7 @@ function `f` is applied to each item of `xs` from the last back to the first. ## Examples ```rescript -assertEqual(Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b), "dcba") +Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" ``` */ let reduceReverse: (array<'b>, 'a, ('a, 'b) => 'a) => 'a @@ -625,7 +624,7 @@ starting at `min(length(xs), length(ys))` down to and including zero. ## Examples ```rescript -assertEqual(Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y), 6) +Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 ``` */ let reduceReverse2: (t<'a>, array<'b>, 'c, ('c, 'a, 'b) => 'c) => 'c @@ -634,14 +633,14 @@ let reduceReverse2: (t<'a>, array<'b>, 'c, ('c, 'a, 'b) => 'c) => 'c let reduceWithIndexU: (t<'a>, 'b, ('b, 'a, int) => 'b) => 'b /** Applies `f` to each element of `xs` from beginning to end. Function `f` has -three parameters: the item from the array and an “accumulator”, which starts +three parameters: the item from the array and an “accumulator”, which starts with a value of `init` and the index of each element. `reduceWithIndex` returns the final value of the accumulator. ## Examples ```rescript -assertEqual(Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i), 16) +Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 ``` */ let reduceWithIndex: (t<'a>, 'b, ('b, 'a, int) => 'b) => 'b @@ -653,15 +652,15 @@ let joinWithU: (t<'a>, string, 'a => string) => string Concatenates all the elements of `xs` converted to string with `toString`, each separated by `sep`, the string given as the second argument, into a single string. -If the array has only one element, then that element will be returned without +If the array has only one element, then that element will be returned without using the separator. If the array is empty, the empty string will be returned. ## Examples ```rescript -assertEqual(Belt.Array.joinWith([0, 1], ", ", Js.Int.toString), "0, 1") -assertEqual(Belt.Array.joinWith([], " ", Js.Int.toString), "") -assertEqual(Belt.Array.joinWith([1], " ", Js.Int.toString), "1") +Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" +Belt.Array.joinWith([], " ", Js.Int.toString) == "" +Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" ``` */ let joinWith: (t<'a>, string, 'a => string) => string @@ -675,9 +674,9 @@ where `p` is a predicate: a function taking an element and returning a `bool`. ## Examples ```rescript -assertEqual(Belt.Array.some([2, 3, 4], (x) => mod(x, 2) == 1), true) +Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true -assertEqual(Belt.Array.some([(-1), (-3), (-5)], (x) => x > 0), false) +Belt.Array.some([-1, -3, -5], x => x > 0) == false ``` */ let some: (t<'a>, 'a => bool) => bool @@ -691,9 +690,9 @@ predicate: a function taking an element and returning a `bool`. ## Examples ```rescript -assertEqual(Belt.Array.every([1, 3, 5], (x) => mod(x, 2) == 1), true) +Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true -assertEqual(Belt.Array.every([1, (-3), 5], (x) => x > 0), false) +Belt.Array.every([1, -3, 5], x => x > 0) == false ``` */ let every: (t<'a>, 'a => bool) => bool @@ -707,13 +706,13 @@ elements up to the shorter length (i.e. `min(length(xs), length(ys))`) ## Examples ```rescript -assertEqual(Belt.Array.every2([1, 2, 3], [0, 1], (a, b) => a > b), true) +Belt.Array.every2([1, 2, 3], [0, 1], (a, b) => a > b) == true -assertEqual(Belt.Array.every2([], [1], (x, y) => x > y), true) +Belt.Array.every2([], [1], (x, y) => x > y) == true -assertEqual(Belt.Array.every2([2, 3], [1], (x, y) => x > y), true) +Belt.Array.every2([2, 3], [1], (x, y) => x > y) == true -assertEqual(Belt.Array.every2([0, 1], [5, 0], (x, y) => x > y), false) +Belt.Array.every2([0, 1], [5, 0], (x, y) => x > y) == false ``` */ let every2: (t<'a>, array<'b>, ('a, 'b) => bool) => bool @@ -727,11 +726,11 @@ up to the shorter length (i.e. `min(length(xs), length(ys))`) ## Examples ```rescript -assertEqual(Belt.Array.some2([0, 2], [1, 0, 3], (a, b) => a > b), true) +Belt.Array.some2([0, 2], [1, 0, 3], (a, b) => a > b) == true -assertEqual(Belt.Array.some2([], [1], (x, y) => x > y), false) +Belt.Array.some2([], [1], (x, y) => x > y) == false -assertEqual(Belt.Array.some2([2, 3], [1, 4], (x, y) => x > y), true) +Belt.Array.some2([2, 3], [1, 4], (x, y) => x > y) == true ``` */ let some2: (t<'a>, array<'b>, ('a, 'b) => bool) => bool @@ -749,11 +748,11 @@ returns zero for all `x` and `y`. ## Examples ```rescript -assertEqual(Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)), -1) +Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 -assertEqual(Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)), 1) +Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 -assertEqual(Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)), 0) +Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 ``` */ let cmp: (t<'a>, t<'a>, ('a, 'a) => int) => int @@ -767,7 +766,7 @@ one by one using `f(xi, yi)`; and return true if all results are true false othe ## Examples ```rescript -assertEqual(Belt.Array.eq([1, 2, 3], [(-1), (-2), (-3)], (a, b) => abs(a) == abs(b)), true) +Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true ``` */ let eq: (t<'a>, t<'a>, ('a, 'a) => bool) => bool @@ -784,7 +783,7 @@ let arr = ["ant", "bee", "cat", "dog", "elk"] Belt.Array.truncateToLengthUnsafe(arr, 3) -assertEqual(arr, ["ant", "bee", "cat"]) +arr == ["ant", "bee", "cat"] ``` */ @set diff --git a/runtime/Belt_Float.resi b/runtime/Belt_Float.resi index 6f58321f3c..8b225a6c47 100644 --- a/runtime/Belt_Float.resi +++ b/runtime/Belt_Float.resi @@ -30,7 +30,7 @@ Converts a given `float` to an `int`. ## Examples ```rescript -assertEqual(Belt.Float.toInt(1.0), 1) +Belt.Float.toInt(1.0) == 1 ``` */ external toInt: float => int = "%intoffloat" @@ -41,7 +41,7 @@ Converts a given `int` to a `float`. ## Examples ```rescript -assertEqual(Belt.Float.fromInt(1), 1.0) +Belt.Float.fromInt(1) == 1.0 ``` */ external fromInt: int => float = "%identity" @@ -52,7 +52,7 @@ Converts a given `string` to a `float`. Returns `Some(float)` when the input is ## Examples ```rescript -assertEqual(Belt.Float.fromString("1.0"), Some(1.0)) +Belt.Float.fromString("1.0") == Some(1.0) ``` */ let fromString: string => option @@ -63,7 +63,7 @@ Converts a given `float` to a `string`. Uses the JavaScript `String` constructor ## Examples ```rescript -assertEqual(Belt.Float.toString(1.0), "1") +Belt.Float.toString(1.0) == "1" ``` */ @val @@ -77,7 +77,7 @@ Can be opened in a module to avoid dot-notation (`+.`), however this yields a sh ```rescript open Belt.Float -assertEqual(2.0 + 2.0, 4.0) +2.0 + 2.0 == 4.0 ``` */ external \"+": (float, float) => float = "%addfloat" @@ -90,7 +90,7 @@ Can be opened in a module to avoid dot-notation (`-.`), however this yields a sh ```rescript open Belt.Float -assertEqual(2.0 - 1.0, 1.0) +2.0 - 1.0 == 1.0 ``` */ external \"-": (float, float) => float = "%subfloat" @@ -103,7 +103,7 @@ Can be opened in a module to avoid dot-notation (`*.`), however this yields a sh ```rescript open Belt.Float -assertEqual(2.0 * 2.0, 4.0) +2.0 * 2.0 == 4.0 ``` */ external \"*": (float, float) => float = "%mulfloat" @@ -116,7 +116,7 @@ Can be opened in a module to avoid dot-notation (`/.`), however this yields a sh ```rescript open Belt.Float -assertEqual(4.0 / 2.0, 2.0) +4.0 / 2.0 == 2.0 ``` */ external \"/": (float, float) => float = "%divfloat" diff --git a/runtime/Belt_HashMap.resi b/runtime/Belt_HashMap.resi index 170396b160..ff5d50252a 100644 --- a/runtime/Belt_HashMap.resi +++ b/runtime/Belt_HashMap.resi @@ -114,7 +114,7 @@ module IntHash = Belt.Id.MakeHashable({ let hMap = Belt.HashMap.fromArray([(1, "1")], ~id=module(IntHash)) Belt.HashMap.clear(hMap) -assertEqual(Belt.HashMap.isEmpty(hMap), true) +Belt.HashMap.isEmpty(hMap) == true ``` */ let clear: t<'key, 'value, 'id> => unit @@ -131,7 +131,7 @@ module IntHash = Belt.Id.MakeHashable({ let eq = (a, b) => a == b }) -assertEqual(Belt.HashMap.isEmpty(Belt.HashMap.fromArray([(1, "1")], ~id=module(IntHash))), false) +Belt.HashMap.isEmpty(Belt.HashMap.fromArray([(1, "1")], ~id=module(IntHash))) == false ``` */ let isEmpty: t<_> => bool @@ -152,7 +152,7 @@ let s0 = Belt.HashMap.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntHa Belt.HashMap.set(s0, 2, "3") -assertEqual(Belt.HashMap.valuesToArray(s0), ["1", "3", "3"]) +Belt.HashMap.valuesToArray(s0) == ["1", "3", "3"] ``` */ let set: (t<'key, 'value, 'id>, 'key, 'value) => unit @@ -174,7 +174,7 @@ let s1 = Belt.HashMap.copy(s0) Belt.HashMap.set(s0, 2, "3") -assertEqual(Belt.HashMap.get(s0, 2) != Belt.HashMap.get(s1, 2), true) +(Belt.HashMap.get(s0, 2) != Belt.HashMap.get(s1, 2)) == true ``` */ let copy: t<'key, 'value, 'id> => t<'key, 'value, 'id> @@ -194,8 +194,8 @@ module IntHash = Belt.Id.MakeHashable({ let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) Belt.HashMap.set(s0, 1, "value1") -assertEqual(Belt.HashMap.get(s0, 1), Some("value1")) -assertEqual(Belt.HashMap.get(s0, 2), None) +Belt.HashMap.get(s0, 1) == Some("value1") +Belt.HashMap.get(s0, 2) == None ``` */ let get: (t<'key, 'value, 'id>, 'key) => option<'value> @@ -215,8 +215,8 @@ module IntHash = Belt.Id.MakeHashable({ let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) Belt.HashMap.set(s0, 1, "value1") -assertEqual(Belt.HashMap.has(s0, 1), true) -assertEqual(Belt.HashMap.has(s0, 2), false) +Belt.HashMap.has(s0, 1) == true +Belt.HashMap.has(s0, 2) == false ``` */ let has: (t<'key, 'value, 'id>, 'key) => bool @@ -236,7 +236,7 @@ module IntHash = Belt.Id.MakeHashable({ let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) Belt.HashMap.set(s0, 1, "value1") Belt.HashMap.remove(s0, 1) -assertEqual(Belt.HashMap.has(s0, 1), false) +Belt.HashMap.has(s0, 1) == false ``` */ let remove: (t<'key, 'value, 'id>, 'key) => unit @@ -340,7 +340,7 @@ let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) Belt.HashMap.set(s0, 1, "value1") Belt.HashMap.set(s0, 2, "value2") -assertEqual(Belt.HashMap.size(s0), 2) +Belt.HashMap.size(s0) == 2 ``` */ let size: t<_> => int @@ -361,7 +361,7 @@ let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) Belt.HashMap.set(s0, 1, "value1") Belt.HashMap.set(s0, 2, "value2") -assertEqual(Belt.HashMap.toArray(s0), [(1, "value1"), (2, "value2")]) +Belt.HashMap.toArray(s0) == [(1, "value1"), (2, "value2")] ``` */ let toArray: t<'key, 'value, 'id> => array<('key, 'value)> @@ -382,7 +382,7 @@ let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) Belt.HashMap.set(s0, 1, "value1") Belt.HashMap.set(s0, 2, "value2") -assertEqual(Belt.HashMap.keysToArray(s0), [1, 2]) +Belt.HashMap.keysToArray(s0) == [1, 2] ``` */ let keysToArray: t<'key, _, _> => array<'key> @@ -403,7 +403,7 @@ let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) Belt.HashMap.set(s0, 1, "value1") Belt.HashMap.set(s0, 2, "value2") -assertEqual(Belt.HashMap.valuesToArray(s0), ["value1", "value2"]) +Belt.HashMap.valuesToArray(s0) == ["value1", "value2"] ``` */ let valuesToArray: t<_, 'value, _> => array<'value> @@ -423,7 +423,7 @@ module IntHash = Belt.Id.MakeHashable({ }) let s0 = Belt.HashMap.fromArray([(1, "value1"), (2, "value2")], ~id=module(IntHash)) -assertEqual(Belt.HashMap.toArray(s0), [(1, "value1"), (2, "value2")]) +Belt.HashMap.toArray(s0) == [(1, "value1"), (2, "value2")] ``` */ let fromArray: (array<('key, 'value)>, ~id: id<'key, 'id>) => t<'key, 'value, 'id> diff --git a/runtime/Belt_HashSet.resi b/runtime/Belt_HashSet.resi index 68309c8cbe..5261290148 100644 --- a/runtime/Belt_HashSet.resi +++ b/runtime/Belt_HashSet.resi @@ -32,21 +32,11 @@ different _hash_ functions will have different type. ## Examples ```rescript -module I0 = unpack( - Belt.Id.hashable( - ~hash=(a: int) => land(a, 65535), - ~eq=(a, b) => a == b, - ) -) +module I0 = unpack(Belt.Id.hashable(~hash=(a: int) => land(a, 65535), ~eq=(a, b) => a == b)) let s0 = Belt.HashSet.make(~id=module(I0), ~hintSize=40) -module I1 = unpack( - Belt.Id.hashable( - ~hash=(a: int) => land(a, 255), - ~eq=(a, b) => a == b, - ) -) +module I1 = unpack(Belt.Id.hashable(~hash=(a: int) => land(a, 255), ~eq=(a, b) => a == b)) let s1 = Belt.HashSet.make(~id=module(I1), ~hintSize=40) diff --git a/runtime/Belt_Int.resi b/runtime/Belt_Int.resi index 1ee951c34c..ad309941d1 100644 --- a/runtime/Belt_Int.resi +++ b/runtime/Belt_Int.resi @@ -78,7 +78,7 @@ Addition of two `int` values. Same as the addition from `Pervasives`. ```rescript open Belt.Int -assertEqual(2 + 2, 4) +2 + 2 == 4 ``` */ external \"+": (int, int) => int = "%addint" @@ -90,7 +90,7 @@ Subtraction of two `int` values. Same as the subtraction from `Pervasives`. ```rescript open Belt.Int -assertEqual(2 - 1, 1) +2 - 1 == 1 ``` */ external \"-": (int, int) => int = "%subint" @@ -102,7 +102,7 @@ Multiplication of two `int` values. Same as the multiplication from `Pervasives` ```rescript open Belt.Int -assertEqual(2 * 2, 4) +2 * 2 == 4 ``` */ external \"*": (int, int) => int = "%mulint" @@ -114,7 +114,7 @@ Division of two `int` values. Same as the division from `Pervasives`. ```rescript open Belt.Int -assertEqual(4 / 2, 2) +4 / 2 == 2 ``` */ external \"/": (int, int) => int = "%divint" diff --git a/runtime/Belt_List.resi b/runtime/Belt_List.resi index 9ff36258d2..8a1ac719b0 100644 --- a/runtime/Belt_List.resi +++ b/runtime/Belt_List.resi @@ -41,7 +41,7 @@ Returns the length of a list. ## Examples ```rescript -assertEqual(Belt.List.length(list{1, 2, 3}), 3) +Belt.List.length(list{1, 2, 3}) == 3 ``` */ let length: t<'a> => int @@ -56,8 +56,8 @@ Returns `Some(value)` where `value` is the first element in the list, or ## Examples ```rescript -assertEqual(Belt.List.head(list{}), None) -assertEqual(Belt.List.head(list{1, 2, 3}), Some(1)) +Belt.List.head(list{}) == None +Belt.List.head(list{1, 2, 3}) == Some(1) ``` */ let head: t<'a> => option<'a> @@ -71,7 +71,8 @@ with care. ```rescript Belt.List.headExn(list{1, 2, 3})->assertEqual(1) -switch Belt.List.headExn(list{}) { // Raises an Error +switch Belt.List.headExn(list{}) { +// Raises an Error | exception _ => assert(true) | _ => assert(false) } @@ -88,7 +89,8 @@ with care. ```rescript Belt.List.headOrThrow(list{1, 2, 3})->assertEqual(1) -switch Belt.List.headOrThrow(list{}) { // Raises an Error +switch Belt.List.headOrThrow(list{}) { +// Raises an Error | exception _ => assert(true) | _ => assert(false) } @@ -103,9 +105,9 @@ where `tail` is everything except the first element of `someList`. ## Examples ```rescript -assertEqual(Belt.List.tail(list{1, 2, 3}), Some(list{2, 3})) +Belt.List.tail(list{1, 2, 3}) == Some(list{2, 3}) -assertEqual(Belt.List.tail(list{}), None) +Belt.List.tail(list{}) == None ``` */ let tail: t<'a> => option> @@ -119,7 +121,8 @@ with care. ```rescript Belt.List.tailExn(list{1, 2, 3})->assertEqual(list{2, 3}) -switch Belt.List.tailExn(list{}) { // Raises an Error +switch Belt.List.tailExn(list{}) { +// Raises an Error | exception _ => assert(true) | _ => assert(false) } @@ -136,7 +139,8 @@ with care. ```rescript Belt.List.tailOrThrow(list{1, 2, 3})->assertEqual(list{2, 3}) -switch Belt.List.tailOrThrow(list{}) { // Raises an Error +switch Belt.List.tailOrThrow(list{}) { +// Raises an Error | exception _ => assert(true) | _ => assert(false) } @@ -152,7 +156,7 @@ Adds `value` to the beginning of `someList`. ```rescript Belt.List.add(list{2, 3}, 1) // list{1, 2, 3} -assertEqual(Belt.List.add(list{"World", "!"}, "Hello"), list{"Hello", "World", "!"}) +Belt.List.add(list{"World", "!"}, "Hello") == list{"Hello", "World", "!"} ``` */ let add: (t<'a>, 'a) => t<'a> @@ -166,9 +170,9 @@ length. ```rescript let abc = list{"A", "B", "C"} -assertEqual(abc->Belt.List.get(1), Some("B")) +abc->Belt.List.get(1) == Some("B") -assertEqual(abc->Belt.List.get(4), None) +abc->Belt.List.get(4) == None ``` */ let get: (t<'a>, int) => option<'a> @@ -184,7 +188,8 @@ let abc = list{"A", "B", "C"} abc->Belt.List.getExn(1)->assertEqual("B") -switch abc->Belt.List.getExn(4) { // Raises an Error +switch abc->Belt.List.getExn(4) { +// Raises an Error | exception _ => assert(true) | _ => assert(false) } @@ -203,7 +208,8 @@ let abc = list{"A", "B", "C"} abc->Belt.List.getOrThrow(1)->assertEqual("B") -switch abc->Belt.List.getOrThrow(4) { // Raises an Error +switch abc->Belt.List.getOrThrow(4) { +// Raises an Error | exception _ => assert(true) | _ => assert(false) } @@ -217,7 +223,7 @@ Returns a list of length `numItems` with each element filled with value `v`. Ret ## Examples ```rescript -assertEqual(Belt.List.make(3, 1), list{1, 1, 1}) +Belt.List.make(3, 1) == list{1, 1, 1} ``` */ let make: (int, 'a) => t<'a> @@ -233,9 +239,9 @@ Returns an empty list if `numItems` is negative. ## Examples ```rescript -assertEqual(Belt.List.makeBy(5, i => i), list{0, 1, 2, 3, 4}) +Belt.List.makeBy(5, i => i) == list{0, 1, 2, 3, 4} -assertEqual(Belt.List.makeBy(5, i => i * i), list{0, 1, 4, 9, 16}) +Belt.List.makeBy(5, i => i * i) == list{0, 1, 4, 9, 16} ``` */ let makeBy: (int, int => 'a) => t<'a> @@ -257,11 +263,11 @@ Return a new list, dropping the first `n` elements. Returns `None` if `someList` ## Examples ```rescript -assertEqual(list{1, 2, 3}->Belt.List.drop(2), Some(list{3})) +list{1, 2, 3}->Belt.List.drop(2) == Some(list{3}) -assertEqual(list{1, 2, 3}->Belt.List.drop(3), Some(list{})) +list{1, 2, 3}->Belt.List.drop(3) == Some(list{}) -assertEqual(list{1, 2, 3}->Belt.List.drop(4), None) +list{1, 2, 3}->Belt.List.drop(4) == None ``` */ let drop: (t<'a>, int) => option> @@ -272,11 +278,11 @@ Returns a list with the first `n` elements from `someList`, or `None` if `someLi ## Examples ```rescript -assertEqual(list{1, 2, 3}->Belt.List.take(1), Some(list{1})) +list{1, 2, 3}->Belt.List.take(1) == Some(list{1}) -assertEqual(list{1, 2, 3}->Belt.List.take(2), Some(list{1, 2})) +list{1, 2, 3}->Belt.List.take(2) == Some(list{1, 2}) -assertEqual(list{1, 2, 3}->Belt.List.take(4), None) +list{1, 2, 3}->Belt.List.take(4) == None ``` */ let take: (t<'a>, int) => option> @@ -287,9 +293,9 @@ Split the list `someList` at `index`. Returns `None` when the length of `someLis ## Examples ```rescript -assertEqual(list{"Hello", "World"}->Belt.List.splitAt(1), Some((list{"Hello"}, list{"World"}))) +list{"Hello", "World"}->Belt.List.splitAt(1) == Some((list{"Hello"}, list{"World"})) -assertEqual(list{0, 1, 2, 3, 4}->Belt.List.splitAt(2), Some((list{0, 1}, list{2, 3, 4}))) +list{0, 1, 2, 3, 4}->Belt.List.splitAt(2) == Some((list{0, 1}, list{2, 3, 4})) ``` */ let splitAt: (t<'a>, int) => option<(list<'a>, list<'a>)> @@ -300,7 +306,7 @@ Returns the list obtained by adding `secondList` after `firstList`. ## Examples ```rescript -assertEqual(Belt.List.concat(list{1, 2, 3}, list{4, 5}), list{1, 2, 3, 4, 5}) +Belt.List.concat(list{1, 2, 3}, list{4, 5}) == list{1, 2, 3, 4, 5} ``` */ let concat: (t<'a>, t<'a>) => t<'a> @@ -312,7 +318,7 @@ order. ## Examples ```rescript -assertEqual(Belt.List.concatMany([list{1, 2, 3}, list{}, list{3}]), list{1, 2, 3, 3}) +Belt.List.concatMany([list{1, 2, 3}, list{}, list{3}]) == list{1, 2, 3, 3} ``` */ let concatMany: array> => t<'a> @@ -323,7 +329,7 @@ Equivalent to writing: `concat(reverse(firstList, secondList)` ## Examples ```rescript -assertEqual(Belt.List.reverseConcat(list{1, 2}, list{3, 4}), list{2, 1, 3, 4}) +Belt.List.reverseConcat(list{1, 2}, list{3, 4}) == list{2, 1, 3, 4} ``` */ let reverseConcat: (t<'a>, t<'a>) => t<'a> @@ -334,7 +340,7 @@ Return the list obtained by concatenating all the lists in list `ls`, in order. ## Examples ```rescript -assertEqual(Belt.List.flatten(list{list{1, 2, 3}, list{}, list{3}}), list{1, 2, 3, 3}) +Belt.List.flatten(list{list{1, 2, 3}, list{}, list{3}}) == list{1, 2, 3, 3} ``` */ let flatten: t> => t<'a> @@ -349,7 +355,7 @@ Returns a new list with `f` applied to each element of `someList`. ## Examples ```rescript -assertEqual(list{1, 2}->Belt.List.map(x => x + 1), list{2, 3}) +list{1, 2}->Belt.List.map(x => x + 1) == list{2, 3} ``` */ let map: (t<'a>, 'a => 'b) => t<'b> @@ -360,7 +366,7 @@ Returns a list of pairs from the two lists with the length of the shorter list. ## Examples ```rescript -assertEqual(Belt.List.zip(list{1, 2}, list{3, 4, 5}), list{(1, 3), (2, 4)}) +Belt.List.zip(list{1, 2}, list{3, 4, 5}) == list{(1, 3), (2, 4)} ``` */ let zip: (t<'a>, t<'b>) => t<('a, 'b)> @@ -375,7 +381,7 @@ See [Belt.List.zip](#zip) ## Examples ```rescript -assertEqual(Belt.List.zipBy(list{1, 2, 3}, list{4, 5}, (a, b) => 2 * a + b), list{6, 9}) +Belt.List.zipBy(list{1, 2, 3}, list{4, 5}, (a, b) => 2 * a + b) == list{6, 9} ``` */ let zipBy: (t<'a>, t<'b>, ('a, 'b) => 'c) => t<'c> @@ -391,7 +397,7 @@ Function `f` takes two arguments: the index starting from 0 and the element from ## Examples ```rescript -assertEqual(list{1, 2, 3}->Belt.List.mapWithIndex((index, x) => index + x), list{1, 3, 5}) +list{1, 2, 3}->Belt.List.mapWithIndex((index, x) => index + x) == list{1, 3, 5} ``` */ let mapWithIndex: (t<'a>, (int, 'a) => 'b) => t<'b> @@ -402,7 +408,7 @@ Converts the given array to a list. ## Examples ```rescript -assertEqual(Belt.List.fromArray([1, 2, 3]), list{1, 2, 3}) +Belt.List.fromArray([1, 2, 3]) == list{1, 2, 3} ``` */ let fromArray: array<'a> => t<'a> @@ -413,7 +419,7 @@ Converts the given list to an array. ## Examples ```rescript -assertEqual(Belt.List.toArray(list{1, 2, 3}), [1, 2, 3]) +Belt.List.toArray(list{1, 2, 3}) == [1, 2, 3] ``` */ let toArray: t<'a> => array<'a> @@ -429,7 +435,7 @@ Returns a new list whose elements are those of `someList` in reversed order. ## Examples ```rescript -assertEqual(Belt.List.reverse(list{1, 2, 3}), list{3, 2, 1}) +Belt.List.reverse(list{1, 2, 3}) == list{3, 2, 1} ``` */ let reverse: t<'a> => t<'a> @@ -507,11 +513,11 @@ Applies `f` to each element of `someList` from beginning to end. Function `f` ha ## Examples ```rescript -assertEqual(list{1, 2, 3, 4}->Belt.List.reduce(0, (a, b) => a + b), 10) +list{1, 2, 3, 4}->Belt.List.reduce(0, (a, b) => a + b) == 10 /* same as */ -assertEqual(list{1, 2, 3, 4}->Belt.List.reduce(0, (acc, item) => acc + item), 10) +list{1, 2, 3, 4}->Belt.List.reduce(0, (acc, item) => acc + item) == 10 ``` */ let reduce: (t<'a>, 'b, ('b, 'a) => 'b) => 'b @@ -526,10 +532,7 @@ Applies `f` to each element of `someList` from beginning to end. Function `f` ha ## Examples ```rescript -assertEqual( - list{1, 2, 3, 4}->Belt.List.reduceWithIndex(0, (acc, item, index) => acc + item + index), - 16 -) +list{1, 2, 3, 4}->Belt.List.reduceWithIndex(0, (acc, item, index) => acc + item + index) == 16 ``` */ let reduceWithIndex: (t<'a>, 'b, ('b, 'a, int) => 'b) => 'b @@ -545,11 +548,11 @@ item of `someList` from the last back to the first. ## Examples ```rescript -assertEqual(list{1, 2, 3, 4}->Belt.List.reduceReverse(0, (a, b) => a + b), 10) +list{1, 2, 3, 4}->Belt.List.reduceReverse(0, (a, b) => a + b) == 10 -assertEqual(list{1, 2, 3, 4}->Belt.List.reduceReverse(10, (a, b) => a - b), 0) +list{1, 2, 3, 4}->Belt.List.reduceReverse(10, (a, b) => a - b) == 0 -assertEqual(list{1, 2, 3, 4}->Belt.List.reduceReverse(list{}, Belt.List.add), list{1, 2, 3, 4}) +list{1, 2, 3, 4}->Belt.List.reduceReverse(list{}, Belt.List.add) == list{1, 2, 3, 4} ``` */ let reduceReverse: (t<'a>, 'b, ('b, 'a) => 'b) => 'b @@ -564,7 +567,7 @@ Equivalent to: `zipBy(xs, ys, f)->reverse` ## Examples ```rescript -assertEqual(Belt.List.mapReverse2(list{1, 2, 3}, list{1, 2}, (a, b) => a + b), list{4, 2}) +Belt.List.mapReverse2(list{1, 2, 3}, list{1, 2}, (a, b) => a + b) == list{4, 2} ``` */ let mapReverse2: (t<'a>, t<'b>, ('a, 'b) => 'c) => t<'c> @@ -600,10 +603,8 @@ Applies `f` to each element of `firstList` and `secondList` from beginning to en ## Examples ```rescript -assertEqual( - Belt.List.reduce2(list{1, 2, 3}, list{4, 5}, 0, (acc, x, y) => acc + x * x + y), +Belt.List.reduce2(list{1, 2, 3}, list{4, 5}, 0, (acc, x, y) => acc + x * x + y) == 0 + (1 * 1 + 4) + (2 * 2 + 5) -) ``` */ let reduce2: (t<'b>, t<'c>, 'a, ('a, 'b, 'c) => 'a) => 'a @@ -622,10 +623,8 @@ accumulator. ## Examples ```rescript -assertEqual( - Belt.List.reduceReverse2(list{1, 2, 3}, list{4, 5}, 0, (acc, x, y) => acc + x * x + y), +Belt.List.reduceReverse2(list{1, 2, 3}, list{4, 5}, 0, (acc, x, y) => acc + x * x + y) == 0 + (1 * 1 + 4) + (2 * 2 + 5) -) ``` */ let reduceReverse2: (t<'a>, t<'b>, 'c, ('c, 'a, 'b) => 'c) => 'c @@ -642,9 +641,9 @@ Returns `true` if all elements satisfy `pred`, where `pred` is a predicate: a fu ```rescript let isBelow10 = value => value < 10 -assertEqual(list{1, 9, 8, 2}->Belt.List.every(isBelow10), true) +list{1, 9, 8, 2}->Belt.List.every(isBelow10) == true -assertEqual(list{1, 99, 8, 2}->Belt.List.every(isBelow10), false) +list{1, 99, 8, 2}->Belt.List.every(isBelow10) == false ``` */ let every: (t<'a>, 'a => bool) => bool @@ -663,9 +662,9 @@ returning a bool. ```rescript let isAbove100 = value => value > 100 -assertEqual(list{101, 1, 2, 3}->Belt.List.some(isAbove100), true) +list{101, 1, 2, 3}->Belt.List.some(isAbove100) == true -assertEqual(list{1, 2, 3, 4}->Belt.List.some(isAbove100), false) +list{1, 2, 3, 4}->Belt.List.some(isAbove100) == false ``` */ let some: (t<'a>, 'a => bool) => bool @@ -681,13 +680,13 @@ up to the shorter length (i.e. `min(length(firstList), length(secondList))`) ## Examples ```rescript -assertEqual(Belt.List.every2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b), true) +Belt.List.every2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) == true -assertEqual(Belt.List.every2(list{}, list{1}, (a, b) => a > b), true) +Belt.List.every2(list{}, list{1}, (a, b) => a > b) == true -assertEqual(Belt.List.every2(list{2, 3}, list{1}, (a, b) => a > b), true) +Belt.List.every2(list{2, 3}, list{1}, (a, b) => a > b) == true -assertEqual(Belt.List.every2(list{0, 1}, list{5, 0}, (a, b) => a > b), false) +Belt.List.every2(list{0, 1}, list{5, 0}, (a, b) => a > b) == false ``` */ let every2: (t<'a>, t<'b>, ('a, 'b) => bool) => bool @@ -703,13 +702,13 @@ to the shorter length (i.e. `min(length(firstList), length(secondList))`) ## Examples ```rescript -assertEqual(Belt.List.some2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b), true) +Belt.List.some2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) == true -assertEqual(Belt.List.some2(list{}, list{1}, (a, b) => a > b), false) +Belt.List.some2(list{}, list{1}, (a, b) => a > b) == false -assertEqual(Belt.List.some2(list{2, 3}, list{1}, (a, b) => a > b), true) +Belt.List.some2(list{2, 3}, list{1}, (a, b) => a > b) == true -assertEqual(Belt.List.some2(list{0, 1}, list{5, 0}, (a, b) => a > b), true) +Belt.List.some2(list{0, 1}, list{5, 0}, (a, b) => a > b) == true ``` */ let some2: (t<'a>, t<'b>, ('a, 'b) => bool) => bool @@ -723,11 +722,11 @@ less than `length(secondList)`, `0` if `length(firstList)` equals ## Examples ```rescript -assertEqual(Belt.List.cmpByLength(list{1, 2}, list{3, 4, 5, 6}), -1) +Belt.List.cmpByLength(list{1, 2}, list{3, 4, 5, 6}) == -1 -assertEqual(Belt.List.cmpByLength(list{1, 2, 3}, list{4, 5, 6}), 0) +Belt.List.cmpByLength(list{1, 2, 3}, list{4, 5, 6}) == 0 -assertEqual(Belt.List.cmpByLength(list{1, 2, 3, 4}, list{5, 6}), 1) +Belt.List.cmpByLength(list{1, 2, 3, 4}, list{5, 6}) == 1 ``` */ let cmpByLength: (t<'a>, t<'a>) => int @@ -747,15 +746,15 @@ If all items have compared equal, but `secondList` is exhausted first, return `1 ## Examples ```rescript -assertEqual(Belt.List.cmp(list{3}, list{3, 7}, (a, b) => compare(a, b)), (-1)) +Belt.List.cmp(list{3}, list{3, 7}, (a, b) => compare(a, b)) == -1 -assertEqual(Belt.List.cmp(list{5, 3}, list{5}, (a, b) => compare(a, b)), 1) +Belt.List.cmp(list{5, 3}, list{5}, (a, b) => compare(a, b)) == 1 -assertEqual(Belt.List.cmp(list{1, 3, 5}, list{1, 4, 2}, (a, b) => compare(a, b)), (-1)) +Belt.List.cmp(list{1, 3, 5}, list{1, 4, 2}, (a, b) => compare(a, b)) == -1 -assertEqual(Belt.List.cmp(list{1, 3, 5}, list{1, 2, 3}, (a, b) => compare(a, b)), 1) +Belt.List.cmp(list{1, 3, 5}, list{1, 2, 3}, (a, b) => compare(a, b)) == 1 -assertEqual(Belt.List.cmp(list{1, 3, 5}, list{1, 3, 5}, (a, b) => compare(a, b)), 0) +Belt.List.cmp(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, @@ -777,11 +776,11 @@ of `firstList` and `secondList` are not the same. ## Examples ```rescript -assertEqual(Belt.List.eq(list{1, 2, 3}, list{1, 2}, (a, b) => a == b), false) +Belt.List.eq(list{1, 2, 3}, list{1, 2}, (a, b) => a == b) == false -assertEqual(Belt.List.eq(list{1, 2}, list{1, 2}, (a, b) => a == b), true) +Belt.List.eq(list{1, 2}, list{1, 2}, (a, b) => a == b) == true -assertEqual(Belt.List.eq(list{1, 2, 3}, list{(-1), (-2), (-3)}, (a, b) => abs(a) == abs(b)), true) +Belt.List.eq(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 @@ -797,11 +796,11 @@ Returns `true` if the list contains at least one element for which ## Examples ```rescript -assertEqual(list{1, 2, 3}->Belt.List.has(2, (a, b) => a == b), true) +list{1, 2, 3}->Belt.List.has(2, (a, b) => a == b) == true -assertEqual(list{1, 2, 3}->Belt.List.has(4, (a, b) => a == b), false) +list{1, 2, 3}->Belt.List.has(4, (a, b) => a == b) == false -assertEqual(list{(-1), (-2), (-3)}->Belt.List.has(2, (a, b) => abs(a) == abs(b)), true) +list{-1, -2, -3}->Belt.List.has(2, (a, b) => abs(a) == abs(b)) == true ``` */ let has: (t<'a>, 'b, ('a, 'b) => bool) => bool @@ -817,9 +816,9 @@ predicate function `pred`. Returns `None` if no element satisfies the function. ## Examples ```rescript -assertEqual(Belt.List.getBy(list{1, 4, 3, 2}, x => x > 3), Some(4)) +Belt.List.getBy(list{1, 4, 3, 2}, x => x > 3) == Some(4) -assertEqual(Belt.List.getBy(list{1, 4, 3, 2}, x => x > 4), None) +Belt.List.getBy(list{1, 4, 3, 2}, x => x > 4) == None ``` */ let getBy: (t<'a>, 'a => bool) => option<'a> @@ -836,9 +835,9 @@ Returns a list of all elements in `someList` which satisfy the predicate functio ```rescript let isEven = x => mod(x, 2) == 0 -assertEqual(Belt.List.keep(list{1, 2, 3, 4}, isEven), list{2, 4}) +Belt.List.keep(list{1, 2, 3, 4}, isEven) == list{2, 4} -assertEqual(Belt.List.keep(list{None, Some(2), Some(3), None}, Belt.Option.isSome), list{Some(2), Some(3)}) +Belt.List.keep(list{None, Some(2), Some(3), None}, Belt.Option.isSome) == list{Some(2), Some(3)} ``` */ let keep: (t<'a>, 'a => bool) => t<'a> @@ -851,9 +850,9 @@ Returns a list of all elements in `someList` which satisfy the predicate functio ```rescript let isEven = x => mod(x, 2) == 0 -assertEqual(Belt.List.filter(list{1, 2, 3, 4}, isEven), list{2, 4}) +Belt.List.filter(list{1, 2, 3, 4}, isEven) == list{2, 4} -assertEqual(Belt.List.filter(list{None, Some(2), Some(3), None}, Belt.Option.isSome), list{Some(2), Some(3)}) +Belt.List.filter(list{None, Some(2), Some(3), None}, Belt.Option.isSome) == list{Some(2), Some(3)} ``` */ @deprecated("This function will soon be deprecated. Please, use `List.keep` instead.") @@ -871,7 +870,7 @@ Returns a list of all elements in `someList` which satisfy the predicate functio ```rescript let isEven = x => mod(x, 2) == 0 -assertEqual(Belt.List.keepWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)), list{1, 3}) +Belt.List.keepWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) == list{1, 3} ``` */ let keepWithIndex: (t<'a>, ('a, int) => bool) => t<'a> @@ -884,7 +883,7 @@ Returns a list of all elements in `someList` which satisfy the predicate functio ```rescript let isEven = x => mod(x, 2) == 0 -assertEqual(Belt.List.filterWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)), list{1, 3}) +Belt.List.filterWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) == list{1, 3} ``` */ @deprecated( @@ -906,16 +905,15 @@ If `f(x)` returns `None`, the element is _not_ retained in the result. ```rescript let isEven = x => mod(x, 2) == 0 -list{1, 2, 3, 4} -->Belt.List.keepMap(x => - if (isEven(x)) { - Some(x) - } else { - None - } - ) /* list{2, 4} */ - -assertEqual(list{Some(1), Some(2), None}->Belt.List.keepMap(x => x), list{1, 2}) +list{1, 2, 3, 4}->Belt.List.keepMap(x => + if isEven(x) { + Some(x) + } else { + None + } +) /* list{2, 4} */ + +list{Some(1), Some(2), None}->Belt.List.keepMap(x => x) == list{1, 2} ``` */ let keepMap: (t<'a>, 'a => option<'b>) => t<'b> @@ -925,7 +923,7 @@ let keepMap: (t<'a>, 'a => option<'b>) => t<'b> let partitionU: (t<'a>, 'a => bool) => (t<'a>, t<'a>) /** -Creates a pair of lists; the first list consists of all elements of `someList` that satisfy the predicate function `pred`; the second list consists of all elements of `someList` that _do not_ satisfy `pred. +Creates a pair of lists; the first list consists of all elements of `someList` that satisfy the predicate function `pred`; the second list consists of all elements of `someList` that _do not_ satisfy \`pred. In other words: @@ -949,12 +947,10 @@ Takes a list of pairs and creates a pair of lists. The first list contains all t ## Examples ```rescript -assertEqual(Belt.List.unzip(list{(1, 2), (3, 4)}), (list{1, 3}, list{2, 4})) +Belt.List.unzip(list{(1, 2), (3, 4)}) == (list{1, 3}, list{2, 4}) -assertEqual( - Belt.List.unzip(list{("H", "W"), ("e", "o"), ("l", "r"), ("l", "l"), ("o", "d"), (" ", "!")}), +Belt.List.unzip(list{("H", "W"), ("e", "o"), ("l", "r"), ("l", "l"), ("o", "d"), (" ", "!")}) == (list{"H", "e", "l", "l", "o", " "}, list{"W", "o", "r", "l", "d", "!"}) -) ``` */ let unzip: t<('a, 'b)> => (t<'a>, t<'b>) @@ -971,11 +967,9 @@ Return the second element of a pair in `someList` where the first element equals ```rescript list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.getAssoc(3, (a, b) => a == b) /* Some("c") */ -assertEqual( - list{(9, "morning"), (15, "afternoon"), (22, "night")} - ->Belt.List.getAssoc(15, (k, item) => k /* 15 */ == item /* 9, 5, 22 */), - Some("afternoon") -) +list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.getAssoc(15, (k, item) => + k /* 15 */ == item + /* 9, 5, 22 */) == Some("afternoon") ``` */ let getAssoc: (t<('a, 'c)>, 'b, ('a, 'b) => bool) => option<'c> @@ -990,15 +984,11 @@ Returns `true` if there is a pair in `someList` where the first element equals ` ## Examples ```rescript -assertEqual( - list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.hasAssoc(1, (a, b) => a == b), - true -) +list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.hasAssoc(1, (a, b) => a == b) == true -assertEqual( - list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.hasAssoc(25, (k, item) => k /* 25 */ == item /* 9, 5, 22 */), - false -) +list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.hasAssoc(25, (k, item) => + k /* 25 */ == item + /* 9, 5, 22 */) == false ``` */ let hasAssoc: (t<('a, 'c)>, 'b, ('a, 'b) => bool) => bool @@ -1013,16 +1003,12 @@ Return a list after removing the first pair whose first value is `k` per the equ ## Examples ```rescript -assertEqual( - list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.removeAssoc(1, (a, b) => a == b), +list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.removeAssoc(1, (a, b) => a == b) == list{(2, "b"), (3, "c")} -) -assertEqual( - list{(9, "morning"), (15, "afternoon"), (22, "night")} - ->Belt.List.removeAssoc(9, (k, item) => k /* 9 */ == item /* 9, 5, 22 */), - list{(15, "afternoon"), (22, "night")} -) +list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.removeAssoc(9, (k, item) => + k /* 9 */ == item + /* 9, 5, 22 */) == list{(15, "afternoon"), (22, "night")} ``` */ let removeAssoc: (t<('a, 'c)>, 'b, ('a, 'b) => bool) => t<('a, 'c)> @@ -1037,21 +1023,15 @@ If `k` exists in `someList` by satisfying the `eqFunction` predicate, return a n ## Examples ```rescript -assertEqual( - list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.setAssoc(2, "x", (a, b) => a == b), +list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.setAssoc(2, "x", (a, b) => a == b) == list{(1, "a"), (2, "x"), (3, "c")} -) -assertEqual( - list{(1, "a"), (3, "c")}->Belt.List.setAssoc(2, "b", (a, b) => a == b), +list{(1, "a"), (3, "c")}->Belt.List.setAssoc(2, "b", (a, b) => a == b) == list{(2, "b"), (1, "a"), (3, "c")} -) -assertEqual( - list{(9, "morning"), (3, "morning?!"), (22, "night")} - ->Belt.List.setAssoc(15, "afternoon", (a, b) => mod(a, 12) == mod(b, 12)), - list{(9, "morning"), (15, "afternoon"), (22, "night")} -) +list{(9, "morning"), (3, "morning?!"), (22, "night")}->Belt.List.setAssoc(15, "afternoon", (a, b) => + mod(a, 12) == mod(b, 12) +) == list{(9, "morning"), (15, "afternoon"), (22, "night")} ``` **Please note** @@ -1072,10 +1052,7 @@ Returns a sorted list. ## Examples ```rescript -assertEqual( - Belt.List.sort(list{5, 4, 9, 3, 7}, (a, b) => a - b), - list{3, 4, 5, 7, 9} -) +Belt.List.sort(list{5, 4, 9, 3, 7}, (a, b) => a - b) == list{3, 4, 5, 7, 9} ``` */ let sort: (t<'a>, ('a, 'a) => int) => t<'a> diff --git a/runtime/Belt_Map.resi b/runtime/Belt_Map.resi index 20d1c5babb..ebf9dc68a1 100644 --- a/runtime/Belt_Map.resi +++ b/runtime/Belt_Map.resi @@ -75,7 +75,7 @@ module IntCmp = Belt.Id.MakeComparable({ let cmp = (a, b) => Pervasives.compare(a, b) }) -assertEqual(Belt.Map.isEmpty(Belt.Map.fromArray([(1, "1")], ~id=module(IntCmp))), false) +Belt.Map.isEmpty(Belt.Map.fromArray([(1, "1")], ~id=module(IntCmp))) == false ``` */ let isEmpty: t<_> => bool @@ -87,11 +87,11 @@ let isEmpty: t<_> => bool ```rescript module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) }) -assertEqual(Belt.Map.has(Belt.Map.fromArray([(1, "1")], ~id=module(IntCmp)), 1), true) +Belt.Map.has(Belt.Map.fromArray([(1, "1")], ~id=module(IntCmp)), 1) == true ``` */ let has: (t<'k, 'v, 'id>, 'k) => bool @@ -160,7 +160,7 @@ let acc = ref(list{}) Belt.Map.forEach(s0, (k, v) => acc := list{(k, v), ...acc.contents}) -assertEqual(acc.contents, list{(4, "4"), (3, "3"), (2, "2"), (1, "1")}) +acc.contents == list{(4, "4"), (3, "3"), (2, "2"), (1, "1")} ``` */ let forEach: (t<'k, 'v, 'id>, ('k, 'v) => unit) => unit @@ -182,13 +182,8 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "3")]) -assertEqual( - Belt.Map.reduce(s0, list{}, (acc, k, v) => list{ - (k, v), - ...acc, - }), +Belt.Map.reduce(s0, list{}, (acc, k, v) => list{(k, v), ...acc}) == list{(4, "4"), (3, "3"), (2, "2"), (1, "1")} -) ``` */ let reduce: (t<'k, 'v, 'id>, 'acc, ('acc, 'k, 'v) => 'acc) => 'acc @@ -219,10 +214,7 @@ module IntCmp = Belt.Id.MakeComparable({ let cmp = (a, b) => Pervasives.compare(a, b) }) -assertEqual( - Belt.Map.size(Belt.Map.fromArray([(2, "2"), (2, "1"), (3, "3")], ~id=module(IntCmp))), - 2 -) +Belt.Map.size(Belt.Map.fromArray([(2, "2"), (2, "1"), (3, "3")], ~id=module(IntCmp))) == 2 ``` */ let size: t<'k, 'v, 'id> => int @@ -238,14 +230,11 @@ module IntCmp = Belt.Id.MakeComparable({ let cmp = (a, b) => Pervasives.compare(a, b) }) -assertEqual( - Belt.Map.toArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))), - [ +Belt.Map.toArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))) == [ (1, "1"), (2, "2"), (3, "3"), ] -) ``` */ let toArray: t<'k, 'v, 'id> => array<('k, 'v)> @@ -264,14 +253,11 @@ module IntCmp = Belt.Id.MakeComparable({ let cmp = (a, b) => Pervasives.compare(a, b) }) -assertEqual( - Belt.Map.toArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))), - [ +Belt.Map.toArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))) == [ (1, "1"), (2, "2"), (3, "3"), ] -) ``` */ let fromArray: (array<('k, 'v)>, ~id: id<'k, 'id>) => t<'k, 'v, 'id> @@ -287,10 +273,11 @@ module IntCmp = Belt.Id.MakeComparable({ let cmp = (a, b) => Pervasives.compare(a, b) }) -assertEqual( - Belt.Map.keysToArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))), - [1, 2, 3] -) +Belt.Map.keysToArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))) == [ + 1, + 2, + 3, + ] ``` */ let keysToArray: t<'k, 'v, 'id> => array<'k> @@ -306,12 +293,11 @@ module IntCmp = Belt.Id.MakeComparable({ let cmp = (a, b) => Pervasives.compare(a, b) }) -assertEqual( - Belt.Map.valuesToArray( - Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), - ), - ["1", "2", "3"] -) +Belt.Map.valuesToArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))) == [ + "1", + "2", + "3", + ] ``` */ let valuesToArray: t<'k, 'v, 'id> => array<'v> @@ -351,15 +337,9 @@ module IntCmp = Belt.Id.MakeComparable({ let cmp = (a, b) => Pervasives.compare(a, b) }) -assertEqual( - Belt.Map.get(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), 2), - Some("2") -) +Belt.Map.get(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), 2) == Some("2") -assertEqual( - Belt.Map.get(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), 4), - None -) +Belt.Map.get(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), 4) == None ``` */ let get: (t<'k, 'v, 'id>, 'k) => option<'v> @@ -413,9 +393,9 @@ let s1 = Belt.Map.remove(s0, 1) let s2 = Belt.Map.remove(s1, 1) -assertEqual(s1, s2) +s1 == s2 -assertEqual(Belt.Map.keysToArray(s1), [2, 3]) +Belt.Map.keysToArray(s1) == [2, 3] ``` */ let remove: (t<'k, 'v, 'id>, 'k) => t<'k, 'v, 'id> @@ -445,7 +425,7 @@ let s0 = Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)) let s1 = Belt.Map.set(s0, 2, "3") -assertEqual(Belt.Map.valuesToArray(s1), ["1", "3", "3"]) +Belt.Map.valuesToArray(s1) == ["1", "3", "3"] ``` */ let set: (t<'k, 'v, 'id>, 'k, 'v) => t<'k, 'v, 'id> diff --git a/runtime/Belt_MapDict.resi b/runtime/Belt_MapDict.resi index 729061597e..8866d1146b 100644 --- a/runtime/Belt_MapDict.resi +++ b/runtime/Belt_MapDict.resi @@ -72,13 +72,13 @@ match predicate `p`. ```rescript module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare + type t = int + let cmp = Pervasives.compare }) let s0 = Belt.Map.Dict.fromArray([(4, "4"), (1, "1"), (2, "2"), (3, "3")], ~cmp=IntCmp.cmp) -assertEqual(Belt.Map.Dict.findFirstBy(s0, (k, _) => k == 4), Some((4, "4"))) +Belt.Map.Dict.findFirstBy(s0, (k, _) => k == 4) == Some((4, "4")) ``` */ let findFirstBy: (t<'k, 'v, 'id>, ('k, 'v) => bool) => option<('k, 'v)> diff --git a/runtime/Belt_MapInt.resi b/runtime/Belt_MapInt.resi index d45ced168e..277e9bbe8f 100644 --- a/runtime/Belt_MapInt.resi +++ b/runtime/Belt_MapInt.resi @@ -35,8 +35,8 @@ to match predicate `p`. ```rescript let mapInt = Belt.Map.Int.fromArray([(1, "one"), (2, "two"), (3, "three")]) -mapInt-> -Belt.Map.Int.findFirstBy((k, v) => k == 1 && v == "one") +mapInt +->Belt.Map.Int.findFirstBy((k, v) => k == 1 && v == "one") ->assertEqual(Some(1, "one")) ``` */ diff --git a/runtime/Belt_MapString.resi b/runtime/Belt_MapString.resi index ed68669798..5ee67f6817 100644 --- a/runtime/Belt_MapString.resi +++ b/runtime/Belt_MapString.resi @@ -35,8 +35,8 @@ to match predicate `p`. ```rescript let mapString = Belt.Map.String.fromArray([("1", "one"), ("2", "two"), ("3", "three")]) -mapString-> -Belt.Map.String.findFirstBy((k, v) => k == "1" && v == "one") +mapString +->Belt.Map.String.findFirstBy((k, v) => k == "1" && v == "one") ->assertEqual(Some("1", "one")) ``` */ diff --git a/runtime/Belt_MutableSet.resi b/runtime/Belt_MutableSet.resi index aac4e7de5e..f595a91b29 100644 --- a/runtime/Belt_MutableSet.resi +++ b/runtime/Belt_MutableSet.resi @@ -81,7 +81,7 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.MutableSet.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) -assertEqual(s0->Belt.MutableSet.toArray, [1, 2, 3, 4]) +s0->Belt.MutableSet.toArray == [1, 2, 3, 4] ``` */ let fromArray: (array<'value>, ~id: id<'value, 'id>) => t<'value, 'id> @@ -105,7 +105,7 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.MutableSet.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) let copied = s0->Belt.MutableSet.copy -assertEqual(copied->Belt.MutableSet.toArray, [1, 2, 3, 4]) +copied->Belt.MutableSet.toArray == [1, 2, 3, 4] ``` */ let copy: t<'value, 'id> => t<'value, 'id> @@ -124,8 +124,8 @@ module IntCmp = Belt.Id.MakeComparable({ let empty = Belt.MutableSet.fromArray([], ~id=module(IntCmp)) let notEmpty = Belt.MutableSet.fromArray([1], ~id=module(IntCmp)) -assertEqual(Belt.MutableSet.isEmpty(empty), true) -assertEqual(Belt.MutableSet.isEmpty(notEmpty), false) +Belt.MutableSet.isEmpty(empty) == true +Belt.MutableSet.isEmpty(notEmpty) == false ``` */ let isEmpty: t<_> => bool @@ -143,8 +143,8 @@ module IntCmp = Belt.Id.MakeComparable({ let set = Belt.MutableSet.fromArray([1, 4, 2, 5], ~id=module(IntCmp)) -assertEqual(set->Belt.MutableSet.has(3), false) -assertEqual(set->Belt.MutableSet.has(1), true) +set->Belt.MutableSet.has(3) == false +set->Belt.MutableSet.has(1) == true ``` */ let has: (t<'value, 'id>, 'value) => bool @@ -165,7 +165,7 @@ s0->Belt.MutableSet.add(1) s0->Belt.MutableSet.add(2) s0->Belt.MutableSet.add(2) -assertEqual(s0->Belt.MutableSet.toArray, [1, 2]) +s0->Belt.MutableSet.toArray == [1, 2] ``` */ let add: (t<'value, 'id>, 'value) => unit @@ -186,7 +186,7 @@ module IntCmp = Belt.Id.MakeComparable({ let set = Belt.MutableSet.make(~id=module(IntCmp)) set->Belt.MutableSet.mergeMany([5, 4, 3, 2, 1]) -assertEqual(set->Belt.MutableSet.toArray, [1, 2, 3, 4, 5]) +set->Belt.MutableSet.toArray == [1, 2, 3, 4, 5] ``` */ let mergeMany: (t<'value, 'id>, array<'value>) => unit @@ -207,7 +207,7 @@ s0->Belt.MutableSet.remove(1) s0->Belt.MutableSet.remove(3) s0->Belt.MutableSet.remove(3) -assertEqual(s0->Belt.MutableSet.toArray, [2,4,5]) +s0->Belt.MutableSet.toArray == [2, 4, 5] ``` */ let remove: (t<'value, 'id>, 'value) => unit @@ -229,7 +229,7 @@ module IntCmp = Belt.Id.MakeComparable({ let set = Belt.MutableSet.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) set->Belt.MutableSet.removeMany([5, 4, 3, 2, 1]) -assertEqual(set->Belt.MutableSet.toArray, []) +set->Belt.MutableSet.toArray == [] ``` */ let removeMany: (t<'value, 'id>, array<'value>) => unit @@ -248,7 +248,7 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) let union = Belt.MutableSet.union(s0, s1) -assertEqual(union->Belt.MutableSet.toArray, [1,2,3,4,5,6]) +union->Belt.MutableSet.toArray == [1, 2, 3, 4, 5, 6] ``` */ let union: (t<'value, 'id>, t<'value, 'id>) => t<'value, 'id> @@ -267,7 +267,7 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) let intersect = Belt.MutableSet.intersect(s0, s1) -assertEqual(intersect->Belt.MutableSet.toArray, [2,3,5]) +intersect->Belt.MutableSet.toArray == [2, 3, 5] ``` */ let intersect: (t<'value, 'id>, t<'value, 'id>) => t<'value, 'id> @@ -285,8 +285,8 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) -assertEqual(Belt.MutableSet.toArray(Belt.MutableSet.diff(s0, s1)), [6]) -assertEqual(Belt.MutableSet.toArray(Belt.MutableSet.diff(s1, s0)), [1,4]) +Belt.MutableSet.toArray(Belt.MutableSet.diff(s0, s1)) == [6] +Belt.MutableSet.toArray(Belt.MutableSet.diff(s1, s0)) == [1, 4] ``` */ let diff: (t<'value, 'id>, t<'value, 'id>) => t<'value, 'id> @@ -305,9 +305,9 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) let s2 = Belt.MutableSet.intersect(s0, s1) -assertEqual(Belt.MutableSet.subset(s2, s0), true) -assertEqual(Belt.MutableSet.subset(s2, s1), true) -assertEqual(Belt.MutableSet.subset(s1, s0), false) +Belt.MutableSet.subset(s2, s0) == true +Belt.MutableSet.subset(s2, s1) == true +Belt.MutableSet.subset(s1, s0) == false ``` */ let subset: (t<'value, 'id>, t<'value, 'id>) => bool @@ -332,7 +332,7 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.MutableSet.fromArray([5, 2, 3], ~id=module(IntCmp)) let s1 = Belt.MutableSet.fromArray([3, 2, 5], ~id=module(IntCmp)) -assertEqual(Belt.MutableSet.eq(s0, s1), true) +Belt.MutableSet.eq(s0, s1) == true ``` */ let eq: (t<'value, 'id>, t<'value, 'id>) => bool @@ -357,7 +357,7 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) let acc = ref(list{}) s0->Belt.MutableSet.forEach(x => acc := Belt.List.add(acc.contents, x)) -assertEqual(acc.contents, list{6, 5, 3, 2}) +acc.contents == list{6, 5, 3, 2} ``` */ let forEach: (t<'value, 'id>, 'value => unit) => unit @@ -377,10 +377,8 @@ module IntCmp = Belt.Id.MakeComparable({ }) let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) -assertEqual( - s0->Belt.MutableSet.reduce(list{}, (acc, element) => acc->Belt.List.add(element)), +s0->Belt.MutableSet.reduce(list{}, (acc, element) => acc->Belt.List.add(element)) == list{6, 5, 3, 2} -) ``` */ let reduce: (t<'value, 'id>, 'a, ('a, 'value) => 'a) => 'a @@ -402,7 +400,7 @@ module IntCmp = Belt.Id.MakeComparable({ let isEven = x => mod(x, 2) == 0 let s0 = Belt.MutableSet.fromArray([2, 4, 6, 8], ~id=module(IntCmp)) -assertEqual(s0->Belt.MutableSet.every(isEven), true) +s0->Belt.MutableSet.every(isEven) == true ``` */ let every: (t<'value, 'id>, 'value => bool) => bool @@ -424,7 +422,7 @@ module IntCmp = Belt.Id.MakeComparable({ let isOdd = x => mod(x, 2) != 0 let s0 = Belt.MutableSet.fromArray([1, 2, 4, 6, 8], ~id=module(IntCmp)) -assertEqual(s0->Belt.MutableSet.some(isOdd), true) +s0->Belt.MutableSet.some(isOdd) == true ``` */ let some: (t<'value, 'id>, 'value => bool) => bool @@ -448,7 +446,7 @@ let isEven = x => mod(x, 2) == 0 let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) let s1 = s0->Belt.MutableSet.keep(isEven) -assertEqual(s1->Belt.MutableSet.toArray, [2, 4]) +s1->Belt.MutableSet.toArray == [2, 4] ``` */ let keep: (t<'value, 'id>, 'value => bool) => t<'value, 'id> @@ -470,8 +468,8 @@ let isOdd = x => mod(x, 2) != 0 let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) let (s1, s2) = s0->Belt.MutableSet.partition(isOdd) -assertEqual(s1->Belt.MutableSet.toArray, [1,3,5]) -assertEqual(s2->Belt.MutableSet.toArray, [2,4]) +s1->Belt.MutableSet.toArray == [1, 3, 5] +s2->Belt.MutableSet.toArray == [2, 4] ``` */ let partition: (t<'value, 'id>, 'value => bool) => (t<'value, 'id>, t<'value, 'id>) @@ -489,7 +487,7 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) -assertEqual(s0->Belt.MutableSet.size, 4) +s0->Belt.MutableSet.size == 4 ``` */ let size: t<'value, 'id> => int @@ -507,7 +505,7 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) -assertEqual(s0->Belt.MutableSet.toList, list{1, 2, 3, 5}) +s0->Belt.MutableSet.toList == list{1, 2, 3, 5} ``` */ let toList: t<'value, 'id> => list<'value> @@ -525,7 +523,7 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) -assertEqual(s0->Belt.MutableSet.toArray, [1,2,3,5]) +s0->Belt.MutableSet.toArray == [1, 2, 3, 5] ``` */ let toArray: t<'value, 'id> => array<'value> @@ -544,8 +542,8 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.MutableSet.make(~id=module(IntCmp)) let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) -assertEqual(s0->Belt.MutableSet.minimum, None) -assertEqual(s1->Belt.MutableSet.minimum, Some(1)) +s0->Belt.MutableSet.minimum == None +s1->Belt.MutableSet.minimum == Some(1) ``` */ let minimum: t<'value, 'id> => option<'value> @@ -564,8 +562,8 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.MutableSet.make(~id=module(IntCmp)) let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) -assertEqual(s0->Belt.MutableSet.minUndefined, Js.undefined) -assertEqual(s1->Belt.MutableSet.minUndefined, Js.Undefined.return(1)) +s0->Belt.MutableSet.minUndefined == Js.undefined +s1->Belt.MutableSet.minUndefined == Js.Undefined.return(1) ``` */ let minUndefined: t<'value, 'id> => Js.undefined<'value> @@ -584,8 +582,8 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.MutableSet.make(~id=module(IntCmp)) let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) -assertEqual(s0->Belt.MutableSet.maximum, None) -assertEqual(s1->Belt.MutableSet.maximum, Some(5)) +s0->Belt.MutableSet.maximum == None +s1->Belt.MutableSet.maximum == Some(5) ``` */ let maximum: t<'value, 'id> => option<'value> @@ -604,8 +602,8 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.MutableSet.make(~id=module(IntCmp)) let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) -assertEqual(s0->Belt.MutableSet.maxUndefined, Js.undefined) -assertEqual(s1->Belt.MutableSet.maxUndefined, Js.Undefined.return(5)) +s0->Belt.MutableSet.maxUndefined == Js.undefined +s1->Belt.MutableSet.maxUndefined == Js.Undefined.return(5) ``` */ let maxUndefined: t<'value, 'id> => Js.undefined<'value> @@ -623,8 +621,8 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) -assertEqual(s0->Belt.MutableSet.get(3), Some(3)) -assertEqual(s0->Belt.MutableSet.get(20), None) +s0->Belt.MutableSet.get(3) == Some(3) +s0->Belt.MutableSet.get(20) == None ``` */ let get: (t<'value, 'id>, 'value) => option<'value> @@ -659,9 +657,9 @@ let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) let ((smaller, larger), present) = s0->Belt.MutableSet.split(3) -assertEqual(present, true) -assertEqual(smaller->Belt.MutableSet.toArray, [1,2]) -assertEqual(larger->Belt.MutableSet.toArray, [4,5]) +present == true +smaller->Belt.MutableSet.toArray == [1, 2] +larger->Belt.MutableSet.toArray == [4, 5] ``` */ let split: (t<'value, 'id>, 'value) => ((t<'value, 'id>, t<'value, 'id>), bool) diff --git a/runtime/Belt_Option.resi b/runtime/Belt_Option.resi index 32a8933ef9..ce087901c8 100644 --- a/runtime/Belt_Option.resi +++ b/runtime/Belt_Option.resi @@ -50,9 +50,9 @@ If `optionValue` is `Some(value)` and `p(value) = true`, it returns `Some(value) ## Examples ```rescript -assertEqual(Belt.Option.keep(Some(10), x => x > 5), Some(10)) -assertEqual(Belt.Option.keep(Some(4), x => x > 5), None) -assertEqual(Belt.Option.keep(None, x => x > 5), None) +Belt.Option.keep(Some(10), x => x > 5) == Some(10) +Belt.Option.keep(Some(4), x => x > 5) == None +Belt.Option.keep(None, x => x > 5) == None ``` */ let keep: (option<'a>, 'a => bool) => option<'a> @@ -83,7 +83,8 @@ Some(3) ->Belt.Option.getExn ->assertEqual(3) -switch Belt.Option.getExn(None) { // Raises an exception +switch Belt.Option.getExn(None) { +// Raises an exception | exception _ => assert(true) | _ => assert(false) } @@ -101,7 +102,8 @@ Some(3) ->Belt.Option.getOrThrow ->assertEqual(3) -switch Belt.Option.getOrThrow(None) { // Raises an exception +switch Belt.Option.getOrThrow(None) { +// Raises an exception | exception _ => assert(true) | _ => assert(false) } @@ -131,10 +133,10 @@ If `optionValue` is `None`, the default is returned. ```rescript let someValue = Some(3) -assertEqual(someValue->Belt.Option.mapWithDefault(0, x => x + 5), 8) +someValue->Belt.Option.mapWithDefault(0, x => x + 5) == 8 let noneValue = None -assertEqual(noneValue->Belt.Option.mapWithDefault(0, x => x + 5), 0) +noneValue->Belt.Option.mapWithDefault(0, x => x + 5) == 0 ``` */ let mapWithDefault: (option<'a>, 'b, 'a => 'b) => 'b @@ -149,9 +151,9 @@ If `optionValue` is `Some(value)` this returns `f(value)`, otherwise it returns ## Examples ```rescript -assertEqual(Belt.Option.map(Some(3), x => x * x), Some(9)) +Belt.Option.map(Some(3), x => x * x) == Some(9) -assertEqual(Belt.Option.map(None, x => x * x), None) +Belt.Option.map(None, x => x * x) == None ``` */ let map: (option<'a>, 'a => 'b) => option<'b> @@ -169,17 +171,17 @@ The function `f` must have a return type of `option<'b>`. ```rescript let addIfAboveOne = value => - if (value > 1) { - Some(value + 1) - } else { - None - } + if value > 1 { + Some(value + 1) + } else { + None + } -assertEqual(Belt.Option.flatMap(Some(2), addIfAboveOne), Some(3)) +Belt.Option.flatMap(Some(2), addIfAboveOne) == Some(3) -assertEqual(Belt.Option.flatMap(Some(-4), addIfAboveOne), None) +Belt.Option.flatMap(Some(-4), addIfAboveOne) == None -assertEqual(Belt.Option.flatMap(None, addIfAboveOne), None) +Belt.Option.flatMap(None, addIfAboveOne) == None ``` */ let flatMap: (option<'a>, 'a => option<'b>) => option<'b> @@ -190,18 +192,18 @@ If `optionalValue` is `Some(value)`, returns `value`, otherwise default. ## Examples ```rescript -assertEqual(Belt.Option.getWithDefault(None, "Banana"), "Banana") +Belt.Option.getWithDefault(None, "Banana") == "Banana" -assertEqual(Belt.Option.getWithDefault(Some("Apple"), "Banana"), "Apple") +Belt.Option.getWithDefault(Some("Apple"), "Banana") == "Apple" ``` ```rescript let greet = (firstName: option) => - "Greetings " ++ firstName->Belt.Option.getWithDefault("Anonymous") + "Greetings " ++ firstName->Belt.Option.getWithDefault("Anonymous") -assertEqual(Some("Jane")->greet, "Greetings Jane") +Some("Jane")->greet == "Greetings Jane" -assertEqual(None->greet, "Greetings Anonymous") +None->greet == "Greetings Anonymous" ``` */ let getWithDefault: (option<'a>, 'a) => 'a @@ -213,9 +215,9 @@ returns `Some(value)`, otherwise `otherOptional` ## Examples ```rescript -assertEqual(Belt.Option.orElse(Some(1812), Some(1066)), Some(1812)) -assertEqual(Belt.Option.orElse(None, Some(1066)), Some(1066)) -assertEqual(Belt.Option.orElse(None, None), None) +Belt.Option.orElse(Some(1812), Some(1066)) == Some(1812) +Belt.Option.orElse(None, Some(1066)) == Some(1066) +Belt.Option.orElse(None, None) == None ``` */ let orElse: (option<'a>, option<'a>) => option<'a> @@ -226,9 +228,9 @@ Returns `true` if the argument is `Some(value)`, `false` otherwise. ## Examples ```rescript -assertEqual(Belt.Option.isSome(None), false) +Belt.Option.isSome(None) == false -assertEqual(Belt.Option.isSome(Some(1)), true) +Belt.Option.isSome(Some(1)) == true ``` */ let isSome: option<'a> => bool @@ -239,9 +241,9 @@ Returns `true` if the argument is `None`, `false` otherwise. ## Examples ```rescript -assertEqual(Belt.Option.isNone(None), true) +Belt.Option.isNone(None) == true -assertEqual(Belt.Option.isNone(Some(1)), false) +Belt.Option.isNone(Some(1)) == false ``` */ let isNone: option<'a> => bool @@ -268,13 +270,13 @@ let clockEqual = (a, b) => mod(a, 12) == mod(b, 12) open Belt.Option -assertEqual(eq(Some(3), Some(15), clockEqual), true) +eq(Some(3), Some(15), clockEqual) == true -assertEqual(eq(Some(3), None, clockEqual), false) +eq(Some(3), None, clockEqual) == false -assertEqual(eq(None, Some(3), clockEqual), false) +eq(None, Some(3), clockEqual) == false -assertEqual(eq(None, None, clockEqual), true) +eq(None, None, clockEqual) == true ``` */ let eq: (option<'a>, option<'b>, ('a, 'b) => bool) => bool @@ -309,17 +311,17 @@ let clockCompare = (a, b) => compare(mod(a, 12), mod(b, 12)) open Belt.Option -assertEqual(cmp(Some(3), Some(15), clockCompare), 0) +cmp(Some(3), Some(15), clockCompare) == 0 -assertEqual(cmp(Some(3), Some(14), clockCompare), 1) +cmp(Some(3), Some(14), clockCompare) == 1 -assertEqual(cmp(Some(2), Some(15), clockCompare), (-1)) +cmp(Some(2), Some(15), clockCompare) == -1 -assertEqual(cmp(None, Some(15), clockCompare), (-1)) +cmp(None, Some(15), clockCompare) == -1 -assertEqual(cmp(Some(14), None, clockCompare), 1) +cmp(Some(14), None, clockCompare) == 1 -assertEqual(cmp(None, None, clockCompare), 0) +cmp(None, None, clockCompare) == 0 ``` */ let cmp: (option<'a>, option<'b>, ('a, 'b) => int) => int diff --git a/runtime/Belt_Range.resi b/runtime/Belt_Range.resi index 49e37b17e9..d68393e542 100644 --- a/runtime/Belt_Range.resi +++ b/runtime/Belt_Range.resi @@ -37,7 +37,7 @@ let forEachU: (int, int, int => unit) => unit ## Examples ```rescript -Belt.Range.forEach(0, 4, (i) => Js.log(i)) +Belt.Range.forEach(0, 4, i => Js.log(i)) // Prints: // 0 @@ -57,9 +57,9 @@ let everyU: (int, int, int => bool) => bool ## Examples ```rescript -assertEqual(Belt.Range.every(0, 4, (i) => i < 5), true) +Belt.Range.every(0, 4, i => i < 5) == true -assertEqual(Belt.Range.every(0, 4, (i) => i < 4), false) +Belt.Range.every(0, 4, i => i < 4) == false ``` */ let every: (int, int, int => bool) => bool @@ -74,9 +74,9 @@ let everyByU: (int, int, ~step: int, int => bool) => bool ## Examples ```rescript -assertEqual(Belt.Range.everyBy(0, 4, ~step=1, (i) => mod(i, 2) === 0), false) +Belt.Range.everyBy(0, 4, ~step=1, i => mod(i, 2) === 0) == false -assertEqual(Belt.Range.everyBy(0, 4, ~step=2, (i) => mod(i, 2) === 0), true) +Belt.Range.everyBy(0, 4, ~step=2, i => mod(i, 2) === 0) == true ``` */ let everyBy: (int, int, ~step: int, int => bool) => bool @@ -90,9 +90,9 @@ let someU: (int, int, int => bool) => bool ## Examples ```rescript -assertEqual(Belt.Range.some(0, 4, (i) => i > 5), false) +Belt.Range.some(0, 4, i => i > 5) == false -assertEqual(Belt.Range.some(0, 4, (i) => i > 2), true) +Belt.Range.some(0, 4, i => i > 2) == true ``` */ let some: (int, int, int => bool) => bool @@ -107,8 +107,8 @@ let someByU: (int, int, ~step: int, int => bool) => bool ## Examples ```rescript -assertEqual(Belt.Range.someBy(1, 5, ~step=2, (i) => mod(i, 2) === 0), false) -assertEqual(Belt.Range.someBy(0, 4, ~step=2, (i) => mod(i, 2) === 0), true) +Belt.Range.someBy(1, 5, ~step=2, i => mod(i, 2) === 0) == false +Belt.Range.someBy(0, 4, ~step=2, i => mod(i, 2) === 0) == true ``` */ let someBy: (int, int, ~step: int, int => bool) => bool diff --git a/runtime/Belt_Result.resi b/runtime/Belt_Result.resi index aaa4b1c15b..f4c9afdcb3 100644 --- a/runtime/Belt_Result.resi +++ b/runtime/Belt_Result.resi @@ -43,8 +43,8 @@ Belt.Result.Ok(42) ->Belt.Result.getExn ->assertEqual(42) - -switch Belt.Result.getExn(Belt.Result.Error("Invalid data")) { // raise a exception +switch Belt.Result.getExn(Belt.Result.Error("Invalid data")) { +// raise a exception | exception _ => assert(true) | _ => assert(false) } @@ -62,8 +62,8 @@ Belt.Result.Ok(42) ->Belt.Result.getOrThrow ->assertEqual(42) - -switch Belt.Result.getOrThrow(Belt.Result.Error("Invalid data")) { // raise a exception +switch Belt.Result.getOrThrow(Belt.Result.Error("Invalid data")) { +// raise a exception | exception _ => assert(true) | _ => assert(false) } @@ -81,10 +81,10 @@ otherwise `default`. ```rescript let ok = Belt.Result.Ok(42) -assertEqual(Belt.Result.mapWithDefault(ok, 0, (x) => x / 2), 21) +Belt.Result.mapWithDefault(ok, 0, x => x / 2) == 21 let error = Belt.Result.Error("Invalid data") -assertEqual(Belt.Result.mapWithDefault(error, 0, (x) => x / 2), 0) +Belt.Result.mapWithDefault(error, 0, x => x / 2) == 0 ``` */ let mapWithDefault: (t<'a, 'c>, 'b, 'a => 'b) => 'b @@ -99,11 +99,11 @@ ordinary value. ## Examples ```rescript -let f = (x) => sqrt(Belt.Int.toFloat(x)) +let f = x => sqrt(Belt.Int.toFloat(x)) -assertEqual(Belt.Result.map(Ok(64), f), Ok(8.0)) +Belt.Result.map(Ok(64), f) == Ok(8.0) -assertEqual(Belt.Result.map(Error("Invalid data"), f), Error("Invalid data")) +Belt.Result.map(Error("Invalid data"), f) == Error("Invalid data") ``` */ let map: (t<'a, 'c>, 'a => 'b) => t<'b, 'c> @@ -118,18 +118,18 @@ unchanged. Function `f` takes a value of the same type as `n` and returns a ## Examples ```rescript -let recip = (x) => - if (x !== 0.0) { +let recip = x => + if x !== 0.0 { Belt.Result.Ok(1.0 /. x) } else { Belt.Result.Error("Divide by zero") } -assertEqual(Belt.Result.flatMap(Ok(2.0), recip), Ok(0.5)) +Belt.Result.flatMap(Ok(2.0), recip) == Ok(0.5) -assertEqual(Belt.Result.flatMap(Ok(0.0), recip), Error("Divide by zero")) +Belt.Result.flatMap(Ok(0.0), recip) == Error("Divide by zero") -assertEqual(Belt.Result.flatMap(Error("Already bad"), recip), Error("Already bad")) +Belt.Result.flatMap(Error("Already bad"), recip) == Error("Already bad") ``` */ let flatMap: (t<'a, 'c>, 'a => t<'b, 'c>) => t<'b, 'c> @@ -141,9 +141,9 @@ otherwise `default` ## Examples ```rescript -assertEqual(Belt.Result.getWithDefault(Ok(42), 0), 42) +Belt.Result.getWithDefault(Ok(42), 0) == 42 -assertEqual(Belt.Result.getWithDefault(Error("Invalid Data"), 0), 0) +Belt.Result.getWithDefault(Error("Invalid Data"), 0) == 0 ``` */ let getWithDefault: (t<'a, 'b>, 'a) => 'a @@ -182,13 +182,13 @@ let bad2 = Belt.Result.Error("really invalid") let mod10equal = (a, b) => mod(a, 10) === mod(b, 10) -assertEqual(Belt.Result.eq(good1, good2, mod10equal), true) +Belt.Result.eq(good1, good2, mod10equal) == true -assertEqual(Belt.Result.eq(good1, bad1, mod10equal), false) +Belt.Result.eq(good1, bad1, mod10equal) == false -assertEqual(Belt.Result.eq(bad2, good2, mod10equal), false) +Belt.Result.eq(bad2, good2, mod10equal) == false -assertEqual(Belt.Result.eq(bad1, bad2, mod10equal), true) +Belt.Result.eq(bad1, bad2, mod10equal) == true ``` */ let eq: (t<'a, 'c>, t<'b, 'd>, ('a, 'b) => bool) => bool @@ -220,15 +220,15 @@ let bad2 = Belt.Result.Error("really invalid") let mod10cmp = (a, b) => Pervasives.compare(mod(a, 10), mod(b, 10)) -assertEqual(Belt.Result.cmp(Ok(39), Ok(57), mod10cmp), 1) +Belt.Result.cmp(Ok(39), Ok(57), mod10cmp) == 1 -assertEqual(Belt.Result.cmp(Ok(57), Ok(39), mod10cmp), (-1)) +Belt.Result.cmp(Ok(57), Ok(39), mod10cmp) == -1 -assertEqual(Belt.Result.cmp(Ok(39), Error("y"), mod10cmp), 1) +Belt.Result.cmp(Ok(39), Error("y"), mod10cmp) == 1 -assertEqual(Belt.Result.cmp(Error("x"), Ok(57), mod10cmp), (-1)) +Belt.Result.cmp(Error("x"), Ok(57), mod10cmp) == -1 -assertEqual(Belt.Result.cmp(Error("x"), Error("y"), mod10cmp), 0) +Belt.Result.cmp(Error("x"), Error("y"), mod10cmp) == 0 ``` */ let cmp: (t<'a, 'c>, t<'b, 'd>, ('a, 'b) => int) => int diff --git a/runtime/Belt_Set.resi b/runtime/Belt_Set.resi index 72ae9de5fd..98b43bab84 100644 --- a/runtime/Belt_Set.resi +++ b/runtime/Belt_Set.resi @@ -34,15 +34,14 @@ the top level documentation of Belt, **A special encoding for collection safety* ## Examples ```rescript -module PairComparator = - Belt.Id.MakeComparable({ - type t = (int, int) - let cmp = ((a0, a1), (b0, b1)) => - switch (Pervasives.compare(a0, b0)) { - | 0 => Pervasives.compare(a1, b1) - | c => c - } - }) +module PairComparator = Belt.Id.MakeComparable({ + type t = (int, int) + let cmp = ((a0, a1), (b0, b1)) => + switch Pervasives.compare(a0, b0) { + | 0 => Pervasives.compare(a1, b1) + | c => c + } +}) let mySet = Belt.Set.make(~id=module(PairComparator)) let mySet2 = Belt.Set.add(mySet, (1, 2)) @@ -52,11 +51,10 @@ let mySet2 = Belt.Set.add(mySet, (1, 2)) called `IntCmp`. It is declared like this: ```rescript -module IntCmp = - Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) +module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare +}) ``` */ @@ -193,13 +191,13 @@ s0->Belt.Set.toArray->assertEqual([]) s1->Belt.Set.toArray->assertEqual([1]) s2->Belt.Set.toArray->assertEqual([1, 2]) s3->Belt.Set.toArray->assertEqual([1, 2]) -assertEqual(s2, s3) +s2 == s3 ``` */ let add: (t<'value, 'id>, 'value) => t<'value, 'id> /** -Adds each element of array to set. Unlike `Belt.Set.add`](#add), the reference of return value might be changed even if all values in array already exist in set +Adds each element of array to set. Unlike `Belt.Set.add`\](\#add), the reference of return value might be changed even if all values in array already exist in set ## Examples @@ -231,14 +229,14 @@ module IntCmp = Belt.Id.MakeComparable({ let cmp = Pervasives.compare }) -let s0 = Belt.Set.fromArray([2,3,1,4,5], ~id=module(IntCmp)) +let s0 = Belt.Set.fromArray([2, 3, 1, 4, 5], ~id=module(IntCmp)) let s1 = s0->Belt.Set.remove(1) let s2 = s1->Belt.Set.remove(3) let s3 = s2->Belt.Set.remove(3) -s1->Belt.Set.toArray->assertEqual([2,3,4,5]) -s2->Belt.Set.toArray->assertEqual([2,4,5]) -assertEqual(s2, s3) +s1->Belt.Set.toArray->assertEqual([2, 3, 4, 5]) +s2->Belt.Set.toArray->assertEqual([2, 4, 5]) +s2 == s3 ``` */ let remove: (t<'value, 'id>, 'value) => t<'value, 'id> @@ -254,7 +252,7 @@ module IntCmp = Belt.Id.MakeComparable({ let cmp = Pervasives.compare }) -let set = Belt.Set.fromArray([1, 2, 3, 4],~id=module(IntCmp)) +let set = Belt.Set.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) let newSet = set->Belt.Set.removeMany([5, 4, 3, 2, 1]) @@ -276,13 +274,13 @@ module IntCmp = Belt.Id.MakeComparable({ let cmp = Pervasives.compare }) -let s0 = Belt.Set.fromArray([5,2,3,5,6], ~id=module(IntCmp)) -let s1 = Belt.Set.fromArray([5,2,3,1,5,4], ~id=module(IntCmp)) +let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) +let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) let union = Belt.Set.union(s0, s1) union ->Belt.Set.toArray -->assertEqual([1,2,3,4,5,6]) +->assertEqual([1, 2, 3, 4, 5, 6]) ``` */ let union: (t<'value, 'id>, t<'value, 'id>) => t<'value, 'id> @@ -298,14 +296,14 @@ module IntCmp = Belt.Id.MakeComparable({ let cmp = Pervasives.compare }) -let s0 = Belt.Set.fromArray([5,2,3,5,6], ~id=module(IntCmp)) -let s1 = Belt.Set.fromArray([5,2,3,1,5,4], ~id=module(IntCmp)) +let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) +let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) let intersect = Belt.Set.intersect(s0, s1) intersect ->Belt.Set.toArray -->assertEqual([2,3,5]) +->assertEqual([2, 3, 5]) ``` */ let intersect: (t<'value, 'id>, t<'value, 'id>) => t<'value, 'id> @@ -321,16 +319,16 @@ module IntCmp = Belt.Id.MakeComparable({ let cmp = Pervasives.compare }) -let s0 = Belt.Set.fromArray([5,2,3,5,6], ~id=module(IntCmp)) -let s1 = Belt.Set.fromArray([5,2,3,1,5,4], ~id=module(IntCmp)) +let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) +let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) Belt.Set.diff(s0, s1) ->Belt.Set.toArray ->assertEqual([6]) -Belt.Set.diff(s1,s0) +Belt.Set.diff(s1, s0) ->Belt.Set.toArray -->assertEqual([1,4]) +->assertEqual([1, 4]) ``` */ let diff: (t<'value, 'id>, t<'value, 'id>) => t<'value, 'id> @@ -346,8 +344,8 @@ module IntCmp = Belt.Id.MakeComparable({ let cmp = Pervasives.compare }) -let s0 = Belt.Set.fromArray([5,2,3,5,6], ~id=module(IntCmp)) -let s1 = Belt.Set.fromArray([5,2,3,1,5,4], ~id=module(IntCmp)) +let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) +let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) let s2 = Belt.Set.intersect(s0, s1) Belt.Set.subset(s2, s0)->assertEqual(true) @@ -375,8 +373,8 @@ module IntCmp = Belt.Id.MakeComparable({ let cmp = Pervasives.compare }) -let s0 = Belt.Set.fromArray([5,2,3], ~id=module(IntCmp)) -let s1 = Belt.Set.fromArray([3,2,5], ~id=module(IntCmp)) +let s0 = Belt.Set.fromArray([5, 2, 3], ~id=module(IntCmp)) +let s1 = Belt.Set.fromArray([3, 2, 5], ~id=module(IntCmp)) Belt.Set.eq(s0, s1)->assertEqual(true) ``` @@ -400,7 +398,7 @@ module IntCmp = Belt.Id.MakeComparable({ let cmp = Pervasives.compare }) -let s0 = Belt.Set.fromArray([5,2,3,5,6], ~id=module(IntCmp)) +let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) let acc = ref(list{}) @@ -408,7 +406,7 @@ s0->Belt.Set.forEach(x => { acc := Belt.List.add(acc.contents, x) }) -acc.contents->assertEqual(list{6,5,3,2}) +acc.contents->assertEqual(list{6, 5, 3, 2}) ``` */ let forEach: (t<'value, 'id>, 'value => unit) => unit @@ -427,11 +425,10 @@ module IntCmp = Belt.Id.MakeComparable({ let cmp = Pervasives.compare }) -let s0 = Belt.Set.fromArray([5,2,3,5,6], ~id=module(IntCmp)) +let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) s0 -->Belt.Set.reduce(list{}, (acc, element) => - acc->Belt.List.add(element) -)->assertEqual(list{6,5,3,2}) +->Belt.Set.reduce(list{}, (acc, element) => acc->Belt.List.add(element)) +->assertEqual(list{6, 5, 3, 2}) ``` */ let reduce: (t<'value, 'id>, 'a, ('a, 'value) => 'a) => 'a @@ -452,7 +449,7 @@ module IntCmp = Belt.Id.MakeComparable({ let isEven = x => mod(x, 2) == 0 -let s0 = Belt.Set.fromArray([2,4,6,8], ~id=module(IntCmp)) +let s0 = Belt.Set.fromArray([2, 4, 6, 8], ~id=module(IntCmp)) s0->Belt.Set.every(isEven)->assertEqual(true) ``` */ @@ -474,7 +471,7 @@ module IntCmp = Belt.Id.MakeComparable({ let isOdd = x => mod(x, 2) != 0 -let s0 = Belt.Set.fromArray([1,2,4,6,8], ~id=module(IntCmp)) +let s0 = Belt.Set.fromArray([1, 2, 4, 6, 8], ~id=module(IntCmp)) s0->Belt.Set.some(isOdd)->assertEqual(true) ``` */ @@ -496,7 +493,7 @@ module IntCmp = Belt.Id.MakeComparable({ let isEven = x => mod(x, 2) == 0 -let s0 = Belt.Set.fromArray([1,2,3,4,5], ~id=module(IntCmp)) +let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) let s1 = s0->Belt.Set.keep(isEven) s1->Belt.Set.toArray->assertEqual([2, 4]) @@ -520,11 +517,11 @@ module IntCmp = Belt.Id.MakeComparable({ let isOdd = x => mod(x, 2) != 0 -let s0 = Belt.Set.fromArray([1,2,3,4,5], ~id=module(IntCmp)) +let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) let (s1, s2) = s0->Belt.Set.partition(isOdd) -s1->Belt.Set.toArray->assertEqual([1,3,5]) -s2->Belt.Set.toArray->assertEqual([2,4]) +s1->Belt.Set.toArray->assertEqual([1, 3, 5]) +s2->Belt.Set.toArray->assertEqual([2, 4]) ``` */ let partition: (t<'value, 'id>, 'value => bool) => (t<'value, 'id>, t<'value, 'id>) @@ -540,7 +537,7 @@ module IntCmp = Belt.Id.MakeComparable({ let cmp = Pervasives.compare }) -let s0 = Belt.Set.fromArray([1,2,3,4], ~id=module(IntCmp)) +let s0 = Belt.Set.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) s0->Belt.Set.size->assertEqual(4) ``` @@ -558,9 +555,9 @@ module IntCmp = Belt.Id.MakeComparable({ let cmp = Pervasives.compare }) -let s0 = Belt.Set.fromArray([3,2,1,5], ~id=module(IntCmp)) +let s0 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) -s0->Belt.Set.toArray->assertEqual([1,2,3,5]) +s0->Belt.Set.toArray->assertEqual([1, 2, 3, 5]) ``` */ let toArray: t<'value, 'id> => array<'value> @@ -576,9 +573,9 @@ module IntCmp = Belt.Id.MakeComparable({ let cmp = Pervasives.compare }) -let s0 = Belt.Set.fromArray([3,2,1,5], ~id=module(IntCmp)) +let s0 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) -s0->Belt.Set.toList->assertEqual(list{1,2,3,5}) +s0->Belt.Set.toList->assertEqual(list{1, 2, 3, 5}) ``` */ let toList: t<'value, 'id> => list<'value> @@ -595,7 +592,7 @@ module IntCmp = Belt.Id.MakeComparable({ }) let s0 = Belt.Set.make(~id=module(IntCmp)) -let s1 = Belt.Set.fromArray([3,2,1,5], ~id=module(IntCmp)) +let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) s0->Belt.Set.minimum->assertEqual(None) s1->Belt.Set.minimum->assertEqual(Some(1)) @@ -615,7 +612,7 @@ module IntCmp = Belt.Id.MakeComparable({ }) let s0 = Belt.Set.make(~id=module(IntCmp)) -let s1 = Belt.Set.fromArray([3,2,1,5], ~id=module(IntCmp)) +let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) s0->Belt.Set.minUndefined->Js.Undefined.toOption->assertEqual(None) s1->Belt.Set.minUndefined->Js.Undefined.toOption->assertEqual(Some(1)) @@ -635,7 +632,7 @@ module IntCmp = Belt.Id.MakeComparable({ }) let s0 = Belt.Set.make(~id=module(IntCmp)) -let s1 = Belt.Set.fromArray([3,2,1,5], ~id=module(IntCmp)) +let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) s0->Belt.Set.maximum->assertEqual(None) s1->Belt.Set.maximum->assertEqual(Some(5)) @@ -655,7 +652,7 @@ module IntCmp = Belt.Id.MakeComparable({ }) let s0 = Belt.Set.make(~id=module(IntCmp)) -let s1 = Belt.Set.fromArray([3,2,1,5], ~id=module(IntCmp)) +let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) s0 ->Belt.Set.maxUndefined @@ -681,7 +678,7 @@ module IntCmp = Belt.Id.MakeComparable({ let cmp = Pervasives.compare }) -let s0 = Belt.Set.fromArray([1,2,3,4,5], ~id=module(IntCmp)) +let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) s0->Belt.Set.get(3)->assertEqual(Some(3)) s0->Belt.Set.get(20)->assertEqual(None) @@ -720,8 +717,8 @@ let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) let ((smaller, larger), present) = s0->Belt.Set.split(3) present->assertEqual(true) -smaller->Belt.Set.toArray->assertEqual([1,2]) -larger->Belt.Set.toArray->assertEqual([4,5]) +smaller->Belt.Set.toArray->assertEqual([1, 2]) +larger->Belt.Set.toArray->assertEqual([4, 5]) ``` */ let split: (t<'value, 'id>, 'value) => ((t<'value, 'id>, t<'value, 'id>), bool) diff --git a/runtime/Belt_SetDict.resi b/runtime/Belt_SetDict.resi index 6f652a7b3c..95a26dba93 100644 --- a/runtime/Belt_SetDict.resi +++ b/runtime/Belt_SetDict.resi @@ -62,7 +62,7 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.Set.Dict.fromArray([1, 3, 2, 4], ~cmp=IntCmp.cmp) -assertEqual(s0->Belt.Set.Dict.toArray, [1, 2, 3, 4]) +s0->Belt.Set.Dict.toArray == [1, 2, 3, 4] ``` */ let fromArray: (array<'value>, ~cmp: cmp<'value, 'id>) => t<'value, 'id> @@ -87,8 +87,8 @@ module IntCmp = Belt.Id.MakeComparable({ let empty = Belt.Set.Dict.fromArray([], ~cmp=IntCmp.cmp) let notEmpty = Belt.Set.Dict.fromArray([1], ~cmp=IntCmp.cmp) -assertEqual(Belt.Set.Dict.isEmpty(empty), true) -assertEqual(Belt.Set.Dict.isEmpty(notEmpty), false) +Belt.Set.Dict.isEmpty(empty) == true +Belt.Set.Dict.isEmpty(notEmpty) == false ``` */ let isEmpty: t<_> => bool @@ -106,8 +106,8 @@ module IntCmp = Belt.Id.MakeComparable({ let set = Belt.Set.Dict.fromArray([1, 4, 2, 5], ~cmp=IntCmp.cmp) -assertEqual(set->Belt.Set.Dict.has(3, ~cmp=IntCmp.cmp), false) -assertEqual(set->Belt.Set.Dict.has(1, ~cmp=IntCmp.cmp), true) +set->Belt.Set.Dict.has(3, ~cmp=IntCmp.cmp) == false +set->Belt.Set.Dict.has(1, ~cmp=IntCmp.cmp) == true ``` */ let has: (t<'value, 'id>, 'value, ~cmp: cmp<'value, 'id>) => bool @@ -127,11 +127,11 @@ let s0 = Belt.Set.Dict.empty let s1 = s0->Belt.Set.Dict.add(1, ~cmp=IntCmp.cmp) let s2 = s1->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) let s3 = s2->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) -assertEqual(s0->Belt.Set.Dict.toArray, []) -assertEqual(s1->Belt.Set.Dict.toArray, [1]) -assertEqual(s2->Belt.Set.Dict.toArray, [1, 2]) -assertEqual(s3->Belt.Set.Dict.toArray, [1, 2]) -assertEqual(s2, s3) +s0->Belt.Set.Dict.toArray == [] +s1->Belt.Set.Dict.toArray == [1] +s2->Belt.Set.Dict.toArray == [1, 2] +s3->Belt.Set.Dict.toArray == [1, 2] +s2 == s3 ``` */ let add: (t<'value, 'id>, 'value, ~cmp: cmp<'value, 'id>) => t<'value, 'id> @@ -150,7 +150,7 @@ module IntCmp = Belt.Id.MakeComparable({ let set = Belt.Set.Dict.empty let newSet = set->Belt.Set.Dict.mergeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) -assertEqual(newSet->Belt.Set.Dict.toArray, [1, 2, 3, 4, 5]) +newSet->Belt.Set.Dict.toArray == [1, 2, 3, 4, 5] ``` */ let mergeMany: (t<'value, 'id>, array<'value>, ~cmp: cmp<'value, 'id>) => t<'value, 'id> @@ -171,9 +171,9 @@ let s1 = s0->Belt.Set.Dict.remove(1, ~cmp=IntCmp.cmp) let s2 = s1->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) let s3 = s2->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) -assertEqual(s1->Belt.Set.Dict.toArray, [2,3,4,5]) -assertEqual(s2->Belt.Set.Dict.toArray, [2,4,5]) -assertEqual(s2, s3) +s1->Belt.Set.Dict.toArray == [2, 3, 4, 5] +s2->Belt.Set.Dict.toArray == [2, 4, 5] +s2 == s3 ``` */ let remove: (t<'value, 'id>, 'value, ~cmp: cmp<'value, 'id>) => t<'value, 'id> @@ -192,7 +192,7 @@ module IntCmp = Belt.Id.MakeComparable({ let set = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) let newSet = set->Belt.Set.Dict.removeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) -assertEqual(newSet->Belt.Set.Dict.toArray, []) +newSet->Belt.Set.Dict.toArray == [] ``` */ let removeMany: (t<'value, 'id>, array<'value>, ~cmp: cmp<'value, 'id>) => t<'value, 'id> @@ -211,7 +211,7 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) let union = Belt.Set.Dict.union(s0, s1, ~cmp=IntCmp.cmp) -assertEqual(union->Belt.Set.Dict.toArray, [1,2,3,4,5,6]) +union->Belt.Set.Dict.toArray == [1, 2, 3, 4, 5, 6] ``` */ let union: (t<'value, 'id>, t<'value, 'id>, ~cmp: cmp<'value, 'id>) => t<'value, 'id> @@ -230,7 +230,7 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) let intersect = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) -assertEqual(intersect->Belt.Set.Dict.toArray, [2,3,5]) +intersect->Belt.Set.Dict.toArray == [2, 3, 5] ``` */ let intersect: (t<'value, 'id>, t<'value, 'id>, ~cmp: cmp<'value, 'id>) => t<'value, 'id> @@ -252,8 +252,8 @@ let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) let diff1 = Belt.Set.Dict.diff(s0, s1, ~cmp=IntCmp.cmp) let diff2 = Belt.Set.Dict.diff(s1, s0, ~cmp=IntCmp.cmp) -assertEqual(diff1->Belt.Set.Dict.toArray, [6]) -assertEqual(diff2->Belt.Set.Dict.toArray, [1,4]) +diff1->Belt.Set.Dict.toArray == [6] +diff2->Belt.Set.Dict.toArray == [1, 4] ``` */ let diff: (t<'value, 'id>, t<'value, 'id>, ~cmp: cmp<'value, 'id>) => t<'value, 'id> @@ -272,9 +272,9 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) let s2 = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) -assertEqual(Belt.Set.Dict.subset(s2, s0, ~cmp=IntCmp.cmp), true) -assertEqual(Belt.Set.Dict.subset(s2, s1, ~cmp=IntCmp.cmp), true) -assertEqual(Belt.Set.Dict.subset(s1, s0, ~cmp=IntCmp.cmp), false) +Belt.Set.Dict.subset(s2, s0, ~cmp=IntCmp.cmp) == true +Belt.Set.Dict.subset(s2, s1, ~cmp=IntCmp.cmp) == true +Belt.Set.Dict.subset(s1, s0, ~cmp=IntCmp.cmp) == false ``` */ let subset: (t<'value, 'id>, t<'value, 'id>, ~cmp: cmp<'value, 'id>) => bool @@ -300,7 +300,7 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.Set.Dict.fromArray([5, 2, 3], ~cmp=IntCmp.cmp) let s1 = Belt.Set.Dict.fromArray([3, 2, 5], ~cmp=IntCmp.cmp) -assertEqual(Belt.Set.Dict.eq(s0, s1, ~cmp=IntCmp.cmp), true) +Belt.Set.Dict.eq(s0, s1, ~cmp=IntCmp.cmp) == true ``` */ let eq: (t<'value, 'id>, t<'value, 'id>, ~cmp: cmp<'value, 'id>) => bool @@ -325,7 +325,7 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) let acc = ref(list{}) s0->Belt.Set.Dict.forEach(x => acc := Belt.List.add(acc.contents, x)) -assertEqual(acc.contents, list{6, 5, 3, 2}) +acc.contents == list{6, 5, 3, 2} ``` */ let forEach: (t<'value, 'id>, 'value => unit) => unit @@ -345,10 +345,7 @@ module IntCmp = Belt.Id.MakeComparable({ }) let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) -assertEqual( - s0->Belt.Set.Dict.reduce(list{}, (acc, element) => acc->Belt.List.add(element)), - list{6, 5, 3, 2} -) +s0->Belt.Set.Dict.reduce(list{}, (acc, element) => acc->Belt.List.add(element)) == list{6, 5, 3, 2} ``` */ let reduce: (t<'value, 'id>, 'a, ('a, 'value) => 'a) => 'a @@ -370,7 +367,7 @@ module IntCmp = Belt.Id.MakeComparable({ let isEven = x => mod(x, 2) == 0 let s0 = Belt.Set.Dict.fromArray([2, 4, 6, 8], ~cmp=IntCmp.cmp) -assertEqual(s0->Belt.Set.Dict.every(isEven), true) +s0->Belt.Set.Dict.every(isEven) == true ``` */ let every: (t<'value, 'id>, 'value => bool) => bool @@ -392,7 +389,7 @@ module IntCmp = Belt.Id.MakeComparable({ let isOdd = x => mod(x, 2) != 0 let s0 = Belt.Set.Dict.fromArray([1, 2, 4, 6, 8], ~cmp=IntCmp.cmp) -assertEqual(s0->Belt.Set.Dict.some(isOdd), true) +s0->Belt.Set.Dict.some(isOdd) == true ``` */ let some: (t<'value, 'id>, 'value => bool) => bool @@ -416,7 +413,7 @@ let isEven = x => mod(x, 2) == 0 let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) let s1 = s0->Belt.Set.Dict.keep(isEven) -assertEqual(s1->Belt.Set.Dict.toArray, [2,4]) +s1->Belt.Set.Dict.toArray == [2, 4] ``` */ let keep: (t<'value, 'id>, 'value => bool) => t<'value, 'id> @@ -440,8 +437,8 @@ let isOdd = x => mod(x, 2) != 0 let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) let (s1, s2) = s0->Belt.Set.Dict.partition(isOdd) -assertEqual(s1->Belt.Set.Dict.toArray, [1,3,5]) -assertEqual(s2->Belt.Set.Dict.toArray, [2,4]) +s1->Belt.Set.Dict.toArray == [1, 3, 5] +s2->Belt.Set.Dict.toArray == [2, 4] ``` */ let partition: (t<'value, 'id>, 'value => bool) => (t<'value, 'id>, t<'value, 'id>) @@ -459,7 +456,7 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) -assertEqual(s0->Belt.Set.Dict.size, 4) +s0->Belt.Set.Dict.size == 4 ``` */ let size: t<'value, 'id> => int @@ -477,7 +474,7 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) -assertEqual(s0->Belt.Set.Dict.toList, list{1, 2, 3, 5}) +s0->Belt.Set.Dict.toList == list{1, 2, 3, 5} ``` */ let toList: t<'value, 'id> => list<'value> @@ -495,7 +492,7 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) -assertEqual(s0->Belt.Set.Dict.toArray, [1,2,3,5]) +s0->Belt.Set.Dict.toArray == [1, 2, 3, 5] ``` */ let toArray: t<'value, 'id> => array<'value> @@ -514,8 +511,8 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.Set.Dict.empty let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) -assertEqual(s0->Belt.Set.Dict.minimum, None) -assertEqual(s1->Belt.Set.Dict.minimum, Some(1)) +s0->Belt.Set.Dict.minimum == None +s1->Belt.Set.Dict.minimum == Some(1) ``` */ let minimum: t<'value, 'id> => option<'value> @@ -534,8 +531,8 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.Set.Dict.empty let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) -assertEqual(s0->Belt.Set.Dict.minUndefined, Js.undefined) -assertEqual(s1->Belt.Set.Dict.minUndefined, Js.Undefined.return(1)) +s0->Belt.Set.Dict.minUndefined == Js.undefined +s1->Belt.Set.Dict.minUndefined == Js.Undefined.return(1) ``` */ let minUndefined: t<'value, 'id> => Js.undefined<'value> @@ -554,8 +551,8 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.Set.Dict.empty let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) -assertEqual(s0->Belt.Set.Dict.maximum, None) -assertEqual(s1->Belt.Set.Dict.maximum, Some(5)) +s0->Belt.Set.Dict.maximum == None +s1->Belt.Set.Dict.maximum == Some(5) ``` */ let maximum: t<'value, 'id> => option<'value> @@ -574,8 +571,8 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.Set.Dict.empty let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) -assertEqual(s0->Belt.Set.Dict.maxUndefined, Js.undefined) -assertEqual(s1->Belt.Set.Dict.maxUndefined, Js.Undefined.return(5)) +s0->Belt.Set.Dict.maxUndefined == Js.undefined +s1->Belt.Set.Dict.maxUndefined == Js.Undefined.return(5) ``` */ let maxUndefined: t<'value, 'id> => Js.undefined<'value> @@ -594,8 +591,8 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) -assertEqual(s0->Belt.Set.Dict.get(3, ~cmp=IntCmp.cmp), Some(3)) -assertEqual(s0->Belt.Set.Dict.get(20, ~cmp=IntCmp.cmp), None) +s0->Belt.Set.Dict.get(3, ~cmp=IntCmp.cmp) == Some(3) +s0->Belt.Set.Dict.get(20, ~cmp=IntCmp.cmp) == None ``` */ let get: (t<'value, 'id>, 'value, ~cmp: cmp<'value, 'id>) => option<'value> @@ -630,9 +627,9 @@ let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) let ((smaller, larger), present) = s0->Belt.Set.Dict.split(3, ~cmp=IntCmp.cmp) -assertEqual(present, true) -assertEqual(smaller->Belt.Set.Dict.toArray, [1,2]) -assertEqual(larger->Belt.Set.Dict.toArray, [4,5]) +present == true +smaller->Belt.Set.Dict.toArray == [1, 2] +larger->Belt.Set.Dict.toArray == [4, 5] ``` */ let split: ( diff --git a/runtime/Belt_SortArray.resi b/runtime/Belt_SortArray.resi index b9521d4656..372a225a68 100644 --- a/runtime/Belt_SortArray.resi +++ b/runtime/Belt_SortArray.resi @@ -45,13 +45,13 @@ let strictlySortedLengthU: (array<'a>, ('a, 'a) => bool) => int ## Examples ```rescript -assertEqual(Belt.SortArray.strictlySortedLength([1, 2, 3, 4, 3], (x, y) => x < y), 4) +Belt.SortArray.strictlySortedLength([1, 2, 3, 4, 3], (x, y) => x < y) == 4 -assertEqual(Belt.SortArray.strictlySortedLength([], (x, y) => x < y), 0) +Belt.SortArray.strictlySortedLength([], (x, y) => x < y) == 0 -assertEqual(Belt.SortArray.strictlySortedLength([1], (x, y) => x < y), 1) +Belt.SortArray.strictlySortedLength([1], (x, y) => x < y) == 1 -assertEqual(Belt.SortArray.strictlySortedLength([4, 3, 2, 1], (x, y) => x < y), -4) +Belt.SortArray.strictlySortedLength([4, 3, 2, 1], (x, y) => x < y) == -4 ``` */ let strictlySortedLength: (array<'a>, ('a, 'a) => bool) => int @@ -93,9 +93,9 @@ than all elements return `lnot(-1) == 0` since `lnot(- (len + 1)) == len` ## Examples ```rescript -assertEqual(Belt.SortArray.binarySearchBy([1, 2, 3, 4, 33, 35, 36], 33, Pervasives.compare), 4) +Belt.SortArray.binarySearchBy([1, 2, 3, 4, 33, 35, 36], 33, Pervasives.compare) == 4 -assertEqual(lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)), 2) +lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2 ``` */ let binarySearchBy: (array<'a>, 'a, ('a, 'a) => int) => int diff --git a/runtime/Js_array2.res b/runtime/Js_array2.res index f591d085da..78b7afdf3a 100644 --- a/runtime/Js_array2.res +++ b/runtime/Js_array2.res @@ -102,7 +102,7 @@ external fromMap: (array_like<'a>, 'a => 'b) => array<'b> = "Array.from" /* ES2015 */ /** -Returns `true` if its argument is an array; `false` otherwise. This is a runtime check, which is why the second example returns `true`---a list is internally represented as a nested JavaScript array. +Returns `true` if its argument is an array; `false` otherwise. This is a runtime check, which is why the second example returns `true`\---a list is internally represented as a nested JavaScript array. ## Examples @@ -188,7 +188,7 @@ external copyWithinFromRange: (t<'a>, ~to_: int, ~start: int, ~end_: int) => t<' /** Sets all elements of the given array (the first arumgent) to the designated value (the secon argument), returning the resulting array. *This function - modifies the original array.* +modifies the original array.* See [`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill) @@ -367,14 +367,14 @@ external sortInPlace: t<'a> => t<'a> = "sort" /** Sorts the given array in place and returns the sorted array. *This function - modifies the original array.* +modifies the original array.* The first argument to `sortInPlaceWith()` is a function that compares two items from the array and returns: -* an integer less than zero if the first item is less than the second item * -zero if the items are equal * an integer greater than zero if the first item is -greater than the second item +* an integer less than zero if the first item is less than the second item \* + zero if the items are equal \* an integer greater than zero if the first item is + greater than the second item See [`Array.sort`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) diff --git a/runtime/Js_date.res b/runtime/Js_date.res index be4914110d..73eb494d38 100644 --- a/runtime/Js_date.res +++ b/runtime/Js_date.res @@ -779,13 +779,7 @@ on MDN. ```rescript let date1 = Js.Date.fromFloat(123456654321.0) // 29 November 1973 21:30:54.321 GMT -let futureTime = Js.Date.setMinutesSMs( - date1, - ~minutes=34.0, - ~seconds=56.0, - ~milliseconds=789.0, - (), -) +let futureTime = Js.Date.setMinutesSMs(date1, ~minutes=34.0, ~seconds=56.0, ~milliseconds=789.0, ()) date1 == Js.Date.fromString("1973-11-29T21:34:56.789Z00:00") futureTime == Js.Date.getTime(date1) ``` diff --git a/runtime/Js_dict.resi b/runtime/Js_dict.resi index 086aabd3c6..eb293554c8 100644 --- a/runtime/Js_dict.resi +++ b/runtime/Js_dict.resi @@ -165,7 +165,7 @@ function `f` to map each value. ```rescript let prices = Js.Dict.fromList(list{("pen", 1.00), ("book", 5.00), ("stapler", 7.00)}) -let discount = (. price) => price *. 0.90 +let discount = price => price *. 0.90 let salePrices = Js.Dict.map(discount, prices) salePrices == Js.Dict.fromList(list{("pen", 0.90), ("book", 4.50), ("stapler", 6.30)}) diff --git a/runtime/Js_float.res b/runtime/Js_float.res index 430318e9b6..dd72791c0b 100644 --- a/runtime/Js_float.res +++ b/runtime/Js_float.res @@ -68,7 +68,7 @@ external isFinite: float => bool = "isFinite" /** Formats a `float` using exponential (scientific) notation. Return a `string` representing the given value in exponential notation. Raise -RangeError if digits is not in the range [0, 20] (inclusive). See [`toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential) on MDN. +RangeError if digits is not in the range \[0, 20\] (inclusive). See [`toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential) on MDN. ## Examples @@ -86,9 +86,9 @@ external toExponential: float => string = "toExponential" /** Formats a `float` using exponential (scientific) notation. `digits` specifies how many digits should appear after the decimal point. The value must be in -the range [0, 20] (inclusive). Return a `string` representing the given value +the range \[0, 20\] (inclusive). Return a `string` representing the given value in exponential notation. The output will be rounded or padded with zeroes if -necessary. Raise RangeError if `digits` is not in the range [0, 20] (inclusive). +necessary. Raise RangeError if `digits` is not in the range \[0, 20\] (inclusive). See [`toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential) on MDN. ## Examples @@ -104,7 +104,7 @@ external toExponentialWithPrecision: (float, ~digits: int) => string = "toExpone /** Formats a `float` using fixed point notation. Return a `string` representing the given value in fixed-point notation (usually). Raise RangeError if digits is not -in the range [0, 20] (inclusive). See [`toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed) on MDN. +in the range \[0, 20\] (inclusive). See [`toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed) on MDN. ## Examples @@ -121,13 +121,13 @@ external toFixed: float => string = "toFixed" /** Formats a `float` using fixed point notation. `digits` specifies how many digits -should appear after the decimal point. The value must be in the range [0, 20] +should appear after the decimal point. The value must be in the range \[0, 20\] (inclusive). Defaults to `0`. Return a `string` representing the given value in fixed-point notation (usually). See [`toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed) on MDN. The output will be rounded or padded with zeroes if necessary. -Raise RangeError if digits is not in the range [0, 20] (inclusive) +Raise RangeError if digits is not in the range \[0, 20\] (inclusive) ## Examples @@ -212,10 +212,10 @@ external toString: float => string = "toString" /** Formats a `float` as a string. `radix` specifies the radix base to use for the -formatted number. The value must be in the range [2, 36] (inclusive). Return a +formatted number. The value must be in the range \[2, 36\] (inclusive). Return a `string` representing the given value in fixed-point (usually). See [`toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString) on MDN. -Raise RangeError if radix is not in the range [2, 36] (inclusive) +Raise RangeError if radix is not in the range \[2, 36\] (inclusive) ## Examples diff --git a/runtime/Js_global.res b/runtime/Js_global.res index 5af3149f98..153779b198 100644 --- a/runtime/Js_global.res +++ b/runtime/Js_global.res @@ -49,11 +49,10 @@ let remind = () => { punchSleepyGuy() } -let snooze = mins => - interval := Js.Nullable.return(Js.Global.setInterval(remind, mins * 60 * 1000)) +let snooze = mins => interval := Js.Nullable.return(Js.Global.setInterval(remind, mins * 60 * 1000)) let cancel = () => - Js.Nullable.iter(interval.contents, (. intervalId) => Js.Global.clearInterval(intervalId)) + Js.Nullable.iter(interval.contents, intervalId => Js.Global.clearInterval(intervalId)) ``` */ @val @@ -74,7 +73,7 @@ let timer = ref(Js.Nullable.null) let work = () => closeHackerNewsTab() let procrastinate = mins => { - Js.Nullable.iter(timer.contents, (. timer) => Js.Global.clearTimeout(timer)) + Js.Nullable.iter(timer.contents, timer => Js.Global.clearTimeout(timer)) timer := Js.Nullable.return(Js.Global.setTimeout(work, mins * 60 * 1000)) } ``` diff --git a/runtime/Js_math.res b/runtime/Js_math.res index 8768193681..dfda4e187c 100644 --- a/runtime/Js_math.res +++ b/runtime/Js_math.res @@ -164,7 +164,7 @@ external atanh: float => float = "atanh" /** Returns the angle (in radians) of the quotient `y /. x`. It is also the angle -between the *x*-axis and point (*x*, *y*). See +between the *x*\-axis and point (*x*, *y*). See [`Math.atan2`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2) on MDN. @@ -192,9 +192,9 @@ external cbrt: float => float = "cbrt" /** Returns the smallest integer greater than or equal to the argument. This function may return values not representable by `int`, whose range is --2147483648 to 2147483647. This is because, in JavaScript, there are only +\-2147483648 to 2147483647. This is because, in JavaScript, there are only 64-bit floating point numbers, which can represent integers in the range -±(253-1) exactly. See +±(253\-1) exactly. See [`Math.ceil`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil) on MDN. @@ -313,7 +313,7 @@ Returns the largest integer less than or equal to the argument. This function may return values not representable by `int`, whose range is -2147483648 to 2147483647. This is because, in JavaScript, there are only 64-bit floating point numbers, which can represent integers in the range -±(253-1) exactly. See +±(253\-1) exactly. See [`Math.floor`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor) on MDN. @@ -612,7 +612,7 @@ of exactly 0.5, the argument is rounded to the next integer in the direction of positive infinity. This function may return values not representable by `int`, whose range is -2147483648 to 2147483647. This is because, in JavaScript, there are only 64-bit floating point numbers, which can represent -integers in the range ±(253-1) exactly. See +integers in the range ±(253\-1) exactly. See [`Math.round`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round) on MDN. diff --git a/runtime/Js_null.resi b/runtime/Js_null.resi index bdca318358..7d97c19237 100644 --- a/runtime/Js_null.resi +++ b/runtime/Js_null.resi @@ -51,7 +51,7 @@ using the given function `'a => 'b`, then wrapped back up and returned as ```rescript let maybeGreetWorld = (maybeGreeting: Js.null) => - Js.Null.bind(maybeGreeting, (. greeting) => greeting ++ " world!") + Js.Null.bind(maybeGreeting, greeting => greeting ++ " world!") ``` */ let bind: (t<'a>, 'a => 'b) => t<'b> @@ -64,7 +64,7 @@ If `Js.null<'a>` contains a value, that value is unwrapped and applied to the gi ```rescript let maybeSay = (maybeMessage: Js.null) => - Js.Null.iter(maybeMessage, (. message) => Js.log(message)) + Js.Null.iter(maybeMessage, message => Js.log(message)) ``` */ let iter: (t<'a>, 'a => unit) => unit diff --git a/runtime/Js_null_undefined.resi b/runtime/Js_null_undefined.resi index ba310cca5a..6dbbff513e 100644 --- a/runtime/Js_null_undefined.resi +++ b/runtime/Js_null_undefined.resi @@ -53,7 +53,7 @@ as `Js.null_undefined<'b>`. ```rescript let maybeGreetWorld = (maybeGreeting: Js.null_undefined) => - Js.Null_undefined.bind(maybeGreeting, (. greeting) => greeting ++ " world!") + Js.Null_undefined.bind(maybeGreeting, greeting => greeting ++ " world!") ``` */ let bind: (t<'a>, 'a => 'b) => t<'b> @@ -66,7 +66,7 @@ If `Js.null_undefined<'a>` contains a value, that value is unwrapped and applied ```rescript let maybeSay = (maybeMessage: Js.null_undefined) => - Js.Null_undefined.iter(maybeMessage, (. message) => Js.log(message)) + Js.Null_undefined.iter(maybeMessage, message => Js.log(message)) ``` */ let iter: (t<'a>, 'a => unit) => unit diff --git a/runtime/Js_option.res b/runtime/Js_option.res index e2d2dbaaa8..495a52c07b 100644 --- a/runtime/Js_option.res +++ b/runtime/Js_option.res @@ -61,7 +61,7 @@ calling `eq(v1, v2)`. ## Examples ```rescript -let clockEqual = (. a, b) => mod(a, 12) == mod(b, 12) +let clockEqual = (a, b) => mod(a, 12) == mod(b, 12) Js.Option.isSomeValue(clockEqual, 3, Some(15)) == true Js.Option.isSomeValue(clockEqual, 3, Some(4)) == false Js.Option.isSomeValue(clockEqual, 3, None) == false @@ -105,7 +105,7 @@ If the second and third arguments are of the form: ## Examples ```rescript -let clockEqual = (. a, b) => mod(a, 12) == mod(b, 12) +let clockEqual = (a, b) => mod(a, 12) == mod(b, 12) Js.Option.equal(clockEqual, Some(3), Some(15)) == true Js.Option.equal(clockEqual, Some(3), Some(16)) == false Js.Option.equal(clockEqual, Some(3), None) == false @@ -132,7 +132,7 @@ If the second argument is `Some(v)`, the return value is `f(v)`. ## Examples ```rescript -let reciprocal = (. x) => x == 0 ? None : Some(1.0 /. Belt.Int.toFloat(x)) +let reciprocal = x => x == 0 ? None : Some(1.0 /. Belt.Int.toFloat(x)) Js.Option.andThen(reciprocal, Some(5)) == Some(0.2) Js.Option.andThen(reciprocal, Some(0)) == None Js.Option.andThen(reciprocal, None) == None @@ -153,7 +153,7 @@ value. If it is of the form `Some(v)`, `map()` returns `Some(f(v))`; if it is ## Examples ```rescript -let square = (. x) => x * x +let square = x => x * x Js.Option.map(square, Some(3)) == Some(9) Js.Option.map(square, None) == None ``` @@ -195,7 +195,7 @@ the return value is `Some(v)`. Otherwise, the return value is `None`. ## Examples ```rescript -let isEven = (. x) => mod(x, 2) == 0 +let isEven = x => mod(x, 2) == 0 Js.Option.filter(isEven, Some(2)) == Some(2) Js.Option.filter(isEven, Some(3)) == None Js.Option.filter(isEven, None) == None diff --git a/runtime/Js_re.res b/runtime/Js_re.res index 4b0cb9fa83..41d57f0070 100644 --- a/runtime/Js_re.res +++ b/runtime/Js_re.res @@ -118,7 +118,8 @@ let str = "abbcdefabh" let break = ref(false) while !break.contents { switch Js.Re.exec_(re, str) { - | Some(result) => Js.Nullable.iter(Js.Re.captures(result)[0], (. match_) => { + | Some(result) => + Js.Nullable.iter(Js.Re.captures(result)[0], match_ => { let next = Belt.Int.toString(Js.Re.lastIndex(re)) Js.log("Found " ++ (match_ ++ (". Next match starts at " ++ next))) }) @@ -163,8 +164,8 @@ Returns `Some(Js.Re.result)` if a match is found, `None` otherwise. ```rescript /* Match "quick brown" followed by "jumps", ignoring characters in between * Remember "brown" and "jumps" - * Ignore case - */ + * Ignore case + */ let re = /quick\s(brown).+?(jumps)/ig let result = Js.Re.exec_(re, "The Quick Brown Fox Jumps Over The Lazy Dog") @@ -187,8 +188,7 @@ Returns true if a match is found, false otherwise. let str = "hello world!" -let startsWith = (target, substring) => - Js.Re.fromString("^" ++ substring)->Js.Re.test_(target) +let startsWith = (target, substring) => Js.Re.fromString("^" ++ substring)->Js.Re.test_(target) Js.log(str->startsWith("hello")) /* prints "true" */ ``` diff --git a/runtime/Js_undefined.resi b/runtime/Js_undefined.resi index 5c650f23d0..f33ffa39d4 100644 --- a/runtime/Js_undefined.resi +++ b/runtime/Js_undefined.resi @@ -57,7 +57,7 @@ If `Js.undefined<'a>` contains a value, that value is unwrapped, mapped to a ```rescript let maybeGreetWorld = (maybeGreeting: Js.undefined) => - Js.Undefined.bind(maybeGreeting, (. greeting) => greeting ++ " world!") + Js.Undefined.bind(maybeGreeting, greeting => greeting ++ " world!") ``` */ let bind: (t<'a>, 'a => 'b) => t<'b> @@ -71,7 +71,7 @@ given function. ```rescript let maybeSay = (maybeMessage: Js.undefined) => - Js.Undefined.iter(maybeMessage, (. message) => Js.log(message)) + Js.Undefined.iter(maybeMessage, message => Js.log(message)) ``` */ let iter: (t<'a>, 'a => unit) => unit diff --git a/runtime/Pervasives.res b/runtime/Pervasives.res index 30d8e24ae8..056d34a3be 100644 --- a/runtime/Pervasives.res +++ b/runtime/Pervasives.res @@ -17,7 +17,7 @@ let result = try { | MyException(message) => "Caught exception: " ++ message } -assertEqual(result, "Caught exception: Out of milk") +result == "Caught exception: Out of milk" ``` */ external throw: exn => 'a = "%raise" diff --git a/runtime/Stdlib_Array.resi b/runtime/Stdlib_Array.resi index e98f72c3c1..208b3d8b39 100644 --- a/runtime/Stdlib_Array.resi +++ b/runtime/Stdlib_Array.resi @@ -307,11 +307,11 @@ Beware this will *mutate* the array. ```rescript let array = [] array->Array.removeInPlace(0) -assertEqual(array, []) // Removing from an empty array does nothing +array == [] // Removing from an empty array does nothing let array2 = ["Hello", "Hi", "Good bye"] array2->Array.removeInPlace(1) -assertEqual(array2, ["Hello", "Good bye"]) // Removes the item at index 1 +array2 == ["Hello", "Good bye"] // Removes the item at index 1 ``` */ @send @@ -571,7 +571,7 @@ let myArray = [1, 2, 3] let copyOfMyArray = myArray->Array.copy copyOfMyArray->assertEqual([1, 2, 3]) -assertEqual(myArray === copyOfMyArray, false) +(myArray === copyOfMyArray) == false ``` */ @send @@ -765,7 +765,8 @@ array ->Array.findIndex(item => item == ReScript) ->assertEqual(0) -array->Array.findIndex(item => item == TypeScript) +array +->Array.findIndex(item => item == TypeScript) ->assertEqual(-1) ``` */ @@ -786,11 +787,13 @@ type languages = ReScript | TypeScript | JavaScript let array = [ReScript, JavaScript] -let isReScriptFirst = array->Array.findIndexWithIndex((item, index) => index === 0 && item == ReScript) -let isTypeScriptFirst = array->Array.findIndexWithIndex((item, index) => index === 0 && item == TypeScript) +let isReScriptFirst = + array->Array.findIndexWithIndex((item, index) => index === 0 && item == ReScript) +let isTypeScriptFirst = + array->Array.findIndexWithIndex((item, index) => index === 0 && item == TypeScript) -assertEqual(isReScriptFirst, 0) -assertEqual(isTypeScriptFirst, -1) +isReScriptFirst == 0 +isTypeScriptFirst == -1 ``` */ @send @@ -814,7 +817,8 @@ array ->Array.findLastIndex(item => item == ReScript) ->assertEqual(2) -array->Array.findLastIndex(item => item == TypeScript) +array +->Array.findLastIndex(item => item == TypeScript) ->assertEqual(-1) ``` */ @@ -835,11 +839,13 @@ type languages = ReScript | TypeScript | JavaScript let array = [ReScript, JavaScript, JavaScript, ReScript] -let isReScriptLast = array->Array.findLastIndexWithIndex((item, index) => index === 3 && item == ReScript) -let isTypeScriptLast = array->Array.findLastIndexWithIndex((item, index) => index === 3 && item == TypeScript) +let isReScriptLast = + array->Array.findLastIndexWithIndex((item, index) => index === 3 && item == ReScript) +let isTypeScriptLast = + array->Array.findLastIndexWithIndex((item, index) => index === 3 && item == TypeScript) -assertEqual(isReScriptLast, 3) -assertEqual(isTypeScriptLast, -1) +isReScriptLast == 3 +isTypeScriptLast == -1 ``` */ @send @@ -891,7 +897,7 @@ See [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refere let array = ["Hello", "Hi", "Good bye"] let mappedArray = array->Array.map(greeting => greeting ++ " to you") -assertEqual(mappedArray, ["Hello to you", "Hi to you", "Good bye to you"]) +mappedArray == ["Hello to you", "Hi to you", "Good bye to you"] ``` */ @send @@ -907,11 +913,9 @@ See [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refere ```rescript let array = ["Hello", "Hi", "Good bye"] let mappedArray = - array->Array.mapWithIndex((greeting, index) => - greeting ++ " at position " ++ Int.toString(index) - ) + array->Array.mapWithIndex((greeting, index) => greeting ++ " at position " ++ Int.toString(index)) -assertEqual(mappedArray, ["Hello at position 0", "Hi at position 1", "Good bye at position 2"]) +mappedArray == ["Hello at position 0", "Hi at position 1", "Good bye at position 2"] ``` */ @send @@ -948,7 +952,11 @@ Applies `fn` to each element of `xs` from beginning to end. Function `fn` has th ```rescript Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i)->assertEqual(16) -Array.reduceWithIndex([1, 2, 3], list{}, (acc, v, i) => list{v + i, ...acc})->assertEqual(list{5, 3, 1}) +Array.reduceWithIndex([1, 2, 3], list{}, (acc, v, i) => list{v + i, ...acc})->assertEqual(list{ + 5, + 3, + 1, +}) Array.reduceWithIndex([], list{}, (acc, v, i) => list{v + i, ...acc})->assertEqual(list{}) ``` @@ -1114,7 +1122,7 @@ Beware this will *mutate* the array, and is *unsafe*. let array = ["Hello", "Hi", "Good bye"] array->Array.setUnsafe(1, "Hello") -assertEqual(array[1], Some("Hello")) +array[1] == Some("Hello") ``` */ external setUnsafe: (array<'a>, int, 'a) => unit = "%array_unsafe_set" @@ -1298,7 +1306,6 @@ type language = ReScript | TypeScript | JavaScript let array = [ReScript, TypeScript, JavaScript] - array ->Array.flatMapWithIndex((item, index) => switch item { @@ -1388,7 +1395,7 @@ See [Array.prototype.entries](https://developer.mozilla.org/en-US/docs/Web/JavaS ```rescript let array = [5, 6, 7] -let iterator : Iterator.t<(int, int)> = array->Array.entries +let iterator: Iterator.t<(int, int)> = array->Array.entries iterator->Iterator.next->assertEqual({done: false, value: Some((0, 5))}) iterator->Iterator.next->assertEqual({done: false, value: Some((1, 6))}) ``` @@ -1405,7 +1412,7 @@ See [Array.prototype.values](https://developer.mozilla.org/en-US/docs/Web/JavaSc ```rescript let array = [5, 6, 7] -let iterator : Iterator.t = array->Array.values +let iterator: Iterator.t = array->Array.values iterator->Iterator.next->assertEqual({done: false, value: Some(5)}) iterator->Iterator.next->assertEqual({done: false, value: Some(6)}) ``` diff --git a/runtime/Stdlib_AsyncIterator.resi b/runtime/Stdlib_AsyncIterator.resi index 5d2e9b6dcf..60bdccb489 100644 --- a/runtime/Stdlib_AsyncIterator.resi +++ b/runtime/Stdlib_AsyncIterator.resi @@ -39,17 +39,18 @@ let asyncIterator = AsyncIterator.make(async () => { { AsyncIterator.value: Some(currentValue), - done: currentValue >= 3 + done: currentValue >= 3, } }) // This will log 1, 2, 3 -let main = async () => await asyncIterator->AsyncIterator.forEach(value => - switch value { - | Some(value) => Console.log(value) - | None => () - } -) +let main = async () => + await asyncIterator->AsyncIterator.forEach(value => + switch value { + | Some(value) => Console.log(value) + | None => () + } + ) main()->ignore ``` @@ -70,7 +71,7 @@ let asyncIterator = AsyncIterator.make(async () => { let currentValue = context.contents // Increment current value context := currentValue + 1 - + if currentValue >= 3 { AsyncIterator.done() } else { @@ -89,12 +90,12 @@ let value: 'value => value<'value> ## Examples ```rescript let context = ref(0) - + let asyncIterator = AsyncIterator.make(async () => { let currentValue = context.contents // Increment current value context := currentValue + 1 - + if currentValue >= 3 { AsyncIterator.done() } else { @@ -178,7 +179,7 @@ let asyncIterator: AsyncIterator.t<(string, string)> = %raw(` let main = async () => await asyncIterator->AsyncIterator.forEach(v => { switch v { - | Some(("second", value)) => assertEqual(value, "2") + | Some(("second", value)) => value == "2" | _ => () } }) diff --git a/runtime/Stdlib_BigInt.resi b/runtime/Stdlib_BigInt.resi index 0aabe0f5e8..4b1273b71e 100644 --- a/runtime/Stdlib_BigInt.resi +++ b/runtime/Stdlib_BigInt.resi @@ -59,7 +59,7 @@ switch BigInt.fromStringOrThrow("a") { external fromStringOrThrow: string => bigint = "BigInt" /** -Parses the given `string` into a `bigint` using JavaScript semantics. Returns +Parses the given `string` into a `bigint` using JavaScript semantics. Returns `Some(bigint)` if the string can be parsed, `None` otherwise. ## Examples @@ -97,7 +97,7 @@ BigInt.fromInt(-456)->assertEqual(-456n) @val external fromInt: int => bigint = "BigInt" /** -Converts a `float` to a `bigint` using JavaScript semantics. +Converts a `float` to a `bigint` using JavaScript semantics. Throws an exception if the float is not an integer or is infinite/NaN. ## Examples diff --git a/runtime/Stdlib_Bool.resi b/runtime/Stdlib_Bool.resi index a34dc43a7d..041da855d7 100644 --- a/runtime/Stdlib_Bool.resi +++ b/runtime/Stdlib_Bool.resi @@ -49,7 +49,7 @@ let fromStringOrThrow: string => bool /** Converts a string to a boolean. -Beware, this function will throw an `Invalid_argument` exception +Beware, this function will throw an `Invalid_argument` exception if the string is not a valid boolean. ## Examples diff --git a/runtime/Stdlib_Console.resi b/runtime/Stdlib_Console.resi index 45f0e74515..0af09b1776 100644 --- a/runtime/Stdlib_Console.resi +++ b/runtime/Stdlib_Console.resi @@ -54,7 +54,7 @@ external assert3: (bool, 'a, 'b, 'c) => unit = "console.assert" ```rescript let value = 42 Console.assert4(false, "Hello", "World", "ReScript", "!!!") -Console.assert4(value === 42, [1, 2], (3, 4), [#5, #6], #"polyvar") +Console.assert4(value === 42, [1, 2], (3, 4), [#5, #6], #polyvar) ``` */ @val @@ -68,7 +68,7 @@ external assert4: (bool, 'a, 'b, 'c, 'd) => unit = "console.assert" ```rescript let value = 42 Console.assert5(false, "Hello", "World", "JS", '!', '!') -Console.assert5(value === 42, [1, 2], (3, 4), [#5, #6], #"polyvar", {"name": "ReScript"}) +Console.assert5(value === 42, [1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) ``` */ @val @@ -82,7 +82,7 @@ external assert5: (bool, 'a, 'b, 'c, 'd, 'e) => unit = "console.assert" ```rescript let value = 42 Console.assert6(false, "Hello", "World", "JS", '!', '!', '?') -Console.assert6(value === 42, [1, 2], (3, 4), [#5, #6], #"polyvar", {"name": "ReScript"}, 42) +Console.assert6(value === 42, [1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) ``` */ @val @@ -197,7 +197,7 @@ external debug3: ('a, 'b, 'c) => unit = "console.debug" ```rescript Console.debug4("Hello", "World", "ReScript", "!!!") -Console.debug4([1, 2], (3, 4), [#5, #6], #"polyvar") +Console.debug4([1, 2], (3, 4), [#5, #6], #polyvar) ``` */ @val @@ -210,7 +210,7 @@ external debug4: ('a, 'b, 'c, 'd) => unit = "console.debug" ```rescript Console.debug5("Hello", "World", "JS", '!', '!') -Console.debug5([1, 2], (3, 4), [#5, #6], #"polyvar", {"name": "ReScript"}) +Console.debug5([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) ``` */ @val @@ -223,7 +223,7 @@ external debug5: ('a, 'b, 'c, 'd, 'e) => unit = "console.debug" ```rescript Console.debug6("Hello", "World", "JS", '!', '!', '?') -Console.debug6([1, 2], (3, 4), [#5, #6], #"polyvar", {"name": "ReScript"}, 42) +Console.debug6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) ``` */ @val @@ -257,7 +257,10 @@ on MDN. ```rescript Console.dir({"language": "rescript", "version": "10.1.2"}) -Console.dir({"language": "rescript", "version": {"major": "10", "minor": "1", "patch": "2"}}, ~options={depth: null}) +Console.dir( + {"language": "rescript", "version": {"major": "10", "minor": "1", "patch": "2"}}, + ~options={depth: null}, +) ``` */ @val @@ -321,7 +324,7 @@ external error3: ('a, 'b, 'c) => unit = "console.error" ```rescript Console.error4("Hello", "World", "ReScript", '!') -Console.error4(#first, #second, #third, ("fourth")) +Console.error4(#first, #second, #third, "fourth") ``` */ @val @@ -334,7 +337,7 @@ external error4: ('a, 'b, 'c, 'd) => unit = "console.error" ```rescript Console.error5('e', 'r', 'r', 'o', 'r') -Console.error5(1, #second, #third, ("fourth"), 'c') +Console.error5(1, #second, #third, "fourth", 'c') ``` */ @val @@ -347,7 +350,7 @@ external error5: ('a, 'b, 'c, 'd, 'e) => unit = "console.error" ```rescript Console.error6("Hello", "World", "from", "JS", "!!!", '!') -Console.error6([1, 2], (3, 4), [#5, #6], #"polyvar", {"name": "ReScript"}, 42) +Console.error6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) ``` */ @val @@ -466,7 +469,7 @@ external info4: ('a, 'b, 'c, 'd) => unit = "console.info" ```rescript Console.info5("Hello", "World", "from", "JS", "!!!") -Console.info5([1, 2], (3, 4), [#5, #6], #"polyvar", {"name": "ReScript"}) +Console.info5([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) ``` */ @val @@ -479,7 +482,7 @@ external info5: ('a, 'b, 'c, 'd, 'e) => unit = "console.info" ```rescript Console.info6("Hello", "World", "from", "JS", "!!!", '!') -Console.info6([1, 2], (3, 4), [#5, #6], #"polyvar", {"name": "ReScript"}, 42) +Console.info6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) ``` */ @val @@ -548,7 +551,7 @@ external log3: ('a, 'b, 'c) => unit = "console.log" ```rescript Console.log4("Hello", "World", "ReScript", "!!!") -Console.log4([1, 2], (3, 4), [#5, #6], #"polyvar") +Console.log4([1, 2], (3, 4), [#5, #6], #polyvar) ``` */ @val @@ -561,7 +564,7 @@ external log4: ('a, 'b, 'c, 'd) => unit = "console.log" ```rescript Console.log5("Hello", "World", "JS", '!', '!') -Console.log5([1, 2], (3, 4), [#5, #6], #"polyvar", {"name": "ReScript"}) +Console.log5([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) ``` */ @val @@ -574,7 +577,7 @@ external log5: ('a, 'b, 'c, 'd, 'e) => unit = "console.log" ```rescript Console.log6("Hello", "World", "JS", '!', '!', '?') -Console.log6([1, 2], (3, 4), [#5, #6], #"polyvar", {"name": "ReScript"}, 42) +Console.log6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) ``` */ @val @@ -740,7 +743,7 @@ external warn3: ('a, 'b, 'c) => unit = "console.warn" ```rescript Console.warn4("Hello", "World", "ReScript", "!!!") -Console.warn4(#first, #second, #third, ("fourth")) +Console.warn4(#first, #second, #third, "fourth") ``` */ @val @@ -753,7 +756,7 @@ external warn4: ('a, 'b, 'c, 'd) => unit = "console.warn" ```rescript Console.warn5("Hello", "World", "from", "JS", "!!!") -Console.warn5([1, 2], (3, 4), [#5, #6], #"polyvar", {"name": "ReScript"}) +Console.warn5([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) ``` */ @val @@ -766,7 +769,7 @@ external warn5: ('a, 'b, 'c, 'd, 'e) => unit = "console.warn" ```rescript Console.warn6("Hello", "World", "from", "JS", "!!!", '!') -Console.warn6([1, 2], (3, 4), [#5, #6], #"polyvar", {"name": "ReScript"}, 42) +Console.warn6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) ``` */ @val diff --git a/runtime/Stdlib_Date.resi b/runtime/Stdlib_Date.resi index 39b8121597..c0e90397c1 100644 --- a/runtime/Stdlib_Date.resi +++ b/runtime/Stdlib_Date.resi @@ -61,7 +61,7 @@ external make: unit => t = "Date" `fromString(dateTimeString)` Creates a date object from given date time string. -The string has to be in the ISO 8601 format YYYY-MM-DDTHH:mm:ss.sssZ (https://tc39.es/ecma262/#sec-date-time-string-format). +The string has to be in the ISO 8601 format YYYY-MM-DDTHH:mm:ss.sssZ (https://tc39.es/ecma262/\#sec-date-time-string-format). Invalid date time strings will create invalid dates. You can use the result like any valid date, but many functions like `toString` will return "Invalid Date" or functions like `Date.getTime` will return NaN. @@ -105,7 +105,7 @@ external fromTime: msSinceEpoch => t = "Date" /** Creates a date object with the given year and month. -Be aware of using a value for year < 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years). +Be aware of using a value for year \< 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Date\#interpretation\_of\_two-digit\_years). Months are 0-indexed (0 = January, 11 = December). Values, which are out of range, will be carried over to the next bigger unit (s. example). @@ -125,7 +125,6 @@ Date.makeWithYM(~year=2023, ~month=-1) // Note: The output depends on your local time zone. // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) - ``` */ @new @@ -133,7 +132,7 @@ external makeWithYM: (~year: int, ~month: int) => t = "Date" /** Creates a date object with the given year, month and date (day of month). -Be aware of using a value for year < 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years). +Be aware of using a value for year \< 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Date\#interpretation\_of\_two-digit\_years). Months are 0-indexed (0 = January, 11 = December). Values, which are out of range, will be carried over to the next bigger unit (s. example). @@ -154,7 +153,7 @@ external makeWithYMD: (~year: int, ~month: int, ~day: int) => t = "Date" /** Creates a date object with the given year, month, date (day of month) and hours. -Be aware of using a value for year < 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years). +Be aware of using a value for year \< 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Date\#interpretation\_of\_two-digit\_years). Months are 0-indexed (0 = January, 11 = December). Values, which are out of range, will be carried over to the next bigger unit (s. example). @@ -171,7 +170,6 @@ Date.makeWithYMDH(~year=2023, ~month=1, ~day=20, ~hours=-1) // Note: The output depends on your local time zone. // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) - ``` */ @new @@ -179,7 +177,7 @@ external makeWithYMDH: (~year: int, ~month: int, ~day: int, ~hours: int) => t = /** Creates a date object with the given year, month, date (day of month), hours and minutes. -Be aware of using a value for year < 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years). +Be aware of using a value for year \< 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Date\#interpretation\_of\_two-digit\_years). Months are 0-indexed (0 = January, 11 = December). Values, which are out of range, will be carried over to the next bigger unit (s. example). @@ -196,7 +194,6 @@ Date.makeWithYMDHM(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=-1) // Note: The output depends on your local time zone. // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) - ``` */ @new @@ -205,7 +202,7 @@ external makeWithYMDHM: (~year: int, ~month: int, ~day: int, ~hours: int, ~minut /** Creates a date object with the given year, month, date (day of month), hours, minutes and seconds. -Be aware of using a value for year < 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years). +Be aware of using a value for year \< 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Date\#interpretation\_of\_two-digit\_years). Months are 0-indexed (0 = January, 11 = December). Values, which are out of range, will be carried over to the next bigger unit (s. example). @@ -222,7 +219,6 @@ Date.makeWithYMDHMS(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=40, ~seco // Note: The output depends on your local time zone. // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) - ``` */ @new @@ -237,24 +233,47 @@ external makeWithYMDHMS: ( /** Creates a date object with the given year, month, date (day of month), hours, minutes, seconds and milliseconds. -Be aware of using a value for year < 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years). +Be aware of using a value for year \< 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Date\#interpretation\_of\_two-digit\_years). Months are 0-indexed (0 = January, 11 = December). Values, which are out of range, will be carried over to the next bigger unit (s. example). ## Examples ```rescript -Date.makeWithYMDHMSM(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=40, ~seconds=0, ~milliseconds=0) +Date.makeWithYMDHMSM( + ~year=2023, + ~month=1, + ~day=20, + ~hours=16, + ~minutes=40, + ~seconds=0, + ~milliseconds=0, +) // 2023-02-20T16:40:00.000Z -Date.makeWithYMDHMSM(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=40, ~seconds=0, ~milliseconds=1000) +Date.makeWithYMDHMSM( + ~year=2023, + ~month=1, + ~day=20, + ~hours=16, + ~minutes=40, + ~seconds=0, + ~milliseconds=1000, +) // 2023-02-20T16:40:01.000Z -Date.makeWithYMDHMSM(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=40, ~seconds=0, ~milliseconds=-1) +Date.makeWithYMDHMSM( + ~year=2023, + ~month=1, + ~day=20, + ~hours=16, + ~minutes=40, + ~seconds=0, + ~milliseconds=-1, +) // 2023-02-20T16:39:59.999Z // Note: The output depends on your local time zone. // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) - ``` */ @new @@ -270,21 +289,21 @@ external makeWithYMDHMSM: ( module UTC: { /** Returns the time, in milliseconds, since UNIX epoch (January 1, 1970 00:00:00 UTC). - Be aware of using a value for year < 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years). - Months are 0-indexed (0 = January, 11 = December). - Values, which are out of range, will be carried over to the next bigger unit (s. example). +Be aware of using a value for year \< 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Date\#interpretation\_of\_two-digit\_years). +Months are 0-indexed (0 = January, 11 = December). +Values, which are out of range, will be carried over to the next bigger unit (s. example). ## Examples ```rescript Date.UTC.makeWithYM(~year=2023, ~month=0) // 1672531200000 - + Date.UTC.makeWithYM(~year=2023, ~month=11) // 1701388800000 - + Date.UTC.makeWithYM(~year=2023, ~month=12) // 1704067200000 - + Date.UTC.makeWithYM(~year=2023, ~month=-1) // 1669852800000 ``` @@ -294,18 +313,18 @@ module UTC: { /** Returns the time, in milliseconds, since UNIX epoch (January 1, 1970 00:00:00 UTC). - Be aware of using a value for year < 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years). - Months are 0-indexed (0 = January, 11 = December). - Values, which are out of range, will be carried over to the next bigger unit (s. example). +Be aware of using a value for year \< 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Date\#interpretation\_of\_two-digit\_years). +Months are 0-indexed (0 = January, 11 = December). +Values, which are out of range, will be carried over to the next bigger unit (s. example). ## Examples ```rescript Date.UTC.makeWithYMD(~year=2023, ~month=1, ~day=20) // 1676851200000 - + Date.UTC.makeWithYMD(~year=2023, ~month=1, ~day=-1) // 1675036800000 - + Date.UTC.makeWithYMD(~year=2023, ~month=1, ~day=29) // 1677628800000 ``` @@ -315,18 +334,18 @@ module UTC: { /** Returns the time, in milliseconds, since UNIX epoch (January 1, 1970 00:00:00 UTC). - Be aware of using a value for year < 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years). - Months are 0-indexed (0 = January, 11 = December). - Values, which are out of range, will be carried over to the next bigger unit (s. example). +Be aware of using a value for year \< 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Date\#interpretation\_of\_two-digit\_years). +Months are 0-indexed (0 = January, 11 = December). +Values, which are out of range, will be carried over to the next bigger unit (s. example). ## Examples ```rescript Date.UTC.makeWithYMDH(~year=2023, ~month=1, ~day=20, ~hours=16) // 1676908800000 - + Date.UTC.makeWithYMDH(~year=2023, ~month=1, ~day=20, ~hours=24) // 1676937600000 - + Date.UTC.makeWithYMDH(~year=2023, ~month=1, ~day=20, ~hours=-1) // 1676847600000 ``` @@ -337,18 +356,18 @@ module UTC: { /** Returns the time, in milliseconds, since UNIX epoch (January 1, 1970 00:00:00 UTC). - Be aware of using a value for year < 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years). - Months are 0-indexed (0 = January, 11 = December). - Values, which are out of range, will be carried over to the next bigger unit (s. example). +Be aware of using a value for year \< 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Date\#interpretation\_of\_two-digit\_years). +Months are 0-indexed (0 = January, 11 = December). +Values, which are out of range, will be carried over to the next bigger unit (s. example). ## Examples ```rescript Date.UTC.makeWithYMDHM(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=40) // 1676911200000 - + Date.UTC.makeWithYMDHM(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=60) // 1676912400000 - + Date.UTC.makeWithYMDHM(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=-1) // 1676908740000 ``` @@ -364,18 +383,18 @@ module UTC: { /** Returns the time, in milliseconds, since UNIX epoch (January 1, 1970 00:00:00 UTC). - Be aware of using a value for year < 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years). - Months are 0-indexed (0 = January, 11 = December). - Values, which are out of range, will be carried over to the next bigger unit (s. example). +Be aware of using a value for year \< 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Date\#interpretation\_of\_two-digit\_years). +Months are 0-indexed (0 = January, 11 = December). +Values, which are out of range, will be carried over to the next bigger unit (s. example). ## Examples ```rescript Date.UTC.makeWithYMDHMS(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=40, ~seconds=0) // 1676911200000 - + Date.UTC.makeWithYMDHMS(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=40, ~seconds=60) // 1676911260000 - + Date.UTC.makeWithYMDHMS(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=40, ~seconds=-1) // 1676911199000 ``` @@ -392,19 +411,43 @@ module UTC: { /** Returns the time, in milliseconds, since UNIX epoch (January 1, 1970 00:00:00 UTC). - Be aware of using a value for year < 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years). - Months are 0-indexed (0 = January, 11 = December). - Values, which are out of range, will be carried over to the next bigger unit (s. example). +Be aware of using a value for year \< 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Date\#interpretation\_of\_two-digit\_years). +Months are 0-indexed (0 = January, 11 = December). +Values, which are out of range, will be carried over to the next bigger unit (s. example). ## Examples ```rescript - Date.UTC.makeWithYMDHMSM(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=40, ~seconds=0, ~milliseconds=0)->Console.log + Date.UTC.makeWithYMDHMSM( + ~year=2023, + ~month=1, + ~day=20, + ~hours=16, + ~minutes=40, + ~seconds=0, + ~milliseconds=0, + )->Console.log // 1676911200000 - - Date.UTC.makeWithYMDHMSM(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=40, ~seconds=0, ~milliseconds=1000)->Console.log + + Date.UTC.makeWithYMDHMSM( + ~year=2023, + ~month=1, + ~day=20, + ~hours=16, + ~minutes=40, + ~seconds=0, + ~milliseconds=1000, + )->Console.log // 1676911201000 - - Date.UTC.makeWithYMDHMSM(~year=2023, ~month=1, ~day=20, ~hours=16, ~minutes=40, ~seconds=0, ~milliseconds=-1)->Console.log + + Date.UTC.makeWithYMDHMSM( + ~year=2023, + ~month=1, + ~day=20, + ~hours=16, + ~minutes=40, + ~seconds=0, + ~milliseconds=-1, + )->Console.log // 1676911199999 ``` */ @@ -718,7 +761,12 @@ Beware this will *mutate* the date. ## Examples ```rescript -Date.fromString("2023-02-20T16:40:00.00")->Date.setHoursMSMs(~hours=0, ~minutes=0, ~seconds=0, ~milliseconds=0) +Date.fromString("2023-02-20T16:40:00.00")->Date.setHoursMSMs( + ~hours=0, + ~minutes=0, + ~seconds=0, + ~milliseconds=0, +) ``` */ @send @@ -761,7 +809,11 @@ Beware this will *mutate* the date. ## Examples ```rescript -Date.fromString("2023-02-20T16:40:00.00")->Date.setMinutesSMs(~minutes=0, ~seconds=0, ~milliseconds=0) +Date.fromString("2023-02-20T16:40:00.00")->Date.setMinutesSMs( + ~minutes=0, + ~seconds=0, + ~milliseconds=0, +) ``` */ @send @@ -1034,7 +1086,12 @@ Beware this will *mutate* the date. ## Examples ```rescript -Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHoursMSMs(~hours=0, ~minutes=0, ~seconds=0, ~milliseconds=0) +Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHoursMSMs( + ~hours=0, + ~minutes=0, + ~seconds=0, + ~milliseconds=0, +) ``` */ @send @@ -1082,7 +1139,11 @@ Beware this will *mutate* the date. ## Examples ```rescript -Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMinutesSMs(~minutes=0, ~seconds=0, ~milliseconds=0) +Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMinutesSMs( + ~minutes=0, + ~seconds=0, + ~milliseconds=0, +) ``` */ @send @@ -1220,13 +1281,15 @@ Converts a JavaScript date to a localized date string. It will use the specified ## Examples ```rescript -Date.make()->Date.toLocaleDateStringWithLocaleAndOptions("en-US", { dateStyle: #long })->Console.log +Date.make()->Date.toLocaleDateStringWithLocaleAndOptions("en-US", {dateStyle: #long})->Console.log // February 19, 2023 -Date.make()->Date.toLocaleDateStringWithLocaleAndOptions("de", { hour: #"2-digit", minute: #"2-digit" })->Console.log +Date.make() +->Date.toLocaleDateStringWithLocaleAndOptions("de", {hour: #"2-digit", minute: #"2-digit"}) +->Console.log // 19.2.2023, 15:40 -Date.make()->Date.toLocaleDateStringWithLocaleAndOptions("de", { year: #numeric })->Console.log +Date.make()->Date.toLocaleDateStringWithLocaleAndOptions("de", {year: #numeric})->Console.log // 2023 ``` */ @@ -1269,10 +1332,24 @@ Converts a JavaScript date to a localized date-time string. It will use the spec ## Examples ```rescript -Date.make()->Date.toLocaleStringWithLocaleAndOptions("en", { dateStyle: #short, timeStyle: #short })->Console.log +Date.make() +->Date.toLocaleStringWithLocaleAndOptions("en", {dateStyle: #short, timeStyle: #short}) +->Console.log // 2/19/23, 3:40 PM -Date.make()->Date.toLocaleStringWithLocaleAndOptions("en", { era: #long, year: #numeric, month: #"2-digit", day: #"2-digit", hour: #numeric, timeZoneName: #short })->Console.log +Date.make() +->Date.toLocaleStringWithLocaleAndOptions( + "en", + { + era: #long, + year: #numeric, + month: #"2-digit", + day: #"2-digit", + hour: #numeric, + timeZoneName: #short, + }, +) +->Console.log // 02/19/2023 Anno Domini, 3 PM GMT+1 ``` */ @@ -1314,10 +1391,12 @@ Converts a JavaScript date to a localized time string. It will use the specified ## Examples ```rescript -Date.make()->Date.toLocaleTimeStringWithLocaleAndOptions("en-US", { timeStyle: #long })->Console.log +Date.make()->Date.toLocaleTimeStringWithLocaleAndOptions("en-US", {timeStyle: #long})->Console.log // 3:40:00 PM GMT+1 -Date.make()->Date.toLocaleTimeStringWithLocaleAndOptions("de", { hour: #"2-digit", minute: #"2-digit" })->Console.log +Date.make() +->Date.toLocaleTimeStringWithLocaleAndOptions("de", {hour: #"2-digit", minute: #"2-digit"}) +->Console.log // 15:40 ``` */ diff --git a/runtime/Stdlib_Dict.resi b/runtime/Stdlib_Dict.resi index 604c5d4de9..151bd57bb3 100644 --- a/runtime/Stdlib_Dict.resi +++ b/runtime/Stdlib_Dict.resi @@ -178,7 +178,6 @@ dict2->Dict.set("someKey2", 3) let dict1 = dict1->Dict.assign(dict2) Console.log(dict1->Dict.keysToArray) // Logs `["firstKey", "someKey", "someKey2"]` - ``` */ @val diff --git a/runtime/Stdlib_Float.resi b/runtime/Stdlib_Float.resi index b9e19f3981..ef67cfda09 100644 --- a/runtime/Stdlib_Float.resi +++ b/runtime/Stdlib_Float.resi @@ -37,7 +37,7 @@ Float constants. module Constants: { /** The special value "Not a Number" - See [`NaN`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN) on MDN. +See [`NaN`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN) on MDN. ## Examples @@ -50,7 +50,7 @@ module Constants: { /** Represents the difference between 1 and the smallest floating point number greater than 1. - See [`Number.EPSILON`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/EPSILON) on MDN. +See [`Number.EPSILON`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/EPSILON) on MDN. ## Examples @@ -63,7 +63,7 @@ module Constants: { /** The positive Infinity value - See [`Number.POSITIVE_INFINITY`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/POSITIVE_INFINITY) on MDN. +See [`Number.POSITIVE_INFINITY`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/POSITIVE_INFINITY) on MDN. ## Examples @@ -76,7 +76,7 @@ module Constants: { /** The negative Infinity value - See [`Number.NEGATIVE_INFINITY`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NEGATIVE_INFINITY) on MDN. +See [`Number.NEGATIVE_INFINITY`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NEGATIVE_INFINITY) on MDN. ## Examples @@ -89,7 +89,7 @@ module Constants: { /** The smallest positive numeric value representable in JavaScript. - See [`Number.MIN_VALUE`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_VALUE) on MDN. +See [`Number.MIN_VALUE`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_VALUE) on MDN. ## Examples @@ -102,7 +102,7 @@ module Constants: { /** The maximum positive numeric value representable in JavaScript. - See [`Number.MAX_VALUE`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_VALUE) on MDN. +See [`Number.MAX_VALUE`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_VALUE) on MDN. ## Examples @@ -168,7 +168,7 @@ external isFinite: float => bool = "isFinite" /** `parseFloat(v)` parse the given `v` and returns a float. Leading whitespace in -`v` is ignored. Returns `NaN` if `v` can't be parsed. Use [`fromString`] to +`v` is ignored. Returns `NaN` if `v` can't be parsed. Use \[`fromString`\] to ensure it returns a valid float and not `NaN`. See [`parseFloat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat) on MDN. @@ -188,7 +188,7 @@ external parseFloat: string => float = "parseFloat" /** `parseInt(v, ~radix=?)` parse the given `v` and returns a float. Leading whitespace in this argument `v`is ignored. `radix` specifies the radix base to -use for the formatted number. The value must be in the range [2, 36] (inclusive). +use for the formatted number. The value must be in the range \[2, 36\] (inclusive). Returns `NaN` if `v` can't be parsed and `radix` is smaller than 2 or bigger than 36. See [`parseInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt) on MDN. @@ -213,7 +213,7 @@ external parseInt: ('a, ~radix: int=?) => float = "parseInt" /** `parseIntWithRadix(v, ~radix)` parse the given `v` and returns a float. Leading whitespace in this argument `v`is ignored. `radix` specifies the radix base to -use for the formatted number. The value must be in the range [2, 36] (inclusive). +use for the formatted number. The value must be in the range \[2, 36\] (inclusive). Returns `NaN` if `v` can't be parsed and `radix` is smaller than 2 or bigger than 36. See [`parseInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt) on MDN. @@ -331,8 +331,8 @@ Float.toPrecision(1.0, ~digits=1) == "1" ## Exceptions - `RangeError`: If `digits` is not between 1 and 100 (inclusive). -Implementations are allowed to support larger and smaller values as well. -ECMA-262 only requires a precision of up to 21 significant digits. + Implementations are allowed to support larger and smaller values as well. + ECMA-262 only requires a precision of up to 21 significant digits. */ @send external toPrecision: (float, ~digits: int=?) => string = "toPrecision" @@ -352,9 +352,9 @@ Float.toPrecisionWithPrecision(1.0, ~digits=1) == "1" ## Exceptions - `RangeError`: If `digits` is not between 1 and 100 (inclusive). -Implementations are allowed to support larger and smaller values as well. -ECMA-262 only requires a precision of up to 21 significant digits. - + Implementations are allowed to support larger and smaller values as well. + ECMA-262 only requires a precision of up to 21 significant digits. + */ @deprecated("Use `toPrecision` instead") @send external toPrecisionWithPrecision: (float, ~digits: int) => string = "toPrecision" @@ -464,7 +464,7 @@ external mod: (float, float) => float = "%modfloat" /** `clamp(~min=?, ~max=?, value)` returns `value`, optionally bounded by `min` and `max`. -if `max` < `min` returns `min`. +if `max` \< `min` returns `min`. ## Examples diff --git a/runtime/Stdlib_Int.resi b/runtime/Stdlib_Int.resi index 3963be3cb2..384e351287 100644 --- a/runtime/Stdlib_Int.resi +++ b/runtime/Stdlib_Int.resi @@ -35,8 +35,8 @@ type t = int module Constants: { /** The smallest positive number represented in JavaScript. - See [`Number.MIN_VALUE`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_VALUE) - on MDN. +See [`Number.MIN_VALUE`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_VALUE) +on MDN. ## Examples @@ -48,8 +48,8 @@ module Constants: { let minValue: int /** The largest positive number represented in JavaScript. - See [`Number.MAX_VALUE`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_VALUE) - on MDN. +See [`Number.MAX_VALUE`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_VALUE) +on MDN. ## Examples @@ -164,8 +164,8 @@ Int.toPrecision(1, ~digits=2) // "1.0" ## Exceptions - `RangeError`: If `digits` is not between 1 and 100 (inclusive). -Implementations are allowed to support larger and smaller values as well. -ECMA-262 only requires a precision of up to 21 significant digits. + Implementations are allowed to support larger and smaller values as well. + ECMA-262 only requires a precision of up to 21 significant digits. */ @send external toPrecision: (int, ~digits: int=?) => string = "toPrecision" @@ -184,9 +184,9 @@ Int.toPrecisionWithPrecision(1, ~digits=2) // "1.0" ## Exceptions - `RangeError`: If `digits` is not between 1 and 100 (inclusive). -Implementations are allowed to support larger and smaller values as well. -ECMA-262 only requires a precision of up to 21 significant digits. - + Implementations are allowed to support larger and smaller values as well. + ECMA-262 only requires a precision of up to 21 significant digits. + */ @send @deprecated("Use `toPrecision` instead") external toPrecisionWithPrecision: (int, ~digits: int) => string = "toPrecision" @@ -376,7 +376,7 @@ let rangeWithOptions: (int, int, rangeOptions) => array /** `clamp(~min=?, ~max=?, value)` returns `value`, optionally bounded by `min` and `max`. -if `max` < `min` returns `min`. +if `max` \< `min` returns `min`. ## Examples @@ -490,7 +490,7 @@ module Ref: { ```rescript let myRef = ref(4) Int.Ref.increment(myRef) - assertEqual(myRef.contents, 5) + myRef.contents == 5 ``` */ external increment: ref => unit = "%incr" @@ -503,7 +503,7 @@ module Ref: { ```rescript let myRef = ref(4) Int.Ref.decrement(myRef) - assertEqual(myRef.contents, 3) + myRef.contents == 3 ``` */ external decrement: ref => unit = "%decr" diff --git a/runtime/Stdlib_Iterator.resi b/runtime/Stdlib_Iterator.resi index e1e16fbf9e..6d632b2d1f 100644 --- a/runtime/Stdlib_Iterator.resi +++ b/runtime/Stdlib_Iterator.resi @@ -85,7 +85,8 @@ map->Map.set("someKey", "someValue") map->Map.set("someKey2", "someValue2") // `Map.keys` returns all keys of the map as an iterator. -let mapKeysAsArray = map +let mapKeysAsArray = + map ->Map.keys ->Iterator.toArrayWithMapper(key => key->String.length) @@ -133,7 +134,7 @@ See [Iterator.prototype.drop](https://developer.mozilla.org/en-US/docs/Web/JavaS ## Examples ```rescript -let fibonacci: Iterator.t = [ 1, 1, 2, 3, 5, 8, 13, 21 ]->Array.values +let fibonacci: Iterator.t = [1, 1, 2, 3, 5, 8, 13, 21]->Array.values let seq = fibonacci->Iterator.drop(2) seq->Iterator.next->assertEqual({done: false, value: Some(2)}) @@ -155,7 +156,7 @@ See [Iterator.prototype.every](https://developer.mozilla.org/en-US/docs/Web/Java ## Examples ```rescript -let fibonacci: Iterator.t = [ 1, 1, 2, 3, 5, 8, 13, 21 ]->Array.values +let fibonacci: Iterator.t = [1, 1, 2, 3, 5, 8, 13, 21]->Array.values let areAllEven = fibonacci->Iterator.every(n => n % 2 == 0) areAllEven->assertEqual(false) @@ -176,7 +177,7 @@ See [Iterator.prototype.filter](https://developer.mozilla.org/en-US/docs/Web/Jav ## Examples ```rescript -let fibonacci: Iterator.t = [ 1, 1, 2, 3, 5, 8, 13, 21 ]->Array.values +let fibonacci: Iterator.t = [1, 1, 2, 3, 5, 8, 13, 21]->Array.values let seq = fibonacci->Iterator.filter(n => n % 2 == 0) seq->Iterator.next->assertEqual({done: false, value: Some(2)}) @@ -198,7 +199,7 @@ See [Iterator.prototype.find](https://developer.mozilla.org/en-US/docs/Web/JavaS ## Examples ```rescript -let fibonacci: Iterator.t = [ 1, 1, 2, 3, 5, 8, 13, 21 ]->Array.values +let fibonacci: Iterator.t = [1, 1, 2, 3, 5, 8, 13, 21]->Array.values let seq = fibonacci->Iterator.find(n => n % 2 == 0) seq->assertEqual(Some(2)) @@ -265,7 +266,7 @@ See [Iterator.prototype.reduce](https://developer.mozilla.org/en-US/docs/Web/Jav ## Examples ```rescript -let numbers: Iterator.t = [ 1, 2, 3 ]->Array.values +let numbers: Iterator.t = [1, 2, 3]->Array.values let sum = numbers->Iterator.reduce((acc, n) => acc + n, ~initialValue=0) sum->assertEqual(6) @@ -280,15 +281,15 @@ This feature might not work in older devices or browsers. external reduce: (t<'a>, ('acc, 'a) => 'acc, ~initialValue: 'acc=?) => 'acc = "reduce" /** -`some(iterator, fn)` The some() method of Iterator instances is similar to Array.some: -it tests whether at least one element produced by the iterator passes the test implemented by the provided function. +`some(iterator, fn)` The some() method of Iterator instances is similar to Array.some: +it tests whether at least one element produced by the iterator passes the test implemented by the provided function. It returns a boolean value. See [Iterator.prototype.some](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/some) on MDN. ## Examples ```rescript -let numbers: Iterator.t = [ 1, 2, 3 ]->Array.values +let numbers: Iterator.t = [1, 2, 3]->Array.values let hasEven = numbers->Iterator.some(n => n % 2 == 0) hasEven->assertEqual(true) @@ -309,7 +310,7 @@ See [Iterator.prototype.take](https://developer.mozilla.org/en-US/docs/Web/JavaS ## Examples ```rescript -let fibonacci: Iterator.t = [ 1, 1, 2, 3, 5, 8, 13, 21 ]->Array.values +let fibonacci: Iterator.t = [1, 1, 2, 3, 5, 8, 13, 21]->Array.values let seq = fibonacci->Iterator.take(2) seq->Iterator.next->assertEqual({done: false, value: Some(1)}) diff --git a/runtime/Stdlib_JSON.resi b/runtime/Stdlib_JSON.resi index af6ed6050e..6c777af2a6 100644 --- a/runtime/Stdlib_JSON.resi +++ b/runtime/Stdlib_JSON.resi @@ -18,7 +18,7 @@ type rec t = type replacer = Keys(array) | Replacer((string, t) => t) /** -`parseOrThrow(string, ~reviver=?)` +`parseOrThrow(string, ~reviver=?)` Parses a JSON string or throws a JavaScript exception (SyntaxError), if the string isn't valid. The reviver describes how the value should be transformed. It is a function which receives a key and a value. @@ -56,7 +56,7 @@ try { } ``` -## Exceptions +## Exceptions - Raises a SyntaxError (Exn.t) if the string isn't valid JSON. */ @@ -64,7 +64,7 @@ try { external parseOrThrow: (string, ~reviver: (string, t) => t=?) => t = "JSON.parse" /** -`parseExn(string, ~reviver=?)` +`parseExn(string, ~reviver=?)` Parses a JSON string or throws a JavaScript exception (SyntaxError), if the string isn't valid. The reviver describes how the value should be transformed. It is a function which receives a key and a value. @@ -102,7 +102,7 @@ try { } ``` -## Exceptions +## Exceptions - Raises a SyntaxError (Exn.t) if the string isn't valid JSON. */ @@ -110,7 +110,7 @@ try { external parseExn: (string, ~reviver: (string, t) => t=?) => t = "JSON.parse" /** -`parseExnWithReviver(string, reviver)` +`parseExnWithReviver(string, reviver)` Parses a JSON string or throws a JavaScript exception (SyntaxError), if the string isn't valid. The reviver describes how the value should be transformed. It is a function which receives a key and a value. @@ -138,7 +138,7 @@ try { } ``` -## Exceptions +## Exceptions - Raises a SyntaxError if the string is not a valid JSON. */ @@ -146,7 +146,7 @@ try { external parseExnWithReviver: (string, (string, t) => t) => t = "JSON.parse" /** -`stringify(json, ~replacer=?, ~space=?)` +`stringify(json, ~replacer=?, ~space=?)` Converts a JSON object to a JSON string. The replacer describes how the value should be transformed. It is a function which receives a key and a value, @@ -175,14 +175,16 @@ JSON.stringify(json, ~space=2) JSON.stringify(json, ~replacer=Keys(["foo", "someNumber"])) // {"foo":"bar","someNumber":42} -let replacer = JSON.Replacer((_, value) => { - let decodedValue = value->JSON.Decode.string +let replacer = JSON.Replacer( + (_, value) => { + let decodedValue = value->JSON.Decode.string - switch decodedValue { - | Some(string) => string->String.toUpperCase->JSON.Encode.string - | None => value - } -}) + switch decodedValue { + | Some(string) => string->String.toUpperCase->JSON.Encode.string + | None => value + } + }, +) JSON.stringify(json, ~replacer) // {"foo":"BAR","hello":"WORLD","someNumber":42} @@ -192,7 +194,7 @@ JSON.stringify(json, ~replacer) external stringify: (t, ~replacer: replacer=?, ~space: int=?) => string = "JSON.stringify" /** -`stringifyWithIndent(json, indentation)` +`stringifyWithIndent(json, indentation)` Converts a JSON object to a JSON string. The output will be indented. If you want to stringify any type, use `JSON.stringifyAnyWithIndent` instead. @@ -218,7 +220,7 @@ JSON.stringifyWithIndent(json, 2) external stringifyWithIndent: (t, @as(json`null`) _, int) => string = "JSON.stringify" /** -`stringifyWithReplacer(json, replacer)` +`stringifyWithReplacer(json, replacer)` Converts a JSON object to a JSON string. The replacer describes how the value should be transformed. It is a function which receives a key and a value. @@ -286,7 +288,7 @@ JSON.stringifyWithReplacerAndIndent(json, replacer, 2) external stringifyWithReplacerAndIndent: (t, (string, t) => t, int) => string = "JSON.stringify" /** -`stringifyWithFilter(json, filter)` +`stringifyWithFilter(json, filter)` Converts a JSON object to a JSON string. The filter is an array of keys, which should be included in the output. @@ -309,7 +311,7 @@ JSON.stringifyWithFilter(json, ["foo", "someNumber"]) external stringifyWithFilter: (t, array) => string = "JSON.stringify" /** -`stringifyWithFilterAndIndent(json, filter, indentation)` +`stringifyWithFilterAndIndent(json, filter, indentation)` Converts a JSON object to a JSON string. The output will be indented. The filter is an array of keys, which should be included in the output. @@ -371,22 +373,23 @@ dict ->Option.getUnsafe ->assertEqual(`{"foo":"bar","someNumber":42}`) -let replacer = JSON.Replacer((_, value) => { - let decodedValue = value->JSON.Decode.string +let replacer = JSON.Replacer( + (_, value) => { + let decodedValue = value->JSON.Decode.string - switch decodedValue { - | Some(string) => string->String.toUpperCase->JSON.Encode.string - | None => value - } -}) + switch decodedValue { + | Some(string) => string->String.toUpperCase->JSON.Encode.string + | None => value + } + }, +) dict ->JSON.stringifyAny(~replacer) ->Option.getUnsafe ->assertEqual(`{"foo":"BAR","hello":"WORLD","someNumber":42}`) -JSON.stringifyAny(() => "hello world") -->assertEqual(None) +JSON.stringifyAny(() => "hello world")->assertEqual(None) // Raise a exception switch BigInt.fromInt(0)->JSON.stringifyAny { @@ -438,7 +441,7 @@ switch BigInt.fromInt(0)->JSON.stringifyAny { } ``` -## Exceptions +## Exceptions - Raises a TypeError if the value contains circular references. - Raises a TypeError if the value contains `BigInt`s. @@ -533,7 +536,7 @@ switch BigInt.fromInt(0)->JSON.stringifyAny { } ``` -## Exceptions +## Exceptions - Raises a TypeError if the value contains circular references. - Raises a TypeError if the value contains `BigInt`s. @@ -625,7 +628,7 @@ switch BigInt.fromInt(0)->JSON.stringifyAny { } ``` -## Exceptions +## Exceptions - Raises a TypeError if the value contains circular references. - Raises a TypeError if the value contains `BigInt`s. @@ -652,7 +655,7 @@ module Classify: { ```rescript JSON.Classify.classify("hello world") // String("hello world") - + JSON.Classify.classify(42) // Number(42) ``` @@ -721,7 +724,7 @@ module Encode: { ("foo", JSON.Encode.string("bar")), ("hello", JSON.Encode.string("world")), ]) - + JSON.Encode.object(dict) ``` */ @@ -733,7 +736,7 @@ module Encode: { ## Examples ```rescript let array = [JSON.Encode.string("hello world"), JSON.Encode.int(42)] - + JSON.Encode.array(array) ``` */ @@ -748,7 +751,7 @@ module Decode: { ```rescript JSON.parseOrThrow(`true`)->JSON.Decode.bool // Some(true) - + JSON.parseOrThrow(`"hello world"`)->JSON.Decode.bool // None ``` @@ -762,7 +765,7 @@ module Decode: { ```rescript JSON.parseOrThrow(`null`)->JSON.Decode.null // Some(null) - + JSON.parseOrThrow(`"hello world"`)->JSON.Decode.null // None ``` @@ -776,9 +779,9 @@ module Decode: { ```rescript JSON.parseOrThrow(`"hello world"`)->JSON.Decode.string // Some("hello world") - + JSON.parseOrThrow(`42`)->JSON.Decode.string - // None + // None ``` */ let string: t => option @@ -790,7 +793,7 @@ module Decode: { ```rescript JSON.parseOrThrow(`42.0`)->JSON.Decode.float // Some(42.0) - + JSON.parseOrThrow(`"hello world"`)->JSON.Decode.float // None ``` @@ -804,7 +807,7 @@ module Decode: { ```rescript JSON.parseOrThrow(`{"foo":"bar"}`)->JSON.Decode.object // Some({ foo: 'bar' }) - + JSON.parseOrThrow(`"hello world"`)->JSON.Decode.object // None ``` @@ -818,7 +821,7 @@ module Decode: { ```rescript JSON.parseOrThrow(`["foo", "bar"]`)->JSON.Decode.array // Some([ 'foo', 'bar' ]) - + JSON.parseOrThrow(`"hello world"`)->JSON.Decode.array // None ``` diff --git a/runtime/Stdlib_JsError.resi b/runtime/Stdlib_JsError.resi index 2304cf9569..3b2ebaab27 100644 --- a/runtime/Stdlib_JsError.resi +++ b/runtime/Stdlib_JsError.resi @@ -30,7 +30,7 @@ See [`Error.prototype.message`](https://developer.mozilla.org/en-US/docs/Web/Jav ## Example ```rescript let error = JsError.SyntaxError.make("Some message here") -error->JsError.message->assertEqual("Some message here") +error->JsError.message->assertEqual("Some message here") ``` */ @get @@ -66,9 +66,9 @@ See [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/ ## Example ```rescript let error = JsError.make("Some message here") -error->JsError.message->assertEqual("Some message here") -error->JsError.name->assertEqual("Error") -```` +error->JsError.message->assertEqual("Some message here") +error->JsError.name->assertEqual("Error") +``` */ @new external make: string => t = "Error" diff --git a/runtime/Stdlib_List.resi b/runtime/Stdlib_List.resi index e1385bbe51..af56973811 100644 --- a/runtime/Stdlib_List.resi +++ b/runtime/Stdlib_List.resi @@ -42,7 +42,7 @@ type t<'a> = list<'a> ## Examples ```rescript -assertEqual(List.length(list{1, 2, 3}), 3) +List.length(list{1, 2, 3}) == 3 ``` */ let length: list<'a> => int @@ -53,7 +53,7 @@ let length: list<'a> => int ## Examples ```rescript -assertEqual(List.size(list{1, 2, 3}), 3) +List.size(list{1, 2, 3}) == 3 ``` */ let size: list<'a> => int @@ -65,8 +65,8 @@ list, or `None` if `list` is an empty list. ## Examples ```rescript -assertEqual(List.head(list{}), None) -assertEqual(List.head(list{1, 2, 3}), Some(1)) +List.head(list{}) == None +List.head(list{1, 2, 3}) == Some(1) ``` */ let head: list<'a> => option<'a> @@ -88,7 +88,7 @@ switch List.headExn(list{}) { ## Exceptions - Raises an Error if list is empty. - + */ @deprecated("Use `headOrThrow` instead") let headExn: list<'a> => 'a @@ -120,9 +120,9 @@ where `tail` is everything except the first element of `list`. ## Examples ```rescript -assertEqual(List.tail(list{1, 2, 3}), Some(list{2, 3})) +List.tail(list{1, 2, 3}) == Some(list{2, 3}) -assertEqual(List.tail(list{}), None) +List.tail(list{}) == None ``` */ let tail: list<'a> => option> @@ -174,9 +174,9 @@ let tailOrThrow: list<'a> => list<'a> ## Examples ```rescript -assertEqual(List.add(list{2, 3}, 1), list{1, 2, 3}) +List.add(list{2, 3}, 1) == list{1, 2, 3} -assertEqual(List.add(list{"World", "!"}, "Hello"), list{"Hello", "World", "!"}) +List.add(list{"World", "!"}, "Hello") == list{"Hello", "World", "!"} ``` */ let add: (list<'a>, 'a) => list<'a> @@ -190,9 +190,9 @@ is larger than the length of list `list`. ```rescript let abc = list{"A", "B", "C"} -assertEqual(abc->List.get(1), Some("B")) +abc->List.get(1) == Some("B") -assertEqual(abc->List.get(4), None) +abc->List.get(4) == None ``` */ let get: (list<'a>, int) => option<'a> @@ -253,7 +253,7 @@ with `value`. Returns an empty list if `value` is negative. ## Examples ```rescript -assertEqual(List.make(~length=3, 1), list{1, 1, 1}) +List.make(~length=3, 1) == list{1, 1, 1} ``` */ let make: (~length: int, 'a) => list<'a> @@ -265,9 +265,9 @@ with `f`. Returns an empty list if `length` is negative. ## Examples ```rescript -assertEqual(List.fromInitializer(~length=5, i => i), list{0, 1, 2, 3, 4}) +List.fromInitializer(~length=5, i => i) == list{0, 1, 2, 3, 4} -assertEqual(List.fromInitializer(~length=5, i => i * i), list{0, 1, 4, 9, 16}) +List.fromInitializer(~length=5, i => i * i) == list{0, 1, 4, 9, 16} ``` */ let fromInitializer: (~length: int, int => 'a) => list<'a> @@ -302,11 +302,11 @@ Returns `None` if `list` has fewer than `value` elements. ## Examples ```rescript -assertEqual(list{1, 2, 3}->List.drop(2), Some(list{3})) +list{1, 2, 3}->List.drop(2) == Some(list{3}) -assertEqual(list{1, 2, 3}->List.drop(3), Some(list{})) +list{1, 2, 3}->List.drop(3) == Some(list{}) -assertEqual(list{1, 2, 3}->List.drop(4), None) +list{1, 2, 3}->List.drop(4) == None ``` */ let drop: (list<'a>, int) => option> @@ -318,11 +318,11 @@ or `None` if `list` has fewer than `value` elements. ## Examples ```rescript -assertEqual(list{1, 2, 3}->List.take(1), Some(list{1})) +list{1, 2, 3}->List.take(1) == Some(list{1}) -assertEqual(list{1, 2, 3}->List.take(2), Some(list{1, 2})) +list{1, 2, 3}->List.take(2) == Some(list{1, 2}) -assertEqual(list{1, 2, 3}->List.take(4), None) +list{1, 2, 3}->List.take(4) == None ``` */ let take: (list<'a>, int) => option> @@ -334,9 +334,9 @@ of `list` is less than `n`. ## Examples ```rescript -assertEqual(list{"Hello", "World"}->List.splitAt(1), Some((list{"Hello"}, list{"World"}))) +list{"Hello", "World"}->List.splitAt(1) == Some((list{"Hello"}, list{"World"})) -assertEqual(list{0, 1, 2, 3, 4}->List.splitAt(2), Some((list{0, 1}, list{2, 3, 4}))) +list{0, 1, 2, 3, 4}->List.splitAt(2) == Some((list{0, 1}, list{2, 3, 4})) ``` */ let splitAt: (list<'a>, int) => option<(list<'a>, list<'a>)> @@ -359,7 +359,7 @@ array `arr`, in order. ## Examples ```rescript -assertEqual(List.concatMany([list{1, 2, 3}, list{}, list{3}]), list{1, 2, 3, 3}) +List.concatMany([list{1, 2, 3}, list{}, list{3}]) == list{1, 2, 3, 3} ``` */ let concatMany: array> => list<'a> @@ -370,7 +370,7 @@ let concatMany: array> => list<'a> ## Examples ```rescript -assertEqual(List.reverseConcat(list{1, 2}, list{3, 4}), list{2, 1, 3, 4}) +List.reverseConcat(list{1, 2}, list{3, 4}) == list{2, 1, 3, 4} ``` */ let reverseConcat: (list<'a>, list<'a>) => list<'a> @@ -382,7 +382,7 @@ let reverseConcat: (list<'a>, list<'a>) => list<'a> ## Examples ```rescript -assertEqual(List.flat(list{list{1, 2, 3}, list{}, list{3}}), list{1, 2, 3, 3}) +List.flat(list{list{1, 2, 3}, list{}, list{3}}) == list{1, 2, 3, 3} ``` */ let flat: list> => list<'a> @@ -393,7 +393,7 @@ let flat: list> => list<'a> ## Examples ```rescript -assertEqual(list{1, 2}->List.map(x => x + 1), list{2, 3}) +list{1, 2}->List.map(x => x + 1) == list{2, 3} ``` */ let map: (list<'a>, 'a => 'b) => list<'b> @@ -405,7 +405,7 @@ of the shorter list. ## Examples ```rescript -assertEqual(List.zip(list{1, 2}, list{3, 4, 5}), list{(1, 3), (2, 4)}) +List.zip(list{1, 2}, list{3, 4, 5}) == list{(1, 3), (2, 4)} ``` */ let zip: (list<'a>, list<'b>) => list<('a, 'b)> @@ -416,7 +416,7 @@ let zip: (list<'a>, list<'b>) => list<('a, 'b)> ## Examples ```rescript -assertEqual(List.zipBy(list{1, 2, 3}, list{4, 5}, (a, b) => 2 * a + b), list{6, 9}) +List.zipBy(list{1, 2, 3}, list{4, 5}, (a, b) => 2 * a + b) == list{6, 9} ``` */ let zipBy: (list<'a>, list<'b>, ('a, 'b) => 'c) => list<'c> @@ -429,7 +429,7 @@ that order. ## Examples ```rescript -assertEqual(list{1, 2, 3}->List.mapWithIndex((x, index) => index + x), list{1, 3, 5}) +list{1, 2, 3}->List.mapWithIndex((x, index) => index + x) == list{1, 3, 5} ``` */ let mapWithIndex: (list<'a>, ('a, int) => 'b) => list<'b> @@ -440,7 +440,7 @@ let mapWithIndex: (list<'a>, ('a, int) => 'b) => list<'b> ## Examples ```rescript -assertEqual(List.fromArray([1, 2, 3]), list{1, 2, 3}) +List.fromArray([1, 2, 3]) == list{1, 2, 3} ``` */ let fromArray: array<'a> => list<'a> @@ -451,7 +451,7 @@ let fromArray: array<'a> => list<'a> ## Examples ```rescript -assertEqual(List.toArray(list{1, 2, 3}), [1, 2, 3]) +List.toArray(list{1, 2, 3}) == [1, 2, 3] ``` */ let toArray: list<'a> => array<'a> @@ -463,7 +463,7 @@ reversed order. ## Examples ```rescript -assertEqual(List.reverse(list{1, 2, 3}), list{3, 2, 1}) +List.reverse(list{1, 2, 3}) == list{3, 2, 1} ``` */ let reverse: list<'a> => list<'a> @@ -534,11 +534,11 @@ the final value of the accumulator. ## Examples ```rescript -assertEqual(list{1, 2, 3, 4}->List.reduce(0, (a, b) => a + b), 10) +list{1, 2, 3, 4}->List.reduce(0, (a, b) => a + b) == 10 // same as -assertEqual(list{1, 2, 3, 4}->List.reduce(0, (acc, item) => acc + item), 10) +list{1, 2, 3, 4}->List.reduce(0, (acc, item) => acc + item) == 10 ``` */ let reduce: (list<'a>, 'b, ('b, 'a) => 'b) => 'b @@ -552,7 +552,7 @@ of each element. `reduceWithIndex` returns the final value of the accumulator. ## Examples ```rescript -assertEqual(list{1, 2, 3, 4}->List.reduceWithIndex(0, (acc, item, index) => acc + item + index), 16) +list{1, 2, 3, 4}->List.reduceWithIndex(0, (acc, item, index) => acc + item + index) == 16 ``` */ let reduceWithIndex: (list<'a>, 'b, ('b, 'a, int) => 'b) => 'b @@ -564,11 +564,11 @@ function `f` is applied to each item of `list` from the last back to the first. ## Examples ```rescript -assertEqual(list{1, 2, 3, 4}->List.reduceReverse(0, (a, b) => a + b), 10) +list{1, 2, 3, 4}->List.reduceReverse(0, (a, b) => a + b) == 10 -assertEqual(list{1, 2, 3, 4}->List.reduceReverse(10, (a, b) => a - b), 0) +list{1, 2, 3, 4}->List.reduceReverse(10, (a, b) => a - b) == 0 -assertEqual(list{1, 2, 3, 4}->List.reduceReverse(list{}, List.add), list{1, 2, 3, 4}) +list{1, 2, 3, 4}->List.reduceReverse(list{}, List.add) == list{1, 2, 3, 4} ``` */ let reduceReverse: (list<'a>, 'b, ('b, 'a) => 'b) => 'b @@ -579,7 +579,7 @@ let reduceReverse: (list<'a>, 'b, ('b, 'a) => 'b) => 'b ## Examples ```rescript -assertEqual(List.mapReverse2(list{1, 2, 3}, list{1, 2}, (a, b) => a + b), list{4, 2}) +List.mapReverse2(list{1, 2, 3}, list{1, 2}, (a, b) => a + b) == list{4, 2} ``` */ let mapReverse2: (list<'a>, list<'b>, ('a, 'b) => 'c) => list<'c> @@ -612,10 +612,8 @@ accumulator. ## Examples ```rescript -assertEqual( - List.reduce2(list{1, 2, 3}, list{4, 5}, 0, (acc, x, y) => acc + x * x + y), +List.reduce2(list{1, 2, 3}, list{4, 5}, 0, (acc, x, y) => acc + x * x + y) == 0 + (1 * 1 + 4) + (2 * 2 + 5) -) ``` */ let reduce2: (list<'b>, list<'c>, 'a, ('a, 'b, 'c) => 'a) => 'a @@ -630,10 +628,8 @@ final value of the accumulator. ## Examples ```rescript -assertEqual( - List.reduceReverse2(list{1, 2, 3}, list{4, 5}, 0, (acc, x, y) => acc + x * x + y), - 0 + (1 * 1 + 4) + (2 * 2 + 5) -) +List.reduceReverse2(list{1, 2, 3}, list{4, 5}, 0, (acc, x, y) => acc + x * x + y) == + 0 + (1 * 1 + 4) + (2 * 2 + 5) ``` */ let reduceReverse2: (list<'a>, list<'b>, 'c, ('c, 'a, 'b) => 'c) => 'c @@ -647,9 +643,9 @@ is a predicate: a function taking an element and returning a bool. ```rescript let isBelow10 = value => value < 10 -assertEqual(list{1, 9, 8, 2}->List.every(isBelow10), true) +list{1, 9, 8, 2}->List.every(isBelow10) == true -assertEqual(list{1, 99, 8, 2}->List.every(isBelow10), false) +list{1, 99, 8, 2}->List.every(isBelow10) == false ``` */ let every: (list<'a>, 'a => bool) => bool @@ -664,9 +660,9 @@ returning a bool. ```rescript let isAbove100 = value => value > 100 -assertEqual(list{101, 1, 2, 3}->List.some(isAbove100), true) +list{101, 1, 2, 3}->List.some(isAbove100) == true -assertEqual(list{1, 2, 3, 4}->List.some(isAbove100), false) +list{1, 2, 3, 4}->List.some(isAbove100) == false ``` */ let some: (list<'a>, 'a => bool) => bool @@ -678,13 +674,13 @@ pairs of elements up to the shorter length (i.e. `min(length(list1), length(list ## Examples ```rescript -assertEqual(List.every2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b), true) +List.every2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) == true -assertEqual(List.every2(list{}, list{1}, (a, b) => a > b), true) +List.every2(list{}, list{1}, (a, b) => a > b) == true -assertEqual(List.every2(list{2, 3}, list{1}, (a, b) => a > b), true) +List.every2(list{2, 3}, list{1}, (a, b) => a > b) == true -assertEqual(List.every2(list{0, 1}, list{5, 0}, (a, b) => a > b), false) +List.every2(list{0, 1}, list{5, 0}, (a, b) => a > b) == false ``` */ let every2: (list<'a>, list<'b>, ('a, 'b) => bool) => bool @@ -696,13 +692,13 @@ of elements up to the shorter length (i.e. `min(length(list1), length(list2))`) ## Examples ```rescript -assertEqual(List.some2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b), true) +List.some2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) == true -assertEqual(List.some2(list{}, list{1}, (a, b) => a > b), false) +List.some2(list{}, list{1}, (a, b) => a > b) == false -assertEqual(List.some2(list{2, 3}, list{1}, (a, b) => a > b), true) +List.some2(list{2, 3}, list{1}, (a, b) => a > b) == true -assertEqual(List.some2(list{0, 1}, list{5, 0}, (a, b) => a > b), true) +List.some2(list{0, 1}, list{5, 0}, (a, b) => a > b) == true ``` */ let some2: (list<'a>, list<'b>, ('a, 'b) => bool) => bool @@ -715,11 +711,11 @@ let some2: (list<'a>, list<'b>, ('a, 'b) => bool) => bool ## Examples ```rescript -assertEqual(List.compareLength(list{1, 2}, list{3, 4, 5, 6}), -1.) +List.compareLength(list{1, 2}, list{3, 4, 5, 6}) == -1. -assertEqual(List.compareLength(list{1, 2, 3}, list{4, 5, 6}), 0.) +List.compareLength(list{1, 2, 3}, list{4, 5, 6}) == 0. -assertEqual(List.compareLength(list{1, 2, 3, 4}, list{5, 6}), 1.) +List.compareLength(list{1, 2, 3, 4}, list{5, 6}) == 1. ``` */ let compareLength: (list<'a>, list<'a>) => Stdlib_Ordering.t @@ -738,11 +734,11 @@ zero for all `list1` and `list2`. ## Examples ```rescript -assertEqual(List.compare(list{3}, list{3, 7}, (a, b) => Int.compare(a, b)), -1.) -assertEqual(List.compare(list{5, 3}, list{5}, (a, b) => Int.compare(a, b)), 1.) -assertEqual(List.compare(list{1, 3, 5}, list{1, 4, 2}, (a, b) => Int.compare(a, b)), -1.) -assertEqual(List.compare(list{1, 3, 5}, list{1, 2, 3}, (a, b) => Int.compare(a, b)), 1.) -assertEqual(List.compare(list{1, 3, 5}, list{1, 3, 5}, (a, b) => Int.compare(a, b)), 0.) +List.compare(list{3}, list{3, 7}, (a, b) => Int.compare(a, b)) == -1. +List.compare(list{5, 3}, list{5}, (a, b) => Int.compare(a, b)) == 1. +List.compare(list{1, 3, 5}, list{1, 4, 2}, (a, b) => Int.compare(a, b)) == -1. +List.compare(list{1, 3, 5}, list{1, 2, 3}, (a, b) => Int.compare(a, b)) == 1. +List.compare(list{1, 3, 5}, list{1, 3, 5}, (a, b) => Int.compare(a, b)) == 0. ``` **Please note:** The total ordering of List is different from Array, @@ -760,27 +756,27 @@ of `list1` and `list2` are not the same. ## Examples ```rescript -assertEqual(List.equal(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 -assertEqual(List.equal(list{1, 2}, list{1, 2}, (a, b) => a == b), true) +List.equal(list{1, 2}, list{1, 2}, (a, b) => a == b) == true -assertEqual(List.equal(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 equal: (list<'a>, list<'a>, ('a, 'a) => bool) => bool /** `has(list, element, f)` returns `true` if the list contains at least one -`element` for which `f` returns `true'. +`element` for which `f` returns \`true'. ## Examples ```rescript -assertEqual(list{1, 2, 3}->List.has(2, (a, b) => a == b), true) +list{1, 2, 3}->List.has(2, (a, b) => a == b) == true -assertEqual(list{1, 2, 3}->List.has(4, (a, b) => a == b), false) +list{1, 2, 3}->List.has(4, (a, b) => a == b) == false -assertEqual(list{(-1), (-2), (-3)}->List.has(2, (a, b) => abs(a) == abs(b)), true) +list{-1, -2, -3}->List.has(2, (a, b) => abs(a) == abs(b)) == true ``` */ let has: (list<'a>, 'b, ('a, 'b) => bool) => bool @@ -793,9 +789,9 @@ the function. ## Examples ```rescript -assertEqual(List.find(list{1, 4, 3, 2}, x => x > 3), Some(4)) +List.find(list{1, 4, 3, 2}, x => x > 3) == Some(4) -assertEqual(List.find(list{1, 4, 3, 2}, x => x > 4), None) +List.find(list{1, 4, 3, 2}, x => x > 4) == None ``` */ let find: (list<'a>, 'a => bool) => option<'a> @@ -809,9 +805,9 @@ predicate function `f`. ```rescript let isEven = x => mod(x, 2) == 0 -assertEqual(List.filter(list{1, 2, 3, 4}, isEven), list{2, 4}) +List.filter(list{1, 2, 3, 4}, isEven) == list{2, 4} -assertEqual(List.filter(list{None, Some(2), Some(3), None}, Option.isSome), list{Some(2), Some(3)}) +List.filter(list{None, Some(2), Some(3), None}, Option.isSome) == list{Some(2), Some(3)} ``` */ let filter: (list<'a>, 'a => bool) => list<'a> @@ -825,7 +821,7 @@ satisfy the predicate function `f`. ```rescript let isEven = x => mod(x, 2) == 0 -assertEqual(List.filterWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)), list{1, 3}) +List.filterWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) == list{1, 3} ``` */ let filterWithIndex: (list<'a>, ('a, int) => bool) => list<'a> @@ -840,16 +836,15 @@ let filterWithIndex: (list<'a>, ('a, int) => bool) => list<'a> ```rescript let isEven = x => mod(x, 2) == 0 -list{1, 2, 3, 4} -->List.filterMap(x => - if (isEven(x)) { - Some(x) - } else { - None - } - ) // list{2, 4} +list{1, 2, 3, 4}->List.filterMap(x => + if isEven(x) { + Some(x) + } else { + None + } +) // list{2, 4} -assertEqual(list{Some(1), Some(2), None}->List.filterMap(x => x), list{1, 2}) +list{Some(1), Some(2), None}->List.filterMap(x => x) == list{1, 2} ``` */ let filterMap: (list<'a>, 'a => option<'b>) => list<'b> @@ -864,7 +859,7 @@ consists of all elements of `list` that _do not_ satisfy `f`. ```rescript // (elementsThatSatisfies, elementsThatDoesNotSatisfy) -assertEqual(List.partition(list{1, 2, 3, 4}, x => x > 2), (list{3, 4}, list{1, 2})) +List.partition(list{1, 2, 3, 4}, x => x > 2) == (list{3, 4}, list{1, 2}) ``` */ let partition: (list<'a>, 'a => bool) => (list<'a>, list<'a>) @@ -879,10 +874,8 @@ second items. ```rescript List.unzip(list{(1, 2), (3, 4)}) // (list{1, 3}, list{2, 4}) -assertEqual( - List.unzip(list{("H", "W"), ("e", "o"), ("l", "r"), ("l", "l"), ("o", "d"), (" ", "!")}), +List.unzip(list{("H", "W"), ("e", "o"), ("l", "r"), ("l", "l"), ("o", "d"), (" ", "!")}) == (list{"H", "e", "l", "l", "o", " "}, list{"W", "o", "r", "l", "d", "!"}) -) ``` */ let unzip: list<('a, 'b)> => (list<'a>, list<'b>) @@ -897,11 +890,9 @@ not found. ```rescript list{(1, "a"), (2, "b"), (3, "c")}->List.getAssoc(3, (a, b) => a == b) // Some("c") -assertEqual( - list{(9, "morning"), (15, "afternoon"), (22, "night")} - ->List.getAssoc(15, (k, item) => k /* 15 */ == item /* 9, 5, 22 */), - Some("afternoon") -) +list{(9, "morning"), (15, "afternoon"), (22, "night")}->List.getAssoc(15, (k, item) => + k /* 15 */ == item + /* 9, 5, 22 */) == Some("afternoon") ``` */ @deprecated("Use a `Map` instead") @@ -916,11 +907,9 @@ first element equals `k` as per the predicate function `f`. ```rescript list{(1, "a"), (2, "b"), (3, "c")}->List.hasAssoc(1, (a, b) => a == b) // true -assertEqual( - list{(9, "morning"), (15, "afternoon"), (22, "night")} - ->List.hasAssoc(25, (k, item) => k /* 25 */ == item /* 9, 5, 22 */), - false -) +list{(9, "morning"), (15, "afternoon"), (22, "night")}->List.hasAssoc(25, (k, item) => + k /* 25 */ == item + /* 9, 5, 22 */) == false ``` */ @deprecated("Use a `Map` instead") @@ -936,11 +925,9 @@ list identical to `list`. ```rescript list{(1, "a"), (2, "b"), (3, "c")}->List.removeAssoc(1, (a, b) => a == b) // list{(2, "b"), (3, "c")} -assertEqual( - list{(9, "morning"), (15, "afternoon"), (22, "night")} - ->List.removeAssoc(9, (k, item) => k /* 9 */ == item /* 9, 5, 22 */), - list{(15, "afternoon"), (22, "night")} -) +list{(9, "morning"), (15, "afternoon"), (22, "night")}->List.removeAssoc(9, (k, item) => + k /* 9 */ == item + /* 9, 5, 22 */) == list{(15, "afternoon"), (22, "night")} ``` */ @deprecated("Use a `Map` instead") @@ -955,21 +942,15 @@ predicate, return a new list with the key and value replaced by the new `k` and ## Examples ```rescript -assertEqual( - list{(1, "a"), (2, "b"), (3, "c")}->List.setAssoc(2, "x", (a, b) => a == b), +list{(1, "a"), (2, "b"), (3, "c")}->List.setAssoc(2, "x", (a, b) => a == b) == list{(1, "a"), (2, "x"), (3, "c")} -) -assertEqual( - list{(1, "a"), (3, "c")}->List.setAssoc(2, "b", (a, b) => a == b), +list{(1, "a"), (3, "c")}->List.setAssoc(2, "b", (a, b) => a == b) == list{(2, "b"), (1, "a"), (3, "c")} -) -assertEqual( - list{(9, "morning"), (3, "morning?!"), (22, "night")} - ->List.setAssoc(15, "afternoon", (a, b) => mod(a, 12) == mod(b, 12)), - list{(9, "morning"), (15, "afternoon"), (22, "night")} -) +list{(9, "morning"), (3, "morning?!"), (22, "night")}->List.setAssoc(15, "afternoon", (a, b) => + mod(a, 12) == mod(b, 12) +) == list{(9, "morning"), (15, "afternoon"), (22, "night")} ``` **Please note**: In the last example, since: `15 mod 12` equals `3 mod 12`. Both @@ -984,10 +965,7 @@ let setAssoc: (list<('a, 'c)>, 'a, 'c, ('a, 'a) => bool) => list<('a, 'c)> ## Examples ```rescript -assertEqual( - List.sort(list{5, 4, 9, 3, 7}, Int.compare), - list{3, 4, 5, 7, 9} -) +List.sort(list{5, 4, 9, 3, 7}, Int.compare) == list{3, 4, 5, 7, 9} ``` */ let sort: (list<'a>, ('a, 'a) => Stdlib_Ordering.t) => list<'a> diff --git a/runtime/Stdlib_Math.resi b/runtime/Stdlib_Math.resi index a515274078..322dd87156 100644 --- a/runtime/Stdlib_Math.resi +++ b/runtime/Stdlib_Math.resi @@ -33,7 +33,7 @@ Mathematical Constants module Constants: { /** `Math.Constants.e` returns Euler's number, ≈ 2.718281828459045. - See [`Math.E`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/E) on MDN. +See [`Math.E`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/E) on MDN. ## Examples @@ -46,7 +46,7 @@ module Constants: { /** `Math.Constants.ln2` returns Natural logarithm of 2, ≈ 0.6931471805599453. - See [`Math.LN2`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/LN2) on MDN. +See [`Math.LN2`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/LN2) on MDN. ## Examples @@ -59,7 +59,7 @@ module Constants: { /** `Math.Constants.ln10` returns Natural logarithm of 10, ≈ 2.302585092994046. - See [`Math.LN10`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/LN10) on MDN. +See [`Math.LN10`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/LN10) on MDN. ## Examples @@ -72,7 +72,7 @@ module Constants: { /** `Math.Constants.log2e` returns Base 2 logarithm of E, ≈ 1.4426950408889634. - See [`Math.LOG2E`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/LOG2E) on MDN. +See [`Math.LOG2E`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/LOG2E) on MDN. ## Examples @@ -85,7 +85,7 @@ module Constants: { /** `Math.Constants.log10e` returns Base 10 logarithm of E, ≈ 0.4342944819032518. - See [`Math.LOG10E`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/LOG10E) on MDN. +See [`Math.LOG10E`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/LOG10E) on MDN. ## Examples @@ -97,8 +97,8 @@ module Constants: { external log10e: float = "Math.LOG10E" /** `Math.Constants.pi` returns Pi - ratio of the circumference to the diameter - of a circle, ≈ 3.141592653589793. - See [`Math.PI`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/PI) on MDN. +of a circle, ≈ 3.141592653589793. +See [`Math.PI`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/PI) on MDN. ## Examples @@ -110,7 +110,7 @@ module Constants: { external pi: float = "Math.PI" /** `Math.Constants.sqrt1_2` returns Square root of 1/2, ≈ 0.7071067811865476. - See [`Math.SQRT1_2`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/SQRT1_2) on MDN. +See [`Math.SQRT1_2`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/SQRT1_2) on MDN. ## Examples @@ -122,7 +122,7 @@ module Constants: { external sqrt1_2: float = "Math.SQRT1_2" /** `Math.Constants.e` returns Absolute value for integer argument. - See [`Math.abs`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs) on MDN. +See [`Math.abs`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs) on MDN. ## Examples @@ -140,13 +140,13 @@ Provide Math utilities for `int` module Int: { /** `abs(v)` returns absolute value of `v`. - See [`Math.abs`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs) on MDN. +See [`Math.abs`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs) on MDN. ## Examples ```rescript - assertEqual(Math.Int.abs(-2), 2) - assertEqual(Math.Int.abs(3), 3) + Math.Int.abs(-2) == 2 + Math.Int.abs(3) == 3 ``` */ @val @@ -154,16 +154,16 @@ module Int: { /** `clz32(v)` returns the number of leading zero bits of the argument's 32 bit - int representation. - See [`Math.clz32`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32) on MDN. +int representation. +See [`Math.clz32`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32) on MDN. ## Examples ```rescript // 00000000000000000000000000000001 - assertEqual(Math.Int.clz32(1), 31) + Math.Int.clz32(1) == 31 // 00000000000000000000000000000100 - assertEqual(Math.Int.clz32(4), 29) + Math.Int.clz32(4) == 29 ``` */ @val @@ -171,15 +171,15 @@ module Int: { /** `imul(a, b)` returns 32-bit integer multiplication. Use this only when you - need to optimize performance of multiplication of numbers stored as 32-bit - integers. - See [`Math.imul`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul) on MDN. +need to optimize performance of multiplication of numbers stored as 32-bit +integers. +See [`Math.imul`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul) on MDN. ## Examples ```rescript - assertEqual(Math.Int.imul(3, 4), 12) - assertEqual(Math.Int.imul(-5, 12), -60) + Math.Int.imul(3, 4) == 12 + Math.Int.imul(-5, 12) == -60 ``` */ @val @@ -187,13 +187,13 @@ module Int: { /** `min(a, b)` returns the minimum of its two integer arguments. - See [`Math.min`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min) on MDN. +See [`Math.min`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min) on MDN. ## Examples ```rescript - assertEqual(Math.Int.min(1, 2), 1) - assertEqual(Math.Int.min(-1, -2), -2) + Math.Int.min(1, 2) == 1 + Math.Int.min(-1, -2) == -2 ``` */ @val @@ -201,15 +201,15 @@ module Int: { /** `minMany(arr)` returns the minimum of the integers in the given array `arr`. - Returns `Infinity` if `arr` is empty. - See [`Math.min`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min) on MDN. +Returns `Infinity` if `arr` is empty. +See [`Math.min`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min) on MDN. ## Examples ```rescript - assertEqual(Math.Int.minMany([1, 2]), 1) - assertEqual(Math.Int.minMany([-1, -2]), -2) - assertEqual(Math.Int.minMany([])->Int.toFloat->Float.isFinite, false) + Math.Int.minMany([1, 2]) == 1 + Math.Int.minMany([-1, -2]) == -2 + Math.Int.minMany([])->Int.toFloat->Float.isFinite == false ``` */ @variadic @val @@ -217,13 +217,13 @@ module Int: { /** `max(a, b)` returns the maximum of its two integer arguments. - See [`Math.max`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max) on MDN. +See [`Math.max`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max) on MDN. ## Examples ```rescript - assertEqual(Math.Int.max(1, 2), 2) - assertEqual(Math.Int.max(-1, -2), -1) + Math.Int.max(1, 2) == 2 + Math.Int.max(-1, -2) == -1 ``` */ @val @@ -231,15 +231,15 @@ module Int: { /** `maxMany(arr)` returns the maximum of the integers in the given array `arr`. - Returns `Infinity` if `arr` is empty. - See [`Math.max`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max) on MDN. +Returns `Infinity` if `arr` is empty. +See [`Math.max`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max) on MDN. ## Examples ```rescript - assertEqual(Math.Int.maxMany([1, 2]), 2) - assertEqual(Math.Int.maxMany([-1, -2]), -1) - assertEqual(Math.Int.maxMany([])->Int.toFloat->Float.isFinite, false) + Math.Int.maxMany([1, 2]) == 2 + Math.Int.maxMany([-1, -2]) == -1 + Math.Int.maxMany([])->Int.toFloat->Float.isFinite == false ``` */ @variadic @val @@ -247,13 +247,13 @@ module Int: { /** `pow(a, ~exp)` raises the given base `a` to the given exponent `exp`. - See [`Math.pow`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow) on MDN. +See [`Math.pow`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow) on MDN. ## Examples ```rescript - assertEqual(Math.Int.pow(2, ~exp=4), 16) - assertEqual(Math.Int.pow(3, ~exp=4), 81) + Math.Int.pow(2, ~exp=4) == 16 + Math.Int.pow(3, ~exp=4) == 81 ``` */ @val @@ -261,54 +261,54 @@ module Int: { /** `sign(v)` returns the sign of its integer argument: `-1` if negative, `0` if - zero, `1` if positive. - See [`Math.sign`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign) on MDN. +zero, `1` if positive. +See [`Math.sign`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign) on MDN. ## Examples ```rescript - assertEqual(Math.Int.sign(3), 1) - assertEqual(Math.Int.sign(-3), -1) - assertEqual(Math.Int.sign(0), 0) + Math.Int.sign(3) == 1 + Math.Int.sign(-3) == -1 + Math.Int.sign(0) == 0 ``` */ @val external sign: int => int = "Math.sign" /** - floor(v) returns the largest `int` less than or equal to the argument; - See [`Math.floor`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor) - on MDN. + floor(v) returns the largest `int` less than or equal to the argument; +See [`Math.floor`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor) +on MDN. ## Examples ```rescript - assertEqual(Math.Int.floor(3.7), 3) - assertEqual(Math.Int.floor(3.0), 3) - assertEqual(Math.Int.floor(-3.1), -4) + Math.Int.floor(3.7) == 3 + Math.Int.floor(3.0) == 3 + Math.Int.floor(-3.1) == -4 ``` */ let floor: float => int /** ceil(v) returns the smallest `int` greater than or equal to the argument; - See [`Math.floor`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor) - on MDN. +See [`Math.floor`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor) +on MDN. ## Examples ```rescript - assertEqual(Math.Int.ceil(3.7), 4) - assertEqual(Math.Int.ceil(3.0), 3) - assertEqual(Math.Int.ceil(-3.1), -3) + Math.Int.ceil(3.7) == 4 + Math.Int.ceil(3.0) == 3 + Math.Int.ceil(-3.1) == -3 ``` */ let ceil: float => int /** - `random(minVal, maxVal)` returns a random integer number in the half-closed interval [minVal, maxVal). - See [`Math.random`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random) - on MDN. + `random(minVal, maxVal)` returns a random integer number in the half-closed interval \[minVal, maxVal). +See [`Math.random`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random) +on MDN. ## Examples @@ -328,8 +328,8 @@ See [`Math.abs`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen ## Examples ```rescript -assertEqual(Math.abs(-2.0), 2.0) -assertEqual(Math.abs(3.0), 3.0) +Math.abs(-2.0) == 2.0 +Math.abs(3.0) == 3.0 ``` */ @val @@ -337,14 +337,14 @@ external abs: float => float = "Math.abs" /** `acos(v)` returns arccosine (in radians) of argument `v`, returns `NaN` if the -argument is outside the range [-1.0, 1.0]. +argument is outside the range \[-1.0, 1.0\]. See [`Math.acos`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acos) on MDN. ## Examples ```rescript -assertEqual(Math.acos(-1.0), 3.141592653589793) -assertEqual(Math.acos(-3.0)->Float.isNaN, true) +Math.acos(-1.0) == 3.141592653589793 +Math.acos(-3.0)->Float.isNaN == true ``` */ @val @@ -358,8 +358,8 @@ See [`Math.acosh`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer ## Examples ```rescript -assertEqual(Math.acosh(1.0), 0.0) -assertEqual(Math.acosh(0.5)->Float.isNaN, true) +Math.acosh(1.0) == 0.0 +Math.acosh(0.5)->Float.isNaN == true ``` */ @val @@ -367,14 +367,14 @@ external acosh: float => float = "Math.acosh" /** `asin(v)` returns the inverse sine (in radians) of argument `v`, returns `NaN` -if the argument `v` is outside the range [-1.0, 1.0]. +if the argument `v` is outside the range \[-1.0, 1.0\]. See [`Math.asin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asin) on MDN. ## Examples ```rescript -assertEqual(Math.asin(-1.0), -1.5707963267948966) -assertEqual(Math.asin(-2.0)->Float.isNaN, true) +Math.asin(-1.0) == -1.5707963267948966 +Math.asin(-2.0)->Float.isNaN == true ``` */ @val @@ -387,8 +387,8 @@ See [`Math.asinh`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer ## Examples ```rescript -assertEqual(Math.asinh(-1.0), -0.881373587019543) -assertEqual(Math.asinh(-0.0), -0.0) +Math.asinh(-1.0) == -0.881373587019543 +Math.asinh(-0.0) == -0.0 ``` */ @val @@ -401,9 +401,9 @@ See [`Math.atan`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refere ## Examples ```rescript -assertEqual(Math.atan(-0.0), -0.0) -assertEqual(Math.atan(0.0), 0.0) -assertEqual(Math.atan(1.0), 0.7853981633974483) +Math.atan(-0.0) == -0.0 +Math.atan(0.0) == 0.0 +Math.atan(1.0) == 0.7853981633974483 ``` */ @val @@ -411,18 +411,18 @@ external atan: float => float = "Math.atan" /** `atanh(v)` returns the invert hyperbolic tangent of argument `v`. Returns `NaN` -if the argument `v` is is outside the range [-1.0, 1.0] and `Infinity` if `v` +if the argument `v` is is outside the range \[-1.0, 1.0\] and `Infinity` if `v` is `-1.0` or `1.0`. See [`Math.atanh`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atanh) on MDN. ## Examples ```rescript -assertEqual(Math.atanh(-2.0)->Float.isNaN, true) -assertEqual(Math.atanh(-1.0)->Float.isFinite, false) -assertEqual(Math.atanh(-0.0), -0.0) -assertEqual(Math.atanh(0.0), 0.0) -assertEqual(Math.atanh(0.5), 0.5493061443340548) +Math.atanh(-2.0)->Float.isNaN == true +Math.atanh(-1.0)->Float.isFinite == false +Math.atanh(-0.0) == -0.0 +Math.atanh(0.0) == 0.0 +Math.atanh(0.5) == 0.5493061443340548 ``` */ @val @@ -430,16 +430,16 @@ external atanh: float => float = "Math.atanh" /** `atan2(~y, ~x)` returns the angle (in radians) of the quotient `y /. x`. It is -also the angle between the *x*-axis and point (*x*, *y*). +also the angle between the *x*\-axis and point (*x*, *y*). See [`Math.atan2`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2) on MDN. ## Examples ```rescript -assertEqual(Math.atan2(~y=0.0, ~x=10.0), 0.0) -assertEqual(Math.atan2(~x=5.0, ~y=5.0), Math.Constants.pi /. 4.0) -assertEqual(Math.atan2(~x=90.0, ~y=15.0),0.16514867741462683) -assertEqual(Math.atan2(~x=15.0, ~y=90.0), 1.4056476493802699) +Math.atan2(~y=0.0, ~x=10.0) == 0.0 +Math.atan2(~x=5.0, ~y=5.0) == Math.Constants.pi /. 4.0 +Math.atan2(~x=90.0, ~y=15.0) == 0.16514867741462683 +Math.atan2(~x=15.0, ~y=90.0) == 1.4056476493802699 ``` */ @val @@ -452,9 +452,9 @@ See [`Math.cbrt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refere ## Examples ```rescript -assertEqual(Math.cbrt(-1.0), -1.0) -assertEqual(Math.cbrt(-0.0), -0.0) -assertEqual(Math.cbrt(0.0), 0.0) +Math.cbrt(-1.0) == -1.0 +Math.cbrt(-0.0) == -0.0 +Math.cbrt(0.0) == 0.0 ``` */ @val @@ -469,10 +469,10 @@ See [`Math.ceil`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refere ## Examples ```rescript -assertEqual(Math.ceil(3.1), 4.0) -assertEqual(Math.ceil(3.0), 3.0) -assertEqual(Math.ceil(-3.1), -3.0) -assertEqual(Math.ceil(2_150_000_000.3), 2_150_000_001.0) +Math.ceil(3.1) == 4.0 +Math.ceil(3.0) == 3.0 +Math.ceil(-3.1) == -3.0 +Math.ceil(2_150_000_000.3) == 2_150_000_001.0 ``` */ @val @@ -485,9 +485,9 @@ See [`Math.cos`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen ## Examples ```rescript -assertEqual(Math.cos(-0.0), 1.0) -assertEqual(Math.cos(0.0), 1.0) -assertEqual(Math.cos(1.0), 0.5403023058681398) +Math.cos(-0.0) == 1.0 +Math.cos(0.0) == 1.0 +Math.cos(1.0) == 0.5403023058681398 ``` */ @val @@ -501,9 +501,9 @@ See [`Math.cosh`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refere ## Examples ```rescript -assertEqual(Math.cosh(-1.0), 1.5430806348152437) -assertEqual(Math.cosh(-0.0), 1.0) -assertEqual(Math.cosh(0.0), 1.0) +Math.cosh(-1.0) == 1.5430806348152437 +Math.cosh(-0.0) == 1.0 +Math.cosh(0.0) == 1.0 ``` */ @val @@ -517,8 +517,8 @@ See [`Math.exp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen ## Examples ```rescript -assertEqual(Math.exp(-1.0), 0.36787944117144233) -assertEqual(Math.exp(0.0), 1.0) +Math.exp(-1.0) == 0.36787944117144233 +Math.exp(0.0) == 1.0 ``` */ @val @@ -532,8 +532,8 @@ See [`Math.expm1`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer ## Examples ```rescript -assertEqual(Math.expm1(-1.0), -0.6321205588285577) -assertEqual(Math.expm1(-0.0), -0.0) +Math.expm1(-1.0) == -0.6321205588285577 +Math.expm1(-0.0) == -0.0 ``` */ @val @@ -547,9 +547,9 @@ See [`Math.floor`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer ## Examples ```rescript -assertEqual(Math.floor(-45.95), -46.0) -assertEqual(Math.floor(-45.05), -46.0) -assertEqual(Math.floor(-0.0), -0.0) +Math.floor(-45.95) == -46.0 +Math.floor(-45.05) == -46.0 +Math.floor(-0.0) == -0.0 ``` */ @val @@ -562,8 +562,8 @@ See [`Math.fround`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe ## Examples ```rescript -assertEqual(Math.fround(5.5), 5.5) -assertEqual(Math.fround(5.05), 5.050000190734863) +Math.fround(5.5) == 5.5 +Math.fround(5.05) == 5.050000190734863 ``` */ @val @@ -577,8 +577,8 @@ See [`Math.hypot`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer ## Examples ```rescript -assertEqual(Math.hypot(3.0, 4.0), 5.0) -assertEqual(Math.hypot(3.0, 5.0), 5.8309518948453) +Math.hypot(3.0, 4.0) == 5.0 +Math.hypot(3.0, 5.0) == 5.8309518948453 ``` */ @val @@ -593,8 +593,8 @@ See [`Math.hypot`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer ## Examples ```rescript -assertEqual(Math.hypotMany([3.0, 4.0, 5.0]), 7.0710678118654755) -assertEqual(Math.hypotMany([]), 0.0) +Math.hypotMany([3.0, 4.0, 5.0]) == 7.0710678118654755 +Math.hypotMany([]) == 0.0 ``` */ @variadic @val @@ -609,10 +609,10 @@ See [`Math.log`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen ## Examples ```rescript -assertEqual(Math.log(-1.0)->Float.isNaN, true) -assertEqual(Math.log(-0.0)->Float.isFinite, false) -assertEqual(Math.log(0.0)->Float.isFinite, false) -assertEqual(Math.log(1.0), 0.0) +Math.log(-1.0)->Float.isNaN == true +Math.log(-0.0)->Float.isFinite == false +Math.log(0.0)->Float.isFinite == false +Math.log(1.0) == 0.0 ``` */ @val @@ -626,9 +626,9 @@ See [`Math.log1p`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer ## Examples ```rescript -assertEqual(Math.log1p(-2.0)->Float.isNaN, true) -assertEqual(Math.log1p(-1.0)->Float.isFinite, false) -assertEqual(Math.log1p(-0.0), -0.0) +Math.log1p(-2.0)->Float.isNaN == true +Math.log1p(-1.0)->Float.isFinite == false +Math.log1p(-0.0) == -0.0 ``` */ @val @@ -642,10 +642,10 @@ See [`Math.log10`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer ## Examples ```rescript -assertEqual(Math.log10(-2.0)->Float.isNaN, true) -assertEqual(Math.log10(-0.0)->Float.isFinite, false) -assertEqual(Math.log10(0.0)->Float.isFinite, false) -assertEqual(Math.log10(1.0), 0.0) +Math.log10(-2.0)->Float.isNaN == true +Math.log10(-0.0)->Float.isFinite == false +Math.log10(0.0)->Float.isFinite == false +Math.log10(1.0) == 0.0 ``` */ @val @@ -659,10 +659,10 @@ See [`Math.log2`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refere ## Examples ```rescript -assertEqual(Math.log2(-2.0)->Float.isNaN, true) -assertEqual(Math.log2(-0.0)->Float.isFinite, false) -assertEqual(Math.log2(0.0)->Float.isFinite, false) -assertEqual(Math.log2(1.0), 0.0) +Math.log2(-2.0)->Float.isNaN == true +Math.log2(-0.0)->Float.isFinite == false +Math.log2(0.0)->Float.isFinite == false +Math.log2(1.0) == 0.0 ``` */ @val @@ -675,8 +675,8 @@ See [`Math.min`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen ## Examples ```rescript -assertEqual(Math.min(1.0, 2.0), 1.0) -assertEqual(Math.min(-1.0, -2.0), -2.0) +Math.min(1.0, 2.0) == 1.0 +Math.min(-1.0, -2.0) == -2.0 ``` */ @val @@ -690,9 +690,9 @@ See [`Math.min`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen ## Examples ```rescript -assertEqual(Math.minMany([1.0, 2.0]), 1.0) -assertEqual(Math.minMany([-1.0, -2.0]), -2.0) -assertEqual(Math.minMany([])->Float.isFinite, false) +Math.minMany([1.0, 2.0]) == 1.0 +Math.minMany([-1.0, -2.0]) == -2.0 +Math.minMany([])->Float.isFinite == false ``` */ @variadic @val @@ -705,8 +705,8 @@ See [`Math.max`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen ## Examples ```rescript -assertEqual(Math.max(1.0, 2.0), 2.0) -assertEqual(Math.max(-1.0, -2.0), -1.0) +Math.max(1.0, 2.0) == 2.0 +Math.max(-1.0, -2.0) == -1.0 ``` */ @val @@ -720,9 +720,9 @@ See [`Math.max`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen ## Examples ```rescript -assertEqual(Math.maxMany([1.0, 2.0]), 2.0) -assertEqual(Math.maxMany([-1.0, -2.0]), -1.0) -assertEqual(Math.maxMany([])->Float.isFinite, false) +Math.maxMany([1.0, 2.0]) == 2.0 +Math.maxMany([-1.0, -2.0]) == -1.0 +Math.maxMany([])->Float.isFinite == false ``` */ @variadic @val @@ -735,15 +735,15 @@ See [`Math.pow`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen ## Examples ```rescript -assertEqual(Math.pow(2.0, ~exp=4.0), 16.0) -assertEqual(Math.pow(3.0, ~exp=4.0), 81.0) +Math.pow(2.0, ~exp=4.0) == 16.0 +Math.pow(3.0, ~exp=4.0) == 81.0 ``` */ @val external pow: (float, ~exp: float) => float = "Math.pow" /** -`random()` returns a random number in the half-closed interval [0,1]. +`random()` returns a random number in the half-closed interval \[0,1\]. See [`Math.random`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random) on MDN. ## Examples @@ -765,10 +765,10 @@ See [`Math.round`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer ## Examples ```rescript -assertEqual(Math.round(-20.5), -20.0) -assertEqual(Math.round(-0.1), -0.0) -assertEqual(Math.round(0.0), 0.0) -assertEqual(Math.round(-0.0), -0.0) +Math.round(-20.5) == -20.0 +Math.round(-0.1) == -0.0 +Math.round(0.0) == 0.0 +Math.round(-0.0) == -0.0 ``` */ @val @@ -782,9 +782,9 @@ See [`Math.sign`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refere ## Examples ```rescript -assertEqual(Math.sign(3.0), 1.0) -assertEqual(Math.sign(-3.0), -1.0) -assertEqual(Math.sign(0.0), 0.0) +Math.sign(3.0) == 1.0 +Math.sign(-3.0) == -1.0 +Math.sign(0.0) == 0.0 ``` */ @val @@ -797,9 +797,9 @@ See [`Math.sin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen ## Examples ```rescript -assertEqual(Math.sin(-0.0), -0.0) -assertEqual(Math.sin(0.0), 0.0) -assertEqual(Math.sin(1.0), 0.8414709848078965) +Math.sin(-0.0) == -0.0 +Math.sin(0.0) == 0.0 +Math.sin(1.0) == 0.8414709848078965 ``` */ @val @@ -813,9 +813,9 @@ See [`Math.sinh`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refere ## Examples ```rescript -assertEqual(Math.sinh(-0.0), -0.0) -assertEqual(Math.sinh(0.0), 0.0) -assertEqual(Math.sinh(1.0), 1.1752011936438014) +Math.sinh(-0.0) == -0.0 +Math.sinh(0.0) == 0.0 +Math.sinh(1.0) == 1.1752011936438014 ``` */ @val @@ -828,11 +828,11 @@ See [`Math.sqrt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refere ## Examples ```rescript -assertEqual(Math.sqrt(-1.0)->Float.isNaN, true) -assertEqual(Math.sqrt(-0.0), -0.0) -assertEqual(Math.sqrt(0.0), 0.0) -assertEqual(Math.sqrt(1.0), 1.0) -assertEqual(Math.sqrt(9.0), 3.0) +Math.sqrt(-1.0)->Float.isNaN == true +Math.sqrt(-0.0) == -0.0 +Math.sqrt(0.0) == 0.0 +Math.sqrt(1.0) == 1.0 +Math.sqrt(9.0) == 3.0 ``` */ @val @@ -846,9 +846,9 @@ See [`Math.tan`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen ## Examples ```rescript -assertEqual(Math.tan(-0.0), -0.0) -assertEqual(Math.tan(0.0), 0.0) -assertEqual(Math.tan(1.0), 1.5574077246549023) +Math.tan(-0.0) == -0.0 +Math.tan(0.0) == 0.0 +Math.tan(1.0) == 1.5574077246549023 ``` */ @val @@ -862,9 +862,9 @@ See [`Math.tanh`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refere ## Examples ```rescript -assertEqual(Math.tanh(-0.0), -0.0) -assertEqual(Math.tanh(0.0), 0.0) -assertEqual(Math.tanh(1.0), 0.7615941559557649) +Math.tanh(-0.0) == -0.0 +Math.tanh(0.0) == 0.0 +Math.tanh(1.0) == 0.7615941559557649 ``` */ @val @@ -877,10 +877,10 @@ See [`Math.trunc`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer ## Examples ```rescript -assertEqual(Math.trunc(0.123), 0.0) -assertEqual(Math.trunc(1.999), 1.0) -assertEqual(Math.trunc(13.37), 13.0) -assertEqual(Math.trunc(42.84), 42.0) +Math.trunc(0.123) == 0.0 +Math.trunc(1.999) == 1.0 +Math.trunc(13.37) == 13.0 +Math.trunc(42.84) == 42.0 ``` */ @val diff --git a/runtime/Stdlib_Null.resi b/runtime/Stdlib_Null.resi index fe59b02706..79e343cbd7 100644 --- a/runtime/Stdlib_Null.resi +++ b/runtime/Stdlib_Null.resi @@ -124,8 +124,7 @@ let fromOption: option<'a> => t<'a> Null.getOr(Null.null, "Banana") // Banana Null.getOr(Null.make("Apple"), "Banana") // Apple -let greet = (firstName: option) => - "Greetings " ++ firstName->Option.getOr("Anonymous") +let greet = (firstName: option) => "Greetings " ++ firstName->Option.getOr("Anonymous") Null.make("Jane")->Null.toOption->greet // "Greetings Jane" Null.null->Null.toOption->greet // "Greetings Anonymous" @@ -144,7 +143,7 @@ Null.getExn(Null.make(3))->assertEqual(3) switch Null.getExn(%raw("'ReScript'")) { | exception Invalid_argument(_) => assert(false) -| value => assertEqual(value, "ReScript") +| value => value == "ReScript" } switch Null.getExn(%raw("null")) { @@ -168,7 +167,7 @@ Null.getOrThrow(Null.make(3))->assertEqual(3) switch Null.getOrThrow(%raw("'ReScript'")) { | exception Invalid_argument(_) => assert(false) -| value => assertEqual(value, "ReScript") +| value => value == "ReScript" } switch Null.getOrThrow(%raw("null")) { @@ -252,7 +251,7 @@ returns `value` unchanged. ```rescript let addIfAboveOne = value => - if (value > 1) { + if value > 1 { Null.make(value + 1) } else { Null.null diff --git a/runtime/Stdlib_Nullable.resi b/runtime/Stdlib_Nullable.resi index 002f482e51..a46f954707 100644 --- a/runtime/Stdlib_Nullable.resi +++ b/runtime/Stdlib_Nullable.resi @@ -121,8 +121,7 @@ otherwise return `default`. Nullable.getOr(Nullable.null, "Banana") // Banana Nullable.getOr(Nullable.make("Apple"), "Banana") // Apple -let greet = (firstName: option) => - "Greetings " ++ firstName->Option.getOr("Anonymous") +let greet = (firstName: option) => "Greetings " ++ firstName->Option.getOr("Anonymous") Nullable.make("Jane")->Nullable.toOption->greet // "Greetings Jane" Nullable.null->Nullable.toOption->greet // "Greetings Anonymous" @@ -139,7 +138,7 @@ let getWithDefault: (t<'a>, 'a) => 'a ```rescript switch Nullable.getExn(%raw("'Hello'")) { | exception Invalid_argument(_) => assert(false) -| value => assertEqual(value, "Hello") +| value => value == "Hello" } switch Nullable.getExn(%raw("null")) { @@ -166,7 +165,7 @@ let getExn: t<'a> => 'a ```rescript switch Nullable.getOrThrow(%raw("'Hello'")) { | exception Invalid_argument(_) => assert(false) -| value => assertEqual(value, "Hello") +| value => value == "Hello" } switch Nullable.getOrThrow(%raw("null")) { @@ -203,7 +202,7 @@ Nullable.getUnsafe(Nullable.null) // Raises an error external getUnsafe: t<'a> => 'a = "%identity" /** -`forEach(value, f)` call `f` on `value`. if `value` is not `null` or `undefined`, +`forEach(value, f)` call `f` on `value`. if `value` is not `null` or `undefined`, then if calls `f`, otherwise returns `unit`. ## Examples @@ -256,7 +255,7 @@ otherwise returns `value` unchanged. ```rescript let addIfAboveOne = value => - if (value > 1) { + if value > 1 { Nullable.make(value + 1) } else { Nullable.null diff --git a/runtime/Stdlib_Object.res b/runtime/Stdlib_Object.res index f21e4ff52b..84ec127bff 100644 --- a/runtime/Stdlib_Object.res +++ b/runtime/Stdlib_Object.res @@ -31,11 +31,11 @@ Object.is([1, 2, 3], [1, 2, 3]) // false [1, 2, 3] == [1, 2, 3] // true [1, 2, 3] === [1, 2, 3] // false -let fruit = {"name": "Apple" } +let fruit = {"name": "Apple"} Object.is(fruit, fruit) // true -Object.is(fruit, {"name": "Apple" }) // false -fruit == {"name": "Apple" } // true -fruit === {"name": "Apple" } // false +Object.is(fruit, {"name": "Apple"}) // false +fruit == {"name": "Apple"} // true +fruit === {"name": "Apple"} // false ``` */ @val @@ -143,7 +143,7 @@ external set: ({..}, string, 'a) => unit = "" @set_index external setSymbol: ({..}, Stdlib_Symbol.t, 'a) => unit = "" /** -`keysToArray` returns an array of an object's own enumerable string-keyed property names. See [ECMAScript Language Specification](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.keys) +`keysToArray` returns an array of an object's own enumerable string-keyed property names. See [ECMAScript Language Specification](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.keys) or [Object.keys on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys). ## Examples @@ -173,9 +173,9 @@ let point = {"x": 1, "y": 2} external hasOwnProperty: ({..}, string) => bool = "Object.prototype.hasOwnProperty.call" /** -`seal` seals an object. Sealing an object prevents extensions and makes existing properties non-configurable. A sealed object has a fixed set of properties. Unlike `freeze`, values of existing properties can still be changed as long as they are writable. +`seal` seals an object. Sealing an object prevents extensions and makes existing properties non-configurable. A sealed object has a fixed set of properties. Unlike `freeze`, values of existing properties can still be changed as long as they are writable. -**Note:** `seal` returns the same object that was passed in; it does not create a copy. Any attempt to delete or add properties to a sealed object will fail, either silently or by throwing an error. +**Note:** `seal` returns the same object that was passed in; it does not create a copy. Any attempt to delete or add properties to a sealed object will fail, either silently or by throwing an error. See [ECMAScript Language Specification](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.seal) and [Object.seal on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal) @@ -256,9 +256,9 @@ See [ECMAScript Language Specification](https://tc39.es/ecma262/multipage/fundam ```rescript let point = {"x": 1, "y": 3}->Object.seal let pointIsSealed = point->Object.isSealed // true -let fruit = {"name": "Apple" } +let fruit = {"name": "Apple"} let fruitIsSealed = fruit->Object.isSealed // false - ``` +``` */ @val external isSealed: 'a => bool = "Object.isSealed" @@ -273,9 +273,9 @@ See [ECMAScript Language Specification](https://tc39.es/ecma262/multipage/fundam ```rescript let point = {"x": 1, "y": 3}->Object.freeze let pointIsFrozen = point->Object.isFrozen // true -let fruit = {"name": "Apple" } +let fruit = {"name": "Apple"} let fruitIsFrozen = fruit->Object.isFrozen // false - ``` +``` */ @val external isFrozen: 'a => bool = "Object.isFrozen" diff --git a/runtime/Stdlib_Option.resi b/runtime/Stdlib_Option.resi index 62ca90b2b5..44ba6cac9e 100644 --- a/runtime/Stdlib_Option.resi +++ b/runtime/Stdlib_Option.resi @@ -124,7 +124,7 @@ let getOrThrow: (option<'a>, ~message: string=?) => 'a ```rescript Option.getUnsafe(Some(3)) == 3 -Option.getUnsafe(None: option) // Returns `undefined`, which is not a valid `int` +Option.getUnsafe((None: option)) // Returns `undefined`, which is not a valid `int` ``` ## Notes @@ -170,7 +170,7 @@ let map: (option<'a>, 'a => 'b) => option<'b> ```rescript let addIfAboveOne = value => - if (value > 1) { + if value > 1 { Some(value + 1) } else { None @@ -192,8 +192,7 @@ let flatMap: (option<'a>, 'a => option<'b>) => option<'b> Option.getOr(None, "Banana") // Banana Option.getOr(Some("Apple"), "Banana") // Apple -let greet = (firstName: option) => - "Greetings " ++ firstName->Option.getOr("Anonymous") +let greet = (firstName: option) => "Greetings " ++ firstName->Option.getOr("Anonymous") Some("Jane")->greet // "Greetings Jane" None->greet // "Greetings Anonymous" diff --git a/runtime/Stdlib_Promise.resi b/runtime/Stdlib_Promise.resi index 9f77faced8..626ae5f70c 100644 --- a/runtime/Stdlib_Promise.resi +++ b/runtime/Stdlib_Promise.resi @@ -40,7 +40,7 @@ TestError("some rejected value") ->Promise.reject ->Promise.catch(v => { switch v { - | TestError(msg) => assertEqual(msg, "some rejected value") + | TestError(msg) => msg == "some rejected value" | _ => assert(false) } Promise.resolve() @@ -62,11 +62,10 @@ open Promise let n = 4 Promise.make((resolve, reject) => { - if(n < 5) { - resolve(. "success") - } - else { - reject(. "failed") + if n < 5 { + resolve("success") + } else { + reject("failed") } }) ->then(str => { @@ -99,7 +98,7 @@ open Promise let {promise, resolve, _} = Promise.withResolvers() setTimeout(() => { - resolve(. "success") + resolve("success") }, 1000)->TimeoutId.ignore promise @@ -130,14 +129,14 @@ reject(SomeError("this is an error")) Ok("This result will never be returned")->resolve }) ->catch(e => { - let msg = switch(e) { - | SomeError(msg) => "ReScript error occurred: " ++ msg - | JsExn(obj) => - switch JsExn.message(obj) { - | Some(msg) => "JS exception occurred: " ++ msg - | None => "Some other JS value has been thrown" - } - | _ => "Unexpected error occurred" + let msg = switch e { + | SomeError(msg) => "ReScript error occurred: " ++ msg + | JsExn(obj) => + switch JsExn.message(obj) { + | Some(msg) => "JS exception occurred: " ++ msg + | None => "Some other JS value has been thrown" + } + | _ => "Unexpected error occurred" } Error(msg)->resolve @@ -157,7 +156,7 @@ In case you want to return another promise in your `callback`, consider using let catch: (t<'a>, exn => t<'a>) => t<'a> /** -`then(promise, callback)` returns a new promise based on the result of `promise`'s +`then(promise, callback)` returns a new promise based on the result of `promise`'s value. The `callback` needs to explicitly return a new promise via `resolve`. It is **not allowed** to resolve a nested promise (like `resolve(resolve(1))`). See [`Promise.then`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then) on MDN. @@ -302,7 +301,7 @@ open Promise let promises = [resolve(1), resolve(2), resolve(3)] all(promises) -->then((results) => { +->then(results => { results->Array.forEach(num => { Console.log2("Number: ", num) }) @@ -360,13 +359,11 @@ exception TestError(string) let promises = [resolve(1), resolve(2), reject(TestError("some rejected promise"))] allSettled(promises) -->then((results) => { - results->Array.forEach((result) => { +->then(results => { + results->Array.forEach(result => { switch result { - | Fulfilled({value: num}) => - Console.log2("Number: ", num) - | Rejected({reason}) => - Console.log(reason) + | Fulfilled({value: num}) => Console.log2("Number: ", num) + | Rejected({reason}) => Console.log(reason) } }) diff --git a/runtime/Stdlib_RegExp.resi b/runtime/Stdlib_RegExp.resi index b249ae65bf..fb16a75337 100644 --- a/runtime/Stdlib_RegExp.resi +++ b/runtime/Stdlib_RegExp.resi @@ -23,7 +23,7 @@ module Result: { ```rescript // Match the first two words separated by a space let regexp = RegExp.fromString("(\\w+) (\\w+)") - + switch regexp->RegExp.exec("ReScript is pretty cool, right?") { | None => Console.log("Nope, no match...") | Some(result) => Console.log(result->RegExp.Result.fullMatch) // Prints the full string that matched, "ReScript is" @@ -40,11 +40,12 @@ module Result: { ```rescript // Match the first two words separated by a space let regexp = RegExp.fromString("(\\w+) (\\w+)") - + // This below will log "ReScript" and "is" to the console. switch regexp->RegExp.exec("ReScript is pretty cool, right?") { | None => Console.log("Nope, no match...") - | Some(result) => switch result->RegExp.Result.matches->Array.keepSome { + | Some(result) => + switch result->RegExp.Result.matches->Array.keepSome { | [firstWord, secondWord] => Console.log2(firstWord, secondWord) | _ => Console.log("Didn't find exactly two words...") } @@ -62,7 +63,7 @@ module Result: { ```rescript // Match the first two words separated by a space let regexp = RegExp.fromString("(\\w+) (\\w+)") - + // This below will log the full input string "ReScript is pretty cool, right?" to the console. switch regexp->RegExp.exec("ReScript is pretty cool, right?") { | None => Console.log("Nope, no match...") diff --git a/runtime/Stdlib_Result.resi b/runtime/Stdlib_Result.resi index 08644f11c7..603ecaeddd 100644 --- a/runtime/Stdlib_Result.resi +++ b/runtime/Stdlib_Result.resi @@ -30,20 +30,20 @@ */ /** The type `Result.t(result, err)` describes a variant of two states: - `Ok(someResult)` represents a successful operation, whereby - ``Error(someError)` signals an erroneous operation. +`Ok(someResult)` represents a successful operation, whereby +\``Error(someError)\` signals an erroneous operation. In this concrete example, we are defining our own `Result` type to reflect an HTTP like - query operation: +query operation: ```res example type responseError = NotAvailable | NotFound type queryResult = result - + let failQueryUser = (username: string): queryResult => { Error(NotAvailable) } -``` + ``` */ type t<'res, 'err> = result<'res, 'err> = Ok('res) | Error('err) @@ -52,7 +52,7 @@ type t<'res, 'err> = result<'res, 'err> = Ok('res) | Error('err) ```res example Result.getExn(Result.Ok(42)) == 42 - + switch Result.getExn(Error("Invalid data")) { | exception Not_found => assert(true) | _ => assert(false) @@ -67,7 +67,7 @@ let getExn: result<'a, 'b> => 'a ```res example Result.getOrThrow(Result.Ok(42)) == 42 - + switch Result.getOrThrow(Error("Invalid data")) { | exception Not_found => assert(true) | _ => assert(false) diff --git a/runtime/Stdlib_Set.resi b/runtime/Stdlib_Set.resi index 4945add4d1..916aec8bb1 100644 --- a/runtime/Stdlib_Set.resi +++ b/runtime/Stdlib_Set.resi @@ -295,7 +295,7 @@ See [`Set.isSupersetOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript let set1 = Set.fromArray(["apple", "banana", "pear"]) let set2 = Set.fromArray(["apple", "banana"]) set1->Set.isSupersetOf(set2) // true - ``` +``` */ @send external isSupersetOf: (t<'a>, t<'a>) => bool = "isSupersetOf" diff --git a/runtime/Stdlib_String.resi b/runtime/Stdlib_String.resi index 34effcb378..896bf1dc4b 100644 --- a/runtime/Stdlib_String.resi +++ b/runtime/Stdlib_String.resi @@ -115,8 +115,8 @@ String.fromCodePointMany([0xd55c, 0xae00, 0x1f63a]) == `한글😺` ## Exceptions - `RangeError`: If one of the number is not a valid code point, like -`fromCharCode([1, -5])`. - + `fromCharCode([1, -5])`. + */ @variadic @val external fromCodePointMany: array => string = "String.fromCodePoint" @@ -194,7 +194,7 @@ external getUnsafe: (string, int) => string = "" /** `charAt(str, index)` gets the character at `index` within string `str`. If `index` is negative or greater than the length of `str`, it returns the empty -string. If the string contains characters outside the range \u0000-\uffff, it +string. If the string contains characters outside the range \\u0000-\\uffff, it will return the first 16-bit value at that position in the string. See [`String.charAt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt) on MDN. @@ -446,19 +446,20 @@ no match, it returns `None`. For regular expressions without the g modifier, if there is a match, the return value is `Some(array)` where the array contains: - The entire matched string - Any capture groups if the regexp had parentheses -For regular expressions with the g modifier, a matched expression returns -`Some(array)` with all the matched substrings and no capture groups. -See [`String.match`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match) on MDN. + For regular expressions with the g modifier, a matched expression returns + `Some(array)` with all the matched substrings and no capture groups. + See [`String.match`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match) on MDN. ## Examples ```rescript -String.match("The better bats", %re("/b[aeiou]t/")) == Some([Some("bet")]) -String.match("The better bats", %re("/b[aeiou]t/g")) == Some([Some("bet"), Some("bat")]) -String.match("Today is 2018-04-05.", %re("/(\d+)-(\d+)-(\d+)/")) == +String.match("The better bats", /b[aeiou]t/) == Some([Some("bet")]) +String.match("The better bats", /b[aeiou]t/g) == Some([Some("bet"), Some("bat")]) +String.match("Today is 2018-04-05.", /(\d+)-(\d+)-(\d+)/) == Some([Some("2018-04-05"), Some("2018"), Some("04"), Some("05")]) -String.match("The optional example", %re("/(foo)?(example)/")) == Some([Some("example"), None, Some("example")]) -String.match("The large container.", %re("/b[aeiou]g/")) == None +String.match("The optional example", /(foo)?(example)/) == + Some([Some("example"), None, Some("example")]) +String.match("The large container.", /b[aeiou]g/) == None ``` */ @return(nullable) @send @@ -467,11 +468,11 @@ external match: (string, Stdlib_RegExp.t) => option = "m /** `normalize(str)` returns the normalized Unicode string using Normalization Form Canonical (NFC) Composition. Consider the character ã, which can be represented -as the single codepoint \u00e3 or the combination of a lower case letter A -\u0061 and a combining tilde \u0303. Normalization ensures that both can be +as the single codepoint \\u00e3 or the combination of a lower case letter A +\\u0061 and a combining tilde \\u0303. Normalization ensures that both can be stored in an equivalent binary representation. See [`String.normalize`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize) on MDN. -See also [Unicode technical report #15](https://unicode.org/reports/tr15/) for details. +See also [Unicode technical report \#15](https://unicode.org/reports/tr15/) for details. ## Examples @@ -480,7 +481,7 @@ let string1 = "\u00F1" let string2 = "\u006E\u0303" assert(string1 != string2) // true -assertEqual(String.normalize(string1), String.normalize(string2)) +String.normalize(string1) == String.normalize(string2) ``` */ @send @@ -493,9 +494,9 @@ specified form of normalization, which may be one of: - "NFD" — Normalization Form Canonical Decomposition. - "NFKC" — Normalization Form Compatibility Composition. - "NFKD" — Normalization Form Compatibility Decomposition. -See [`String.normalize`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize) on MDN. -See also [Unicode technical report #15](https://unicode.org/reports/tr15/) for -details. + See [`String.normalize`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize) on MDN. + See also [Unicode technical report \#15](https://unicode.org/reports/tr15/) for + details. ## Examples @@ -556,8 +557,8 @@ See [`String.replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R ## Examples ```rescript -String.replaceRegExp("vowels be gone", %re("/[aeiou]/g"), "x") == "vxwxls bx gxnx" -String.replaceRegExp("Juan Fulano", %re("/(\w+) (\w+)/"), "$2, $1") == "Fulano, Juan" +String.replaceRegExp("vowels be gone", /[aeiou]/g, "x") == "vxwxls bx gxnx" +String.replaceRegExp("Juan Fulano", /(\w+) (\w+)/, "$2, $1") == "Fulano, Juan" ``` */ @send @@ -589,8 +590,8 @@ See [`String.replaceAll`](https://developer.mozilla.org/en-US/docs/Web/JavaScrip ## Examples ```rescript -String.replaceAllRegExp("vowels be gone", %re("/[aeiou]/g"), "x") == "vxwxls bx gxnx" -String.replaceAllRegExp("aabbcc", %re("/b/g"), ".") == "aa..cc" +String.replaceAllRegExp("vowels be gone", /[aeiou]/g, "x") == "vxwxls bx gxnx" +String.replaceAllRegExp("aabbcc", /b/g, ".") == "aa..cc" ``` */ @send @@ -608,7 +609,7 @@ See [`String.replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R ```rescript let str = "beautiful vowels" -let re = %re("/[aeiou]/g") +let re = /[aeiou]/g let matchFn = (~match, ~offset as _, ~input as _) => String.toUpperCase(match) String.unsafeReplaceRegExpBy0(str, re, matchFn) == "bEAUtIfUl vOwEls" ``` @@ -629,7 +630,7 @@ See [`String.replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R ```rescript let str = "Jony is 40" -let re = %re("/(Jony is )\d+/g") +let re = /(Jony is )\d+/g let matchFn = (~match as _, ~group1, ~offset as _, ~input as _) => { group1 ++ "41" } @@ -652,7 +653,7 @@ See [`String.replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R ```rescript let str = "7 times 6" -let re = %re("/(\d+) times (\d+)/") +let re = /(\d+) times (\d+)/ let matchFn = (~match as _, ~group1, ~group2, ~offset as _, ~input as _) => { switch (Int.fromString(group1), Int.fromString(group2)) { | (Some(x), Some(y)) => Int.toString(x * y) @@ -700,7 +701,7 @@ See [`String.replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R ```rescript let str = "beautiful vowels" -let re = %re("/[aeiou]/g") +let re = /[aeiou]/g let matchFn = (~match, ~offset as _, ~input as _) => String.toUpperCase(match) String.replaceRegExpBy0Unsafe(str, re, matchFn) == "bEAUtIfUl vOwEls" ``` @@ -721,7 +722,7 @@ See [`String.replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R ```rescript let str = "Jony is 40" -let re = %re("/(Jony is )\d+/g") +let re = /(Jony is )\d+/g let matchFn = (~match as _, ~group1, ~offset as _, ~input as _) => { group1 ++ "41" } @@ -744,7 +745,7 @@ See [`String.replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R ```rescript let str = "7 times 6" -let re = %re("/(\d+) times (\d+)/") +let re = /(\d+) times (\d+)/ let matchFn = (~match as _, ~group1, ~group2, ~offset as _, ~input as _) => { switch (Int.fromString(group1), Int.fromString(group2)) { | (Some(x), Some(y)) => Int.toString(x * y) @@ -788,8 +789,8 @@ See [`String.search`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Re ## Examples ```rescript -String.search("testing 1 2 3", %re("/\d+/")) == 8 -String.search("no numbers", %re("/\d+/")) == -1 +String.search("testing 1 2 3", /\d+/) == 8 +String.search("no numbers", /\d+/) == -1 ``` */ @send @@ -801,8 +802,8 @@ external search: (string, Stdlib_RegExp.t) => int = "search" ## Examples ```rescript -String.searchOpt("testing 1 2 3", %re("/\d+/")) == Some(8) -String.searchOpt("no numbers", %re("/\d+/")) == None +String.searchOpt("testing 1 2 3", /\d+/) == Some(8) +String.searchOpt("no numbers", /\d+/) == None ``` */ let searchOpt: (string, Stdlib_RegExp.t) => option @@ -811,11 +812,11 @@ let searchOpt: (string, Stdlib_RegExp.t) => option `slice(str, ~start, ~end)` returns the substring of `str` starting at character `start` up to but not including `end`. - If either `start` or `end` is negative, then it is evaluated as -`length(str - start)` or `length(str - end)`. + `length(str - start)` or `length(str - end)`. - If `end` is greater than the length of `str`, then it is treated as -`length(str)`. + `length(str)`. - If `start` is greater than `end`, slice returns the empty string. -See [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN. + See [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN. ## Examples @@ -834,7 +835,7 @@ external slice: (string, ~start: int, ~end: int) => string = "slice" `start` to the end of the string. - If `start` is negative, then it is evaluated as `length(str - start)`. - If `start` is greater than the length of `str`, then sliceToEnd returns the empty string. -See [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN. + See [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN. ## Examples @@ -889,7 +890,7 @@ See [`String.split`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Ref ## Examples ```rescript -String.splitByRegExp("Jan,Feb,Mar", %re("/,/")) == [Some("Jan"), Some("Feb"), Some("Mar")] +String.splitByRegExp("Jan,Feb,Mar", /,/) == [Some("Jan"), Some("Feb"), Some("Mar")] ``` */ @send @@ -905,8 +906,11 @@ See [`String.split`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Ref ## Examples ```rescript -String.splitByRegExpAtMost("Hello World. How are you doing?", / /, ~limit=3) == - [Some("Hello"), Some("World."), Some("How")] +String.splitByRegExpAtMost("Hello World. How are you doing?", / /, ~limit=3) == [ + Some("Hello"), + Some("World."), + Some("How"), + ] ``` */ @send @@ -952,7 +956,7 @@ including end from `str`. - If `start` is less than zero, it is treated as zero. - If `end` is zero or negative, the empty string is returned. - If `start` is greater than `end`, the `start` and `end` points are swapped. -See [`String.substring`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring) on MDN. + See [`String.substring`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring) on MDN. ## Examples @@ -970,8 +974,8 @@ external substring: (string, ~start: int, ~end: int) => string = "substring" `start` to the end. - If `start` is less than or equal to zero, the entire string is returned. - If `start` is greater than or equal to the length of `str`, the empty string -is returned. -See [`String.substring`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring) on MDN. + is returned. + See [`String.substring`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring) on MDN. ## Examples From 7633422eeacbef27354ec035fa086ca71f85348c Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Thu, 10 Jul 2025 10:33:33 +0200 Subject: [PATCH 02/16] handle piped assertEqual --- runtime/Belt_HashMap.resi | 4 +- runtime/Belt_Int.resi | 8 +- runtime/Belt_List.resi | 29 ++- runtime/Belt_Map.resi | 4 +- runtime/Belt_MapInt.resi | 4 +- runtime/Belt_MapString.resi | 4 +- runtime/Belt_Option.resi | 8 +- runtime/Belt_Result.resi | 8 +- runtime/Belt_Set.resi | 106 +++++------ runtime/Stdlib.res | 4 +- runtime/Stdlib_Array.resi | 305 +++++++++++------------------- runtime/Stdlib_AsyncIterator.resi | 4 +- runtime/Stdlib_BigInt.resi | 122 ++++++------ runtime/Stdlib_Dict.resi | 11 +- runtime/Stdlib_Iterator.resi | 36 ++-- runtime/Stdlib_JSON.resi | 52 ++--- runtime/Stdlib_JsError.resi | 8 +- runtime/Stdlib_JsExn.resi | 4 +- runtime/Stdlib_List.resi | 27 ++- runtime/Stdlib_Map.resi | 3 +- runtime/Stdlib_Null.resi | 4 +- runtime/Stdlib_Option.resi | 4 +- runtime/Stdlib_Pair.res | 14 +- runtime/Stdlib_Set.resi | 3 +- runtime/Stdlib_Symbol.resi | 12 +- tools/src/tools.ml | 45 ++++- 26 files changed, 364 insertions(+), 469 deletions(-) diff --git a/runtime/Belt_HashMap.resi b/runtime/Belt_HashMap.resi index ff5d50252a..d06511ae76 100644 --- a/runtime/Belt_HashMap.resi +++ b/runtime/Belt_HashMap.resi @@ -286,9 +286,7 @@ let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) Belt.HashMap.set(s0, 1, "value1") Belt.HashMap.set(s0, 2, "value2") -s0 -->Belt.HashMap.reduce("", (acc, _, value) => acc ++ (", " ++ value)) -->assertEqual(", value1, value2") +s0->Belt.HashMap.reduce("", (acc, _, value) => acc ++ (", " ++ value)) == ", value1, value2" ``` ## More Examples diff --git a/runtime/Belt_Int.resi b/runtime/Belt_Int.resi index ad309941d1..11e0f599f3 100644 --- a/runtime/Belt_Int.resi +++ b/runtime/Belt_Int.resi @@ -32,7 +32,7 @@ Converts a given `int` to a `float`. ## Examples ```rescript -Belt.Int.toFloat(1)->assertEqual(1.0) +Belt.Int.toFloat(1) == 1.0 ``` */ external toFloat: int => float = "%identity" @@ -43,7 +43,7 @@ Converts a given `float` to an `int`. ## Examples ```rescript -Belt.Int.fromFloat(1.0)->assertEqual(1) +Belt.Int.fromFloat(1.0) == 1 ``` */ external fromFloat: float => int = "%intoffloat" @@ -54,7 +54,7 @@ Converts a given `string` to an `int`. Returns `Some(int)` when the input is a n ## Examples ```rescript -Belt.Int.fromString("1")->assertEqual(Some(1)) +Belt.Int.fromString("1") == Some(1) ``` */ let fromString: string => option @@ -65,7 +65,7 @@ Converts a given `int` to a `string`. Uses the JavaScript `String` constructor u ## Examples ```rescript -Belt.Int.toString(1)->assertEqual("1") +Belt.Int.toString(1) == "1" ``` */ @val diff --git a/runtime/Belt_List.resi b/runtime/Belt_List.resi index 8a1ac719b0..b51ef12229 100644 --- a/runtime/Belt_List.resi +++ b/runtime/Belt_List.resi @@ -69,7 +69,7 @@ with care. ## Examples ```rescript -Belt.List.headExn(list{1, 2, 3})->assertEqual(1) +Belt.List.headExn(list{1, 2, 3}) == 1 switch Belt.List.headExn(list{}) { // Raises an Error @@ -87,7 +87,7 @@ with care. ## Examples ```rescript -Belt.List.headOrThrow(list{1, 2, 3})->assertEqual(1) +Belt.List.headOrThrow(list{1, 2, 3}) == 1 switch Belt.List.headOrThrow(list{}) { // Raises an Error @@ -119,7 +119,7 @@ with care. ## Examples ```rescript -Belt.List.tailExn(list{1, 2, 3})->assertEqual(list{2, 3}) +Belt.List.tailExn(list{1, 2, 3}) == list{2, 3} switch Belt.List.tailExn(list{}) { // Raises an Error @@ -137,7 +137,7 @@ with care. ## Examples ```rescript -Belt.List.tailOrThrow(list{1, 2, 3})->assertEqual(list{2, 3}) +Belt.List.tailOrThrow(list{1, 2, 3}) == list{2, 3} switch Belt.List.tailOrThrow(list{}) { // Raises an Error @@ -186,7 +186,7 @@ length. Use with care. ```rescript let abc = list{"A", "B", "C"} -abc->Belt.List.getExn(1)->assertEqual("B") +abc->Belt.List.getExn(1) == "B" switch abc->Belt.List.getExn(4) { // Raises an Error @@ -206,7 +206,7 @@ length. Use with care. ```rescript let abc = list{"A", "B", "C"} -abc->Belt.List.getOrThrow(1)->assertEqual("B") +abc->Belt.List.getOrThrow(1) == "B" switch abc->Belt.List.getOrThrow(4) { // Raises an Error @@ -450,9 +450,7 @@ Equivalent to `Belt.List.map(someList, f)->Belt.List.reverse` ## Examples ```rescript -list{3, 4, 5} -->Belt.List.mapReverse(x => x * x) -->assertEqual(list{25, 16, 9}) +list{3, 4, 5}->Belt.List.mapReverse(x => x * x) == list{25, 16, 9} ``` */ let mapReverse: (t<'a>, 'a => 'b) => t<'b> @@ -934,9 +932,7 @@ In other words: ## Examples ```rescript -list{1, 2, 3, 4} -->Belt.List.partition(x => x > 2) -->assertEqual((list{3, 4}, list{1, 2})) +list{1, 2, 3, 4}->Belt.List.partition(x => x > 2) == (list{3, 4}, list{1, 2}) ``` */ let partition: (t<'a>, 'a => bool) => (t<'a>, t<'a>) @@ -969,7 +965,8 @@ list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.getAssoc(3, (a, b) => a == b) /* S list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.getAssoc(15, (k, item) => k /* 15 */ == item - /* 9, 5, 22 */) == Some("afternoon") +) == Some("afternoon") +/* 9, 5, 22 */ ``` */ let getAssoc: (t<('a, 'c)>, 'b, ('a, 'b) => bool) => option<'c> @@ -988,7 +985,8 @@ list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.hasAssoc(1, (a, b) => a == b) == t list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.hasAssoc(25, (k, item) => k /* 25 */ == item - /* 9, 5, 22 */) == false +) == false +/* 9, 5, 22 */ ``` */ let hasAssoc: (t<('a, 'c)>, 'b, ('a, 'b) => bool) => bool @@ -1008,7 +1006,8 @@ list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.removeAssoc(1, (a, b) => a == b) = list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.removeAssoc(9, (k, item) => k /* 9 */ == item - /* 9, 5, 22 */) == list{(15, "afternoon"), (22, "night")} +) == list{(15, "afternoon"), (22, "night")} +/* 9, 5, 22 */ ``` */ let removeAssoc: (t<('a, 'c)>, 'b, ('a, 'b) => bool) => t<('a, 'c)> diff --git a/runtime/Belt_Map.resi b/runtime/Belt_Map.resi index ebf9dc68a1..4560b16860 100644 --- a/runtime/Belt_Map.resi +++ b/runtime/Belt_Map.resi @@ -131,9 +131,7 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "")]) -s0 -->Belt.Map.findFirstBy((k, _) => k == 4) -->assertEqual(Some(4, "4")) +s0->Belt.Map.findFirstBy((k, _) => k == 4) == Some(4, "4") ``` */ let findFirstBy: (t<'k, 'v, 'id>, ('k, 'v) => bool) => option<('k, 'v)> diff --git a/runtime/Belt_MapInt.resi b/runtime/Belt_MapInt.resi index 277e9bbe8f..28aea4e794 100644 --- a/runtime/Belt_MapInt.resi +++ b/runtime/Belt_MapInt.resi @@ -35,9 +35,7 @@ to match predicate `p`. ```rescript let mapInt = Belt.Map.Int.fromArray([(1, "one"), (2, "two"), (3, "three")]) -mapInt -->Belt.Map.Int.findFirstBy((k, v) => k == 1 && v == "one") -->assertEqual(Some(1, "one")) +mapInt->Belt.Map.Int.findFirstBy((k, v) => k == 1 && v == "one") == Some(1, "one") ``` */ let findFirstBy: (t<'v>, (key, 'v) => bool) => option<(key, 'v)> diff --git a/runtime/Belt_MapString.resi b/runtime/Belt_MapString.resi index 5ee67f6817..17a1299953 100644 --- a/runtime/Belt_MapString.resi +++ b/runtime/Belt_MapString.resi @@ -35,9 +35,7 @@ to match predicate `p`. ```rescript let mapString = Belt.Map.String.fromArray([("1", "one"), ("2", "two"), ("3", "three")]) -mapString -->Belt.Map.String.findFirstBy((k, v) => k == "1" && v == "one") -->assertEqual(Some("1", "one")) +mapString->Belt.Map.String.findFirstBy((k, v) => k == "1" && v == "one") == Some("1", "one") ``` */ let findFirstBy: (t<'v>, (key, 'v) => bool) => option<(key, 'v)> diff --git a/runtime/Belt_Option.resi b/runtime/Belt_Option.resi index ce087901c8..c0a2a60a4e 100644 --- a/runtime/Belt_Option.resi +++ b/runtime/Belt_Option.resi @@ -79,9 +79,7 @@ Raises an Error in case `None` is provided. Use with care. ## Examples ```rescript -Some(3) -->Belt.Option.getExn -->assertEqual(3) +Some(3)->Belt.Option.getExn == 3 switch Belt.Option.getExn(None) { // Raises an exception @@ -98,9 +96,7 @@ Raises an Error in case `None` is provided. Use with care. ## Examples ```rescript -Some(3) -->Belt.Option.getOrThrow -->assertEqual(3) +Some(3)->Belt.Option.getOrThrow == 3 switch Belt.Option.getOrThrow(None) { // Raises an exception diff --git a/runtime/Belt_Result.resi b/runtime/Belt_Result.resi index f4c9afdcb3..c5873d31e6 100644 --- a/runtime/Belt_Result.resi +++ b/runtime/Belt_Result.resi @@ -39,9 +39,7 @@ type t<'a, 'b> = result<'a, 'b> = ## Examples ```rescript -Belt.Result.Ok(42) -->Belt.Result.getExn -->assertEqual(42) +Belt.Result.Ok(42)->Belt.Result.getExn == 42 switch Belt.Result.getExn(Belt.Result.Error("Invalid data")) { // raise a exception @@ -58,9 +56,7 @@ let getExn: t<'a, 'b> => 'a ## Examples ```rescript -Belt.Result.Ok(42) -->Belt.Result.getOrThrow -->assertEqual(42) +Belt.Result.Ok(42)->Belt.Result.getOrThrow == 42 switch Belt.Result.getOrThrow(Belt.Result.Error("Invalid data")) { // raise a exception diff --git a/runtime/Belt_Set.resi b/runtime/Belt_Set.resi index 98b43bab84..fca4aefbd8 100644 --- a/runtime/Belt_Set.resi +++ b/runtime/Belt_Set.resi @@ -102,7 +102,7 @@ module IntCmp = Belt.Id.MakeComparable({ let set = Belt.Set.make(~id=module(IntCmp)) -Belt.Set.isEmpty(set)->assertEqual(true) +Belt.Set.isEmpty(set) == true ``` */ let make: (~id: id<'value, 'id>) => t<'value, 'id> @@ -120,7 +120,7 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.Set.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) -s0->Belt.Set.toArray->assertEqual([1, 2, 3, 4]) +s0->Belt.Set.toArray == [1, 2, 3, 4] ``` */ let fromArray: (array<'value>, ~id: id<'value, 'id>) => t<'value, 'id> @@ -145,8 +145,8 @@ module IntCmp = Belt.Id.MakeComparable({ let empty = Belt.Set.fromArray([], ~id=module(IntCmp)) let notEmpty = Belt.Set.fromArray([1], ~id=module(IntCmp)) -Belt.Set.isEmpty(empty)->assertEqual(true) -Belt.Set.isEmpty(notEmpty)->assertEqual(false) +Belt.Set.isEmpty(empty) == true +Belt.Set.isEmpty(notEmpty) == false ``` */ let isEmpty: t<_> => bool @@ -164,8 +164,8 @@ module IntCmp = Belt.Id.MakeComparable({ let set = Belt.Set.fromArray([1, 4, 2, 5], ~id=module(IntCmp)) -set->Belt.Set.has(3)->assertEqual(false) -set->Belt.Set.has(1)->assertEqual(true) +set->Belt.Set.has(3) == false +set->Belt.Set.has(1) == true ``` */ let has: (t<'value, 'id>, 'value) => bool @@ -187,10 +187,10 @@ let s1 = s0->Belt.Set.add(1) let s2 = s1->Belt.Set.add(2) let s3 = s2->Belt.Set.add(2) -s0->Belt.Set.toArray->assertEqual([]) -s1->Belt.Set.toArray->assertEqual([1]) -s2->Belt.Set.toArray->assertEqual([1, 2]) -s3->Belt.Set.toArray->assertEqual([1, 2]) +s0->Belt.Set.toArray == [] +s1->Belt.Set.toArray == [1] +s2->Belt.Set.toArray == [1, 2] +s3->Belt.Set.toArray == [1, 2] s2 == s3 ``` */ @@ -211,9 +211,7 @@ let set = Belt.Set.make(~id=module(IntCmp)) let newSet = set->Belt.Set.mergeMany([5, 4, 3, 2, 1]) -newSet -->Belt.Set.toArray -->assertEqual([1, 2, 3, 4, 5]) +newSet->Belt.Set.toArray == [1, 2, 3, 4, 5] ``` */ let mergeMany: (t<'value, 'id>, array<'value>) => t<'value, 'id> @@ -234,8 +232,8 @@ let s1 = s0->Belt.Set.remove(1) let s2 = s1->Belt.Set.remove(3) let s3 = s2->Belt.Set.remove(3) -s1->Belt.Set.toArray->assertEqual([2, 3, 4, 5]) -s2->Belt.Set.toArray->assertEqual([2, 4, 5]) +s1->Belt.Set.toArray == [2, 3, 4, 5] +s2->Belt.Set.toArray == [2, 4, 5] s2 == s3 ``` */ @@ -256,9 +254,7 @@ let set = Belt.Set.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) let newSet = set->Belt.Set.removeMany([5, 4, 3, 2, 1]) -newSet -->Belt.Set.toArray -->assertEqual([]) +newSet->Belt.Set.toArray == [] ``` */ let removeMany: (t<'value, 'id>, array<'value>) => t<'value, 'id> @@ -278,9 +274,7 @@ let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) let union = Belt.Set.union(s0, s1) -union -->Belt.Set.toArray -->assertEqual([1, 2, 3, 4, 5, 6]) +union->Belt.Set.toArray == [1, 2, 3, 4, 5, 6] ``` */ let union: (t<'value, 'id>, t<'value, 'id>) => t<'value, 'id> @@ -301,9 +295,7 @@ let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) let intersect = Belt.Set.intersect(s0, s1) -intersect -->Belt.Set.toArray -->assertEqual([2, 3, 5]) +intersect->Belt.Set.toArray == [2, 3, 5] ``` */ let intersect: (t<'value, 'id>, t<'value, 'id>) => t<'value, 'id> @@ -322,13 +314,9 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) -Belt.Set.diff(s0, s1) -->Belt.Set.toArray -->assertEqual([6]) +Belt.Set.diff(s0, s1)->Belt.Set.toArray == [6] -Belt.Set.diff(s1, s0) -->Belt.Set.toArray -->assertEqual([1, 4]) +Belt.Set.diff(s1, s0)->Belt.Set.toArray == [1, 4] ``` */ let diff: (t<'value, 'id>, t<'value, 'id>) => t<'value, 'id> @@ -348,9 +336,9 @@ let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) let s2 = Belt.Set.intersect(s0, s1) -Belt.Set.subset(s2, s0)->assertEqual(true) -Belt.Set.subset(s2, s1)->assertEqual(true) -Belt.Set.subset(s1, s0)->assertEqual(false) +Belt.Set.subset(s2, s0) == true +Belt.Set.subset(s2, s1) == true +Belt.Set.subset(s1, s0) == false ``` */ let subset: (t<'value, 'id>, t<'value, 'id>) => bool @@ -376,7 +364,7 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.Set.fromArray([5, 2, 3], ~id=module(IntCmp)) let s1 = Belt.Set.fromArray([3, 2, 5], ~id=module(IntCmp)) -Belt.Set.eq(s0, s1)->assertEqual(true) +Belt.Set.eq(s0, s1) == true ``` */ let eq: (t<'value, 'id>, t<'value, 'id>) => bool @@ -406,7 +394,7 @@ s0->Belt.Set.forEach(x => { acc := Belt.List.add(acc.contents, x) }) -acc.contents->assertEqual(list{6, 5, 3, 2}) +acc.contents == list{6, 5, 3, 2} ``` */ let forEach: (t<'value, 'id>, 'value => unit) => unit @@ -426,9 +414,7 @@ module IntCmp = Belt.Id.MakeComparable({ }) let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) -s0 -->Belt.Set.reduce(list{}, (acc, element) => acc->Belt.List.add(element)) -->assertEqual(list{6, 5, 3, 2}) +s0->Belt.Set.reduce(list{}, (acc, element) => acc->Belt.List.add(element)) == list{6, 5, 3, 2} ``` */ let reduce: (t<'value, 'id>, 'a, ('a, 'value) => 'a) => 'a @@ -450,7 +436,7 @@ module IntCmp = Belt.Id.MakeComparable({ let isEven = x => mod(x, 2) == 0 let s0 = Belt.Set.fromArray([2, 4, 6, 8], ~id=module(IntCmp)) -s0->Belt.Set.every(isEven)->assertEqual(true) +s0->Belt.Set.every(isEven) == true ``` */ let every: (t<'value, 'id>, 'value => bool) => bool @@ -472,7 +458,7 @@ module IntCmp = Belt.Id.MakeComparable({ let isOdd = x => mod(x, 2) != 0 let s0 = Belt.Set.fromArray([1, 2, 4, 6, 8], ~id=module(IntCmp)) -s0->Belt.Set.some(isOdd)->assertEqual(true) +s0->Belt.Set.some(isOdd) == true ``` */ let some: (t<'value, 'id>, 'value => bool) => bool @@ -496,7 +482,7 @@ let isEven = x => mod(x, 2) == 0 let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) let s1 = s0->Belt.Set.keep(isEven) -s1->Belt.Set.toArray->assertEqual([2, 4]) +s1->Belt.Set.toArray == [2, 4] ``` */ let keep: (t<'value, 'id>, 'value => bool) => t<'value, 'id> @@ -520,8 +506,8 @@ let isOdd = x => mod(x, 2) != 0 let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) let (s1, s2) = s0->Belt.Set.partition(isOdd) -s1->Belt.Set.toArray->assertEqual([1, 3, 5]) -s2->Belt.Set.toArray->assertEqual([2, 4]) +s1->Belt.Set.toArray == [1, 3, 5] +s2->Belt.Set.toArray == [2, 4] ``` */ let partition: (t<'value, 'id>, 'value => bool) => (t<'value, 'id>, t<'value, 'id>) @@ -539,7 +525,7 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.Set.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) -s0->Belt.Set.size->assertEqual(4) +s0->Belt.Set.size == 4 ``` */ let size: t<'value, 'id> => int @@ -557,7 +543,7 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) -s0->Belt.Set.toArray->assertEqual([1, 2, 3, 5]) +s0->Belt.Set.toArray == [1, 2, 3, 5] ``` */ let toArray: t<'value, 'id> => array<'value> @@ -575,7 +561,7 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) -s0->Belt.Set.toList->assertEqual(list{1, 2, 3, 5}) +s0->Belt.Set.toList == list{1, 2, 3, 5} ``` */ let toList: t<'value, 'id> => list<'value> @@ -594,8 +580,8 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.Set.make(~id=module(IntCmp)) let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) -s0->Belt.Set.minimum->assertEqual(None) -s1->Belt.Set.minimum->assertEqual(Some(1)) +s0->Belt.Set.minimum == None +s1->Belt.Set.minimum == Some(1) ``` */ let minimum: t<'value, 'id> => option<'value> @@ -614,8 +600,8 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.Set.make(~id=module(IntCmp)) let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) -s0->Belt.Set.minUndefined->Js.Undefined.toOption->assertEqual(None) -s1->Belt.Set.minUndefined->Js.Undefined.toOption->assertEqual(Some(1)) +s0->Belt.Set.minUndefined->Js.Undefined.toOption == None +s1->Belt.Set.minUndefined->Js.Undefined.toOption == Some(1) ``` */ let minUndefined: t<'value, 'id> => Js.undefined<'value> @@ -634,8 +620,8 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.Set.make(~id=module(IntCmp)) let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) -s0->Belt.Set.maximum->assertEqual(None) -s1->Belt.Set.maximum->assertEqual(Some(5)) +s0->Belt.Set.maximum == None +s1->Belt.Set.maximum == Some(5) ``` */ let maximum: t<'value, 'id> => option<'value> @@ -656,13 +642,11 @@ let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) s0 ->Belt.Set.maxUndefined -->Js.Undefined.toOption -->assertEqual(None) +->Js.Undefined.toOption == None s1 ->Belt.Set.maxUndefined -->Js.Undefined.toOption -->assertEqual(Some(5)) +->Js.Undefined.toOption == Some(5) ``` */ let maxUndefined: t<'value, 'id> => Js.undefined<'value> @@ -680,8 +664,8 @@ module IntCmp = Belt.Id.MakeComparable({ let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) -s0->Belt.Set.get(3)->assertEqual(Some(3)) -s0->Belt.Set.get(20)->assertEqual(None) +s0->Belt.Set.get(3) == Some(3) +s0->Belt.Set.get(20) == None ``` */ let get: (t<'value, 'id>, 'value) => option<'value> @@ -716,9 +700,9 @@ let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) let ((smaller, larger), present) = s0->Belt.Set.split(3) -present->assertEqual(true) -smaller->Belt.Set.toArray->assertEqual([1, 2]) -larger->Belt.Set.toArray->assertEqual([4, 5]) +present == true +smaller->Belt.Set.toArray == [1, 2] +larger->Belt.Set.toArray == [4, 5] ``` */ let split: (t<'value, 'id>, 'value) => ((t<'value, 'id>, t<'value, 'id>), bool) diff --git a/runtime/Stdlib.res b/runtime/Stdlib.res index d13d57685d..f0e44ff0b5 100644 --- a/runtime/Stdlib.res +++ b/runtime/Stdlib.res @@ -114,9 +114,7 @@ let panic = JsError.panic ## Examples ```rescript -list{1, 2} -->List.tailExn -->assertEqual(list{2}) +list{1, 2}->List.tailExn == list{2} ``` */ let assertEqual = (a, b) => { diff --git a/runtime/Stdlib_Array.resi b/runtime/Stdlib_Array.resi index 208b3d8b39..8eb31682b4 100644 --- a/runtime/Stdlib_Array.resi +++ b/runtime/Stdlib_Array.resi @@ -18,8 +18,7 @@ type arrayLike<'a> ```rescript Map.fromArray([("foo", 1), ("bar", 2)]) ->Map.values -->Array.fromIterator -->assertEqual([1, 2]) +->Array.fromIterator == [1, 2] ``` */ @val @@ -38,8 +37,8 @@ external fromArrayLikeWithMap: (arrayLike<'a>, 'a => 'b) => array<'b> = "Array.f ## Examples ```rescript -Array.make(~length=3, #apple)->assertEqual([#apple, #apple, #apple]) -Array.make(~length=6, 7)->assertEqual([7, 7, 7, 7, 7, 7]) +Array.make(~length=3, #apple) == [#apple, #apple, #apple] +Array.make(~length=6, 7) == [7, 7, 7, 7, 7, 7] ``` */ let make: (~length: int, 'a) => array<'a> @@ -52,9 +51,9 @@ Creates an array of length `length` initialized with the value returned from `f ## Examples ```rescript -Array.fromInitializer(~length=3, i => i + 3)->assertEqual([3, 4, 5]) +Array.fromInitializer(~length=3, i => i + 3) == [3, 4, 5] -Array.fromInitializer(~length=7, i => i + 3)->assertEqual([3, 4, 5, 6, 7, 8, 9]) +Array.fromInitializer(~length=7, i => i + 3) == [3, 4, 5, 6, 7, 8, 9] ``` */ let fromInitializer: (~length: int, int => 'a) => array<'a> @@ -75,9 +74,7 @@ See [`Array.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Ref ```rescript let someArray = ["hi", "hello"] -someArray -->Array.length -->assertEqual(2) +someArray->Array.length == 2 ``` */ @get @@ -106,7 +103,7 @@ See [`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer ```rescript let myArray = [1, 2, 3, 4] myArray->Array.fillAll(9) -myArray->assertEqual([9, 9, 9, 9]) +myArray == [9, 9, 9, 9] ``` */ @send @@ -124,7 +121,7 @@ See [`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer ```rescript let myArray = [1, 2, 3, 4] myArray->Array.fillToEnd(9, ~start=1) -myArray->assertEqual([1, 9, 9, 9]) +myArray == [1, 9, 9, 9] ``` */ @send @@ -144,7 +141,7 @@ let myArray = [1, 2, 3, 4] myArray->Array.fill(9, ~start=1, ~end=3) -myArray->assertEqual([1, 9, 9, 4]) +myArray == [1, 9, 9, 4] ``` */ @send @@ -162,11 +159,9 @@ See [`Array.pop`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refere ```rescript let someArray = ["hi", "hello"] -someArray -->Array.pop -->assertEqual(Some("hello")) +someArray->Array.pop == Some("hello") -someArray->assertEqual(["hi"]) // Notice last item is gone. +someArray == ["hi"] // Notice last item is gone. ``` */ @send @@ -186,7 +181,7 @@ let someArray = ["hi", "hello"] someArray->Array.push("yay") -someArray->assertEqual(["hi", "hello", "yay"]) +someArray == ["hi", "hello", "yay"] ``` */ @send @@ -205,7 +200,7 @@ See [`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer let someArray = ["hi", "hello"] someArray->Array.pushMany(["yay", "wehoo"]) -someArray->assertEqual(["hi", "hello", "yay", "wehoo"]) +someArray == ["hi", "hello", "yay", "wehoo"] ``` */ @variadic @send @@ -224,7 +219,7 @@ See [`Array.reverse`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Re let someArray = ["hi", "hello"] someArray->Array.reverse -someArray->assertEqual(["hello", "hi"]) +someArray == ["hello", "hi"] ``` */ @send @@ -242,11 +237,9 @@ See [`Array.shift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe ```rescript let someArray = ["hi", "hello"] -someArray -->Array.shift -->assertEqual(Some("hi")) +someArray->Array.shift == Some("hi") -someArray->assertEqual(["hello"]) // Notice first item is gone. +someArray == ["hello"] // Notice first item is gone. ``` */ @send @@ -262,11 +255,9 @@ See [`Array.toSorted`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R ```rescript let someArray = [3, 2, 1] -someArray -->Array.toSorted(Int.compare) -->assertEqual([1, 2, 3]) +someArray->Array.toSorted(Int.compare) == [1, 2, 3] -someArray->assertEqual([3, 2, 1]) // Original unchanged +someArray == [3, 2, 1] // Original unchanged ``` */ @send @@ -284,7 +275,7 @@ See [`Array.sort`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer ```rescript let array = [3, 2, 1] array->Array.sort((a, b) => float(a - b)) -array->assertEqual([1, 2, 3]) +array == [1, 2, 3] ``` */ @send @@ -331,7 +322,7 @@ See [`Array.unshift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Re ```rescript let someArray = ["hi", "hello"] someArray->Array.unshift("yay") -someArray->assertEqual(["yay", "hi", "hello"]) +someArray == ["yay", "hi", "hello"] ``` */ @send @@ -349,7 +340,7 @@ See [`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer ```rescript let someArray = ["hi", "hello"] someArray->Array.unshiftMany(["yay", "wehoo"]) -someArray->assertEqual(["yay", "wehoo", "hi", "hello"]) +someArray == ["yay", "wehoo", "hi", "hello"] ``` */ @variadic @send @@ -368,7 +359,7 @@ let array2 = ["yay", "wehoo"] let someArray = array1->Array.concat(array2) -someArray->assertEqual(["hi", "hello", "yay", "wehoo"]) +someArray == ["hi", "hello", "yay", "wehoo"] ``` */ @send @@ -401,9 +392,7 @@ See [`Array.flat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer ## Examples ```rescript -[[1], [2], [3, 4]] -->Array.flat -->assertEqual([1, 2, 3, 4]) +[[1], [2], [3, 4]]->Array.flat == [1, 2, 3, 4] ``` */ @send @@ -417,12 +406,10 @@ See [`Array.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R ## Examples ```rescript -[1, 2]->Array.includes(1)->assertEqual(true) -[1, 2]->Array.includes(3)->assertEqual(false) +[1, 2]->Array.includes(1) == true +[1, 2]->Array.includes(3) == false -[{"language": "ReScript"}] -->Array.includes({"language": "ReScript"}) -->assertEqual(false) // false, because of strict equality +[{"language": "ReScript"}]->Array.includes({"language": "ReScript"}) == false // false, because of strict equality ``` */ @send @@ -438,12 +425,10 @@ See [`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Re ## Examples ```rescript -[1, 2]->Array.indexOf(2)->assertEqual(1) -[1, 2]->Array.indexOf(3)->assertEqual(-1) +[1, 2]->Array.indexOf(2) == 1 +[1, 2]->Array.indexOf(3) == -1 -[{"language": "ReScript"}] -->Array.indexOf({"language": "ReScript"}) -->assertEqual(-1) // -1, because of strict equality +[{"language": "ReScript"}]->Array.indexOf({"language": "ReScript"}) == -1 // -1, because of strict equality ``` */ @send @@ -457,11 +442,9 @@ See [`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Re ## Examples ```rescript -[1, 2]->Array.indexOfOpt(2)->assertEqual(Some(1)) -[1, 2]->Array.indexOfOpt(3)->assertEqual(None) -[{"language": "ReScript"}] -->Array.indexOfOpt({"language": "ReScript"}) -->assertEqual(None) // None, because of strict equality +[1, 2]->Array.indexOfOpt(2) == Some(1) +[1, 2]->Array.indexOfOpt(3) == None +[{"language": "ReScript"}]->Array.indexOfOpt({"language": "ReScript"}) == None // None, because of strict equality ``` */ let indexOfOpt: (array<'a>, 'a) => option @@ -475,9 +458,7 @@ See [Array.join](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen ## Examples ```rescript -["One", "Two", "Three"] -->Array.join(" -- ") -->assertEqual("One -- Two -- Three") +["One", "Two", "Three"]->Array.join(" -- ") == "One -- Two -- Three" ``` */ @send @@ -489,9 +470,7 @@ external join: (array, string) => string = "join" ## Examples ```rescript -["One", "Two", "Three"] -->Array.joinWith(" -- ") -->assertEqual("One -- Two -- Three") +["One", "Two", "Three"]->Array.joinWith(" -- ") == "One -- Two -- Three" ``` */ @deprecated("Use `join` instead") @send @@ -505,9 +484,7 @@ See [Array.join](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen ## Examples ```rescript -[1, 2, 3] -->Array.joinUnsafe(" -- ") -->assertEqual("1 -- 2 -- 3") +[1, 2, 3]->Array.joinUnsafe(" -- ") == "1 -- 2 -- 3" ``` */ @send @@ -519,9 +496,7 @@ external joinUnsafe: (array<'a>, string) => string = "join" ## Examples ```rescript -[1, 2, 3] -->Array.joinWithUnsafe(" -- ") -->assertEqual("1 -- 2 -- 3") +[1, 2, 3]->Array.joinWithUnsafe(" -- ") == "1 -- 2 -- 3" ``` */ @deprecated("Use `joinUnsafe` instead") @send @@ -538,9 +513,7 @@ See [`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe ## Examples ```rescript -[1, 2, 3, 4] -->Array.slice(~start=1, ~end=3) -->assertEqual([2, 3]) +[1, 2, 3, 4]->Array.slice(~start=1, ~end=3) == [2, 3] ``` */ @send @@ -554,9 +527,7 @@ See [`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe ## Examples ```rescript -[1, 2, 3, 4] -->Array.sliceToEnd(~start=1) -->assertEqual([2, 3, 4]) +[1, 2, 3, 4]->Array.sliceToEnd(~start=1) == [2, 3, 4] ``` */ @send @@ -570,7 +541,7 @@ external sliceToEnd: (array<'a>, ~start: int) => array<'a> = "slice" let myArray = [1, 2, 3] let copyOfMyArray = myArray->Array.copy -copyOfMyArray->assertEqual([1, 2, 3]) +copyOfMyArray == [1, 2, 3] (myArray === copyOfMyArray) == false ``` */ @@ -585,9 +556,7 @@ See [`Array.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R ## Examples ```rescript -[1, 2, 3, 4] -->Array.toString -->assertEqual("1,2,3,4") +[1, 2, 3, 4]->Array.toString == "1,2,3,4" ``` */ @send @@ -605,13 +574,9 @@ See [`Array.every`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe ```rescript let array = [1, 2, 3, 4] -array -->Array.every(num => num <= 4) -->assertEqual(true) +array->Array.every(num => num <= 4) == true -array -->Array.every(num => num === 1) -->assertEqual(false) +array->Array.every(num => num === 1) == false ``` */ @send @@ -627,13 +592,9 @@ See [`Array.every`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe ```rescript let array = [1, 2, 3, 4] -array -->Array.everyWithIndex((num, index) => index < 5 && num <= 4) -->assertEqual(true) +array->Array.everyWithIndex((num, index) => index < 5 && num <= 4) == true -array -->Array.everyWithIndex((num, index) => index < 2 && num >= 2) -->assertEqual(false) +array->Array.everyWithIndex((num, index) => index < 2 && num >= 2) == false ``` */ @send @@ -647,9 +608,7 @@ See [`Array.filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Ref ## Examples ```rescript -[1, 2, 3, 4] -->Array.filter(num => num > 2) -->assertEqual([3, 4]) +[1, 2, 3, 4]->Array.filter(num => num > 2) == [3, 4] ``` */ @send @@ -663,9 +622,7 @@ See [`Array.filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Ref ## Examples ```rescript -[1, 2, 3, 4] -->Array.filterWithIndex((num, index) => index === 0 || num === 2) -->assertEqual([1, 2]) +[1, 2, 3, 4]->Array.filterWithIndex((num, index) => index === 0 || num === 2) == [1, 2] ``` */ @send @@ -683,9 +640,7 @@ type languages = ReScript | TypeScript | JavaScript let array = [ReScript, TypeScript, JavaScript] -array -->Array.find(item => item == ReScript) -->assertEqual(Some(ReScript)) +array->Array.find(item => item == ReScript) == Some(ReScript) ``` */ @send @@ -703,9 +658,7 @@ type languages = ReScript | TypeScript | JavaScript let array = [TypeScript, JavaScript, ReScript] -array -->Array.findWithIndex((item, index) => index > 1 && item == ReScript) -->assertEqual(Some(ReScript)) +array->Array.findWithIndex((item, index) => index > 1 && item == ReScript) == Some(ReScript) ``` */ @send @@ -721,9 +674,7 @@ See [`Array.findLast`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R ```rescript let array = [1, 2, 3] -array -->Array.findLast(item => item > 0) -->assertEqual(Some(3)) +array->Array.findLast(item => item > 0) == Some(3) ``` */ @send @@ -739,9 +690,7 @@ See [`Array.findLast`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R ```rescript let array = [1, 2, 3] -array -->Array.findLastWithIndex((item, index) => index < 2 && item > 0) -->assertEqual(Some(2)) +array->Array.findLastWithIndex((item, index) => index < 2 && item > 0) == Some(2) ``` */ @send @@ -761,13 +710,9 @@ type languages = ReScript | TypeScript | JavaScript let array = [ReScript, JavaScript] -array -->Array.findIndex(item => item == ReScript) -->assertEqual(0) +array->Array.findIndex(item => item == ReScript) == 0 -array -->Array.findIndex(item => item == TypeScript) -->assertEqual(-1) +array->Array.findIndex(item => item == TypeScript) == -1 ``` */ @send @@ -813,13 +758,9 @@ type languages = ReScript | TypeScript | JavaScript let array = [ReScript, JavaScript, ReScript] -array -->Array.findLastIndex(item => item == ReScript) -->assertEqual(2) +array->Array.findLastIndex(item => item == ReScript) == 2 -array -->Array.findLastIndex(item => item == TypeScript) -->assertEqual(-1) +array->Array.findLastIndex(item => item == TypeScript) == -1 ``` */ @send @@ -929,15 +870,13 @@ Applies `fn` to each element of `xs` from beginning to end. Function `fn` has tw ## Examples ```rescript -Array.reduce([2, 3, 4], 1, (a, b) => a + b)->assertEqual(10) +Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 -Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b)->assertEqual("abcd") +Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" -[1, 2, 3] -->Array.reduce(list{}, List.add) -->assertEqual(list{3, 2, 1}) +[1, 2, 3]->Array.reduce(list{}, List.add) == list{3, 2, 1} -Array.reduce([], list{}, List.add)->assertEqual(list{}) +Array.reduce([], list{}, List.add) == list{} ``` */ let reduce: (array<'a>, 'b, ('b, 'a) => 'b) => 'b @@ -950,15 +889,11 @@ Applies `fn` to each element of `xs` from beginning to end. Function `fn` has th ## Examples ```rescript -Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i)->assertEqual(16) +Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 -Array.reduceWithIndex([1, 2, 3], list{}, (acc, v, i) => list{v + i, ...acc})->assertEqual(list{ - 5, - 3, - 1, -}) +Array.reduceWithIndex([1, 2, 3], list{}, (acc, v, i) => list{v + i, ...acc}) == list{5, 3, 1} -Array.reduceWithIndex([], list{}, (acc, v, i) => list{v + i, ...acc})->assertEqual(list{}) +Array.reduceWithIndex([], list{}, (acc, v, i) => list{v + i, ...acc}) == list{} ``` */ let reduceWithIndex: (array<'a>, 'b, ('b, 'a, int) => 'b) => 'b @@ -971,11 +906,11 @@ Works like `Array.reduce`; except that function `fn` is applied to each item of ## Examples ```rescript -Array.reduceRight(["a", "b", "c", "d"], "", (a, b) => a ++ b)->assertEqual("dcba") +Array.reduceRight(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" -Array.reduceRight([1, 2, 3], list{}, List.add)->assertEqual(list{1, 2, 3}) +Array.reduceRight([1, 2, 3], list{}, List.add) == list{1, 2, 3} -Array.reduceRight([], list{}, List.add)->assertEqual(list{}) +Array.reduceRight([], list{}, List.add) == list{} ``` */ let reduceRight: (array<'a>, 'b, ('b, 'a) => 'b) => 'b @@ -988,9 +923,9 @@ Like `reduceRight`, but with an additional index argument on the callback functi ## Examples ```rescript -Array.reduceRightWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i)->assertEqual(16) +Array.reduceRightWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 -Array.reduceRightWithIndex([], list{}, (acc, v, i) => list{v + i, ...acc})->assertEqual(list{}) +Array.reduceRightWithIndex([], list{}, (acc, v, i) => list{v + i, ...acc}) == list{} ``` */ let reduceRightWithIndex: (array<'a>, 'b, ('b, 'a, int) => 'b) => 'b @@ -1005,9 +940,7 @@ See [`Array.some`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer ```rescript let array = ["Hello", "Hi", "Good bye"] -array -->Array.some(greeting => greeting === "Hello") -->assertEqual(true) +array->Array.some(greeting => greeting === "Hello") == true ``` */ @send @@ -1023,9 +956,7 @@ See [`Array.some`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer ```rescript let array = ["Hello", "Hi", "Good bye"] -array -->Array.someWithIndex((greeting, index) => greeting === "Hello" && index === 0) -->assertEqual(true) +array->Array.someWithIndex((greeting, index) => greeting === "Hello" && index === 0) == true ``` */ @send @@ -1041,13 +972,9 @@ Returns `None` if the index does not exist in the array. Equivalent to doing `ar ```rescript let array = ["Hello", "Hi", "Good bye"] -array -->Array.get(0) -->assertEqual(Some("Hello")) +array->Array.get(0) == Some("Hello") -array -->Array.get(3) -->assertEqual(None) +array->Array.get(3) == None ``` */ @get_index @@ -1064,7 +991,7 @@ Beware this will *mutate* the array. let array = ["Hello", "Hi", "Good bye"] array->Array.set(1, "Hello") -array[1]->assertEqual(Some("Hello")) +array[1] == Some("Hello") ``` */ @set_index @@ -1141,9 +1068,7 @@ type languages = ReScript | TypeScript | JavaScript let array = [ReScript, TypeScript, JavaScript] -array -->Array.findIndexOpt(item => item == ReScript) -->assertEqual(Some(0)) +array->Array.findIndexOpt(item => item == ReScript) == Some(0) ``` */ let findIndexOpt: (array<'a>, 'a => bool) => option @@ -1160,9 +1085,7 @@ See [`Array.findLastIndex`](https://developer.mozilla.org/en-US/docs/Web/JavaScr ```rescript let array = ["hello", "world", "!"] -array -->Array.findLastIndexOpt(item => item->String.includes("o")) -->assertEqual(Some(1)) +array->Array.findLastIndexOpt(item => item->String.includes("o")) == Some(1) ``` */ let findLastIndexOpt: (array<'a>, 'a => bool) => option @@ -1178,8 +1101,8 @@ See [`Array.toReversed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript let someArray = ["hi", "hello"] let reversed = someArray->Array.toReversed -reversed->assertEqual(["hello", "hi"]) -someArray->assertEqual(["hi", "hello"]) // Original unchanged +reversed == ["hello", "hi"] +someArray == ["hi", "hello"] // Original unchanged ``` */ @send @@ -1193,22 +1116,18 @@ Calls `fn` for each element and returns a new array containing results of the `f ## Examples ```rescript -["Hello", "Hi", "Good bye"] -->Array.filterMap(item => +["Hello", "Hi", "Good bye"]->Array.filterMap(item => switch item { | "Hello" => Some(item->String.length) | _ => None } -) -->assertEqual([5]) +) == [5] -[1, 2, 3, 4, 5, 6] -->Array.filterMap(n => mod(n, 2) == 0 ? Some(n * n) : None) -->assertEqual([4, 16, 36]) +[1, 2, 3, 4, 5, 6]->Array.filterMap(n => mod(n, 2) == 0 ? Some(n * n) : None) == [4, 16, 36] -Array.filterMap([1, 2, 3, 4, 5, 6], _ => None)->assertEqual([]) +Array.filterMap([1, 2, 3, 4, 5, 6], _ => None) == [] -Array.filterMap([], n => mod(n, 2) == 0 ? Some(n * n) : None)->assertEqual([]) +Array.filterMap([], n => mod(n, 2) == 0 ? Some(n * n) : None) == [] ``` */ let filterMap: (array<'a>, 'a => option<'b>) => array<'b> @@ -1222,13 +1141,13 @@ and ignoring every value that is `None` ## Examples ```rescript -Array.keepSome([Some(1), None, Some(3)])->assertEqual([1, 3]) +Array.keepSome([Some(1), None, Some(3)]) == [1, 3] -Array.keepSome([Some(1), Some(2), Some(3)])->assertEqual([1, 2, 3]) +Array.keepSome([Some(1), Some(2), Some(3)]) == [1, 2, 3] -Array.keepSome([None, None, None])->assertEqual([]) +Array.keepSome([None, None, None]) == [] -Array.keepSome([])->assertEqual([]) +Array.keepSome([]) == [] ``` */ let keepSome: array> => array<'a> @@ -1243,9 +1162,7 @@ let array = ["Hello", "Hi", "Good bye"] let shuffledArray = array->Array.toShuffled Console.log(shuffledArray) -Array.toShuffled([1, 2, 3]) -->Array.length -->assertEqual(3) +Array.toShuffled([1, 2, 3])->Array.length == 3 ``` */ let toShuffled: array<'a> => array<'a> @@ -1265,9 +1182,7 @@ Console.log(array) let array2 = [1, 2, 3] array2->Array.shuffle -array2 -->Array.length -->assertEqual(3) +array2->Array.length == 3 ``` */ let shuffle: array<'a> => unit @@ -1282,15 +1197,13 @@ type language = ReScript | TypeScript | JavaScript let array = [ReScript, TypeScript, JavaScript] -array -->Array.flatMap(item => +array->Array.flatMap(item => switch item { | ReScript => [1, 2, 3] | TypeScript => [4, 5, 6] | JavaScript => [7, 8, 9] } -) -->assertEqual([1, 2, 3, 4, 5, 6, 7, 8, 9]) +) == [1, 2, 3, 4, 5, 6, 7, 8, 9] ``` */ @send @@ -1306,15 +1219,13 @@ type language = ReScript | TypeScript | JavaScript let array = [ReScript, TypeScript, JavaScript] -array -->Array.flatMapWithIndex((item, index) => +array->Array.flatMapWithIndex((item, index) => switch item { | ReScript => [index] | TypeScript => [index, index + 1] | JavaScript => [index, index + 1, index + 2] } -) -->assertEqual([0, 1, 2, 2, 3, 4]) +) == [0, 1, 2, 2, 3, 4] ``` */ @send @@ -1329,13 +1240,13 @@ Otherwise returns `None` ## Examples ```rescript -Array.findMap([1, 2, 3], n => mod(n, 2) == 0 ? Some(n - 2) : None)->assertEqual(Some(0)) +Array.findMap([1, 2, 3], n => mod(n, 2) == 0 ? Some(n - 2) : None) == Some(0) -Array.findMap([1, 2, 3, 4, 5, 6], n => mod(n, 2) == 0 ? Some(n - 8) : None)->assertEqual(Some(-6)) +Array.findMap([1, 2, 3, 4, 5, 6], n => mod(n, 2) == 0 ? Some(n - 8) : None) == Some(-6) -Array.findMap([1, 2, 3, 4, 5, 6], _ => None)->assertEqual(None) +Array.findMap([1, 2, 3, 4, 5, 6], _ => None) == None -Array.findMap([], n => mod(n, 2) == 0 ? Some(n * n) : None)->assertEqual(None) +Array.findMap([], n => mod(n, 2) == 0 ? Some(n * n) : None) == None ``` */ let findMap: (array<'a>, 'a => option<'b>) => option<'b> @@ -1348,12 +1259,12 @@ Get an element by its index. Negative indices count backwards from the last item ## Examples ```rescript -["a", "b", "c"]->Array.at(0)->assertEqual(Some("a")) -["a", "b", "c"]->Array.at(2)->assertEqual(Some("c")) -["a", "b", "c"]->Array.at(3)->assertEqual(None) -["a", "b", "c"]->Array.at(-1)->assertEqual(Some("c")) -["a", "b", "c"]->Array.at(-3)->assertEqual(Some("a")) -["a", "b", "c"]->Array.at(-4)->assertEqual(None) +["a", "b", "c"]->Array.at(0) == Some("a") +["a", "b", "c"]->Array.at(2) == Some("c") +["a", "b", "c"]->Array.at(3) == None +["a", "b", "c"]->Array.at(-1) == Some("c") +["a", "b", "c"]->Array.at(-3) == Some("a") +["a", "b", "c"]->Array.at(-4) == None ``` */ @send @@ -1367,13 +1278,9 @@ Returns `None` if the array is empty. ## Examples ```rescript -["Hello", "Hi", "Good bye"] -->Array.last -->assertEqual(Some("Good bye")) +["Hello", "Hi", "Good bye"]->Array.last == Some("Good bye") -[] -->Array.last -->assertEqual(None) +[]->Array.last == None ``` */ let last: array<'a> => option<'a> @@ -1396,8 +1303,8 @@ See [Array.prototype.entries](https://developer.mozilla.org/en-US/docs/Web/JavaS ```rescript let array = [5, 6, 7] let iterator: Iterator.t<(int, int)> = array->Array.entries -iterator->Iterator.next->assertEqual({done: false, value: Some((0, 5))}) -iterator->Iterator.next->assertEqual({done: false, value: Some((1, 6))}) +iterator->Iterator.next == {done: false, value: Some((0, 5))} +iterator->Iterator.next == {done: false, value: Some((1, 6))} ``` */ @send @@ -1413,8 +1320,8 @@ See [Array.prototype.values](https://developer.mozilla.org/en-US/docs/Web/JavaSc ```rescript let array = [5, 6, 7] let iterator: Iterator.t = array->Array.values -iterator->Iterator.next->assertEqual({done: false, value: Some(5)}) -iterator->Iterator.next->assertEqual({done: false, value: Some(6)}) +iterator->Iterator.next == {done: false, value: Some(5)} +iterator->Iterator.next == {done: false, value: Some(6)} ``` */ @send diff --git a/runtime/Stdlib_AsyncIterator.resi b/runtime/Stdlib_AsyncIterator.resi index 60bdccb489..3a8b5d9ff7 100644 --- a/runtime/Stdlib_AsyncIterator.resi +++ b/runtime/Stdlib_AsyncIterator.resi @@ -142,9 +142,7 @@ let processMyAsyncIterator = async () => { break := done if done { - value - ->Option.isNone - ->assertEqual(true) + value->Option.isNone == true } } } diff --git a/runtime/Stdlib_BigInt.resi b/runtime/Stdlib_BigInt.resi index 4b1273b71e..41d8421ad5 100644 --- a/runtime/Stdlib_BigInt.resi +++ b/runtime/Stdlib_BigInt.resi @@ -11,8 +11,8 @@ See [`BigInt.asIntN`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Re ## Examples ```rescript -BigInt.asIntN(~width=4, 25n)->assertEqual(-7n) -BigInt.asIntN(~width=4, 3n)->assertEqual(3n) +BigInt.asIntN(~width=4, 25n) == -7n +BigInt.asIntN(~width=4, 3n) == 3n ``` */ @val external asIntN: (~width: int, bigint) => bigint = "BigInt.asIntN" @@ -25,8 +25,8 @@ See [`BigInt.asUintN`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R ## Examples ```rescript -BigInt.asUintN(~width=4, 25n)->assertEqual(9n) -BigInt.asUintN(~width=4, 3n)->assertEqual(3n) +BigInt.asUintN(~width=4, 25n) == 9n +BigInt.asUintN(~width=4, 3n) == 3n ``` */ @val external asUintN: (~width: int, bigint) => bigint = "BigInt.asUintN" @@ -38,15 +38,15 @@ number as a `bigint` if successfully parsed. Throws a syntax exception otherwise ## Examples ```rescript -BigInt.fromStringOrThrow("123")->assertEqual(123n) +BigInt.fromStringOrThrow("123") == 123n -BigInt.fromStringOrThrow("")->assertEqual(0n) +BigInt.fromStringOrThrow("") == 0n -BigInt.fromStringOrThrow("0x11")->assertEqual(17n) +BigInt.fromStringOrThrow("0x11") == 17n -BigInt.fromStringOrThrow("0b11")->assertEqual(3n) +BigInt.fromStringOrThrow("0b11") == 3n -BigInt.fromStringOrThrow("0o11")->assertEqual(9n) +BigInt.fromStringOrThrow("0o11") == 9n /* catch exception */ switch BigInt.fromStringOrThrow("a") { @@ -65,17 +65,17 @@ Parses the given `string` into a `bigint` using JavaScript semantics. Returns ## Examples ```rescript -BigInt.fromString("123")->assertEqual(Some(123n)) +BigInt.fromString("123") == Some(123n) -BigInt.fromString("")->assertEqual(Some(0n)) +BigInt.fromString("") == Some(0n) -BigInt.fromString("0x11")->assertEqual(Some(17n)) +BigInt.fromString("0x11") == Some(17n) -BigInt.fromString("0b11")->assertEqual(Some(3n)) +BigInt.fromString("0b11") == Some(3n) -BigInt.fromString("0o11")->assertEqual(Some(9n)) +BigInt.fromString("0o11") == Some(9n) -BigInt.fromString("invalid")->assertEqual(None) +BigInt.fromString("invalid") == None ``` */ let fromString: string => option @@ -89,9 +89,9 @@ external fromStringExn: string => bigint = "BigInt" ## Examples ```rescript -BigInt.fromInt(123)->assertEqual(123n) -BigInt.fromInt(0)->assertEqual(0n) -BigInt.fromInt(-456)->assertEqual(-456n) +BigInt.fromInt(123) == 123n +BigInt.fromInt(0) == 0n +BigInt.fromInt(-456) == -456n ``` */ @val external fromInt: int => bigint = "BigInt" @@ -103,11 +103,11 @@ Throws an exception if the float is not an integer or is infinite/NaN. ## Examples ```rescript -BigInt.fromFloatOrThrow(123.0)->assertEqual(123n) +BigInt.fromFloatOrThrow(123.0) == 123n -BigInt.fromFloatOrThrow(0.0)->assertEqual(0n) +BigInt.fromFloatOrThrow(0.0) == 0n -BigInt.fromFloatOrThrow(-456.0)->assertEqual(-456n) +BigInt.fromFloatOrThrow(-456.0) == -456n /* This will throw an exception */ switch BigInt.fromFloatOrThrow(123.5) { @@ -126,10 +126,10 @@ Returns `Some(bigint)` if the float is a valid `bigint`, `None` otherwise. ## Examples ```rescript -BigInt.fromFloat(123.0)->assertEqual(Some(123n)) -BigInt.fromFloat(0.0)->assertEqual(Some(0n)) -BigInt.fromFloat(-456.0)->assertEqual(Some(-456n)) -BigInt.fromFloat(123.5)->assertEqual(None) +BigInt.fromFloat(123.0) == Some(123n) +BigInt.fromFloat(0.0) == Some(0n) +BigInt.fromFloat(-456.0) == Some(-456n) +BigInt.fromFloat(123.5) == None ``` */ let fromFloat: float => option @@ -141,7 +141,7 @@ See [`toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen ## Examples ```rescript -BigInt.toString(123n)->assertEqual("123") +BigInt.toString(123n) == "123" ``` */ @send @@ -156,7 +156,7 @@ Returns a string with a language-sensitive representation of this BigInt value. ## Examples ```rescript -BigInt.toString(123n)->assertEqual("123") +BigInt.toString(123n) == "123" ``` */ @send @@ -168,9 +168,9 @@ external toLocaleString: bigint => string = "toLocaleString" ## Examples ```rescript -BigInt.toFloat(123n)->assertEqual(123.0) -BigInt.toFloat(0n)->assertEqual(0.0) -BigInt.toFloat(-456n)->assertEqual(-456.0) +BigInt.toFloat(123n) == 123.0 +BigInt.toFloat(0n) == 0.0 +BigInt.toFloat(-456n) == -456.0 ``` */ @val external toFloat: bigint => float = "Number" @@ -181,9 +181,9 @@ BigInt.toFloat(-456n)->assertEqual(-456.0) ## Examples ```rescript -BigInt.toInt(123n)->assertEqual(123) -BigInt.toInt(0n)->assertEqual(0) -BigInt.toInt(-456n)->assertEqual(-456) +BigInt.toInt(123n) == 123 +BigInt.toInt(0n) == 0 +BigInt.toInt(-456n) == -456 ``` */ let toInt: bigint => int @@ -194,8 +194,8 @@ let toInt: bigint => int ## Examples ```rescript -BigInt.add(5n, 3n)->assertEqual(8n) -BigInt.add(-2n, 7n)->assertEqual(5n) +BigInt.add(5n, 3n) == 8n +BigInt.add(-2n, 7n) == 5n ``` */ external add: (bigint, bigint) => bigint = "%addbigint" @@ -206,8 +206,8 @@ external add: (bigint, bigint) => bigint = "%addbigint" ## Examples ```rescript -BigInt.sub(8n, 3n)->assertEqual(5n) -BigInt.sub(2n, 7n)->assertEqual(-5n) +BigInt.sub(8n, 3n) == 5n +BigInt.sub(2n, 7n) == -5n ``` */ external sub: (bigint, bigint) => bigint = "%subbigint" @@ -218,8 +218,8 @@ external sub: (bigint, bigint) => bigint = "%subbigint" ## Examples ```rescript -BigInt.mul(5n, 3n)->assertEqual(15n) -BigInt.mul(-2n, 7n)->assertEqual(-14n) +BigInt.mul(5n, 3n) == 15n +BigInt.mul(-2n, 7n) == -14n ``` */ external mul: (bigint, bigint) => bigint = "%mulbigint" @@ -230,8 +230,8 @@ external mul: (bigint, bigint) => bigint = "%mulbigint" ## Examples ```rescript -BigInt.div(15n, 3n)->assertEqual(5n) -BigInt.div(14n, 3n)->assertEqual(4n) +BigInt.div(15n, 3n) == 5n +BigInt.div(14n, 3n) == 4n ``` */ external div: (bigint, bigint) => bigint = "%divbigint" @@ -242,8 +242,8 @@ external div: (bigint, bigint) => bigint = "%divbigint" ## Examples ```rescript -BigInt.mod(15n, 4n)->assertEqual(3n) -BigInt.mod(14n, 3n)->assertEqual(2n) +BigInt.mod(15n, 4n) == 3n +BigInt.mod(14n, 3n) == 2n ``` */ external mod: (bigint, bigint) => bigint = "%modbigint" @@ -254,8 +254,8 @@ external mod: (bigint, bigint) => bigint = "%modbigint" ## Examples ```rescript -BigInt.bitwiseAnd(7n, 4n)->assertEqual(4n) -BigInt.bitwiseAnd(15n, 8n)->assertEqual(8n) +BigInt.bitwiseAnd(7n, 4n) == 4n +BigInt.bitwiseAnd(15n, 8n) == 8n ``` */ external bitwiseAnd: (bigint, bigint) => bigint = "%andbigint" @@ -266,8 +266,8 @@ external bitwiseAnd: (bigint, bigint) => bigint = "%andbigint" ## Examples ```rescript -BigInt.bitwiseOr(7n, 4n)->assertEqual(7n) -BigInt.bitwiseOr(8n, 4n)->assertEqual(12n) +BigInt.bitwiseOr(7n, 4n) == 7n +BigInt.bitwiseOr(8n, 4n) == 12n ``` */ external bitwiseOr: (bigint, bigint) => bigint = "%orbigint" @@ -278,8 +278,8 @@ external bitwiseOr: (bigint, bigint) => bigint = "%orbigint" ## Examples ```rescript -BigInt.bitwiseXor(7n, 4n)->assertEqual(3n) -BigInt.bitwiseXor(15n, 8n)->assertEqual(7n) +BigInt.bitwiseXor(7n, 4n) == 3n +BigInt.bitwiseXor(15n, 8n) == 7n ``` */ external bitwiseXor: (bigint, bigint) => bigint = "%xorbigint" @@ -290,8 +290,8 @@ external bitwiseXor: (bigint, bigint) => bigint = "%xorbigint" ## Examples ```rescript -BigInt.bitwiseNot(2n)->assertEqual(-3n) -BigInt.bitwiseNot(-1n)->assertEqual(0n) +BigInt.bitwiseNot(2n) == -3n +BigInt.bitwiseNot(-1n) == 0n ``` */ external bitwiseNot: bigint => bigint = "%bitnot_bigint" @@ -302,8 +302,8 @@ external bitwiseNot: bigint => bigint = "%bitnot_bigint" ## Examples ```rescript -BigInt.shiftLeft(4n, 1n)->assertEqual(8n) -BigInt.shiftLeft(1n, 3n)->assertEqual(8n) +BigInt.shiftLeft(4n, 1n) == 8n +BigInt.shiftLeft(1n, 3n) == 8n ``` */ external shiftLeft: (bigint, bigint) => bigint = "%lslbigint" @@ -314,8 +314,8 @@ external shiftLeft: (bigint, bigint) => bigint = "%lslbigint" ## Examples ```rescript -BigInt.shiftRight(8n, 1n)->assertEqual(4n) -BigInt.shiftRight(16n, 2n)->assertEqual(4n) +BigInt.shiftRight(8n, 1n) == 4n +BigInt.shiftRight(16n, 2n) == 4n ``` */ external shiftRight: (bigint, bigint) => bigint = "%asrbigint" @@ -336,7 +336,7 @@ external ignore: bigint => unit = "%ignore" ## Examples ```rescript -BigInt.land(7n, 4n)->assertEqual(4n) +BigInt.land(7n, 4n) == 4n ``` */ @deprecated("Use `&` operator or `bitwiseAnd` instead.") @@ -350,7 +350,7 @@ external land: (bigint, bigint) => bigint = "%andbigint" ## Examples ```rescript -BigInt.lor(7n, 4n)->assertEqual(7n) +BigInt.lor(7n, 4n) == 7n ``` */ @deprecated("Use `bitwiseOr` instead.") @@ -364,7 +364,7 @@ external lor: (bigint, bigint) => bigint = "%orbigint" ## Examples ```rescript -BigInt.lxor(7n, 4n)->assertEqual(3n) +BigInt.lxor(7n, 4n) == 3n ``` */ @deprecated("Use `^` operator or `bitwiseXor` instead.") @@ -378,7 +378,7 @@ external lxor: (bigint, bigint) => bigint = "%xorbigint" ## Examples ```rescript -BigInt.lnot(2n)->assertEqual(-3n) +BigInt.lnot(2n) == -3n ``` */ @deprecated("Use `~` operator or `bitwiseNot` instead.") @@ -392,7 +392,7 @@ external lnot: bigint => bigint = "%bitnot_bigint" ## Examples ```rescript -BigInt.lsl(4n, 1n)->assertEqual(8n) +BigInt.lsl(4n, 1n) == 8n ``` */ @deprecated("Use `<<` operator or `shiftLeft` instead.") @@ -406,7 +406,7 @@ external lsl: (bigint, bigint) => bigint = "%lslbigint" ## Examples ```rescript -BigInt.asr(8n, 1n)->assertEqual(4n) +BigInt.asr(8n, 1n) == 4n ``` */ @deprecated("Use `>>` operator or `shiftRight` instead.") diff --git a/runtime/Stdlib_Dict.resi b/runtime/Stdlib_Dict.resi index 151bd57bb3..e85f05441c 100644 --- a/runtime/Stdlib_Dict.resi +++ b/runtime/Stdlib_Dict.resi @@ -108,8 +108,7 @@ let iterator: Iterator.t<(string, int)> = %raw(` `) iterator ->Dict.fromIterator -->Dict.valuesToArray -->assertEqual([1, 2]) +->Dict.valuesToArray == [1, 2] ``` */ @val @@ -252,10 +251,10 @@ Be aware that it uses the JavaScript `in` operator under the hood. ```rescript let dict = dict{"key1": Some(1), "key2": None} -dict->Dict.has("key1")->assertEqual(true) -dict->Dict.has("key2")->assertEqual(true) -dict->Dict.has("key3")->assertEqual(false) -dict->Dict.has("toString")->assertEqual(true) +dict->Dict.has("key1") == true +dict->Dict.has("key2") == true +dict->Dict.has("key3") == false +dict->Dict.has("toString") == true ``` */ external has: (dict<'a>, string) => bool = "%dict_has" diff --git a/runtime/Stdlib_Iterator.resi b/runtime/Stdlib_Iterator.resi index 6d632b2d1f..35c9b85107 100644 --- a/runtime/Stdlib_Iterator.resi +++ b/runtime/Stdlib_Iterator.resi @@ -39,8 +39,8 @@ let iterator: Iterator.t = %raw(` return iterator1 })() `) -(iterator->Iterator.next).done->assertEqual(false) -(iterator->Iterator.next).done->assertEqual(true) +(iterator->Iterator.next).done == false +(iterator->Iterator.next).done == true ``` */ @send @@ -61,7 +61,7 @@ map->Map.set("someKey2", "someValue2") // `Map.keys` returns all keys of the map as an iterator. let mapKeysAsArray = map->Map.keys->Iterator.toArray -mapKeysAsArray->assertEqual(["someKey", "someKey2"]) +mapKeysAsArray == ["someKey", "someKey2"] ``` ## Remark @@ -90,7 +90,7 @@ let mapKeysAsArray = ->Map.keys ->Iterator.toArrayWithMapper(key => key->String.length) -mapKeysAsArray->assertEqual([7, 8]) +mapKeysAsArray == [7, 8] ``` */ external toArrayWithMapper: (t<'a>, 'a => 'b) => array<'b> = "Array.from" @@ -108,7 +108,7 @@ iterator->Iterator.forEach(v => { acc := acc.contents ++ v }) -acc.contents->assertEqual("abc") +acc.contents == "abc" ``` ## Remark @@ -137,8 +137,8 @@ See [Iterator.prototype.drop](https://developer.mozilla.org/en-US/docs/Web/JavaS let fibonacci: Iterator.t = [1, 1, 2, 3, 5, 8, 13, 21]->Array.values let seq = fibonacci->Iterator.drop(2) -seq->Iterator.next->assertEqual({done: false, value: Some(2)}) -seq->Iterator.next->assertEqual({done: false, value: Some(3)}) +seq->Iterator.next == {done: false, value: Some(2)} +seq->Iterator.next == {done: false, value: Some(3)} ``` ## Remark @@ -159,7 +159,7 @@ See [Iterator.prototype.every](https://developer.mozilla.org/en-US/docs/Web/Java let fibonacci: Iterator.t = [1, 1, 2, 3, 5, 8, 13, 21]->Array.values let areAllEven = fibonacci->Iterator.every(n => n % 2 == 0) -areAllEven->assertEqual(false) +areAllEven == false ``` ## Remark @@ -180,8 +180,8 @@ See [Iterator.prototype.filter](https://developer.mozilla.org/en-US/docs/Web/Jav let fibonacci: Iterator.t = [1, 1, 2, 3, 5, 8, 13, 21]->Array.values let seq = fibonacci->Iterator.filter(n => n % 2 == 0) -seq->Iterator.next->assertEqual({done: false, value: Some(2)}) -seq->Iterator.next->assertEqual({done: false, value: Some(8)}) +seq->Iterator.next == {done: false, value: Some(2)} +seq->Iterator.next == {done: false, value: Some(8)} ``` ## Remark @@ -202,7 +202,7 @@ See [Iterator.prototype.find](https://developer.mozilla.org/en-US/docs/Web/JavaS let fibonacci: Iterator.t = [1, 1, 2, 3, 5, 8, 13, 21]->Array.values let seq = fibonacci->Iterator.find(n => n % 2 == 0) -seq->assertEqual(Some(2)) +seq == Some(2) ``` ## Remark @@ -228,7 +228,7 @@ let letters = ->Array.values ->Iterator.flatMap(m => Map.keys(m)) ->Array.fromIterator -letters->assertEqual(["a", "b", "c", "d", "e", "f"]) +letters == ["a", "b", "c", "d", "e", "f"] ``` ## Remark @@ -248,7 +248,7 @@ See [Iterator.prototype.map](https://developer.mozilla.org/en-US/docs/Web/JavaSc ```rescript let map = Map.fromArray([("a", 1), ("b", 2), ("c", 3)]) let letters = map->Map.keys->Iterator.map(v => v->String.toUpperCase)->Array.fromIterator -letters->assertEqual(["A", "B", "C"]) +letters == ["A", "B", "C"] ``` ## Remark @@ -269,7 +269,7 @@ See [Iterator.prototype.reduce](https://developer.mozilla.org/en-US/docs/Web/Jav let numbers: Iterator.t = [1, 2, 3]->Array.values let sum = numbers->Iterator.reduce((acc, n) => acc + n, ~initialValue=0) -sum->assertEqual(6) +sum == 6 ``` ## Remark @@ -292,7 +292,7 @@ See [Iterator.prototype.some](https://developer.mozilla.org/en-US/docs/Web/JavaS let numbers: Iterator.t = [1, 2, 3]->Array.values let hasEven = numbers->Iterator.some(n => n % 2 == 0) -hasEven->assertEqual(true) +hasEven == true ``` ## Remark @@ -313,9 +313,9 @@ See [Iterator.prototype.take](https://developer.mozilla.org/en-US/docs/Web/JavaS let fibonacci: Iterator.t = [1, 1, 2, 3, 5, 8, 13, 21]->Array.values let seq = fibonacci->Iterator.take(2) -seq->Iterator.next->assertEqual({done: false, value: Some(1)}) -seq->Iterator.next->assertEqual({done: false, value: Some(1)}) -seq->Iterator.next->assertEqual({done: true, value: None}) +seq->Iterator.next == {done: false, value: Some(1)} +seq->Iterator.next == {done: false, value: Some(1)} +seq->Iterator.next == {done: true, value: None} ``` ## Remark diff --git a/runtime/Stdlib_JSON.resi b/runtime/Stdlib_JSON.resi index 6c777af2a6..6a6f6279c5 100644 --- a/runtime/Stdlib_JSON.resi +++ b/runtime/Stdlib_JSON.resi @@ -356,22 +356,19 @@ let dict = Dict.fromArray([ dict ->JSON.stringifyAny -->Option.getUnsafe -->assertEqual(`{"foo":"bar","hello":"world","someNumber":42}`) +->Option.getUnsafe == `{"foo":"bar","hello":"world","someNumber":42}` dict ->JSON.stringifyAny(~space=2) -->Option.getUnsafe -->assertEqual(`{ +->Option.getUnsafe == `{ "foo": "bar", "hello": "world", "someNumber": 42 -}`) +}` dict ->JSON.stringifyAny(~replacer=Keys(["foo", "someNumber"])) -->Option.getUnsafe -->assertEqual(`{"foo":"bar","someNumber":42}`) +->Option.getUnsafe == `{"foo":"bar","someNumber":42}` let replacer = JSON.Replacer( (_, value) => { @@ -386,10 +383,9 @@ let replacer = JSON.Replacer( dict ->JSON.stringifyAny(~replacer) -->Option.getUnsafe -->assertEqual(`{"foo":"BAR","hello":"WORLD","someNumber":42}`) +->Option.getUnsafe == `{"foo":"BAR","hello":"WORLD","someNumber":42}` -JSON.stringifyAny(() => "hello world")->assertEqual(None) +JSON.stringifyAny(() => "hello world") == None // Raise a exception switch BigInt.fromInt(0)->JSON.stringifyAny { @@ -426,14 +422,13 @@ let dict = Dict.fromArray([ dict ->JSON.stringifyAnyWithIndent(2) -->Option.getUnsafe -->assertEqual(`{ +->Option.getUnsafe == `{ "foo": "bar", "hello": "world", "someNumber": 42 -}`) +}` -JSON.stringifyAny(() => "hello world")->assertEqual(None) +JSON.stringifyAny(() => "hello world") == None switch BigInt.fromInt(0)->JSON.stringifyAny { | exception _ => assert(true) @@ -477,10 +472,9 @@ let replacer = (_, value) => { dict ->JSON.stringifyAnyWithReplacer(replacer) -->Option.getUnsafe -->assertEqual(`{"foo":"BAR","hello":"WORLD","someNumber":42}`) +->Option.getUnsafe == `{"foo":"BAR","hello":"WORLD","someNumber":42}` -JSON.stringifyAny(() => "hello world")->assertEqual(None) +JSON.stringifyAny(() => "hello world") == None switch BigInt.fromInt(0)->JSON.stringifyAny { | exception _ => assert(true) @@ -525,10 +519,9 @@ let replacer = (_, value) => { dict ->JSON.stringifyAnyWithReplacer(replacer) -->Option.getUnsafe -->assertEqual(`{"foo":"BAR","hello":"WORLD","someNumber":42}`) +->Option.getUnsafe == `{"foo":"BAR","hello":"WORLD","someNumber":42}` -JSON.stringifyAny(() => "hello world")->assertEqual(None) +JSON.stringifyAny(() => "hello world") == None switch BigInt.fromInt(0)->JSON.stringifyAny { | exception _ => assert(true) @@ -563,11 +556,9 @@ let dict = Dict.fromArray([ ("someNumber", JSON.Encode.int(42)), ]) -dict -->JSON.stringifyAnyWithFilter(["foo", "someNumber"]) -->assertEqual(`{"foo":"bar","someNumber":42}`) +dict->JSON.stringifyAnyWithFilter(["foo", "someNumber"]) == `{"foo":"bar","someNumber":42}` -JSON.stringifyAny(() => "hello world")->assertEqual(None) +JSON.stringifyAny(() => "hello world") == None switch BigInt.fromInt(0)->JSON.stringifyAny { | exception _ => assert(true) @@ -603,24 +594,21 @@ let dict = Dict.fromArray([ dict ->JSON.stringifyAny -->Option.getUnsafe -->assertEqual(`{"foo":"bar","hello":"world","someNumber":42}`) +->Option.getUnsafe == `{"foo":"bar","hello":"world","someNumber":42}` dict ->JSON.stringifyAny(~space=2) -->Option.getUnsafe -->assertEqual(`{ +->Option.getUnsafe == `{ "foo": "bar", "hello": "world", "someNumber": 42 -}`) +}` dict ->JSON.stringifyAny(~replacer=Keys(["foo", "someNumber"])) -->Option.getUnsafe -->assertEqual(`{"foo":"bar","someNumber":42}`) +->Option.getUnsafe == `{"foo":"bar","someNumber":42}` -JSON.stringifyAny(() => "hello world")->assertEqual(None) +JSON.stringifyAny(() => "hello world") == None switch BigInt.fromInt(0)->JSON.stringifyAny { | exception _ => assert(true) diff --git a/runtime/Stdlib_JsError.resi b/runtime/Stdlib_JsError.resi index 3b2ebaab27..854d19c5d7 100644 --- a/runtime/Stdlib_JsError.resi +++ b/runtime/Stdlib_JsError.resi @@ -30,7 +30,7 @@ See [`Error.prototype.message`](https://developer.mozilla.org/en-US/docs/Web/Jav ## Example ```rescript let error = JsError.SyntaxError.make("Some message here") -error->JsError.message->assertEqual("Some message here") +error->JsError.message == "Some message here" ``` */ @get @@ -44,7 +44,7 @@ See [`Error.prototype.name`](https://developer.mozilla.org/en-US/docs/Web/JavaSc ## Example ```rescript let error = JsError.SyntaxError.make("Some message here") -error->JsError.name->assertEqual("SyntaxError") +error->JsError.name == "SyntaxError" ``` */ @get @@ -66,8 +66,8 @@ See [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/ ## Example ```rescript let error = JsError.make("Some message here") -error->JsError.message->assertEqual("Some message here") -error->JsError.name->assertEqual("Error") +error->JsError.message == "Some message here" +error->JsError.name == "Error" ``` */ @new diff --git a/runtime/Stdlib_JsExn.resi b/runtime/Stdlib_JsExn.resi index d371877636..b76b973bb6 100644 --- a/runtime/Stdlib_JsExn.resi +++ b/runtime/Stdlib_JsExn.resi @@ -48,7 +48,7 @@ See [`Error.prototype.message`](https://developer.mozilla.org/en-US/docs/Web/Jav ## Example ```rescript try {JsError.SyntaxError.throwWithMessage("Some message here")} catch { -| JsExn(e) => e->JsExn.message->Option.getExn->assertEqual("Some message here") +| JsExn(e) => e->JsExn.message->Option.getExn == "Some message here" | _ => assert(false) } ``` @@ -63,7 +63,7 @@ See [`Error.prototype.name`](https://developer.mozilla.org/en-US/docs/Web/JavaSc ## Example ```rescript try {JsError.SyntaxError.throwWithMessage("Some message here")} catch { -| JsExn(e) => e->JsExn.name->Option.getExn->assertEqual("SyntaxError") +| JsExn(e) => e->JsExn.name->Option.getExn == "SyntaxError" | _ => assert(false) } ``` diff --git a/runtime/Stdlib_List.resi b/runtime/Stdlib_List.resi index af56973811..86c9a0615b 100644 --- a/runtime/Stdlib_List.resi +++ b/runtime/Stdlib_List.resi @@ -77,7 +77,7 @@ let head: list<'a> => option<'a> ## Examples ```rescript -List.headExn(list{1, 2, 3})->assertEqual(1) +List.headExn(list{1, 2, 3}) == 1 switch List.headExn(list{}) { | exception Not_found => assert(true) @@ -99,7 +99,7 @@ let headExn: list<'a> => 'a ## Examples ```rescript -List.headOrThrow(list{1, 2, 3})->assertEqual(1) +List.headOrThrow(list{1, 2, 3}) == 1 switch List.headOrThrow(list{}) { | exception Not_found => assert(true) @@ -133,7 +133,7 @@ let tail: list<'a> => option> ## Examples ```rescript -List.tailExn(list{1, 2, 3})->assertEqual(list{2, 3}) +List.tailExn(list{1, 2, 3}) == list{2, 3} switch List.tailExn(list{}) { | exception Not_found => assert(true) @@ -154,7 +154,7 @@ let tailExn: list<'a> => list<'a> ## Examples ```rescript -List.tailOrThrow(list{1, 2, 3})->assertEqual(list{2, 3}) +List.tailOrThrow(list{1, 2, 3}) == list{2, 3} switch List.tailOrThrow(list{}) { | exception Not_found => assert(true) @@ -205,9 +205,7 @@ let get: (list<'a>, int) => option<'a> ```rescript let abc = list{"A", "B", "C"} -abc -->List.getExn(1) -->assertEqual("B") +abc->List.getExn(1) == "B" switch abc->List.getExn(4) { | exception Not_found => assert(true) @@ -230,9 +228,7 @@ let getExn: (list<'a>, int) => 'a ```rescript let abc = list{"A", "B", "C"} -abc -->List.getOrThrow(1) -->assertEqual("B") +abc->List.getOrThrow(1) == "B" switch abc->List.getOrThrow(4) { | exception Not_found => assert(true) @@ -347,7 +343,7 @@ let splitAt: (list<'a>, int) => option<(list<'a>, list<'a>)> ## Examples ```rescript -List.concat(list{1, 2, 3}, list{4, 5})->assertEqual(list{1, 2, 3, 4, 5}) +List.concat(list{1, 2, 3}, list{4, 5}) == list{1, 2, 3, 4, 5} ``` */ let concat: (list<'a>, list<'a>) => list<'a> @@ -892,7 +888,8 @@ list{(1, "a"), (2, "b"), (3, "c")}->List.getAssoc(3, (a, b) => a == b) // Some(" list{(9, "morning"), (15, "afternoon"), (22, "night")}->List.getAssoc(15, (k, item) => k /* 15 */ == item - /* 9, 5, 22 */) == Some("afternoon") +) == Some("afternoon") +/* 9, 5, 22 */ ``` */ @deprecated("Use a `Map` instead") @@ -909,7 +906,8 @@ list{(1, "a"), (2, "b"), (3, "c")}->List.hasAssoc(1, (a, b) => a == b) // true list{(9, "morning"), (15, "afternoon"), (22, "night")}->List.hasAssoc(25, (k, item) => k /* 25 */ == item - /* 9, 5, 22 */) == false +) == false +/* 9, 5, 22 */ ``` */ @deprecated("Use a `Map` instead") @@ -927,7 +925,8 @@ list{(1, "a"), (2, "b"), (3, "c")}->List.removeAssoc(1, (a, b) => a == b) // lis list{(9, "morning"), (15, "afternoon"), (22, "night")}->List.removeAssoc(9, (k, item) => k /* 9 */ == item - /* 9, 5, 22 */) == list{(15, "afternoon"), (22, "night")} +) == list{(15, "afternoon"), (22, "night")} +/* 9, 5, 22 */ ``` */ @deprecated("Use a `Map` instead") diff --git a/runtime/Stdlib_Map.resi b/runtime/Stdlib_Map.resi index 3df63191e3..cc4767e90e 100644 --- a/runtime/Stdlib_Map.resi +++ b/runtime/Stdlib_Map.resi @@ -74,8 +74,7 @@ let iterator: Iterator.t<(string, string)> = %raw(` iterator ->Map.fromIterator -->Map.size -->assertEqual(2) +->Map.size == 2 ``` */ @new diff --git a/runtime/Stdlib_Null.resi b/runtime/Stdlib_Null.resi index 79e343cbd7..464c14e131 100644 --- a/runtime/Stdlib_Null.resi +++ b/runtime/Stdlib_Null.resi @@ -139,7 +139,7 @@ let getWithDefault: (t<'a>, 'a) => 'a `getExn(value)` raises an exception if `null`, otherwise returns the value. ```rescript -Null.getExn(Null.make(3))->assertEqual(3) +Null.getExn(Null.make(3)) == 3 switch Null.getExn(%raw("'ReScript'")) { | exception Invalid_argument(_) => assert(false) @@ -163,7 +163,7 @@ let getExn: t<'a> => 'a `getOrThrow(value)` raises an exception if `null`, otherwise returns the value. ```rescript -Null.getOrThrow(Null.make(3))->assertEqual(3) +Null.getOrThrow(Null.make(3)) == 3 switch Null.getOrThrow(%raw("'ReScript'")) { | exception Invalid_argument(_) => assert(false) diff --git a/runtime/Stdlib_Option.resi b/runtime/Stdlib_Option.resi index 44ba6cac9e..aa121dd618 100644 --- a/runtime/Stdlib_Option.resi +++ b/runtime/Stdlib_Option.resi @@ -74,7 +74,7 @@ let forEach: (option<'a>, 'a => unit) => unit `getExn(opt, ~message=?)` returns `value` if `opt` is `Some(value)`, otherwise raises an exception with the message provided, or a generic message if no message was provided. ```rescript -Option.getExn(Some(3))->assertEqual(3) +Option.getExn(Some(3)) == 3 switch Option.getExn(None) { | exception _ => assert(true) @@ -98,7 +98,7 @@ let getExn: (option<'a>, ~message: string=?) => 'a `getOrThrow(opt, ~message=?)` returns `value` if `opt` is `Some(value)`, otherwise raises an exception with the message provided, or a generic message if no message was provided. ```rescript -Option.getOrThrow(Some(3))->assertEqual(3) +Option.getOrThrow(Some(3)) == 3 switch Option.getOrThrow(None) { | exception _ => assert(true) diff --git a/runtime/Stdlib_Pair.res b/runtime/Stdlib_Pair.res index 745bad6557..e579a83aaa 100644 --- a/runtime/Stdlib_Pair.res +++ b/runtime/Stdlib_Pair.res @@ -10,7 +10,7 @@ type t<'a, 'b> = ('a, 'b) ## Examples ```rescript -Pair.first((1, 2))->assertEqual(1) +Pair.first((1, 2)) == 1 ``` */ external first: (('a, 'b)) => 'a = "%field0" @@ -21,7 +21,7 @@ external first: (('a, 'b)) => 'a = "%field0" ## Examples ```rescript -Pair.second((1, 2))->assertEqual(2) +Pair.second((1, 2)) == 2 ``` */ external second: (('a, 'b)) => 'b = "%field1" @@ -41,9 +41,9 @@ equality on the first element and `f2` for equality on the second element. ## Examples ```rescript -Pair.equal((1, "test"), (1, "test"), Int.equal, String.equal)->assertEqual(true) +Pair.equal((1, "test"), (1, "test"), Int.equal, String.equal) == true -Pair.equal((1, "test"), (2, "test"), Int.equal, String.equal)->assertEqual(false) +Pair.equal((1, "test"), (2, "test"), Int.equal, String.equal) == false ``` */ let equal = ((a1, a2), (b1, b2), eq1, eq2) => eq1(a1, b1) && eq2(a2, b2) @@ -56,9 +56,9 @@ if they are equal, the second element is compared. ## Examples ```rescript -Pair.compare((1, "a"), (1, "a"), Int.compare, String.compare)->assertEqual(Ordering.equal) -Pair.compare((1, "a"), (1, "b"), Int.compare, String.compare)->assertEqual(Ordering.less) -Pair.compare((2, "a"), (1, "b"), Int.compare, String.compare)->assertEqual(Ordering.greater) +Pair.compare((1, "a"), (1, "a"), Int.compare, String.compare) == Ordering.equal +Pair.compare((1, "a"), (1, "b"), Int.compare, String.compare) == Ordering.less +Pair.compare((2, "a"), (1, "b"), Int.compare, String.compare) == Ordering.greater ``` */ let compare = ((a1, a2), (b1, b2), cmp1, cmp2) => diff --git a/runtime/Stdlib_Set.resi b/runtime/Stdlib_Set.resi index 916aec8bb1..36312a84aa 100644 --- a/runtime/Stdlib_Set.resi +++ b/runtime/Stdlib_Set.resi @@ -69,8 +69,7 @@ let iterator: Iterator.t = %raw(` iterator ->Set.fromIterator -->Set.size -->assertEqual(3) +->Set.size == 3 ``` */ @new diff --git a/runtime/Stdlib_Symbol.resi b/runtime/Stdlib_Symbol.resi index 9b55a61d3a..4de31c03cb 100644 --- a/runtime/Stdlib_Symbol.resi +++ b/runtime/Stdlib_Symbol.resi @@ -18,9 +18,7 @@ Makes a new unique Symbol value. ## Examples ```rescript -Symbol.make("sym1") -->Symbol.description -->assertEqual(Some("sym1")) +Symbol.make("sym1")->Symbol.description == Some("sym1") ``` */ @val @@ -35,7 +33,7 @@ Otherwise a new Symbol gets created and registered with key. ## Examples ```rescript -Symbol.getFor("sym1")->assertEqual(Symbol.getFor("sym1")) +Symbol.getFor("sym1") == Symbol.getFor("sym1") ``` */ @val @scope("Symbol") @@ -51,7 +49,7 @@ Retrieves a shared Symbol key from the global Symbol registry for the given Symb ```rescript let globalSym = Symbol.getFor("sym1") // Global symbol -globalSym->Option.flatMap(Symbol.description)->assertEqual(Some("sym1")) +globalSym->Option.flatMap(Symbol.description) == Some("sym1") ``` */ @val @scope("Symbol") @@ -65,7 +63,7 @@ Returns `Some(string)` containing the description of this symbol, or `None` if t ```rescript let sym = Symbol.make("sym1") -Symbol.description(sym)->assertEqual(Some("sym1")) +Symbol.description(sym) == Some("sym1") ``` */ @get @@ -81,7 +79,7 @@ external description: t => option = "description" ```rescript let sym = Symbol.make("sym1") -Symbol.toString(sym)->assertEqual("Symbol(sym1)") +Symbol.toString(sym) == "Symbol(sym1)" ``` */ @send diff --git a/tools/src/tools.ml b/tools/src/tools.ml index 05cc125284..d5b4539158 100644 --- a/tools/src/tools.ml +++ b/tools/src/tools.ml @@ -702,7 +702,7 @@ module FormatCodeblocks = struct ({txt = Lident "assertEqual"} as identTxt); } as ident; partial = false; - args = [(Nolabel, _arg1); (Nolabel, _arg2)] as args; + args = [(Nolabel, _); (Nolabel, _)] as args; } when hasTransform AssertEqualFnToEquals -> { @@ -721,6 +721,49 @@ module FormatCodeblocks = struct transformed_jsx = false; }; } + (* Piped *) + | Pexp_apply + { + funct = {pexp_desc = Pexp_ident {txt = Lident "->"}}; + partial = false; + args = + [ + (_, lhs); + ( Nolabel, + { + pexp_desc = + Pexp_apply + { + funct = + { + pexp_desc = + Pexp_ident + ({txt = Lident "assertEqual"} as + identTxt); + } as ident; + partial = false; + args = [rhs]; + }; + } ); + ]; + } + when hasTransform AssertEqualFnToEquals -> + { + exp with + pexp_desc = + Pexp_apply + { + funct = + { + ident with + pexp_desc = + Pexp_ident {identTxt with txt = Lident "=="}; + }; + args = [(Nolabel, lhs); rhs]; + partial = false; + transformed_jsx = false; + }; + } | _ -> Ast_mapper.default_mapper.expr mapper exp); } in From f52f6d50b14fe35c390ac6aee3257d2552eba96a Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Thu, 10 Jul 2025 10:36:18 +0200 Subject: [PATCH 03/16] compiled files --- lib/es6/Stdlib.js | 2 +- lib/js/Stdlib.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/es6/Stdlib.js b/lib/es6/Stdlib.js index 8eb78b0f8b..bbb1fc648d 100644 --- a/lib/es6/Stdlib.js +++ b/lib/es6/Stdlib.js @@ -12,7 +12,7 @@ function assertEqual(a, b) { RE_EXN_ID: "Assert_failure", _1: [ "Stdlib.res", - 124, + 122, 4 ], Error: new Error() diff --git a/lib/js/Stdlib.js b/lib/js/Stdlib.js index 7f7d377f06..283c1d3303 100644 --- a/lib/js/Stdlib.js +++ b/lib/js/Stdlib.js @@ -12,7 +12,7 @@ function assertEqual(a, b) { RE_EXN_ID: "Assert_failure", _1: [ "Stdlib.res", - 124, + 122, 4 ], Error: new Error() From 8c9e810880faaa4a9554c4edffb61590429ec644 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Thu, 10 Jul 2025 18:41:33 +0200 Subject: [PATCH 04/16] add extraction command for code blocks --- .../FormatDocstringsTest1.res | 2 + .../FormatDocstringsTest1.res.expected | 2 + ...ocstringsTest1.res.extracted.json.expected | 1 + ...cstringsTest1.resi.extracted.json.expected | 1 + ...ocstringsTest2.res.extracted.json.expected | 1 + ...ringsTestError.res.extracted.json.expected | 12 + ...tRescriptBlocks.md.extracted.json.expected | 1 + tests/tools_tests/test.sh | 13 +- tools/bin/main.ml | 33 ++- tools/src/tools.ml | 236 +++++++++++++++++- 10 files changed, 284 insertions(+), 18 deletions(-) create mode 100644 tests/tools_tests/src/expected/FormatDocstringsTest1.res.extracted.json.expected create mode 100644 tests/tools_tests/src/expected/FormatDocstringsTest1.resi.extracted.json.expected create mode 100644 tests/tools_tests/src/expected/FormatDocstringsTest2.res.extracted.json.expected create mode 100644 tests/tools_tests/src/expected/FormatDocstringsTestError.res.extracted.json.expected create mode 100644 tests/tools_tests/src/expected/FormatRescriptBlocks.md.extracted.json.expected diff --git a/tests/tools_tests/src/docstrings-format/FormatDocstringsTest1.res b/tests/tools_tests/src/docstrings-format/FormatDocstringsTest1.res index f9c0a27339..84e10acfcf 100644 --- a/tests/tools_tests/src/docstrings-format/FormatDocstringsTest1.res +++ b/tests/tools_tests/src/docstrings-format/FormatDocstringsTest1.res @@ -14,6 +14,8 @@ And another code block in the same docstring: ```rescript type user={name:string,age:int,active:bool} let createUser=(name,age)=>{name:name,age:age,active:true} +let x=12 +x == 12 ``` */ let testFunction1 = () => "test1" diff --git a/tests/tools_tests/src/expected/FormatDocstringsTest1.res.expected b/tests/tools_tests/src/expected/FormatDocstringsTest1.res.expected index 99c9a398f3..29cdface2f 100644 --- a/tests/tools_tests/src/expected/FormatDocstringsTest1.res.expected +++ b/tests/tools_tests/src/expected/FormatDocstringsTest1.res.expected @@ -18,6 +18,8 @@ And another code block in the same docstring: ```rescript type user = {name: string, age: int, active: bool} let createUser = (name, age) => {name, age, active: true} +let x = 12 +x == 12 ``` */ let testFunction1 = () => "test1" diff --git a/tests/tools_tests/src/expected/FormatDocstringsTest1.res.extracted.json.expected b/tests/tools_tests/src/expected/FormatDocstringsTest1.res.extracted.json.expected new file mode 100644 index 0000000000..fd6e23276c --- /dev/null +++ b/tests/tools_tests/src/expected/FormatDocstringsTest1.res.extracted.json.expected @@ -0,0 +1 @@ +["let processUsers = (users: array) => {\\n users\\n ->Array.map(user => {...user, active: false})\\n ->Array.filter(u => u.age > 21)\\n}\\n\\ntype status = Loading | Success(string) | Error(option)", "module UserService = {\\n let validate = user => user.age >= 18 && user.name !== \\\"\\\"\\n let getName = user => user.name\\n}", "let badly_formatted = (x, y) => {\\n let result = x + y\\n if result > 0 {\\n Console.log(\\\"positive\\\")\\n } else {\\n Console.log(\\\"negative\\\")\\n }\\n result\\n}", "type user = {name: string, age: int, active: bool}\\nlet createUser = (name, age) => {name, age, active: true}\\nlet x = 12\\nassertEqual(x, 12)"] diff --git a/tests/tools_tests/src/expected/FormatDocstringsTest1.resi.extracted.json.expected b/tests/tools_tests/src/expected/FormatDocstringsTest1.resi.extracted.json.expected new file mode 100644 index 0000000000..2c8f76497f --- /dev/null +++ b/tests/tools_tests/src/expected/FormatDocstringsTest1.resi.extracted.json.expected @@ -0,0 +1 @@ +["let processUsers = (users: array) => {\\n users\\n ->Array.map(user => {...user, active: false})\\n ->Array.filter(u => u.age > 21)\\n}\\n\\ntype status = Loading | Success(string) | Error(option)", "module UserService = {\\n let validate = user => user.age >= 18 && user.name !== \\\"\\\"\\n let getName = user => user.name\\n}", "let badly_formatted = (x, y) => {\\n let result = x + y\\n if result > 0 {\\n Console.log(\\\"positive\\\")\\n } else {\\n Console.log(\\\"negative\\\")\\n }\\n result\\n}", "type user = {name: string, age: int, active: bool}\\nlet createUser = (name, age) => {name, age, active: true}"] diff --git a/tests/tools_tests/src/expected/FormatDocstringsTest2.res.extracted.json.expected b/tests/tools_tests/src/expected/FormatDocstringsTest2.res.extracted.json.expected new file mode 100644 index 0000000000..afdd1ba126 --- /dev/null +++ b/tests/tools_tests/src/expected/FormatDocstringsTest2.res.extracted.json.expected @@ -0,0 +1 @@ +["type x = int\\nlet x: int => string\\nmodule M: {\\n let ff: string => int\\n}", "let processData = (data: array) => {\\n data\\n ->Array.filter(x => x > 0)\\n ->Array.map(x => x * 2)\\n ->Array.reduce(0, (acc, x) => acc + x)\\n}\\n\\nlet asyncExample = async () => {\\n let data = await fetchData()\\n let processed = await processData(data)\\n Console.log(processed)\\n}", "let component = () => {\\n
\\n

{\\\"Title\\\"->React.string}

\\n \\n
\\n}", "let handleResult = (result: result) => {\\n switch result {\\n | Ok(value) => Console.log(`Success: ${value}`)\\n | Error(error) => Console.error(`Error: ${error}`)\\n }\\n}"] diff --git a/tests/tools_tests/src/expected/FormatDocstringsTestError.res.extracted.json.expected b/tests/tools_tests/src/expected/FormatDocstringsTestError.res.extracted.json.expected new file mode 100644 index 0000000000..c5b52e6828 --- /dev/null +++ b/tests/tools_tests/src/expected/FormatDocstringsTestError.res.extracted.json.expected @@ -0,0 +1,12 @@ + + Syntax error in code block in docstring + FormatDocstringsTestError.res:5:10-6:3 + + 3 │ + 4 │ + 5 │ let name= + 6 │ let x=12 + + This let-binding misses an expression + + diff --git a/tests/tools_tests/src/expected/FormatRescriptBlocks.md.extracted.json.expected b/tests/tools_tests/src/expected/FormatRescriptBlocks.md.extracted.json.expected new file mode 100644 index 0000000000..1727e5d0f7 --- /dev/null +++ b/tests/tools_tests/src/expected/FormatRescriptBlocks.md.extracted.json.expected @@ -0,0 +1 @@ +["type user = {name: string, age: int, active: bool}\\nlet createUser = (name, age) => {name, age, active: true}", "let badly_formatted = (x, y) => {\\n let result = x + y\\n if result > 0 {\\n Console.log(\\\"positive\\\")\\n } else {\\n Console.log(\\\"negative\\\")\\n }\\n result\\n}"] diff --git a/tests/tools_tests/test.sh b/tests/tools_tests/test.sh index 7289d651c8..73e42acfd6 100755 --- a/tests/tools_tests/test.sh +++ b/tests/tools_tests/test.sh @@ -10,17 +10,24 @@ done for file in ppx/*.res; do output="src/expected/$(basename $file).jsout" ../../cli/bsc.js -ppx "../../_build/install/default/bin/rescript-tools ppx" $file > $output - # # CI. We use LF, and the CI OCaml fork prints CRLF. Convert. if [ "$RUNNER_OS" == "Windows" ]; then perl -pi -e 's/\r\n/\n/g' -- $output fi done -# Test format-docstrings command +# Test format-codeblocks command for file in src/docstrings-format/*.{res,resi,md}; do output="src/expected/$(basename $file).expected" ../../_build/install/default/bin/rescript-tools format-codeblocks "$file" --stdout > $output - # # CI. We use LF, and the CI OCaml fork prints CRLF. Convert. + if [ "$RUNNER_OS" == "Windows" ]; then + perl -pi -e 's/\r\n/\n/g' -- $output + fi +done + +# Test extract-codeblocks command +for file in src/docstrings-format/*.{res,resi,md}; do + output="src/expected/$(basename $file).extracted.json.expected" + ../../_build/install/default/bin/rescript-tools extract-codeblocks "$file" --transform-assert-equal > $output if [ "$RUNNER_OS" == "Windows" ]; then perl -pi -e 's/\r\n/\n/g' -- $output fi diff --git a/tools/bin/main.ml b/tools/bin/main.ml index da44211ac6..a33bf67856 100644 --- a/tools/bin/main.ml +++ b/tools/bin/main.ml @@ -7,14 +7,23 @@ Usage: rescript-tools doc Example: rescript-tools doc ./path/to/EntryPointLib.res|} -let formatDocstringsHelp = +let formatCodeblocksHelp = {|ReScript Tools -Format ReScript code blocks in docstrings +Format ReScript code blocks in docstrings or markdown files -Usage: rescript-tools format-docstrings [--stdout] [--transform-assert-equal] +Usage: rescript-tools format-codeblocks [--stdout] [--transform-assert-equal] -Example: rescript-tools format-docstrings ./path/to/MyModule.res|} +Example: rescript-tools format-codeblocks ./path/to/MyModule.res|} + +let extractCodeblocksHelp = + {|ReScript Tools + +Extract ReScript code blocks from docstrings or markdown files + +Usage: rescript-tools extract-codeblocks [--transform-assert-equal] + +Example: rescript-tools extract-codeblocks ./path/to/MyModule.res|} let help = {|ReScript Tools @@ -27,6 +36,8 @@ doc Generate documentation format-codeblocks Format ReScript code blocks [--stdout] Output to stdout [--transform-assert-equal] Transform `assertEqual` to `==` +extract-codeblocks Extract ReScript code blocks from file + [--transform-assert-equal] Transform `==` to `assertEqual` reanalyze Reanalyze -v, --version Print version -h, --help Print help|} @@ -57,7 +68,7 @@ let main () = | _ -> logAndExit (Error docHelp)) | "format-codeblocks" :: rest -> ( match rest with - | ["-h"] | ["--help"] -> logAndExit (Ok formatDocstringsHelp) + | ["-h"] | ["--help"] -> logAndExit (Ok formatCodeblocksHelp) | path :: args -> ( let isStdout = List.mem "--stdout" args in let transformAssertEqual = List.mem "--transform-assert-equal" args in @@ -71,7 +82,17 @@ let main () = | Ok content, `Stdout -> print_endline content | result, `File -> logAndExit result | Error e, _ -> logAndExit (Error e)) - | _ -> logAndExit (Error formatDocstringsHelp)) + | _ -> logAndExit (Error formatCodeblocksHelp)) + | "extract-codeblocks" :: rest -> ( + match rest with + | ["-h"] | ["--help"] -> logAndExit (Ok extractCodeblocksHelp) + | path :: args -> + let transformAssertEqual = List.mem "--transform-assert-equal" args in + Clflags.color := Some Misc.Color.Never; + logAndExit + (Tools.ExtractCodeblocks.extractCodeblocksFromFile ~transformAssertEqual + ~entryPointFile:path) + | _ -> logAndExit (Error extractCodeblocksHelp)) | "reanalyze" :: _ -> let len = Array.length Sys.argv in for i = 1 to len - 2 do diff --git a/tools/src/tools.ml b/tools/src/tools.ml index d5b4539158..a6f2544a5c 100644 --- a/tools/src/tools.ml +++ b/tools/src/tools.ml @@ -677,6 +677,15 @@ let extractEmbedded ~extensionPoints ~filename = ]) |> List.rev |> array +let isResLang lang = + match String.lowercase_ascii lang with + | "res" | "rescript" | "resi" -> true + | lang -> + (* Cover ```res example, and similar *) + String.starts_with ~prefix:"res " lang + || String.starts_with ~prefix:"rescript " lang + || String.starts_with ~prefix:"resi " lang + module FormatCodeblocks = struct module Transform = struct type transform = AssertEqualFnToEquals (** assertEqual(a, b) -> a == b *) @@ -770,15 +779,6 @@ module FormatCodeblocks = struct mapper.structure mapper ast end - let isResLang lang = - match String.lowercase_ascii lang with - | "res" | "rescript" | "resi" -> true - | lang -> - (* Cover ```res example, and similar *) - String.starts_with ~prefix:"res " lang - || String.starts_with ~prefix:"rescript " lang - || String.starts_with ~prefix:"resi " lang - let formatRescriptCodeBlocks content ~transformAssertEqual ~displayFilename ~addError ~markdownBlockStartLine = (* Detect ReScript code blocks. *) @@ -963,3 +963,221 @@ module FormatCodeblocks = struct Ok (Filename.basename path ^ ": formatted successfully")) else Ok (Filename.basename path ^ ": needed no formatting") end + +module ExtractCodeblocks = struct + module Transform = struct + type transform = EqualsToAssertEqualFn (** a == b -> assertEqual(a, b) *) + + (* TOOD: Make this only transform structure items, not any expression? *) + let transform ~transforms ast = + match transforms with + | [] -> ast + | transforms -> + let hasTransform transform = transforms |> List.mem transform in + let mapper = + { + Ast_mapper.default_mapper with + expr = + (fun mapper exp -> + match exp.pexp_desc with + | Pexp_apply + { + funct = + { + pexp_desc = + Pexp_ident ({txt = Lident "=="} as identTxt); + } as ident; + partial = false; + args = [(Nolabel, _); (Nolabel, _)] as args; + } + when hasTransform EqualsToAssertEqualFn -> + { + exp with + pexp_desc = + Pexp_apply + { + funct = + { + ident with + pexp_desc = + Pexp_ident + {identTxt with txt = Lident "assertEqual"}; + }; + args; + partial = false; + transformed_jsx = false; + }; + } + | _ -> Ast_mapper.default_mapper.expr mapper exp); + } + in + mapper.structure mapper ast + end + + let extractRescriptCodeBlocks content ~transformAssertEqual ~displayFilename + ~addError ~markdownBlockStartLine = + (* Detect ReScript code blocks. *) + let codeBlocks = ref [] in + let addCodeBlock codeBlock = codeBlocks := codeBlock :: !codeBlocks in + let block _m = function + | Cmarkit.Block.Code_block (codeBlock, meta) -> ( + match Cmarkit.Block.Code_block.info_string codeBlock with + | Some (lang, _) when isResLang lang -> + let currentLine = + meta |> Cmarkit.Meta.textloc |> Cmarkit.Textloc.first_line |> fst + in + (* Account for 0-based line numbers *) + let currentLine = currentLine + 1 in + let code = Cmarkit.Block.Code_block.code codeBlock in + let codeText = + code |> List.map Cmarkit.Block_line.to_string |> String.concat "\n" + in + let n = List.length code in + let newlinesNeeded = + max 0 (markdownBlockStartLine + currentLine - n) + in + let codeWithOffset = String.make newlinesNeeded '\n' ^ codeText in + let reportParseError diagnostics = + let buf = Buffer.create 1000 in + let formatter = Format.formatter_of_buffer buf in + Res_diagnostics.print_report ~formatter + ~custom_intro:(Some "Syntax error in code block in docstring") + diagnostics codeWithOffset; + addError (Buffer.contents buf) + in + let mappedCode = + if lang |> String.split_on_char ' ' |> List.hd = "resi" then + let {Res_driver.parsetree; comments; invalid; diagnostics} = + Res_driver.parse_interface_from_source ~for_printer:true + ~display_filename:displayFilename ~source:codeWithOffset + in + if invalid then ( + reportParseError diagnostics; + codeText) + else + Res_printer.print_interface parsetree ~comments |> String.trim + else + let {Res_driver.parsetree; comments; invalid; diagnostics} = + Res_driver.parse_implementation_from_source ~for_printer:true + ~display_filename:displayFilename ~source:codeWithOffset + in + if invalid then ( + reportParseError diagnostics; + codeText) + else + let parsetree = + if transformAssertEqual then + Transform.transform ~transforms:[EqualsToAssertEqualFn] + parsetree + else parsetree + in + Res_printer.print_implementation parsetree ~comments + |> String.trim + in + addCodeBlock mappedCode; + Cmarkit.Mapper.default + | _ -> Cmarkit.Mapper.default) + | _ -> Cmarkit.Mapper.default + in + let mapper = Cmarkit.Mapper.make ~block () in + let _ = + content + |> Cmarkit.Doc.of_string ~locs:true + |> Cmarkit.Mapper.map_doc mapper + in + !codeBlocks + + let extractCodeblocksFromFile ~transformAssertEqual ~entryPointFile = + let path = + match Filename.is_relative entryPointFile with + | true -> Unix.realpath entryPointFile + | false -> entryPointFile + in + let errors = ref [] in + let addError error = errors := error :: !errors in + + let codeBlocks = ref [] in + let addCodeBlock codeBlock = codeBlocks := codeBlock :: !codeBlocks in + + (* Looks for docstrings and extracts code blocks in ReScript files *) + let makeIterator ~transformAssertEqual ~displayFilename = + { + Ast_iterator.default_iterator with + attribute = + (fun mapper ((name, payload) as attr) -> + match (name, Ast_payload.is_single_string payload, payload) with + | ( {txt = "res.doc"}, + Some (contents, None), + PStr [{pstr_desc = Pstr_eval ({pexp_loc}, _)}] ) -> + let codeBlocks = + extractRescriptCodeBlocks ~transformAssertEqual ~addError + ~displayFilename + ~markdownBlockStartLine:pexp_loc.loc_start.pos_lnum contents + in + codeBlocks |> List.iter addCodeBlock + | _ -> Ast_iterator.default_iterator.attribute mapper attr); + } + in + let content = + if Filename.check_suffix path ".md" then + let content = + let ic = open_in path in + let n = in_channel_length ic in + let s = Bytes.create n in + really_input ic s 0 n; + close_in ic; + Bytes.to_string s + in + let displayFilename = Filename.basename path in + let codeBlocks = + extractRescriptCodeBlocks ~transformAssertEqual ~addError + ~displayFilename ~markdownBlockStartLine:1 content + in + Ok codeBlocks + else if Filename.check_suffix path ".res" then ( + let parser = + Res_driver.parsing_engine.parse_implementation ~for_printer:true + in + let {Res_driver.parsetree = structure; filename} = + parser ~filename:path + in + let filename = Filename.basename filename in + let iterator = + makeIterator ~transformAssertEqual ~displayFilename:filename + in + iterator.structure iterator structure; + Ok !codeBlocks) + else if Filename.check_suffix path ".resi" then ( + let parser = + Res_driver.parsing_engine.parse_interface ~for_printer:true + in + let {Res_driver.parsetree = signature; filename} = + parser ~filename:path + in + let iterator = + makeIterator ~transformAssertEqual ~displayFilename:filename + in + iterator.signature iterator signature; + Ok !codeBlocks) + else + Error + (Printf.sprintf + "File extension not supported. This command accepts .res, .resi, \ + and .md files") + in + match content with + | Error e -> Error e + | Ok codeBlocks -> + let errors = !errors in + if List.length errors > 0 then ( + errors |> List.rev |> String.concat "\n" |> print_endline; + Error + (Printf.sprintf "%s: Error formatting docstrings." + (Filename.basename path))) + else + Ok + (codeBlocks + |> List.map (fun codeBlock -> + Protocol.wrapInQuotes (Json.escape codeBlock)) + |> Protocol.array) +end From 2f283cecd61c36ed615a04a4cbd0df9a2538b06a Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Thu, 10 Jul 2025 21:13:01 +0200 Subject: [PATCH 05/16] change transform to only work on structure items --- .../ExtractCodeBlocksTest.res | 8 ++ .../ExtractCodeBlocksTest.res.expected | 9 +++ ...CodeBlocksTest.res.extracted.json.expected | 1 + tools/src/tools.ml | 78 +++++++++++-------- 4 files changed, 65 insertions(+), 31 deletions(-) create mode 100644 tests/tools_tests/src/docstrings-format/ExtractCodeBlocksTest.res create mode 100644 tests/tools_tests/src/expected/ExtractCodeBlocksTest.res.expected create mode 100644 tests/tools_tests/src/expected/ExtractCodeBlocksTest.res.extracted.json.expected diff --git a/tests/tools_tests/src/docstrings-format/ExtractCodeBlocksTest.res b/tests/tools_tests/src/docstrings-format/ExtractCodeBlocksTest.res new file mode 100644 index 0000000000..6885ac9010 --- /dev/null +++ b/tests/tools_tests/src/docstrings-format/ExtractCodeBlocksTest.res @@ -0,0 +1,8 @@ +/** +```res +let x =12 +let y = 12->Array.filter(x => x == 12) +x == 12 +``` + */ +let testFunction1 = () => "test1" diff --git a/tests/tools_tests/src/expected/ExtractCodeBlocksTest.res.expected b/tests/tools_tests/src/expected/ExtractCodeBlocksTest.res.expected new file mode 100644 index 0000000000..bd742f290d --- /dev/null +++ b/tests/tools_tests/src/expected/ExtractCodeBlocksTest.res.expected @@ -0,0 +1,9 @@ +/** +```res +let x = 12 +let y = 12->Array.filter(x => x == 12) +x == 12 +``` + */ +let testFunction1 = () => "test1" + diff --git a/tests/tools_tests/src/expected/ExtractCodeBlocksTest.res.extracted.json.expected b/tests/tools_tests/src/expected/ExtractCodeBlocksTest.res.extracted.json.expected new file mode 100644 index 0000000000..e9c56110c8 --- /dev/null +++ b/tests/tools_tests/src/expected/ExtractCodeBlocksTest.res.extracted.json.expected @@ -0,0 +1 @@ +["let x = 12\\nlet y = 12->Array.filter(x => x == 12)\\nassertEqual(x, 12)"] diff --git a/tools/src/tools.ml b/tools/src/tools.ml index a6f2544a5c..a44509bedf 100644 --- a/tools/src/tools.ml +++ b/tools/src/tools.ml @@ -966,9 +966,10 @@ end module ExtractCodeblocks = struct module Transform = struct - type transform = EqualsToAssertEqualFn (** a == b -> assertEqual(a, b) *) + type transform = + | EqualsToAssertEqualFn + (** a == b -> assertEqual(a, b), for structure items only *) - (* TOOD: Make this only transform structure items, not any expression? *) let transform ~transforms ast = match transforms with | [] -> ast @@ -977,38 +978,53 @@ module ExtractCodeblocks = struct let mapper = { Ast_mapper.default_mapper with - expr = - (fun mapper exp -> - match exp.pexp_desc with - | Pexp_apply - { - funct = - { - pexp_desc = - Pexp_ident ({txt = Lident "=="} as identTxt); - } as ident; - partial = false; - args = [(Nolabel, _); (Nolabel, _)] as args; - } + structure_item = + (fun mapper str_item -> + match str_item.pstr_desc with + | Pstr_eval + ( ({ + pexp_desc = + Pexp_apply + { + funct = + { + pexp_desc = + Pexp_ident + ({txt = Lident "=="} as identTxt); + } as ident; + partial = false; + args = [(Nolabel, _); (Nolabel, _)] as args; + }; + } as exp), + x1 ) when hasTransform EqualsToAssertEqualFn -> { - exp with - pexp_desc = - Pexp_apply - { - funct = - { - ident with - pexp_desc = - Pexp_ident - {identTxt with txt = Lident "assertEqual"}; - }; - args; - partial = false; - transformed_jsx = false; - }; + str_item with + pstr_desc = + Pstr_eval + ( { + exp with + pexp_desc = + Pexp_apply + { + funct = + { + ident with + pexp_desc = + Pexp_ident + { + identTxt with + txt = Lident "assertEqual"; + }; + }; + args; + partial = false; + transformed_jsx = false; + }; + }, + x1 ); } - | _ -> Ast_mapper.default_mapper.expr mapper exp); + | _ -> Ast_mapper.default_mapper.structure_item mapper str_item); } in mapper.structure mapper ast From 6df0c01179ee3fb80a8bf1c7ec6e2b02c4f5f0ad Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Thu, 10 Jul 2025 21:16:11 +0200 Subject: [PATCH 06/16] refactor --- tools/src/tools.ml | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/tools/src/tools.ml b/tools/src/tools.ml index a44509bedf..2c955acdb2 100644 --- a/tools/src/tools.ml +++ b/tools/src/tools.ml @@ -677,6 +677,14 @@ let extractEmbedded ~extensionPoints ~filename = ]) |> List.rev |> array +let readFile path = + let ic = open_in path in + let n = in_channel_length ic in + let s = Bytes.create n in + really_input ic s 0 n; + close_in ic; + Bytes.to_string s + let isResLang lang = match String.lowercase_ascii lang with | "res" | "rescript" | "resi" -> true @@ -897,14 +905,7 @@ module FormatCodeblocks = struct in let content = if Filename.check_suffix path ".md" then - let content = - let ic = open_in path in - let n = in_channel_length ic in - let s = Bytes.create n in - really_input ic s 0 n; - close_in ic; - Bytes.to_string s - in + let content = readFile path in let displayFilename = Filename.basename path in let formattedContents, hadCodeBlocks = formatRescriptCodeBlocks ~transformAssertEqual ~addError @@ -1136,14 +1137,7 @@ module ExtractCodeblocks = struct in let content = if Filename.check_suffix path ".md" then - let content = - let ic = open_in path in - let n = in_channel_length ic in - let s = Bytes.create n in - really_input ic s 0 n; - close_in ic; - Bytes.to_string s - in + let content = readFile path in let displayFilename = Filename.basename path in let codeBlocks = extractRescriptCodeBlocks ~transformAssertEqual ~addError From d1e125687bd3f3b1f6555ba995ed4ecba28910d2 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Thu, 10 Jul 2025 22:06:47 +0200 Subject: [PATCH 07/16] change code block extraction approach to use the typed artifacts instead, since we need more info for each block than we do for formatting --- ...CodeBlocksTest.res.extracted.json.expected | 6 +- ...ocstringsTest1.res.extracted.json.expected | 18 +- ...cstringsTest1.resi.extracted.json.expected | 18 +- ...ocstringsTest2.res.extracted.json.expected | 18 +- ...tRescriptBlocks.md.extracted.json.expected | 10 +- tools/src/tools.ml | 201 +++++++++++++----- 6 files changed, 216 insertions(+), 55 deletions(-) diff --git a/tests/tools_tests/src/expected/ExtractCodeBlocksTest.res.extracted.json.expected b/tests/tools_tests/src/expected/ExtractCodeBlocksTest.res.extracted.json.expected index e9c56110c8..def40bdaf6 100644 --- a/tests/tools_tests/src/expected/ExtractCodeBlocksTest.res.extracted.json.expected +++ b/tests/tools_tests/src/expected/ExtractCodeBlocksTest.res.extracted.json.expected @@ -1 +1,5 @@ -["let x = 12\\nlet y = 12->Array.filter(x => x == 12)\\nassertEqual(x, 12)"] +[{ + "id": "ExtractCodeBlocksTest.testFunction1", + "name": "testFunction1", + "code": "let x = 12\nlet y = 12->Array.filter(x => x == 12)\nassertEqual(x, 12)" + }] diff --git a/tests/tools_tests/src/expected/FormatDocstringsTest1.res.extracted.json.expected b/tests/tools_tests/src/expected/FormatDocstringsTest1.res.extracted.json.expected index fd6e23276c..a121729265 100644 --- a/tests/tools_tests/src/expected/FormatDocstringsTest1.res.extracted.json.expected +++ b/tests/tools_tests/src/expected/FormatDocstringsTest1.res.extracted.json.expected @@ -1 +1,17 @@ -["let processUsers = (users: array) => {\\n users\\n ->Array.map(user => {...user, active: false})\\n ->Array.filter(u => u.age > 21)\\n}\\n\\ntype status = Loading | Success(string) | Error(option)", "module UserService = {\\n let validate = user => user.age >= 18 && user.name !== \\\"\\\"\\n let getName = user => user.name\\n}", "let badly_formatted = (x, y) => {\\n let result = x + y\\n if result > 0 {\\n Console.log(\\\"positive\\\")\\n } else {\\n Console.log(\\\"negative\\\")\\n }\\n result\\n}", "type user = {name: string, age: int, active: bool}\\nlet createUser = (name, age) => {name, age, active: true}\\nlet x = 12\\nassertEqual(x, 12)"] +[{ + "id": "FormatDocstringsTest1.testFunction3", + "name": "testFunction3", + "code": "let processUsers = (users: array) => {\n users\n ->Array.map(user => {...user, active: false})\n ->Array.filter(u => u.age > 21)\n}\n\ntype status = Loading | Success(string) | Error(option)" + }, { + "id": "FormatDocstringsTest1.Nested.testFunction2", + "name": "testFunction2", + "code": "module UserService = {\n let validate = user => user.age >= 18 && user.name !== \"\"\n let getName = user => user.name\n}" + }, { + "id": "FormatDocstringsTest1.testFunction1-2", + "name": "testFunction1", + "code": "type user = {name: string, age: int, active: bool}\nlet createUser = (name, age) => {name, age, active: true}" + }, { + "id": "FormatDocstringsTest1.testFunction1-1", + "name": "testFunction1", + "code": "let badly_formatted = (x, y) => {\n let result = x + y\n if result > 0 {\n Console.log(\"positive\")\n } else {\n Console.log(\"negative\")\n }\n result\n}" + }] diff --git a/tests/tools_tests/src/expected/FormatDocstringsTest1.resi.extracted.json.expected b/tests/tools_tests/src/expected/FormatDocstringsTest1.resi.extracted.json.expected index 2c8f76497f..a121729265 100644 --- a/tests/tools_tests/src/expected/FormatDocstringsTest1.resi.extracted.json.expected +++ b/tests/tools_tests/src/expected/FormatDocstringsTest1.resi.extracted.json.expected @@ -1 +1,17 @@ -["let processUsers = (users: array) => {\\n users\\n ->Array.map(user => {...user, active: false})\\n ->Array.filter(u => u.age > 21)\\n}\\n\\ntype status = Loading | Success(string) | Error(option)", "module UserService = {\\n let validate = user => user.age >= 18 && user.name !== \\\"\\\"\\n let getName = user => user.name\\n}", "let badly_formatted = (x, y) => {\\n let result = x + y\\n if result > 0 {\\n Console.log(\\\"positive\\\")\\n } else {\\n Console.log(\\\"negative\\\")\\n }\\n result\\n}", "type user = {name: string, age: int, active: bool}\\nlet createUser = (name, age) => {name, age, active: true}"] +[{ + "id": "FormatDocstringsTest1.testFunction3", + "name": "testFunction3", + "code": "let processUsers = (users: array) => {\n users\n ->Array.map(user => {...user, active: false})\n ->Array.filter(u => u.age > 21)\n}\n\ntype status = Loading | Success(string) | Error(option)" + }, { + "id": "FormatDocstringsTest1.Nested.testFunction2", + "name": "testFunction2", + "code": "module UserService = {\n let validate = user => user.age >= 18 && user.name !== \"\"\n let getName = user => user.name\n}" + }, { + "id": "FormatDocstringsTest1.testFunction1-2", + "name": "testFunction1", + "code": "type user = {name: string, age: int, active: bool}\nlet createUser = (name, age) => {name, age, active: true}" + }, { + "id": "FormatDocstringsTest1.testFunction1-1", + "name": "testFunction1", + "code": "let badly_formatted = (x, y) => {\n let result = x + y\n if result > 0 {\n Console.log(\"positive\")\n } else {\n Console.log(\"negative\")\n }\n result\n}" + }] diff --git a/tests/tools_tests/src/expected/FormatDocstringsTest2.res.extracted.json.expected b/tests/tools_tests/src/expected/FormatDocstringsTest2.res.extracted.json.expected index afdd1ba126..5a1f7968f0 100644 --- a/tests/tools_tests/src/expected/FormatDocstringsTest2.res.extracted.json.expected +++ b/tests/tools_tests/src/expected/FormatDocstringsTest2.res.extracted.json.expected @@ -1 +1,17 @@ -["type x = int\\nlet x: int => string\\nmodule M: {\\n let ff: string => int\\n}", "let processData = (data: array) => {\\n data\\n ->Array.filter(x => x > 0)\\n ->Array.map(x => x * 2)\\n ->Array.reduce(0, (acc, x) => acc + x)\\n}\\n\\nlet asyncExample = async () => {\\n let data = await fetchData()\\n let processed = await processData(data)\\n Console.log(processed)\\n}", "let component = () => {\\n
\\n

{\\\"Title\\\"->React.string}

\\n \\n
\\n}", "let handleResult = (result: result) => {\\n switch result {\\n | Ok(value) => Console.log(`Success: ${value}`)\\n | Error(error) => Console.error(`Error: ${error}`)\\n }\\n}"] +[{ + "id": "FormatDocstringsTest2.testResi", + "name": "testResi", + "code": "type x = int\nlet x: int => string\nmodule M: {\n let ff: string => int\n}" + }, { + "id": "FormatDocstringsTest2.testPipes", + "name": "testPipes", + "code": "let processData = (data: array) => {\n data\n ->Array.filter(x => x > 0)\n ->Array.map(x => x * 2)\n ->Array.reduce(0, (acc, x) => acc + x)\n}\n\nlet asyncExample = async () => {\n let data = await fetchData()\n let processed = await processData(data)\n Console.log(processed)\n}" + }, { + "id": "FormatDocstringsTest2.testJsx-2", + "name": "testJsx", + "code": "let handleResult = (result: result) => {\n switch result {\n | Ok(value) => Console.log(`Success: ${value}`)\n | Error(error) => Console.error(`Error: ${error}`)\n }\n}" + }, { + "id": "FormatDocstringsTest2.testJsx-1", + "name": "testJsx", + "code": "let component = () => {\n
\n

{\"Title\"->React.string}

\n \n
\n}" + }] diff --git a/tests/tools_tests/src/expected/FormatRescriptBlocks.md.extracted.json.expected b/tests/tools_tests/src/expected/FormatRescriptBlocks.md.extracted.json.expected index 1727e5d0f7..88e74994d5 100644 --- a/tests/tools_tests/src/expected/FormatRescriptBlocks.md.extracted.json.expected +++ b/tests/tools_tests/src/expected/FormatRescriptBlocks.md.extracted.json.expected @@ -1 +1,9 @@ -["type user = {name: string, age: int, active: bool}\\nlet createUser = (name, age) => {name, age, active: true}", "let badly_formatted = (x, y) => {\\n let result = x + y\\n if result > 0 {\\n Console.log(\\\"positive\\\")\\n } else {\\n Console.log(\\\"negative\\\")\\n }\\n result\\n}"] +[{ + "id": "codeblock-1", + "name": "codeblock-1", + "code": "type user = {name: string, age: int, active: bool}\nlet createUser = (name, age) => {name, age, active: true}" + }, { + "id": "codeblock-2", + "name": "codeblock-2", + "code": "let badly_formatted = (x, y) => {\n let result = x + y\n if result > 0 {\n Console.log(\"positive\")\n } else {\n Console.log(\"negative\")\n }\n result\n}" + }] diff --git a/tools/src/tools.ml b/tools/src/tools.ml index 2c955acdb2..288207b672 100644 --- a/tools/src/tools.ml +++ b/tools/src/tools.ml @@ -1031,6 +1031,116 @@ module ExtractCodeblocks = struct mapper.structure mapper ast end + type codeBlock = {id: string; code: string; name: string} + + let getDocstring = function + | d :: _ -> d + | _ -> "" + + let extractCodeBlocks ~entryPointFile + ~(processDocstrings : id:string -> name:string -> string -> unit) = + let path = + match Filename.is_relative entryPointFile with + | true -> Unix.realpath entryPointFile + | false -> entryPointFile + in + let result = + match + FindFiles.isImplementation path = false + && FindFiles.isInterface path = false + with + | false -> ( + let path = + if FindFiles.isImplementation path then + let pathAsResi = + (path |> Filename.dirname) ^ "/" + ^ (path |> Filename.basename |> Filename.chop_extension) + ^ ".resi" + in + if Sys.file_exists pathAsResi then pathAsResi else path + else path + in + match Cmt.loadFullCmtFromPath ~path with + | None -> + Error + (Printf.sprintf + "error: failed to generate doc for %s, try to build the project" + path) + | Some full -> + let file = full.file in + let structure = file.structure in + let open SharedTypes in + let env = QueryEnv.fromFile file in + let rec extractCodeBlocksForModule + ?(modulePath = [env.file.moduleName]) + (structure : Module.structure) = + let id = modulePath |> List.rev |> ident in + let name = structure.name in + processDocstrings ~id ~name (getDocstring structure.docstring); + + structure.items + |> List.iter (fun (item : Module.item) -> + match item.kind with + | Value _typ -> + let id = modulePath |> makeId ~identifier:item.name in + let name = item.name in + processDocstrings ~id ~name (getDocstring item.docstring) + | Type (_typ, _) -> + let id = modulePath |> makeId ~identifier:item.name in + let name = item.name in + processDocstrings ~id ~name (getDocstring item.docstring) + | Module {type_ = Ident _p; isModuleType = false} -> + (* module Whatever = OtherModule *) + let id = + (modulePath |> List.rev |> List.hd) ^ "." ^ item.name + in + let name = item.name in + processDocstrings ~id ~name (getDocstring item.docstring) + | Module {type_ = Structure m; isModuleType = false} -> + (* module Whatever = {} in res or module Whatever: {} in resi. *) + let modulePath = m.name :: modulePath in + let id = modulePath |> List.rev |> ident in + let name = m.name in + processDocstrings ~id ~name (getDocstring m.docstring); + extractCodeBlocksForModule ~modulePath m + | Module {type_ = Structure m; isModuleType = true} -> + (* module type Whatever = {} *) + let modulePath = m.name :: modulePath in + let id = modulePath |> List.rev |> ident in + let name = m.name in + processDocstrings ~id ~name (getDocstring m.docstring); + extractCodeBlocksForModule ~modulePath m + | Module + { + type_ = + Constraint (Structure _impl, Structure interface); + } -> + (* module Whatever: { } = { }. Prefer the interface. *) + let modulePath = interface.name :: modulePath in + let id = modulePath |> List.rev |> ident in + let name = interface.name in + processDocstrings ~id ~name + (getDocstring interface.docstring); + extractCodeBlocksForModule ~modulePath interface + | Module {type_ = Constraint (Structure m, Ident _p)} -> + (* module M: T = { }. Print M *) + let modulePath = m.name :: modulePath in + let id = modulePath |> List.rev |> ident in + let name = m.name in + processDocstrings ~id ~name (getDocstring m.docstring); + extractCodeBlocksForModule ~modulePath m + | Module.Module _ -> ()) + in + extractCodeBlocksForModule structure; + Ok ()) + | true -> + Error + (Printf.sprintf + "error: failed to read %s, expected an .res or .resi file" path) + in + + result + let extractRescriptCodeBlocks content ~transformAssertEqual ~displayFilename ~addError ~markdownBlockStartLine = (* Detect ReScript code blocks. *) @@ -1110,31 +1220,13 @@ module ExtractCodeblocks = struct | true -> Unix.realpath entryPointFile | false -> entryPointFile in + let displayFilename = Filename.basename path in let errors = ref [] in let addError error = errors := error :: !errors in let codeBlocks = ref [] in let addCodeBlock codeBlock = codeBlocks := codeBlock :: !codeBlocks in - (* Looks for docstrings and extracts code blocks in ReScript files *) - let makeIterator ~transformAssertEqual ~displayFilename = - { - Ast_iterator.default_iterator with - attribute = - (fun mapper ((name, payload) as attr) -> - match (name, Ast_payload.is_single_string payload, payload) with - | ( {txt = "res.doc"}, - Some (contents, None), - PStr [{pstr_desc = Pstr_eval ({pexp_loc}, _)}] ) -> - let codeBlocks = - extractRescriptCodeBlocks ~transformAssertEqual ~addError - ~displayFilename - ~markdownBlockStartLine:pexp_loc.loc_start.pos_lnum contents - in - codeBlocks |> List.iter addCodeBlock - | _ -> Ast_iterator.default_iterator.attribute mapper attr); - } - in let content = if Filename.check_suffix path ".md" then let content = readFile path in @@ -1143,37 +1235,41 @@ module ExtractCodeblocks = struct extractRescriptCodeBlocks ~transformAssertEqual ~addError ~displayFilename ~markdownBlockStartLine:1 content in - Ok codeBlocks - else if Filename.check_suffix path ".res" then ( - let parser = - Res_driver.parsing_engine.parse_implementation ~for_printer:true - in - let {Res_driver.parsetree = structure; filename} = - parser ~filename:path - in - let filename = Filename.basename filename in - let iterator = - makeIterator ~transformAssertEqual ~displayFilename:filename - in - iterator.structure iterator structure; - Ok !codeBlocks) - else if Filename.check_suffix path ".resi" then ( - let parser = - Res_driver.parsing_engine.parse_interface ~for_printer:true - in - let {Res_driver.parsetree = signature; filename} = - parser ~filename:path - in - let iterator = - makeIterator ~transformAssertEqual ~displayFilename:filename - in - iterator.signature iterator signature; - Ok !codeBlocks) + Ok + (codeBlocks + |> List.mapi (fun index codeBlock -> + { + id = "codeblock-" ^ string_of_int (index + 1); + name = "codeblock-" ^ string_of_int (index + 1); + code = codeBlock; + })) else - Error - (Printf.sprintf - "File extension not supported. This command accepts .res, .resi, \ - and .md files") + let extracted = + extractCodeBlocks ~entryPointFile + ~processDocstrings:(fun ~id ~name code -> + let codeBlocks = + code + |> extractRescriptCodeBlocks ~transformAssertEqual ~addError + ~displayFilename ~markdownBlockStartLine:1 + in + if List.length codeBlocks > 1 then + codeBlocks |> List.rev + |> List.iteri (fun index codeBlock -> + addCodeBlock + { + id = id ^ "-" ^ string_of_int (index + 1); + name; + code = codeBlock; + }) + else + codeBlocks + |> List.iter (fun codeBlock -> + addCodeBlock {id; name; code = codeBlock})) + in + + match extracted with + | Ok () -> Ok !codeBlocks + | Error e -> Error e in match content with | Error e -> Error e @@ -1188,6 +1284,11 @@ module ExtractCodeblocks = struct Ok (codeBlocks |> List.map (fun codeBlock -> - Protocol.wrapInQuotes (Json.escape codeBlock)) + Protocol.stringifyObject + [ + ("id", Some (Protocol.wrapInQuotes codeBlock.id)); + ("name", Some (Protocol.wrapInQuotes codeBlock.name)); + ("code", Some (Protocol.wrapInQuotes codeBlock.code)); + ]) |> Protocol.array) end From 0aae7d7a1003afc360b71c02bafc97d6728ed552 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Thu, 10 Jul 2025 22:07:24 +0200 Subject: [PATCH 08/16] add ExtractCodeBlocks to RescriptTools for simplicity --- lib/es6/RescriptTools.js | 3 +++ lib/es6/RescriptTools_ExtractCodeBlocks.js | 1 + lib/js/RescriptTools.js | 3 +++ lib/js/RescriptTools_ExtractCodeBlocks.js | 1 + runtime/RescriptTools.res | 1 + runtime/RescriptTools_ExtractCodeBlocks.res | 10 ++++++++++ 6 files changed, 19 insertions(+) create mode 100644 lib/es6/RescriptTools_ExtractCodeBlocks.js create mode 100644 lib/js/RescriptTools_ExtractCodeBlocks.js create mode 100644 runtime/RescriptTools_ExtractCodeBlocks.res diff --git a/lib/es6/RescriptTools.js b/lib/es6/RescriptTools.js index 84f6ade54b..c7ca659da5 100644 --- a/lib/es6/RescriptTools.js +++ b/lib/es6/RescriptTools.js @@ -3,7 +3,10 @@ let Docgen; +let ExtractCodeBlocks; + export { Docgen, + ExtractCodeBlocks, } /* No side effect */ diff --git a/lib/es6/RescriptTools_ExtractCodeBlocks.js b/lib/es6/RescriptTools_ExtractCodeBlocks.js new file mode 100644 index 0000000000..ae1b9f17e6 --- /dev/null +++ b/lib/es6/RescriptTools_ExtractCodeBlocks.js @@ -0,0 +1 @@ +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/lib/js/RescriptTools.js b/lib/js/RescriptTools.js index 064bdaddf4..138d9cf128 100644 --- a/lib/js/RescriptTools.js +++ b/lib/js/RescriptTools.js @@ -3,5 +3,8 @@ let Docgen; +let ExtractCodeBlocks; + exports.Docgen = Docgen; +exports.ExtractCodeBlocks = ExtractCodeBlocks; /* No side effect */ diff --git a/lib/js/RescriptTools_ExtractCodeBlocks.js b/lib/js/RescriptTools_ExtractCodeBlocks.js new file mode 100644 index 0000000000..ae1b9f17e6 --- /dev/null +++ b/lib/js/RescriptTools_ExtractCodeBlocks.js @@ -0,0 +1 @@ +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/runtime/RescriptTools.res b/runtime/RescriptTools.res index ea41dd74eb..1aeac799fe 100644 --- a/runtime/RescriptTools.res +++ b/runtime/RescriptTools.res @@ -1,4 +1,5 @@ module Docgen = RescriptTools_Docgen +module ExtractCodeBlocks = RescriptTools_ExtractCodeBlocks /** Returns the full file system path to the `rescript-tools` binary for the current platform, side stepping the JS that wraps the CLI. diff --git a/runtime/RescriptTools_ExtractCodeBlocks.res b/runtime/RescriptTools_ExtractCodeBlocks.res new file mode 100644 index 0000000000..8174dc2c14 --- /dev/null +++ b/runtime/RescriptTools_ExtractCodeBlocks.res @@ -0,0 +1,10 @@ +type codeBlock = { + id: string, + name: string, + code: string, +} + +/** +`decodeFromJson(json)` parse JSON generated from `rescript-tools extract-codeblocks` command +*/ +external decodeFromJson: Stdlib_JSON.t => array = "%identity" From 77bf1a53f9bd73fd6f1201151e440b80a086d05d Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Thu, 10 Jul 2025 22:30:15 +0200 Subject: [PATCH 09/16] integrate code block extraction into doctests script --- analysis/src/Protocol.ml | 5 + runtime/RescriptTools_ExtractCodeBlocks.res | 2 +- tests/docstring_tests/DocTest.res | 200 +-------------- tests/docstring_tests/DocTest.res.js | 227 ++---------------- ...CodeBlocksTest.res.extracted.json.expected | 5 +- ...ocstringsTest1.res.extracted.json.expected | 5 +- ...cstringsTest1.resi.extracted.json.expected | 5 +- ...ocstringsTest2.res.extracted.json.expected | 5 +- ...ringsTestError.res.extracted.json.expected | 16 +- ...tRescriptBlocks.md.extracted.json.expected | 5 +- tools/bin/main.ml | 17 +- tools/src/tools.ml | 10 +- 12 files changed, 77 insertions(+), 425 deletions(-) diff --git a/analysis/src/Protocol.ml b/analysis/src/Protocol.ml index 3631192cb7..e3e4208628 100644 --- a/analysis/src/Protocol.ml +++ b/analysis/src/Protocol.ml @@ -137,6 +137,11 @@ let optWrapInQuotes s = | None -> None | Some s -> Some (wrapInQuotes s) +let stringifyResult = function + | Ok r -> stringifyObject [("TAG", Some (wrapInQuotes "Ok")); ("_0", Some r)] + | Error e -> + stringifyObject [("TAG", Some (wrapInQuotes "Error")); ("_0", Some e)] + let stringifyCompletionItem c = stringifyObject [ diff --git a/runtime/RescriptTools_ExtractCodeBlocks.res b/runtime/RescriptTools_ExtractCodeBlocks.res index 8174dc2c14..b77ae5e8f6 100644 --- a/runtime/RescriptTools_ExtractCodeBlocks.res +++ b/runtime/RescriptTools_ExtractCodeBlocks.res @@ -7,4 +7,4 @@ type codeBlock = { /** `decodeFromJson(json)` parse JSON generated from `rescript-tools extract-codeblocks` command */ -external decodeFromJson: Stdlib_JSON.t => array = "%identity" +external decodeFromJson: Stdlib_JSON.t => result, string> = "%identity" diff --git a/tests/docstring_tests/DocTest.res b/tests/docstring_tests/DocTest.res index 54ea5c88fc..bb3d6282da 100644 --- a/tests/docstring_tests/DocTest.res +++ b/tests/docstring_tests/DocTest.res @@ -1,14 +1,5 @@ open Node -module Docgen = RescriptTools.Docgen - -type example = { - id: string, - kind: string, - name: string, - docstrings: array, -} - // Only major version let nodeVersion = Process.version @@ -49,189 +40,21 @@ let getOutput = buffer => let extractDocFromFile = async file => { let toolsBin = Path.join([Process.cwd(), "cli", "rescript-tools.js"]) - let {stdout} = await SpawnAsync.run(~command=toolsBin, ~args=["doc", file]) + let {stdout} = await SpawnAsync.run( + ~command=toolsBin, + ~args=["extract-codeblocks", file, "--transform-assert-equal"], + ) try { stdout ->getOutput ->JSON.parseOrThrow - ->Docgen.decodeFromJson + ->RescriptTools.ExtractCodeBlocks.decodeFromJson } catch { - | JsExn(_) => JsError.panic(`Failed to generate docstrings from ${file}`) - | _ => assert(false) - } -} - -let getExamples = ({items}: Docgen.doc) => { - let rec loop = (items: list, acc: list) => { - switch items { - | list{Value({docstrings, id, name}), ...rest} => - loop(rest, list{{id, name, docstrings, kind: "value"}, ...acc}) - | list{Type({docstrings, id, name}), ...rest} => - loop(rest, list{{id, name, docstrings, kind: "type"}, ...acc}) - | list{Module({id, name, docstrings, items}), ...rest} => - loop( - list{...rest, ...List.fromArray(items)}, - list{{id, name, docstrings, kind: "module"}, ...acc}, - ) - | list{ModuleType({id, name, docstrings, items}), ...rest} => - loop( - list{...rest, ...List.fromArray(items)}, - list{{id, name, docstrings, kind: "moduleType"}, ...acc}, - ) - | list{ModuleAlias({id, name, docstrings, items}), ...rest} => - loop( - list{...rest, ...List.fromArray(items)}, - list{{id, name, docstrings, kind: "moduleAlias"}, ...acc}, - ) - | list{} => acc - } + | JsExn(e) => + Console.error(e) + JsError.panic(`Failed to extract code blocks from ${file}`) } - - items - ->List.fromArray - ->loop(list{}) - ->List.toArray - ->Array.filter(({docstrings}) => Array.length(docstrings) > 0) -} - -let getCodeBlocks = example => { - let rec loopEndCodeBlock = (lines, acc) => { - switch lines { - | list{hd, ...rest} => - if ( - hd - ->String.trim - ->String.endsWith("```") - ) { - acc - } else { - loopEndCodeBlock(rest, list{hd, ...acc}) - } - | list{} => panic(`Failed to find end of code block for ${example.kind}: ${example.id}`) - } - } - - // Transform lines that contain == patterns to use assertEqual - let transformEqualityAssertions = code => { - let lines = code->String.split("\n") - lines - ->Array.mapWithIndex((line, idx) => { - let trimmedLine = line->String.trim - - // Check if the line contains == and is not inside a comment - if ( - trimmedLine->String.includes("==") && - !(trimmedLine->String.startsWith("//")) && - !(trimmedLine->String.startsWith("/*")) && - // Not an expression line - !(trimmedLine->String.startsWith("if")) && - !(trimmedLine->String.startsWith("|")) && - !(trimmedLine->String.startsWith("let")) && - !(trimmedLine->String.startsWith("~")) && - !(trimmedLine->String.startsWith("module")) && - !(trimmedLine->String.startsWith("->")) && - !(trimmedLine->String.endsWith(",")) - ) { - // Split string at == (not ===) and transform to assertEqual - let parts = { - let rec searchFrom = (currentLine: string, startIndex: int): option<(string, string)> => { - if startIndex >= currentLine->String.length { - // Base case: reached end of string without finding a suitable "==" - None - } else { - let lineSuffix = currentLine->String.sliceToEnd(~start=startIndex) - let idxEqEqInSuffix = lineSuffix->String.indexOfOpt("==") - let idxEqEqEqInSuffix = lineSuffix->String.indexOfOpt("===") - - switch (idxEqEqInSuffix, idxEqEqEqInSuffix) { - | (None, _) => - // No "==" found in the rest of the string. - None - | (Some(iEqEq), None) => - // Found "==" but no "===" in the suffix. - // This "==" must be standalone. - // Calculate its absolute index in the original `currentLine`. - let actualIdx = startIndex + iEqEq - let left = currentLine->String.slice(~start=0, ~end=actualIdx) - let right = currentLine->String.sliceToEnd(~start=actualIdx + 2) - Some((left, right)) - | (Some(iEqEq), Some(iEqEqEq)) => - // Found both "==" and "===" in the suffix. - if iEqEq < iEqEqEq { - // The "==" occurs before "===". This "==" is standalone. - // Example: "a == b === c". In suffix "a == b === c", iEqEq is for "a ==". - let actualIdx = startIndex + iEqEq - let left = currentLine->String.slice(~start=0, ~end=actualIdx) - let right = currentLine->String.sliceToEnd(~start=actualIdx + 2) - Some((left, right)) - } else { - // iEqEq >= iEqEqEq - // This means the first "==" encountered (at iEqEq relative to suffix) - // is part of or comes after the first "===" encountered (at iEqEqEq relative to suffix). - // Example: "a === b". In suffix "a === b", iEqEqEq is for "a ===", iEqEq is also for "a ==". - // We must skip over the "===" found at iEqEqEq and search again. - // The next search should start after this "===". - // The "===" starts at (startIndex + iEqEqEq) in the original line. It has length 3. - searchFrom(currentLine, startIndex + iEqEqEq + 3) - } - } - } - } - searchFrom(line, 0) - } - let parts = switch parts { - | Some((left, right)) if right->String.trim->String.length === 0 => - Some(( - left, - lines - ->Array.get(idx + 1) - ->Option.getOrThrow( - ~message="Expected to have an expected expression on the next line", - ), - )) - | _ => parts - } - switch parts { - | Some((left, right)) if !(right->String.includes(")") || right->String.includes("//")) => - `(${left->String.trim})->assertEqual(${right->String.trim})` - | _ => line - } - } else { - line - } - }) - ->Array.join("\n") - } - - let rec loop = (lines: list, acc: list) => { - switch lines { - | list{hd, ...rest} => - switch hd - ->String.trim - ->String.startsWith("```res") { - | true => - let code = loopEndCodeBlock(rest, list{}) - let codeString = - code - ->List.reverse - ->List.toArray - ->Array.join("\n") - ->transformEqualityAssertions - loop(rest, list{codeString, ...acc}) - | false => loop(rest, acc) - } - | list{} => acc - } - } - - example.docstrings - ->Array.reduce([], (acc, docstring) => acc->Array.concat(docstring->String.split("\n"))) - ->List.fromArray - ->loop(list{}) - ->List.toArray - ->Belt.Array.reverse - ->Array.join("\n\n") } let batchSize = OS.cpus()->Array.length @@ -258,7 +81,10 @@ let extractExamples = async () => { let examples = [] await docFiles->ArrayUtils.forEachAsyncInBatches(~batchSize, async f => { let doc = await extractDocFromFile(Path.join(["runtime", f])) - examples->Array.pushMany(doc->getExamples) + switch doc { + | Ok(doc) => examples->Array.pushMany(doc) + | Error(e) => Console.error(e) + } }) examples->Array.sort((a, b) => String.compare(a.id, b.id)) @@ -303,7 +129,7 @@ let main = async () => { ) None } else { - let code = getCodeBlocks(example) + let code = example.code if code->String.length === 0 { None diff --git a/tests/docstring_tests/DocTest.res.js b/tests/docstring_tests/DocTest.res.js index d18c54da14..52324e74a7 100644 --- a/tests/docstring_tests/DocTest.res.js +++ b/tests/docstring_tests/DocTest.res.js @@ -1,25 +1,19 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -import * as Stdlib from "rescript/lib/es6/Stdlib.js"; import * as Nodefs from "node:fs"; import * as Nodeos from "node:os"; import * as Nodeurl from "node:url"; -import * as Belt_List from "rescript/lib/es6/Belt_List.js"; import * as Nodepath from "node:path"; import * as ArrayUtils from "./ArrayUtils.res.js"; -import * as Belt_Array from "rescript/lib/es6/Belt_Array.js"; import * as SpawnAsync from "./SpawnAsync.res.js"; import * as Stdlib_Int from "rescript/lib/es6/Stdlib_Int.js"; import * as Stdlib_Dict from "rescript/lib/es6/Stdlib_Dict.js"; -import * as Stdlib_List from "rescript/lib/es6/Stdlib_List.js"; import * as Stdlib_Array from "rescript/lib/es6/Stdlib_Array.js"; import * as Stdlib_Option from "rescript/lib/es6/Stdlib_Option.js"; -import * as Stdlib_String from "rescript/lib/es6/Stdlib_String.js"; import * as Stdlib_JsError from "rescript/lib/es6/Stdlib_JsError.js"; import * as Primitive_string from "rescript/lib/es6/Primitive_string.js"; import * as Promises from "node:fs/promises"; import * as Primitive_exceptions from "rescript/lib/es6/Primitive_exceptions.js"; -import * as RescriptTools_Docgen from "rescript/lib/es6/RescriptTools_Docgen.js"; let nodeVersion = Stdlib_Option.getOrThrow(Stdlib_Int.fromString(Stdlib_Option.getOrThrow(process.version.replace("v", "").split(".")[0], "Failed to find major version of Node"), undefined), "Failed to convert node version to Int"); @@ -53,215 +47,22 @@ function getOutput(buffer) { async function extractDocFromFile(file) { let toolsBin = Nodepath.join(process.cwd(), "cli", "rescript-tools.js"); let match = await SpawnAsync.run(toolsBin, [ - "doc", - file + "extract-codeblocks", + file, + "--transform-assert-equal" ], undefined); try { - return RescriptTools_Docgen.decodeFromJson(JSON.parse(getOutput(match.stdout))); - } catch (raw_exn) { - let exn = Primitive_exceptions.internalToException(raw_exn); - if (exn.RE_EXN_ID === "JsExn") { - return Stdlib_JsError.panic("Failed to generate docstrings from " + file); + return JSON.parse(getOutput(match.stdout)); + } catch (raw_e) { + let e = Primitive_exceptions.internalToException(raw_e); + if (e.RE_EXN_ID === "JsExn") { + console.error(e._1); + return Stdlib_JsError.panic("Failed to extract code blocks from " + file); } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "DocTest.res", - 61, - 9 - ], - Error: new Error() - }; + throw e; } } -function getExamples(param) { - let loop = (_items, _acc) => { - while (true) { - let acc = _acc; - let items = _items; - if (items === 0) { - return acc; - } - let match = items.hd; - switch (match.kind) { - case "value" : - _acc = { - hd: { - id: match.id, - kind: "value", - name: match.name, - docstrings: match.docstrings - }, - tl: acc - }; - _items = items.tl; - continue; - case "type" : - _acc = { - hd: { - id: match.id, - kind: "type", - name: match.name, - docstrings: match.docstrings - }, - tl: acc - }; - _items = items.tl; - continue; - case "module" : - _acc = { - hd: { - id: match.id, - kind: "module", - name: match.name, - docstrings: match.docstrings - }, - tl: acc - }; - _items = Belt_List.concatMany([ - items.tl, - Stdlib_List.fromArray(match.items) - ]); - continue; - case "moduleType" : - _acc = { - hd: { - id: match.id, - kind: "moduleType", - name: match.name, - docstrings: match.docstrings - }, - tl: acc - }; - _items = Belt_List.concatMany([ - items.tl, - Stdlib_List.fromArray(match.items) - ]); - continue; - case "moduleAlias" : - _acc = { - hd: { - id: match.id, - kind: "moduleAlias", - name: match.name, - docstrings: match.docstrings - }, - tl: acc - }; - _items = Belt_List.concatMany([ - items.tl, - Stdlib_List.fromArray(match.items) - ]); - continue; - } - }; - }; - return Stdlib_List.toArray(loop(Stdlib_List.fromArray(param.items), /* [] */0)).filter(param => param.docstrings.length > 0); -} - -function getCodeBlocks(example) { - let loopEndCodeBlock = (_lines, _acc) => { - while (true) { - let acc = _acc; - let lines = _lines; - if (lines === 0) { - return Stdlib.panic("Failed to find end of code block for " + example.kind + ": " + example.id); - } - let hd = lines.hd; - if (hd.trim().endsWith("```")) { - return acc; - } - _acc = { - hd: hd, - tl: acc - }; - _lines = lines.tl; - continue; - }; - }; - let transformEqualityAssertions = code => { - let lines = code.split("\n"); - return lines.map((line, idx) => { - let trimmedLine = line.trim(); - if (!(trimmedLine.includes("==") && !trimmedLine.startsWith("//") && !trimmedLine.startsWith("/*") && !trimmedLine.startsWith("if") && !trimmedLine.startsWith("|") && !trimmedLine.startsWith("let") && !trimmedLine.startsWith("~") && !trimmedLine.startsWith("module") && !trimmedLine.startsWith("->") && !trimmedLine.endsWith(","))) { - return line; - } - let searchFrom = (currentLine, _startIndex) => { - while (true) { - let startIndex = _startIndex; - if (startIndex >= currentLine.length) { - return; - } - let lineSuffix = currentLine.slice(startIndex); - let idxEqEqInSuffix = Stdlib_String.indexOfOpt(lineSuffix, "=="); - let idxEqEqEqInSuffix = Stdlib_String.indexOfOpt(lineSuffix, "==="); - if (idxEqEqInSuffix === undefined) { - return; - } - if (idxEqEqEqInSuffix !== undefined) { - if (idxEqEqInSuffix < idxEqEqEqInSuffix) { - let actualIdx = startIndex + idxEqEqInSuffix | 0; - let left = currentLine.slice(0, actualIdx); - let right = currentLine.slice(actualIdx + 2 | 0); - return [ - left, - right - ]; - } - _startIndex = (startIndex + idxEqEqEqInSuffix | 0) + 3 | 0; - continue; - } - let actualIdx$1 = startIndex + idxEqEqInSuffix | 0; - let left$1 = currentLine.slice(0, actualIdx$1); - let right$1 = currentLine.slice(actualIdx$1 + 2 | 0); - return [ - left$1, - right$1 - ]; - }; - }; - let parts = searchFrom(line, 0); - let parts$1 = parts !== undefined && parts[1].trim().length === 0 ? [ - parts[0], - Stdlib_Option.getOrThrow(lines[idx + 1 | 0], "Expected to have an expected expression on the next line") - ] : parts; - if (parts$1 === undefined) { - return line; - } - let right = parts$1[1]; - if (right.includes(")") || right.includes("//")) { - return line; - } else { - return "(" + parts$1[0].trim() + ")->assertEqual(" + right.trim() + ")"; - } - }).join("\n"); - }; - let loop = (_lines, _acc) => { - while (true) { - let acc = _acc; - let lines = _lines; - if (lines === 0) { - return acc; - } - let rest = lines.tl; - if (lines.hd.trim().startsWith("```res")) { - let code = loopEndCodeBlock(rest, /* [] */0); - let codeString = transformEqualityAssertions(Stdlib_List.toArray(Stdlib_List.reverse(code)).join("\n")); - _acc = { - hd: codeString, - tl: acc - }; - _lines = rest; - continue; - } - _lines = rest; - continue; - }; - }; - return Belt_Array.reverse(Stdlib_List.toArray(loop(Stdlib_List.fromArray(Stdlib_Array.reduce(example.docstrings, [], (acc, docstring) => acc.concat(docstring.split("\n")))), /* [] */0))).join("\n\n"); -} - let batchSize = Nodeos.cpus().length; async function extractExamples() { @@ -281,7 +82,11 @@ async function extractExamples() { let examples = []; await ArrayUtils.forEachAsyncInBatches(docFiles, batchSize, async f => { let doc = await extractDocFromFile(Nodepath.join("runtime", f)); - examples.push(...getExamples(doc)); + if (doc.TAG === "Ok") { + examples.push(...doc._0); + return; + } + console.error(doc._0); }); examples.sort((a, b) => Primitive_string.compare(a.id, b.id)); return examples; @@ -312,7 +117,7 @@ async function main() { console.warn("Ignoring " + example.id + " tests. Not supported by Node " + nodeVersion.toString()); return; } - let code = getCodeBlocks(example); + let code = example.code; if (code.length === 0) { return; } else { diff --git a/tests/tools_tests/src/expected/ExtractCodeBlocksTest.res.extracted.json.expected b/tests/tools_tests/src/expected/ExtractCodeBlocksTest.res.extracted.json.expected index def40bdaf6..aa06f3882d 100644 --- a/tests/tools_tests/src/expected/ExtractCodeBlocksTest.res.extracted.json.expected +++ b/tests/tools_tests/src/expected/ExtractCodeBlocksTest.res.extracted.json.expected @@ -1,5 +1,8 @@ -[{ +{ + "TAG": "Ok", + "_0": [{ "id": "ExtractCodeBlocksTest.testFunction1", "name": "testFunction1", "code": "let x = 12\nlet y = 12->Array.filter(x => x == 12)\nassertEqual(x, 12)" }] + } diff --git a/tests/tools_tests/src/expected/FormatDocstringsTest1.res.extracted.json.expected b/tests/tools_tests/src/expected/FormatDocstringsTest1.res.extracted.json.expected index a121729265..5fee63a034 100644 --- a/tests/tools_tests/src/expected/FormatDocstringsTest1.res.extracted.json.expected +++ b/tests/tools_tests/src/expected/FormatDocstringsTest1.res.extracted.json.expected @@ -1,4 +1,6 @@ -[{ +{ + "TAG": "Ok", + "_0": [{ "id": "FormatDocstringsTest1.testFunction3", "name": "testFunction3", "code": "let processUsers = (users: array) => {\n users\n ->Array.map(user => {...user, active: false})\n ->Array.filter(u => u.age > 21)\n}\n\ntype status = Loading | Success(string) | Error(option)" @@ -15,3 +17,4 @@ "name": "testFunction1", "code": "let badly_formatted = (x, y) => {\n let result = x + y\n if result > 0 {\n Console.log(\"positive\")\n } else {\n Console.log(\"negative\")\n }\n result\n}" }] + } diff --git a/tests/tools_tests/src/expected/FormatDocstringsTest1.resi.extracted.json.expected b/tests/tools_tests/src/expected/FormatDocstringsTest1.resi.extracted.json.expected index a121729265..5fee63a034 100644 --- a/tests/tools_tests/src/expected/FormatDocstringsTest1.resi.extracted.json.expected +++ b/tests/tools_tests/src/expected/FormatDocstringsTest1.resi.extracted.json.expected @@ -1,4 +1,6 @@ -[{ +{ + "TAG": "Ok", + "_0": [{ "id": "FormatDocstringsTest1.testFunction3", "name": "testFunction3", "code": "let processUsers = (users: array) => {\n users\n ->Array.map(user => {...user, active: false})\n ->Array.filter(u => u.age > 21)\n}\n\ntype status = Loading | Success(string) | Error(option)" @@ -15,3 +17,4 @@ "name": "testFunction1", "code": "let badly_formatted = (x, y) => {\n let result = x + y\n if result > 0 {\n Console.log(\"positive\")\n } else {\n Console.log(\"negative\")\n }\n result\n}" }] + } diff --git a/tests/tools_tests/src/expected/FormatDocstringsTest2.res.extracted.json.expected b/tests/tools_tests/src/expected/FormatDocstringsTest2.res.extracted.json.expected index 5a1f7968f0..1619063e79 100644 --- a/tests/tools_tests/src/expected/FormatDocstringsTest2.res.extracted.json.expected +++ b/tests/tools_tests/src/expected/FormatDocstringsTest2.res.extracted.json.expected @@ -1,4 +1,6 @@ -[{ +{ + "TAG": "Ok", + "_0": [{ "id": "FormatDocstringsTest2.testResi", "name": "testResi", "code": "type x = int\nlet x: int => string\nmodule M: {\n let ff: string => int\n}" @@ -15,3 +17,4 @@ "name": "testJsx", "code": "let component = () => {\n
\n

{\"Title\"->React.string}

\n \n
\n}" }] + } diff --git a/tests/tools_tests/src/expected/FormatDocstringsTestError.res.extracted.json.expected b/tests/tools_tests/src/expected/FormatDocstringsTestError.res.extracted.json.expected index c5b52e6828..9f24eec825 100644 --- a/tests/tools_tests/src/expected/FormatDocstringsTestError.res.extracted.json.expected +++ b/tests/tools_tests/src/expected/FormatDocstringsTestError.res.extracted.json.expected @@ -1,12 +1,4 @@ - - Syntax error in code block in docstring - FormatDocstringsTestError.res:5:10-6:3 - - 3 │ - 4 │ - 5 │ let name= - 6 │ let x=12 - - This let-binding misses an expression - - +{ + "TAG": "Error", + "_0": "\n Syntax error in code block in docstring\n FormatDocstringsTestError.res:5:10-6:3\n\n 3 │ \n 4 │ \n 5 │ let name= \n 6 │ let x=12\n\n This let-binding misses an expression\n\n" + } diff --git a/tests/tools_tests/src/expected/FormatRescriptBlocks.md.extracted.json.expected b/tests/tools_tests/src/expected/FormatRescriptBlocks.md.extracted.json.expected index 88e74994d5..dabca83343 100644 --- a/tests/tools_tests/src/expected/FormatRescriptBlocks.md.extracted.json.expected +++ b/tests/tools_tests/src/expected/FormatRescriptBlocks.md.extracted.json.expected @@ -1,4 +1,6 @@ -[{ +{ + "TAG": "Ok", + "_0": [{ "id": "codeblock-1", "name": "codeblock-1", "code": "type user = {name: string, age: int, active: bool}\nlet createUser = (name, age) => {name, age, active: true}" @@ -7,3 +9,4 @@ "name": "codeblock-2", "code": "let badly_formatted = (x, y) => {\n let result = x + y\n if result > 0 {\n Console.log(\"positive\")\n } else {\n Console.log(\"negative\")\n }\n result\n}" }] + } diff --git a/tools/bin/main.ml b/tools/bin/main.ml index a33bf67856..88f7ffa575 100644 --- a/tools/bin/main.ml +++ b/tools/bin/main.ml @@ -86,12 +86,21 @@ let main () = | "extract-codeblocks" :: rest -> ( match rest with | ["-h"] | ["--help"] -> logAndExit (Ok extractCodeblocksHelp) - | path :: args -> + | path :: args -> ( let transformAssertEqual = List.mem "--transform-assert-equal" args in Clflags.color := Some Misc.Color.Never; - logAndExit - (Tools.ExtractCodeblocks.extractCodeblocksFromFile ~transformAssertEqual - ~entryPointFile:path) + + (* TODO: Add result/JSON mode *) + match + Tools.ExtractCodeblocks.extractCodeblocksFromFile ~transformAssertEqual + ~entryPointFile:path + with + | Ok _ as r -> + print_endline (Analysis.Protocol.stringifyResult r); + exit 0 + | Error _ as r -> + print_endline (Analysis.Protocol.stringifyResult r); + exit 1) | _ -> logAndExit (Error extractCodeblocksHelp)) | "reanalyze" :: _ -> let len = Array.length Sys.argv in diff --git a/tools/src/tools.ml b/tools/src/tools.ml index 288207b672..bf2ed65c64 100644 --- a/tools/src/tools.ml +++ b/tools/src/tools.ml @@ -1275,11 +1275,11 @@ module ExtractCodeblocks = struct | Error e -> Error e | Ok codeBlocks -> let errors = !errors in - if List.length errors > 0 then ( - errors |> List.rev |> String.concat "\n" |> print_endline; - Error - (Printf.sprintf "%s: Error formatting docstrings." - (Filename.basename path))) + if List.length errors > 0 then + let errors = + errors |> List.rev |> String.concat "\n" |> Protocol.wrapInQuotes + in + Error errors else Ok (codeBlocks From 699b8922b9ba189fdc459689a1b863a181325749 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Thu, 10 Jul 2025 22:49:43 +0200 Subject: [PATCH 10/16] only include code blocks with tests in them --- tests/docstring_tests/DocTest.res | 4 +++- tests/docstring_tests/DocTest.res.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/docstring_tests/DocTest.res b/tests/docstring_tests/DocTest.res index bb3d6282da..5e1c520dd9 100644 --- a/tests/docstring_tests/DocTest.res +++ b/tests/docstring_tests/DocTest.res @@ -82,7 +82,9 @@ let extractExamples = async () => { await docFiles->ArrayUtils.forEachAsyncInBatches(~batchSize, async f => { let doc = await extractDocFromFile(Path.join(["runtime", f])) switch doc { - | Ok(doc) => examples->Array.pushMany(doc) + | Ok(doc) => + // TODO: Should this be a flag in the actual command instead, to only include code blocks with tests? + examples->Array.pushMany(doc->Array.filter(d => d.code->String.includes("assertEqual("))) | Error(e) => Console.error(e) } }) diff --git a/tests/docstring_tests/DocTest.res.js b/tests/docstring_tests/DocTest.res.js index 52324e74a7..f202642d02 100644 --- a/tests/docstring_tests/DocTest.res.js +++ b/tests/docstring_tests/DocTest.res.js @@ -83,7 +83,7 @@ async function extractExamples() { await ArrayUtils.forEachAsyncInBatches(docFiles, batchSize, async f => { let doc = await extractDocFromFile(Nodepath.join("runtime", f)); if (doc.TAG === "Ok") { - examples.push(...doc._0); + examples.push(...doc._0.filter(d => d.code.includes("assertEqual("))); return; } console.error(doc._0); From cba82539735d800488f255f6a473902fe9590ab6 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Fri, 11 Jul 2025 08:59:06 +0200 Subject: [PATCH 11/16] update analysis examples --- .../tests/src/expected/Completion.res.txt | 178 +++++++++--------- .../expected/CompletionExpressions.res.txt | 2 +- .../expected/CompletionInferValues.res.txt | 28 +-- .../tests/src/expected/CompletionJsx.res.txt | 28 +-- .../src/expected/CompletionPipeChain.res.txt | 4 +- .../tests/src/expected/Definition.res.txt | 2 +- .../expected/DotPipeCompletionSpec.res.txt | 10 +- .../src/expected/RecordCompletion.res.txt | 8 +- .../tests/src/expected/RecoveryOnProp.res.txt | 10 + .../tests/src/expected/SignatureHelp.res.txt | 2 +- 10 files changed, 146 insertions(+), 126 deletions(-) diff --git a/tests/analysis_tests/tests/src/expected/Completion.res.txt b/tests/analysis_tests/tests/src/expected/Completion.res.txt index 18d9163214..dbfc94944f 100644 --- a/tests/analysis_tests/tests/src/expected/Completion.res.txt +++ b/tests/analysis_tests/tests/src/expected/Completion.res.txt @@ -17,25 +17,25 @@ Path MyList.m "kind": 12, "tags": [], "detail": "(list<'a>, list<'b>, ('a, 'b) => 'c) => list<'c>", - "documentation": {"kind": "markdown", "value": "\n`mapReverse2(list1, list2, f)` is equivalent to `List.zipBy(list1, list2, f)->List.reverse`.\n\n## Examples\n\n```rescript\nassertEqual(List.mapReverse2(list{1, 2, 3}, list{1, 2}, (a, b) => a + b), list{4, 2})\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`mapReverse2(list1, list2, f)` is equivalent to `List.zipBy(list1, list2, f)->List.reverse`.\n\n## Examples\n\n```rescript\nList.mapReverse2(list{1, 2, 3}, list{1, 2}, (a, b) => a + b) == list{4, 2}\n```\n"} }, { "label": "make", "kind": 12, "tags": [], "detail": "(~length: int, 'a) => list<'a>", - "documentation": {"kind": "markdown", "value": "\n`make(length, value)` returns a list of length `length` with each element filled\nwith `value`. Returns an empty list if `value` is negative.\n\n## Examples\n\n```rescript\nassertEqual(List.make(~length=3, 1), list{1, 1, 1})\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`make(length, value)` returns a list of length `length` with each element filled\nwith `value`. Returns an empty list if `value` is negative.\n\n## Examples\n\n```rescript\nList.make(~length=3, 1) == list{1, 1, 1}\n```\n"} }, { "label": "mapWithIndex", "kind": 12, "tags": [], "detail": "(list<'a>, ('a, int) => 'b) => list<'b>", - "documentation": {"kind": "markdown", "value": "\n`mapWithIndex(list, f)` applies `f` to each element of `list`. Function `f`\ntakes two arguments: the index starting from 0 and the element from `list`, in\nthat order.\n\n## Examples\n\n```rescript\nassertEqual(list{1, 2, 3}->List.mapWithIndex((x, index) => index + x), list{1, 3, 5})\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`mapWithIndex(list, f)` applies `f` to each element of `list`. Function `f`\ntakes two arguments: the index starting from 0 and the element from `list`, in\nthat order.\n\n## Examples\n\n```rescript\nlist{1, 2, 3}->List.mapWithIndex((x, index) => index + x) == list{1, 3, 5}\n```\n"} }, { "label": "map", "kind": 12, "tags": [], "detail": "(list<'a>, 'a => 'b) => list<'b>", - "documentation": {"kind": "markdown", "value": "\n`map(list, f)` returns a new list with `f` applied to each element of `list`.\n\n## Examples\n\n```rescript\nassertEqual(list{1, 2}->List.map(x => x + 1), list{2, 3})\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`map(list, f)` returns a new list with `f` applied to each element of `list`.\n\n## Examples\n\n```rescript\nlist{1, 2}->List.map(x => x + 1) == list{2, 3}\n```\n"} }] Complete src/Completion.res 3:9 @@ -57,37 +57,37 @@ Path Array. "kind": 12, "tags": [], "detail": "(array<'a>, array<'a>) => array<'a>", - "documentation": {"kind": "markdown", "value": "\n`concat(array1, array2)` concatenates the two arrays, creating a new array.\n\nSee [`Array.concat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat) on MDN.\n\n## Examples\n\n```rescript\nlet array1 = [\"hi\", \"hello\"]\nlet array2 = [\"yay\", \"wehoo\"]\n\nlet someArray = array1->Array.concat(array2)\n\nsomeArray->assertEqual([\"hi\", \"hello\", \"yay\", \"wehoo\"])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`concat(array1, array2)` concatenates the two arrays, creating a new array.\n\nSee [`Array.concat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat) on MDN.\n\n## Examples\n\n```rescript\nlet array1 = [\"hi\", \"hello\"]\nlet array2 = [\"yay\", \"wehoo\"]\n\nlet someArray = array1->Array.concat(array2)\n\nsomeArray == [\"hi\", \"hello\", \"yay\", \"wehoo\"]\n```\n"} }, { "label": "filterMap", "kind": 12, "tags": [], "detail": "(array<'a>, 'a => option<'b>) => array<'b>", - "documentation": {"kind": "markdown", "value": "\n`filterMap(array, fn)`\n\nCalls `fn` for each element and returns a new array containing results of the `fn` calls which are not `None`.\n\n## Examples\n\n```rescript\n[\"Hello\", \"Hi\", \"Good bye\"]\n->Array.filterMap(item =>\n switch item {\n | \"Hello\" => Some(item->String.length)\n | _ => None\n }\n)\n->assertEqual([5])\n\n[1, 2, 3, 4, 5, 6]\n->Array.filterMap(n => mod(n, 2) == 0 ? Some(n * n) : None)\n->assertEqual([4, 16, 36])\n\nArray.filterMap([1, 2, 3, 4, 5, 6], _ => None)->assertEqual([])\n\nArray.filterMap([], n => mod(n, 2) == 0 ? Some(n * n) : None)->assertEqual([])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`filterMap(array, fn)`\n\nCalls `fn` for each element and returns a new array containing results of the `fn` calls which are not `None`.\n\n## Examples\n\n```rescript\n[\"Hello\", \"Hi\", \"Good bye\"]->Array.filterMap(item =>\n switch item {\n | \"Hello\" => Some(item->String.length)\n | _ => None\n }\n) == [5]\n\n[1, 2, 3, 4, 5, 6]->Array.filterMap(n => mod(n, 2) == 0 ? Some(n * n) : None) == [4, 16, 36]\n\nArray.filterMap([1, 2, 3, 4, 5, 6], _ => None) == []\n\nArray.filterMap([], n => mod(n, 2) == 0 ? Some(n * n) : None) == []\n```\n"} }, { "label": "findLastWithIndex", "kind": 12, "tags": [], "detail": "(array<'a>, ('a, int) => bool) => option<'a>", - "documentation": {"kind": "markdown", "value": "\n`findLastWithIndex(array, checker)` returns the last element of `array` where the provided `checker` function returns true.\n\nSee [`Array.findLast`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast) on MDN.\n\n## Examples\n\n```rescript\nlet array = [1, 2, 3]\n\narray\n->Array.findLastWithIndex((item, index) => index < 2 && item > 0)\n->assertEqual(Some(2))\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`findLastWithIndex(array, checker)` returns the last element of `array` where the provided `checker` function returns true.\n\nSee [`Array.findLast`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast) on MDN.\n\n## Examples\n\n```rescript\nlet array = [1, 2, 3]\n\narray->Array.findLastWithIndex((item, index) => index < 2 && item > 0) == Some(2)\n```\n"} }, { "label": "findLast", "kind": 12, "tags": [], "detail": "(array<'a>, 'a => bool) => option<'a>", - "documentation": {"kind": "markdown", "value": "\n`findLast(array, checker)` returns the last element of `array` where the provided `checker` function returns true.\n\nSee [`Array.findLast`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast) on MDN.\n\n## Examples\n\n```rescript\nlet array = [1, 2, 3]\n\narray\n->Array.findLast(item => item > 0)\n->assertEqual(Some(3))\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`findLast(array, checker)` returns the last element of `array` where the provided `checker` function returns true.\n\nSee [`Array.findLast`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast) on MDN.\n\n## Examples\n\n```rescript\nlet array = [1, 2, 3]\n\narray->Array.findLast(item => item > 0) == Some(3)\n```\n"} }, { "label": "shift", "kind": 12, "tags": [], "detail": "array<'a> => option<'a>", - "documentation": {"kind": "markdown", "value": "\n`shift(array)` removes the first item in the array, and returns it.\n\nBeware this will *mutate* the array.\n\nSee [`Array.shift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift) on MDN.\n\n## Examples\n\n```rescript\nlet someArray = [\"hi\", \"hello\"]\n\nsomeArray\n->Array.shift\n->assertEqual(Some(\"hi\"))\n\nsomeArray->assertEqual([\"hello\"]) // Notice first item is gone.\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`shift(array)` removes the first item in the array, and returns it.\n\nBeware this will *mutate* the array.\n\nSee [`Array.shift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift) on MDN.\n\n## Examples\n\n```rescript\nlet someArray = [\"hi\", \"hello\"]\n\nsomeArray->Array.shift == Some(\"hi\")\n\nsomeArray == [\"hello\"] // Notice first item is gone.\n```\n"} }, { "label": "findMap", "kind": 12, "tags": [], "detail": "(array<'a>, 'a => option<'b>) => option<'b>", - "documentation": {"kind": "markdown", "value": "\n`findMap(arr, fn)`\n\nCalls `fn` for each element and returns the first value from `fn` that is `Some(_)`.\nOtherwise returns `None`\n\n## Examples\n\n```rescript\nArray.findMap([1, 2, 3], n => mod(n, 2) == 0 ? Some(n - 2) : None)->assertEqual(Some(0))\n\nArray.findMap([1, 2, 3, 4, 5, 6], n => mod(n, 2) == 0 ? Some(n - 8) : None)->assertEqual(Some(-6))\n\nArray.findMap([1, 2, 3, 4, 5, 6], _ => None)->assertEqual(None)\n\nArray.findMap([], n => mod(n, 2) == 0 ? Some(n * n) : None)->assertEqual(None)\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`findMap(arr, fn)`\n\nCalls `fn` for each element and returns the first value from `fn` that is `Some(_)`.\nOtherwise returns `None`\n\n## Examples\n\n```rescript\nArray.findMap([1, 2, 3], n => mod(n, 2) == 0 ? Some(n - 2) : None) == Some(0)\n\nArray.findMap([1, 2, 3, 4, 5, 6], n => mod(n, 2) == 0 ? Some(n - 8) : None) == Some(-6)\n\nArray.findMap([1, 2, 3, 4, 5, 6], _ => None) == None\n\nArray.findMap([], n => mod(n, 2) == 0 ? Some(n * n) : None) == None\n```\n"} }, { "label": "concatMany", "kind": 12, @@ -99,31 +99,31 @@ Path Array. "kind": 12, "tags": [1], "detail": "(array, string) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `join` instead\n\n\n`joinWith(array, separator)` produces a string where all items of `array` are printed, separated by `separator`. Array items must be strings, to join number or other arrays, use `joinWithUnsafe`. Under the hood this will run JavaScript's `toString` on all the array items.\n\n## Examples\n\n```rescript\n[\"One\", \"Two\", \"Three\"]\n->Array.joinWith(\" -- \")\n->assertEqual(\"One -- Two -- Three\")\n```\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: Use `join` instead\n\n\n`joinWith(array, separator)` produces a string where all items of `array` are printed, separated by `separator`. Array items must be strings, to join number or other arrays, use `joinWithUnsafe`. Under the hood this will run JavaScript's `toString` on all the array items.\n\n## Examples\n\n```rescript\n[\"One\", \"Two\", \"Three\"]->Array.joinWith(\" -- \") == \"One -- Two -- Three\"\n```\n"} }, { "label": "joinWithUnsafe", "kind": 12, "tags": [1], "detail": "(array<'a>, string) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `joinUnsafe` instead\n\n\n`joinWithUnsafe(array, separator)` produces a string where all items of `array` are printed, separated by `separator`. Under the hood this will run JavaScript's `toString` on all the array items.\n\n## Examples\n\n```rescript\n[1, 2, 3]\n->Array.joinWithUnsafe(\" -- \")\n->assertEqual(\"1 -- 2 -- 3\")\n```\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: Use `joinUnsafe` instead\n\n\n`joinWithUnsafe(array, separator)` produces a string where all items of `array` are printed, separated by `separator`. Under the hood this will run JavaScript's `toString` on all the array items.\n\n## Examples\n\n```rescript\n[1, 2, 3]->Array.joinWithUnsafe(\" -- \") == \"1 -- 2 -- 3\"\n```\n"} }, { "label": "reduceRight", "kind": 12, "tags": [], "detail": "(array<'a>, 'b, ('b, 'a) => 'b) => 'b", - "documentation": {"kind": "markdown", "value": "\n`reduceRight(xs, init, fn)`\n\nWorks like `Array.reduce`; except that function `fn` is applied to each item of `xs` from the last back to the first.\n\n## Examples\n\n```rescript\nArray.reduceRight([\"a\", \"b\", \"c\", \"d\"], \"\", (a, b) => a ++ b)->assertEqual(\"dcba\")\n\nArray.reduceRight([1, 2, 3], list{}, List.add)->assertEqual(list{1, 2, 3})\n\nArray.reduceRight([], list{}, List.add)->assertEqual(list{})\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`reduceRight(xs, init, fn)`\n\nWorks like `Array.reduce`; except that function `fn` is applied to each item of `xs` from the last back to the first.\n\n## Examples\n\n```rescript\nArray.reduceRight([\"a\", \"b\", \"c\", \"d\"], \"\", (a, b) => a ++ b) == \"dcba\"\n\nArray.reduceRight([1, 2, 3], list{}, List.add) == list{1, 2, 3}\n\nArray.reduceRight([], list{}, List.add) == list{}\n```\n"} }, { "label": "reduceRightWithIndex", "kind": 12, "tags": [], "detail": "(array<'a>, 'b, ('b, 'a, int) => 'b) => 'b", - "documentation": {"kind": "markdown", "value": "\n`reduceRightWithIndex(xs, init, fn)`\n\nLike `reduceRight`, but with an additional index argument on the callback function.\n\n## Examples\n\n```rescript\nArray.reduceRightWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i)->assertEqual(16)\n\nArray.reduceRightWithIndex([], list{}, (acc, v, i) => list{v + i, ...acc})->assertEqual(list{})\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`reduceRightWithIndex(xs, init, fn)`\n\nLike `reduceRight`, but with an additional index argument on the callback function.\n\n## Examples\n\n```rescript\nArray.reduceRightWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16\n\nArray.reduceRightWithIndex([], list{}, (acc, v, i) => list{v + i, ...acc}) == list{}\n```\n"} }, { "label": "toShuffled", "kind": 12, "tags": [], "detail": "array<'a> => array<'a>", - "documentation": {"kind": "markdown", "value": "\n`toShuffled(array)` returns a new array with all items in `array` in a random order.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet shuffledArray = array->Array.toShuffled\nConsole.log(shuffledArray)\n\nArray.toShuffled([1, 2, 3])\n->Array.length\n->assertEqual(3)\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`toShuffled(array)` returns a new array with all items in `array` in a random order.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet shuffledArray = array->Array.toShuffled\nConsole.log(shuffledArray)\n\nArray.toShuffled([1, 2, 3])->Array.length == 3\n```\n"} }, { "label": "getSymbol", "kind": 12, @@ -141,79 +141,79 @@ Path Array. "kind": 12, "tags": [], "detail": "(array<'a>, 'a => bool) => option", - "documentation": {"kind": "markdown", "value": "\n`findIndexOpt(array, checker)` returns the index of the first element of `array` where the provided `checker` function returns true.\n\nReturns `None` if no item matches.\n\nSee [`Array.findIndex`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex) on MDN.\n\n## Examples\n\n```rescript\ntype languages = ReScript | TypeScript | JavaScript\n\nlet array = [ReScript, TypeScript, JavaScript]\n\narray\n->Array.findIndexOpt(item => item == ReScript)\n->assertEqual(Some(0))\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`findIndexOpt(array, checker)` returns the index of the first element of `array` where the provided `checker` function returns true.\n\nReturns `None` if no item matches.\n\nSee [`Array.findIndex`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex) on MDN.\n\n## Examples\n\n```rescript\ntype languages = ReScript | TypeScript | JavaScript\n\nlet array = [ReScript, TypeScript, JavaScript]\n\narray->Array.findIndexOpt(item => item == ReScript) == Some(0)\n```\n"} }, { "label": "shuffle", "kind": 12, "tags": [], "detail": "array<'a> => unit", - "documentation": {"kind": "markdown", "value": "\n`shuffle(array)` randomizes the position of all items in `array`.\n\nBeware this will *mutate* the array.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\narray->Array.shuffle\nConsole.log(array)\n\nlet array2 = [1, 2, 3]\narray2->Array.shuffle\n\narray2\n->Array.length\n->assertEqual(3)\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`shuffle(array)` randomizes the position of all items in `array`.\n\nBeware this will *mutate* the array.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\narray->Array.shuffle\nConsole.log(array)\n\nlet array2 = [1, 2, 3]\narray2->Array.shuffle\n\narray2->Array.length == 3\n```\n"} }, { "label": "copy", "kind": 12, "tags": [], "detail": "array<'a> => array<'a>", - "documentation": {"kind": "markdown", "value": "\n`copy(array)` makes a copy of the array with the items in it, but does not make copies of the items themselves.\n\n## Examples\n\n```rescript\nlet myArray = [1, 2, 3]\nlet copyOfMyArray = myArray->Array.copy\n\ncopyOfMyArray->assertEqual([1, 2, 3])\nassertEqual(myArray === copyOfMyArray, false)\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`copy(array)` makes a copy of the array with the items in it, but does not make copies of the items themselves.\n\n## Examples\n\n```rescript\nlet myArray = [1, 2, 3]\nlet copyOfMyArray = myArray->Array.copy\n\ncopyOfMyArray == [1, 2, 3]\n(myArray === copyOfMyArray) == false\n```\n"} }, { "label": "setUnsafe", "kind": 12, "tags": [], "detail": "(array<'a>, int, 'a) => unit", - "documentation": {"kind": "markdown", "value": "\n`setUnsafe(array, index, item)` sets the provided `item` at `index` of `array`.\n\nBeware this will *mutate* the array, and is *unsafe*.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\narray->Array.setUnsafe(1, \"Hello\")\n\nassertEqual(array[1], Some(\"Hello\"))\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`setUnsafe(array, index, item)` sets the provided `item` at `index` of `array`.\n\nBeware this will *mutate* the array, and is *unsafe*.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\narray->Array.setUnsafe(1, \"Hello\")\n\narray[1] == Some(\"Hello\")\n```\n"} }, { "label": "findIndexWithIndex", "kind": 12, "tags": [], "detail": "(array<'a>, ('a, int) => bool) => int", - "documentation": {"kind": "markdown", "value": "\n`findIndexWithIndex(array, checker)` returns the index of the first element of `array` where the provided `checker` function returns true.\n\nReturns `-1` if the item does not exist. Consider using `Array.findIndexOpt` if you want an option instead (where `-1` would be `None`).\n\nSee [`Array.findIndex`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex) on MDN.\n\n## Examples\n\n```rescript\ntype languages = ReScript | TypeScript | JavaScript\n\nlet array = [ReScript, JavaScript]\n\nlet isReScriptFirst = array->Array.findIndexWithIndex((item, index) => index === 0 && item == ReScript)\nlet isTypeScriptFirst = array->Array.findIndexWithIndex((item, index) => index === 0 && item == TypeScript)\n\nassertEqual(isReScriptFirst, 0)\nassertEqual(isTypeScriptFirst, -1)\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`findIndexWithIndex(array, checker)` returns the index of the first element of `array` where the provided `checker` function returns true.\n\nReturns `-1` if the item does not exist. Consider using `Array.findIndexOpt` if you want an option instead (where `-1` would be `None`).\n\nSee [`Array.findIndex`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex) on MDN.\n\n## Examples\n\n```rescript\ntype languages = ReScript | TypeScript | JavaScript\n\nlet array = [ReScript, JavaScript]\n\nlet isReScriptFirst =\n array->Array.findIndexWithIndex((item, index) => index === 0 && item == ReScript)\nlet isTypeScriptFirst =\n array->Array.findIndexWithIndex((item, index) => index === 0 && item == TypeScript)\n\nisReScriptFirst == 0\nisTypeScriptFirst == -1\n```\n"} }, { "label": "someWithIndex", "kind": 12, "tags": [], "detail": "(array<'a>, ('a, int) => bool) => bool", - "documentation": {"kind": "markdown", "value": "\n`someWithIndex(array, checker)` returns true if running the provided `checker` function on any element in `array` returns true.\n\nSee [`Array.some`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\n\narray\n->Array.someWithIndex((greeting, index) => greeting === \"Hello\" && index === 0)\n->assertEqual(true)\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`someWithIndex(array, checker)` returns true if running the provided `checker` function on any element in `array` returns true.\n\nSee [`Array.some`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\n\narray->Array.someWithIndex((greeting, index) => greeting === \"Hello\" && index === 0) == true\n```\n"} }, { "label": "slice", "kind": 12, "tags": [], "detail": "(array<'a>, ~start: int, ~end: int) => array<'a>", - "documentation": {"kind": "markdown", "value": "\n`slice(array, ~start, ~end)` creates a new array of items copied from `array` from `start` until (but not including) `end`.\n\nSee [`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice) on MDN.\n\n## Examples\n\n```rescript\n[1, 2, 3, 4]\n->Array.slice(~start=1, ~end=3)\n->assertEqual([2, 3])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`slice(array, ~start, ~end)` creates a new array of items copied from `array` from `start` until (but not including) `end`.\n\nSee [`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice) on MDN.\n\n## Examples\n\n```rescript\n[1, 2, 3, 4]->Array.slice(~start=1, ~end=3) == [2, 3]\n```\n"} }, { "label": "fillToEnd", "kind": 12, "tags": [], "detail": "(array<'a>, 'a, ~start: int) => unit", - "documentation": {"kind": "markdown", "value": "\n`fillToEnd(array, value, ~start)` fills `array` with `value` from the `start` index.\n\nBeware this will *mutate* the array.\n\nSee [`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill) on MDN.\n\n## Examples\n\n```rescript\nlet myArray = [1, 2, 3, 4]\nmyArray->Array.fillToEnd(9, ~start=1)\nmyArray->assertEqual([1, 9, 9, 9])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`fillToEnd(array, value, ~start)` fills `array` with `value` from the `start` index.\n\nBeware this will *mutate* the array.\n\nSee [`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill) on MDN.\n\n## Examples\n\n```rescript\nlet myArray = [1, 2, 3, 4]\nmyArray->Array.fillToEnd(9, ~start=1)\nmyArray == [1, 9, 9, 9]\n```\n"} }, { "label": "includes", "kind": 12, "tags": [], "detail": "(array<'a>, 'a) => bool", - "documentation": {"kind": "markdown", "value": "\n`includes(array, item)` checks whether `array` includes `item`, by doing a [strict check for equality](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality).\n\nSee [`Array.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes) on MDN.\n\n## Examples\n\n```rescript\n[1, 2]->Array.includes(1)->assertEqual(true)\n[1, 2]->Array.includes(3)->assertEqual(false)\n\n[{\"language\": \"ReScript\"}]\n->Array.includes({\"language\": \"ReScript\"})\n->assertEqual(false) // false, because of strict equality\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`includes(array, item)` checks whether `array` includes `item`, by doing a [strict check for equality](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality).\n\nSee [`Array.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes) on MDN.\n\n## Examples\n\n```rescript\n[1, 2]->Array.includes(1) == true\n[1, 2]->Array.includes(3) == false\n\n[{\"language\": \"ReScript\"}]->Array.includes({\"language\": \"ReScript\"}) == false // false, because of strict equality\n```\n"} }, { "label": "findLastIndex", "kind": 12, "tags": [], "detail": "(array<'a>, 'a => bool) => int", - "documentation": {"kind": "markdown", "value": "\n`findLastIndex(array, checker)` returns the index of the last element of `array` where the provided `checker` function returns true.\n\nReturns `-1` if the item does not exist. Consider using `Array.findLastIndexOpt` if you want an option instead (where `-1` would be `None`).\n\nSee [`Array.findLastIndex`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex) on MDN.\n\n## Examples\n\n```rescript\ntype languages = ReScript | TypeScript | JavaScript\n\nlet array = [ReScript, JavaScript, ReScript]\n\narray\n->Array.findLastIndex(item => item == ReScript)\n->assertEqual(2)\n\narray->Array.findLastIndex(item => item == TypeScript)\n->assertEqual(-1)\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`findLastIndex(array, checker)` returns the index of the last element of `array` where the provided `checker` function returns true.\n\nReturns `-1` if the item does not exist. Consider using `Array.findLastIndexOpt` if you want an option instead (where `-1` would be `None`).\n\nSee [`Array.findLastIndex`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex) on MDN.\n\n## Examples\n\n```rescript\ntype languages = ReScript | TypeScript | JavaScript\n\nlet array = [ReScript, JavaScript, ReScript]\n\narray->Array.findLastIndex(item => item == ReScript) == 2\n\narray->Array.findLastIndex(item => item == TypeScript) == -1\n```\n"} }, { "label": "fromInitializer", "kind": 12, "tags": [], "detail": "(~length: int, int => 'a) => array<'a>", - "documentation": {"kind": "markdown", "value": "\n`fromInitializer(~length, f)`\n\nCreates an array of length `length` initialized with the value returned from `f ` for each index.\n\n## Examples\n\n```rescript\nArray.fromInitializer(~length=3, i => i + 3)->assertEqual([3, 4, 5])\n\nArray.fromInitializer(~length=7, i => i + 3)->assertEqual([3, 4, 5, 6, 7, 8, 9])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`fromInitializer(~length, f)`\n\nCreates an array of length `length` initialized with the value returned from `f ` for each index.\n\n## Examples\n\n```rescript\nArray.fromInitializer(~length=3, i => i + 3) == [3, 4, 5]\n\nArray.fromInitializer(~length=7, i => i + 3) == [3, 4, 5, 6, 7, 8, 9]\n```\n"} }, { "label": "find", "kind": 12, "tags": [], "detail": "(array<'a>, 'a => bool) => option<'a>", - "documentation": {"kind": "markdown", "value": "\n`find(array, checker)` returns the first element of `array` where the provided `checker` function returns true.\n\nSee [`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) on MDN.\n\n## Examples\n\n```rescript\ntype languages = ReScript | TypeScript | JavaScript\n\nlet array = [ReScript, TypeScript, JavaScript]\n\narray\n->Array.find(item => item == ReScript)\n->assertEqual(Some(ReScript))\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`find(array, checker)` returns the first element of `array` where the provided `checker` function returns true.\n\nSee [`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) on MDN.\n\n## Examples\n\n```rescript\ntype languages = ReScript | TypeScript | JavaScript\n\nlet array = [ReScript, TypeScript, JavaScript]\n\narray->Array.find(item => item == ReScript) == Some(ReScript)\n```\n"} }, { "label": "make", "kind": 12, "tags": [], "detail": "(~length: int, 'a) => array<'a>", - "documentation": {"kind": "markdown", "value": "\n`make(~length, init)` creates an array of length `length` initialized with the value of `init`.\n\n## Examples\n\n```rescript\nArray.make(~length=3, #apple)->assertEqual([#apple, #apple, #apple])\nArray.make(~length=6, 7)->assertEqual([7, 7, 7, 7, 7, 7])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`make(~length, init)` creates an array of length `length` initialized with the value of `init`.\n\n## Examples\n\n```rescript\nArray.make(~length=3, #apple) == [#apple, #apple, #apple]\nArray.make(~length=6, 7) == [7, 7, 7, 7, 7, 7]\n```\n"} }, { "label": "lastIndexOfFrom", "kind": 12, @@ -237,31 +237,31 @@ Path Array. "kind": 12, "tags": [], "detail": "(array<'a>, ('a, 'a) => Ordering.t) => unit", - "documentation": {"kind": "markdown", "value": "\n`sort(array, comparator)` sorts `array` in-place using the `comparator` function.\n\nBeware this will *mutate* the array.\n\nSee [`Array.sort`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) on MDN.\n\n## Examples\n\n```rescript\nlet array = [3, 2, 1]\narray->Array.sort((a, b) => float(a - b))\narray->assertEqual([1, 2, 3])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`sort(array, comparator)` sorts `array` in-place using the `comparator` function.\n\nBeware this will *mutate* the array.\n\nSee [`Array.sort`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) on MDN.\n\n## Examples\n\n```rescript\nlet array = [3, 2, 1]\narray->Array.sort((a, b) => float(a - b))\narray == [1, 2, 3]\n```\n"} }, { "label": "length", "kind": 12, "tags": [], "detail": "array<'a> => int", - "documentation": {"kind": "markdown", "value": "\n`length(array)` returns the length of (i.e. number of items in) the array.\n\nSee [`Array.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length) on MDN.\n\n## Examples\n\n```rescript\nlet someArray = [\"hi\", \"hello\"]\n\nsomeArray\n->Array.length\n->assertEqual(2)\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`length(array)` returns the length of (i.e. number of items in) the array.\n\nSee [`Array.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length) on MDN.\n\n## Examples\n\n```rescript\nlet someArray = [\"hi\", \"hello\"]\n\nsomeArray->Array.length == 2\n```\n"} }, { "label": "every", "kind": 12, "tags": [], "detail": "(array<'a>, 'a => bool) => bool", - "documentation": {"kind": "markdown", "value": "\n`every(array, predicate)` returns true if `predicate` returns true for all items in `array`.\n\nSee [`Array.every`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every) on MDN.\n\n## Examples\n\n```rescript\nlet array = [1, 2, 3, 4]\n\narray\n->Array.every(num => num <= 4)\n->assertEqual(true)\n\narray\n->Array.every(num => num === 1)\n->assertEqual(false)\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`every(array, predicate)` returns true if `predicate` returns true for all items in `array`.\n\nSee [`Array.every`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every) on MDN.\n\n## Examples\n\n```rescript\nlet array = [1, 2, 3, 4]\n\narray->Array.every(num => num <= 4) == true\n\narray->Array.every(num => num === 1) == false\n```\n"} }, { "label": "flat", "kind": 12, "tags": [], "detail": "array> => array<'a>", - "documentation": {"kind": "markdown", "value": "\n`flat(arrays)` concatenates an array of arrays into a single array.\n\nSee [`Array.flat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat) on MDN.\n\n## Examples\n\n```rescript\n[[1], [2], [3, 4]]\n->Array.flat\n->assertEqual([1, 2, 3, 4])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`flat(arrays)` concatenates an array of arrays into a single array.\n\nSee [`Array.flat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat) on MDN.\n\n## Examples\n\n```rescript\n[[1], [2], [3, 4]]->Array.flat == [1, 2, 3, 4]\n```\n"} }, { "label": "map", "kind": 12, "tags": [], "detail": "(array<'a>, 'a => 'b) => array<'b>", - "documentation": {"kind": "markdown", "value": "\n`map(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray = array->Array.map(greeting => greeting ++ \" to you\")\n\nassertEqual(mappedArray, [\"Hello to you\", \"Hi to you\", \"Good bye to you\"])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`map(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray = array->Array.map(greeting => greeting ++ \" to you\")\n\nmappedArray == [\"Hello to you\", \"Hi to you\", \"Good bye to you\"]\n```\n"} }, { "label": "with", "kind": 12, @@ -279,7 +279,7 @@ Path Array. "kind": 12, "tags": [], "detail": "array<'a> => array<'a>", - "documentation": {"kind": "markdown", "value": "\n`toReversed(array)` creates a new array with all items from `array` in reversed order.\n\nSee [`Array.toReversed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed) on MDN.\n\n## Examples\n\n```rescript\nlet someArray = [\"hi\", \"hello\"]\nlet reversed = someArray->Array.toReversed\n\nreversed->assertEqual([\"hello\", \"hi\"])\nsomeArray->assertEqual([\"hi\", \"hello\"]) // Original unchanged\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`toReversed(array)` creates a new array with all items from `array` in reversed order.\n\nSee [`Array.toReversed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed) on MDN.\n\n## Examples\n\n```rescript\nlet someArray = [\"hi\", \"hello\"]\nlet reversed = someArray->Array.toReversed\n\nreversed == [\"hello\", \"hi\"]\nsomeArray == [\"hi\", \"hello\"] // Original unchanged\n```\n"} }, { "label": "copyWithin", "kind": 12, @@ -291,37 +291,37 @@ Path Array. "kind": 12, "tags": [], "detail": "array<'a> => string", - "documentation": {"kind": "markdown", "value": "\n`toString(array)` stringifies `array` by running `toString` on all of the array elements and joining them with \",\".\n\nSee [`Array.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString) on MDN.\n\n## Examples\n\n```rescript\n[1, 2, 3, 4]\n->Array.toString\n->assertEqual(\"1,2,3,4\")\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`toString(array)` stringifies `array` by running `toString` on all of the array elements and joining them with \",\".\n\nSee [`Array.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString) on MDN.\n\n## Examples\n\n```rescript\n[1, 2, 3, 4]->Array.toString == \"1,2,3,4\"\n```\n"} }, { "label": "everyWithIndex", "kind": 12, "tags": [], "detail": "(array<'a>, ('a, int) => bool) => bool", - "documentation": {"kind": "markdown", "value": "\n`everyWithIndex(array, checker)` returns true if all items in `array` returns true when running the provided `checker` function.\n\nSee [`Array.every`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every) on MDN.\n\n## Examples\n\n```rescript\nlet array = [1, 2, 3, 4]\n\narray\n->Array.everyWithIndex((num, index) => index < 5 && num <= 4)\n->assertEqual(true)\n\narray\n->Array.everyWithIndex((num, index) => index < 2 && num >= 2)\n->assertEqual(false)\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`everyWithIndex(array, checker)` returns true if all items in `array` returns true when running the provided `checker` function.\n\nSee [`Array.every`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every) on MDN.\n\n## Examples\n\n```rescript\nlet array = [1, 2, 3, 4]\n\narray->Array.everyWithIndex((num, index) => index < 5 && num <= 4) == true\n\narray->Array.everyWithIndex((num, index) => index < 2 && num >= 2) == false\n```\n"} }, { "label": "fill", "kind": 12, "tags": [], "detail": "(array<'a>, 'a, ~start: int, ~end: int) => unit", - "documentation": {"kind": "markdown", "value": "\n`fill(array, value, ~start, ~end)` fills `array` with `value` from `start` to `end`.\n\nBeware this will *mutate* the array.\n\nSee [`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill) on MDN.\n\n## Examples\n\n```rescript\nlet myArray = [1, 2, 3, 4]\n\nmyArray->Array.fill(9, ~start=1, ~end=3)\n\nmyArray->assertEqual([1, 9, 9, 4])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`fill(array, value, ~start, ~end)` fills `array` with `value` from `start` to `end`.\n\nBeware this will *mutate* the array.\n\nSee [`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill) on MDN.\n\n## Examples\n\n```rescript\nlet myArray = [1, 2, 3, 4]\n\nmyArray->Array.fill(9, ~start=1, ~end=3)\n\nmyArray == [1, 9, 9, 4]\n```\n"} }, { "label": "findWithIndex", "kind": 12, "tags": [], "detail": "(array<'a>, ('a, int) => bool) => option<'a>", - "documentation": {"kind": "markdown", "value": "\n`findWithIndex(array, checker)` returns the first element of `array` where the provided `checker` function returns true.\n\nSee [`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) on MDN.\n\n## Examples\n\n```rescript\ntype languages = ReScript | TypeScript | JavaScript\n\nlet array = [TypeScript, JavaScript, ReScript]\n\narray\n->Array.findWithIndex((item, index) => index > 1 && item == ReScript)\n->assertEqual(Some(ReScript))\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`findWithIndex(array, checker)` returns the first element of `array` where the provided `checker` function returns true.\n\nSee [`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) on MDN.\n\n## Examples\n\n```rescript\ntype languages = ReScript | TypeScript | JavaScript\n\nlet array = [TypeScript, JavaScript, ReScript]\n\narray->Array.findWithIndex((item, index) => index > 1 && item == ReScript) == Some(ReScript)\n```\n"} }, { "label": "reverse", "kind": 12, "tags": [], "detail": "array<'a> => unit", - "documentation": {"kind": "markdown", "value": "\n`reverse(array)` reverses the order of the items in `array`.\n\nBeware this will *mutate* the array.\n\nSee [`Array.reverse`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse) on MDN.\n\n## Examples\n\n```rescript\nlet someArray = [\"hi\", \"hello\"]\nsomeArray->Array.reverse\n\nsomeArray->assertEqual([\"hello\", \"hi\"])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`reverse(array)` reverses the order of the items in `array`.\n\nBeware this will *mutate* the array.\n\nSee [`Array.reverse`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse) on MDN.\n\n## Examples\n\n```rescript\nlet someArray = [\"hi\", \"hello\"]\nsomeArray->Array.reverse\n\nsomeArray == [\"hello\", \"hi\"]\n```\n"} }, { "label": "findLastIndexWithIndex", "kind": 12, "tags": [], "detail": "(array<'a>, ('a, int) => bool) => int", - "documentation": {"kind": "markdown", "value": "\n`findLastIndexWithIndex(array, checker)` returns the index of the last element of `array` where the provided `checker` function returns true.\n\nReturns `-1` if the item does not exist. Consider using `Array.findLastIndexOpt` if you want an option instead (where `-1` would be `None`).\n\nSee [`Array.findLastIndex`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex) on MDN.\n\n## Examples\n\n```rescript\ntype languages = ReScript | TypeScript | JavaScript\n\nlet array = [ReScript, JavaScript, JavaScript, ReScript]\n\nlet isReScriptLast = array->Array.findLastIndexWithIndex((item, index) => index === 3 && item == ReScript)\nlet isTypeScriptLast = array->Array.findLastIndexWithIndex((item, index) => index === 3 && item == TypeScript)\n\nassertEqual(isReScriptLast, 3)\nassertEqual(isTypeScriptLast, -1)\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`findLastIndexWithIndex(array, checker)` returns the index of the last element of `array` where the provided `checker` function returns true.\n\nReturns `-1` if the item does not exist. Consider using `Array.findLastIndexOpt` if you want an option instead (where `-1` would be `None`).\n\nSee [`Array.findLastIndex`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex) on MDN.\n\n## Examples\n\n```rescript\ntype languages = ReScript | TypeScript | JavaScript\n\nlet array = [ReScript, JavaScript, JavaScript, ReScript]\n\nlet isReScriptLast =\n array->Array.findLastIndexWithIndex((item, index) => index === 3 && item == ReScript)\nlet isTypeScriptLast =\n array->Array.findLastIndexWithIndex((item, index) => index === 3 && item == TypeScript)\n\nisReScriptLast == 3\nisTypeScriptLast == -1\n```\n"} }, { "label": "getUnsafe", "kind": 12, @@ -333,13 +333,13 @@ Path Array. "kind": 12, "tags": [], "detail": "array<'a> => Iterator.t<(int, 'a)>", - "documentation": {"kind": "markdown", "value": "\n`entries(array)` returns a new array iterator object that contains the key/value pairs for each index in the array.\n\nSee [Array.prototype.entries](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries) on MDN.\n\n## Examples\n\n```rescript\nlet array = [5, 6, 7]\nlet iterator : Iterator.t<(int, int)> = array->Array.entries\niterator->Iterator.next->assertEqual({done: false, value: Some((0, 5))})\niterator->Iterator.next->assertEqual({done: false, value: Some((1, 6))})\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`entries(array)` returns a new array iterator object that contains the key/value pairs for each index in the array.\n\nSee [Array.prototype.entries](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries) on MDN.\n\n## Examples\n\n```rescript\nlet array = [5, 6, 7]\nlet iterator: Iterator.t<(int, int)> = array->Array.entries\niterator->Iterator.next == {done: false, value: Some((0, 5))}\niterator->Iterator.next == {done: false, value: Some((1, 6))}\n```\n"} }, { "label": "unshiftMany", "kind": 12, "tags": [], "detail": "(array<'a>, array<'a>) => unit", - "documentation": {"kind": "markdown", "value": "\n`unshiftMany(array, itemsArray)` inserts many new items to the start of the array.\n\nBeware this will *mutate* the array.\n\nSee [`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift) on MDN.\n\n## Examples\n\n```rescript\nlet someArray = [\"hi\", \"hello\"]\nsomeArray->Array.unshiftMany([\"yay\", \"wehoo\"])\nsomeArray->assertEqual([\"yay\", \"wehoo\", \"hi\", \"hello\"])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`unshiftMany(array, itemsArray)` inserts many new items to the start of the array.\n\nBeware this will *mutate* the array.\n\nSee [`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift) on MDN.\n\n## Examples\n\n```rescript\nlet someArray = [\"hi\", \"hello\"]\nsomeArray->Array.unshiftMany([\"yay\", \"wehoo\"])\nsomeArray == [\"yay\", \"wehoo\", \"hi\", \"hello\"]\n```\n"} }, { "label": "lastIndexOf", "kind": 12, @@ -351,7 +351,7 @@ Path Array. "kind": 12, "tags": [], "detail": "(array<'a>, 'a => bool) => array<'a>", - "documentation": {"kind": "markdown", "value": "\n`filter(array, checker)` returns a new array containing all elements from `array` for which the provided `checker` function returns true.\n\nSee [`Array.filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) on MDN.\n\n## Examples\n\n```rescript\n[1, 2, 3, 4]\n->Array.filter(num => num > 2)\n->assertEqual([3, 4])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`filter(array, checker)` returns a new array containing all elements from `array` for which the provided `checker` function returns true.\n\nSee [`Array.filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) on MDN.\n\n## Examples\n\n```rescript\n[1, 2, 3, 4]->Array.filter(num => num > 2) == [3, 4]\n```\n"} }, { "label": "compare", "kind": 12, @@ -363,13 +363,13 @@ Path Array. "kind": 12, "tags": [], "detail": "(array, string) => string", - "documentation": {"kind": "markdown", "value": "\n`join(array, separator)` produces a string where all items of `array` are printed, separated by `separator`. Array items must be strings, to join number or other arrays, use `joinUnsafe`. Under the hood this will run JavaScript's `toString` on all the array items.\n\nSee [Array.join](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)\n\n## Examples\n\n```rescript\n[\"One\", \"Two\", \"Three\"]\n->Array.join(\" -- \")\n->assertEqual(\"One -- Two -- Three\")\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`join(array, separator)` produces a string where all items of `array` are printed, separated by `separator`. Array items must be strings, to join number or other arrays, use `joinUnsafe`. Under the hood this will run JavaScript's `toString` on all the array items.\n\nSee [Array.join](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)\n\n## Examples\n\n```rescript\n[\"One\", \"Two\", \"Three\"]->Array.join(\" -- \") == \"One -- Two -- Three\"\n```\n"} }, { "label": "last", "kind": 12, "tags": [], "detail": "array<'a> => option<'a>", - "documentation": {"kind": "markdown", "value": "\n`last(array)` returns the last element of `array`.\n\nReturns `None` if the array is empty.\n\n## Examples\n\n```rescript\n[\"Hello\", \"Hi\", \"Good bye\"]\n->Array.last\n->assertEqual(Some(\"Good bye\"))\n\n[]\n->Array.last\n->assertEqual(None)\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`last(array)` returns the last element of `array`.\n\nReturns `None` if the array is empty.\n\n## Examples\n\n```rescript\n[\"Hello\", \"Hi\", \"Good bye\"]->Array.last == Some(\"Good bye\")\n\n[]->Array.last == None\n```\n"} }, { "label": "ignore", "kind": 12, @@ -387,13 +387,13 @@ Path Array. "kind": 12, "tags": [], "detail": "array<'a> => Iterator.t<'a>", - "documentation": {"kind": "markdown", "value": "\n`values(array)` returns a new array iterator object that contains the values for each index in the array.\n\nSee [Array.prototype.values](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values) on MDN.\n\n## Examples\n\n```rescript\nlet array = [5, 6, 7]\nlet iterator : Iterator.t = array->Array.values\niterator->Iterator.next->assertEqual({done: false, value: Some(5)})\niterator->Iterator.next->assertEqual({done: false, value: Some(6)})\n```\n "} + "documentation": {"kind": "markdown", "value": "\n`values(array)` returns a new array iterator object that contains the values for each index in the array.\n\nSee [Array.prototype.values](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values) on MDN.\n\n## Examples\n\n```rescript\nlet array = [5, 6, 7]\nlet iterator: Iterator.t = array->Array.values\niterator->Iterator.next == {done: false, value: Some(5)}\niterator->Iterator.next == {done: false, value: Some(6)}\n```\n "} }, { "label": "indexOfOpt", "kind": 12, "tags": [], "detail": "(array<'a>, 'a) => option", - "documentation": {"kind": "markdown", "value": "\n`indexOfOpt(array, item)` returns an option of the index of the provided `item` in `array`. Uses [strict check for equality](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality) when comparing items.\n\nSee [`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf) on MDN.\n\n## Examples\n\n```rescript\n[1, 2]->Array.indexOfOpt(2)->assertEqual(Some(1))\n[1, 2]->Array.indexOfOpt(3)->assertEqual(None)\n[{\"language\": \"ReScript\"}]\n->Array.indexOfOpt({\"language\": \"ReScript\"})\n->assertEqual(None) // None, because of strict equality\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`indexOfOpt(array, item)` returns an option of the index of the provided `item` in `array`. Uses [strict check for equality](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality) when comparing items.\n\nSee [`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf) on MDN.\n\n## Examples\n\n```rescript\n[1, 2]->Array.indexOfOpt(2) == Some(1)\n[1, 2]->Array.indexOfOpt(3) == None\n[{\"language\": \"ReScript\"}]->Array.indexOfOpt({\"language\": \"ReScript\"}) == None // None, because of strict equality\n```\n"} }, { "label": "forEachWithIndex", "kind": 12, @@ -405,13 +405,13 @@ Path Array. "kind": 12, "tags": [], "detail": "(array<'a>, 'b, ('b, 'a) => 'b) => 'b", - "documentation": {"kind": "markdown", "value": "\n`reduce(xs, init, fn)`\n\nApplies `fn` to each element of `xs` from beginning to end. Function `fn` has two parameters: the item from the list and an “accumulator”; which starts with a value of `init`. `reduce` returns the final value of the accumulator.\n\n## Examples\n\n```rescript\nArray.reduce([2, 3, 4], 1, (a, b) => a + b)->assertEqual(10)\n\nArray.reduce([\"a\", \"b\", \"c\", \"d\"], \"\", (a, b) => a ++ b)->assertEqual(\"abcd\")\n\n[1, 2, 3]\n->Array.reduce(list{}, List.add)\n->assertEqual(list{3, 2, 1})\n\nArray.reduce([], list{}, List.add)->assertEqual(list{})\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`reduce(xs, init, fn)`\n\nApplies `fn` to each element of `xs` from beginning to end. Function `fn` has two parameters: the item from the list and an “accumulator”; which starts with a value of `init`. `reduce` returns the final value of the accumulator.\n\n## Examples\n\n```rescript\nArray.reduce([2, 3, 4], 1, (a, b) => a + b) == 10\n\nArray.reduce([\"a\", \"b\", \"c\", \"d\"], \"\", (a, b) => a ++ b) == \"abcd\"\n\n[1, 2, 3]->Array.reduce(list{}, List.add) == list{3, 2, 1}\n\nArray.reduce([], list{}, List.add) == list{}\n```\n"} }, { "label": "sliceToEnd", "kind": 12, "tags": [], "detail": "(array<'a>, ~start: int) => array<'a>", - "documentation": {"kind": "markdown", "value": "\n`sliceToEnd(array, start)` creates a new array from `array`, with all items from `array` starting from `start`.\n\nSee [`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice) on MDN.\n\n## Examples\n\n```rescript\n[1, 2, 3, 4]\n->Array.sliceToEnd(~start=1)\n->assertEqual([2, 3, 4])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`sliceToEnd(array, start)` creates a new array from `array`, with all items from `array` starting from `start`.\n\nSee [`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice) on MDN.\n\n## Examples\n\n```rescript\n[1, 2, 3, 4]->Array.sliceToEnd(~start=1) == [2, 3, 4]\n```\n"} }, { "label": "fromArrayLikeWithMap", "kind": 12, @@ -423,25 +423,25 @@ Path Array. "kind": 12, "tags": [], "detail": "(array<'a>, 'a) => unit", - "documentation": {"kind": "markdown", "value": "\n`fillAll(array, value)` fills the entire `array` with `value`.\n\nBeware this will *mutate* the array.\n\nSee [`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill) on MDN.\n\n## Examples\n\n```rescript\nlet myArray = [1, 2, 3, 4]\nmyArray->Array.fillAll(9)\nmyArray->assertEqual([9, 9, 9, 9])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`fillAll(array, value)` fills the entire `array` with `value`.\n\nBeware this will *mutate* the array.\n\nSee [`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill) on MDN.\n\n## Examples\n\n```rescript\nlet myArray = [1, 2, 3, 4]\nmyArray->Array.fillAll(9)\nmyArray == [9, 9, 9, 9]\n```\n"} }, { "label": "set", "kind": 12, "tags": [], "detail": "(array<'a>, int, 'a) => unit", - "documentation": {"kind": "markdown", "value": "\n`set(array, index, item)` sets the provided `item` at `index` of `array`.\n\nBeware this will *mutate* the array.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\narray->Array.set(1, \"Hello\")\n\narray[1]->assertEqual(Some(\"Hello\"))\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`set(array, index, item)` sets the provided `item` at `index` of `array`.\n\nBeware this will *mutate* the array.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\narray->Array.set(1, \"Hello\")\n\narray[1] == Some(\"Hello\")\n```\n"} }, { "label": "filterWithIndex", "kind": 12, "tags": [], "detail": "(array<'a>, ('a, int) => bool) => array<'a>", - "documentation": {"kind": "markdown", "value": "\n`filterWithIndex(array, checker)` returns a new array containing all elements from `array` for which the provided `checker` function returns true.\n\nSee [`Array.filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) on MDN.\n\n## Examples\n\n```rescript\n[1, 2, 3, 4]\n->Array.filterWithIndex((num, index) => index === 0 || num === 2)\n->assertEqual([1, 2])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`filterWithIndex(array, checker)` returns a new array containing all elements from `array` for which the provided `checker` function returns true.\n\nSee [`Array.filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) on MDN.\n\n## Examples\n\n```rescript\n[1, 2, 3, 4]->Array.filterWithIndex((num, index) => index === 0 || num === 2) == [1, 2]\n```\n"} }, { "label": "findIndex", "kind": 12, "tags": [], "detail": "(array<'a>, 'a => bool) => int", - "documentation": {"kind": "markdown", "value": "\n`findIndex(array, checker)` returns the index of the first element of `array` where the provided `checker` function returns true.\n\nReturns `-1` if the item does not exist. Consider using `Array.findIndexOpt` if you want an option instead (where `-1` would be `None`).\n\nSee [`Array.findIndex`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex) on MDN.\n\n## Examples\n\n```rescript\ntype languages = ReScript | TypeScript | JavaScript\n\nlet array = [ReScript, JavaScript]\n\narray\n->Array.findIndex(item => item == ReScript)\n->assertEqual(0)\n\narray->Array.findIndex(item => item == TypeScript)\n->assertEqual(-1)\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`findIndex(array, checker)` returns the index of the first element of `array` where the provided `checker` function returns true.\n\nReturns `-1` if the item does not exist. Consider using `Array.findIndexOpt` if you want an option instead (where `-1` would be `None`).\n\nSee [`Array.findIndex`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex) on MDN.\n\n## Examples\n\n```rescript\ntype languages = ReScript | TypeScript | JavaScript\n\nlet array = [ReScript, JavaScript]\n\narray->Array.findIndex(item => item == ReScript) == 0\n\narray->Array.findIndex(item => item == TypeScript) == -1\n```\n"} }, { "label": "setSymbol", "kind": 12, @@ -459,19 +459,19 @@ Path Array. "kind": 12, "tags": [], "detail": "(array<'a>, string) => string", - "documentation": {"kind": "markdown", "value": "\n`joinUnsafe(array, separator)` produces a string where all items of `array` are printed, separated by `separator`. Under the hood this will run JavaScript's `toString` on all the array items.\n\nSee [Array.join](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)\n\n## Examples\n\n```rescript\n[1, 2, 3]\n->Array.joinUnsafe(\" -- \")\n->assertEqual(\"1 -- 2 -- 3\")\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`joinUnsafe(array, separator)` produces a string where all items of `array` are printed, separated by `separator`. Under the hood this will run JavaScript's `toString` on all the array items.\n\nSee [Array.join](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)\n\n## Examples\n\n```rescript\n[1, 2, 3]->Array.joinUnsafe(\" -- \") == \"1 -- 2 -- 3\"\n```\n"} }, { "label": "mapWithIndex", "kind": 12, "tags": [], "detail": "(array<'a>, ('a, int) => 'b) => array<'b>", - "documentation": {"kind": "markdown", "value": "\n`mapWithIndex(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray =\n array->Array.mapWithIndex((greeting, index) =>\n greeting ++ \" at position \" ++ Int.toString(index)\n )\n\nassertEqual(mappedArray, [\"Hello at position 0\", \"Hi at position 1\", \"Good bye at position 2\"])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`mapWithIndex(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray =\n array->Array.mapWithIndex((greeting, index) => greeting ++ \" at position \" ++ Int.toString(index))\n\nmappedArray == [\"Hello at position 0\", \"Hi at position 1\", \"Good bye at position 2\"]\n```\n"} }, { "label": "flatMapWithIndex", "kind": 12, "tags": [], "detail": "(array<'a>, ('a, int) => array<'b>) => array<'b>", - "documentation": {"kind": "markdown", "value": "\n`flatMapWithIndex(array, mapper)` returns a new array concatenating the arrays returned from running `mapper` on all items in `array`.\n\n## Examples\n\n```rescript\ntype language = ReScript | TypeScript | JavaScript\n\nlet array = [ReScript, TypeScript, JavaScript]\n\n\narray\n->Array.flatMapWithIndex((item, index) =>\n switch item {\n | ReScript => [index]\n | TypeScript => [index, index + 1]\n | JavaScript => [index, index + 1, index + 2]\n }\n)\n->assertEqual([0, 1, 2, 2, 3, 4])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`flatMapWithIndex(array, mapper)` returns a new array concatenating the arrays returned from running `mapper` on all items in `array`.\n\n## Examples\n\n```rescript\ntype language = ReScript | TypeScript | JavaScript\n\nlet array = [ReScript, TypeScript, JavaScript]\n\narray->Array.flatMapWithIndex((item, index) =>\n switch item {\n | ReScript => [index]\n | TypeScript => [index, index + 1]\n | JavaScript => [index, index + 1, index + 2]\n }\n) == [0, 1, 2, 2, 3, 4]\n```\n"} }, { "label": "copyWithinToEnd", "kind": 12, @@ -483,37 +483,37 @@ Path Array. "kind": 12, "tags": [], "detail": "(array<'a>, 'a) => unit", - "documentation": {"kind": "markdown", "value": "\n`unshift(array, item)` inserts a new item at the start of the array.\n\nBeware this will *mutate* the array.\n\nSee [`Array.unshift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift) on MDN.\n\n## Examples\n\n```rescript\nlet someArray = [\"hi\", \"hello\"]\nsomeArray->Array.unshift(\"yay\")\nsomeArray->assertEqual([\"yay\", \"hi\", \"hello\"])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`unshift(array, item)` inserts a new item at the start of the array.\n\nBeware this will *mutate* the array.\n\nSee [`Array.unshift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift) on MDN.\n\n## Examples\n\n```rescript\nlet someArray = [\"hi\", \"hello\"]\nsomeArray->Array.unshift(\"yay\")\nsomeArray == [\"yay\", \"hi\", \"hello\"]\n```\n"} }, { "label": "indexOf", "kind": 12, "tags": [], "detail": "(array<'a>, 'a) => int", - "documentation": {"kind": "markdown", "value": "\n`indexOf(array, item)` returns the index of the provided `item` in `array`. Uses [strict check for equality](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality) when comparing items.\n\nReturns `-1` if the item doesn not exist. Check out `Array.indexOfOpt` for a version that returns `None` instead of `-1` if the item does not exist.\n\nSee [`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf) on MDN.\n\n## Examples\n\n```rescript\n[1, 2]->Array.indexOf(2)->assertEqual(1)\n[1, 2]->Array.indexOf(3)->assertEqual(-1)\n\n[{\"language\": \"ReScript\"}]\n->Array.indexOf({\"language\": \"ReScript\"})\n->assertEqual(-1) // -1, because of strict equality\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`indexOf(array, item)` returns the index of the provided `item` in `array`. Uses [strict check for equality](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality) when comparing items.\n\nReturns `-1` if the item doesn not exist. Check out `Array.indexOfOpt` for a version that returns `None` instead of `-1` if the item does not exist.\n\nSee [`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf) on MDN.\n\n## Examples\n\n```rescript\n[1, 2]->Array.indexOf(2) == 1\n[1, 2]->Array.indexOf(3) == -1\n\n[{\"language\": \"ReScript\"}]->Array.indexOf({\"language\": \"ReScript\"}) == -1 // -1, because of strict equality\n```\n"} }, { "label": "push", "kind": 12, "tags": [], "detail": "(array<'a>, 'a) => unit", - "documentation": {"kind": "markdown", "value": "\n`push(array, item)` appends `item` to the end of `array`.\n\nBeware this will *mutate* the array.\n\nSee [`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push) on MDN.\n\n## Examples\n\n```rescript\nlet someArray = [\"hi\", \"hello\"]\n\nsomeArray->Array.push(\"yay\")\n\nsomeArray->assertEqual([\"hi\", \"hello\", \"yay\"])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`push(array, item)` appends `item` to the end of `array`.\n\nBeware this will *mutate* the array.\n\nSee [`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push) on MDN.\n\n## Examples\n\n```rescript\nlet someArray = [\"hi\", \"hello\"]\n\nsomeArray->Array.push(\"yay\")\n\nsomeArray == [\"hi\", \"hello\", \"yay\"]\n```\n"} }, { "label": "toSorted", "kind": 12, "tags": [], "detail": "(array<'a>, ('a, 'a) => Ordering.t) => array<'a>", - "documentation": {"kind": "markdown", "value": "\n`toSorted(array, comparator)` returns a new, sorted array from `array`, using the `comparator` function.\n\nSee [`Array.toSorted`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted) on MDN.\n\n## Examples\n\n```rescript\nlet someArray = [3, 2, 1]\n\nsomeArray\n->Array.toSorted(Int.compare)\n->assertEqual([1, 2, 3])\n\nsomeArray->assertEqual([3, 2, 1]) // Original unchanged\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`toSorted(array, comparator)` returns a new, sorted array from `array`, using the `comparator` function.\n\nSee [`Array.toSorted`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted) on MDN.\n\n## Examples\n\n```rescript\nlet someArray = [3, 2, 1]\n\nsomeArray->Array.toSorted(Int.compare) == [1, 2, 3]\n\nsomeArray == [3, 2, 1] // Original unchanged\n```\n"} }, { "label": "reduceWithIndex", "kind": 12, "tags": [], "detail": "(array<'a>, 'b, ('b, 'a, int) => 'b) => 'b", - "documentation": {"kind": "markdown", "value": "\n`reduceWithIndex(x, init, fn)`\n\nApplies `fn` to each element of `xs` from beginning to end. Function `fn` has three parameters: the item from the array and an “accumulator”, which starts with a value of `init` and the index of each element. `reduceWithIndex` returns the final value of the accumulator.\n\n## Examples\n\n```rescript\nArray.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i)->assertEqual(16)\n\nArray.reduceWithIndex([1, 2, 3], list{}, (acc, v, i) => list{v + i, ...acc})->assertEqual(list{5, 3, 1})\n\nArray.reduceWithIndex([], list{}, (acc, v, i) => list{v + i, ...acc})->assertEqual(list{})\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`reduceWithIndex(x, init, fn)`\n\nApplies `fn` to each element of `xs` from beginning to end. Function `fn` has three parameters: the item from the array and an “accumulator”, which starts with a value of `init` and the index of each element. `reduceWithIndex` returns the final value of the accumulator.\n\n## Examples\n\n```rescript\nArray.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16\n\nArray.reduceWithIndex([1, 2, 3], list{}, (acc, v, i) => list{v + i, ...acc}) == list{5, 3, 1}\n\nArray.reduceWithIndex([], list{}, (acc, v, i) => list{v + i, ...acc}) == list{}\n```\n"} }, { "label": "some", "kind": 12, "tags": [], "detail": "(array<'a>, 'a => bool) => bool", - "documentation": {"kind": "markdown", "value": "\n`some(array, predicate)` returns true if `predicate` returns true for any element in `array`.\n\nSee [`Array.some`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\n\narray\n->Array.some(greeting => greeting === \"Hello\")\n->assertEqual(true)\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`some(array, predicate)` returns true if `predicate` returns true for any element in `array`.\n\nSee [`Array.some`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\n\narray->Array.some(greeting => greeting === \"Hello\") == true\n```\n"} }, { "label": "unsafe_get", "kind": 12, @@ -531,49 +531,49 @@ Path Array. "kind": 12, "tags": [], "detail": "array> => array<'a>", - "documentation": {"kind": "markdown", "value": "\n`keepSome(arr)`\n\nReturns a new array containing `value` for all elements that are `Some(value)`\nand ignoring every value that is `None`\n\n## Examples\n\n```rescript\nArray.keepSome([Some(1), None, Some(3)])->assertEqual([1, 3])\n\nArray.keepSome([Some(1), Some(2), Some(3)])->assertEqual([1, 2, 3])\n\nArray.keepSome([None, None, None])->assertEqual([])\n\nArray.keepSome([])->assertEqual([])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`keepSome(arr)`\n\nReturns a new array containing `value` for all elements that are `Some(value)`\nand ignoring every value that is `None`\n\n## Examples\n\n```rescript\nArray.keepSome([Some(1), None, Some(3)]) == [1, 3]\n\nArray.keepSome([Some(1), Some(2), Some(3)]) == [1, 2, 3]\n\nArray.keepSome([None, None, None]) == []\n\nArray.keepSome([]) == []\n```\n"} }, { "label": "at", "kind": 12, "tags": [], "detail": "(array<'a>, int) => option<'a>", - "documentation": {"kind": "markdown", "value": "\n`at(array, index)`\n\nGet an element by its index. Negative indices count backwards from the last item.\n\n## Examples\n\n```rescript\n[\"a\", \"b\", \"c\"]->Array.at(0)->assertEqual(Some(\"a\"))\n[\"a\", \"b\", \"c\"]->Array.at(2)->assertEqual(Some(\"c\"))\n[\"a\", \"b\", \"c\"]->Array.at(3)->assertEqual(None)\n[\"a\", \"b\", \"c\"]->Array.at(-1)->assertEqual(Some(\"c\"))\n[\"a\", \"b\", \"c\"]->Array.at(-3)->assertEqual(Some(\"a\"))\n[\"a\", \"b\", \"c\"]->Array.at(-4)->assertEqual(None)\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`at(array, index)`\n\nGet an element by its index. Negative indices count backwards from the last item.\n\n## Examples\n\n```rescript\n[\"a\", \"b\", \"c\"]->Array.at(0) == Some(\"a\")\n[\"a\", \"b\", \"c\"]->Array.at(2) == Some(\"c\")\n[\"a\", \"b\", \"c\"]->Array.at(3) == None\n[\"a\", \"b\", \"c\"]->Array.at(-1) == Some(\"c\")\n[\"a\", \"b\", \"c\"]->Array.at(-3) == Some(\"a\")\n[\"a\", \"b\", \"c\"]->Array.at(-4) == None\n```\n"} }, { "label": "pop", "kind": 12, "tags": [], "detail": "array<'a> => option<'a>", - "documentation": {"kind": "markdown", "value": "\n`pop(array)` removes the last item from `array` and returns it.\n\nBeware this will *mutate* the array.\n\nSee [`Array.pop`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop) on MDN.\n\n## Examples\n\n```rescript\nlet someArray = [\"hi\", \"hello\"]\n\nsomeArray\n->Array.pop\n->assertEqual(Some(\"hello\"))\n\nsomeArray->assertEqual([\"hi\"]) // Notice last item is gone.\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`pop(array)` removes the last item from `array` and returns it.\n\nBeware this will *mutate* the array.\n\nSee [`Array.pop`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop) on MDN.\n\n## Examples\n\n```rescript\nlet someArray = [\"hi\", \"hello\"]\n\nsomeArray->Array.pop == Some(\"hello\")\n\nsomeArray == [\"hi\"] // Notice last item is gone.\n```\n"} }, { "label": "get", "kind": 12, "tags": [], "detail": "(array<'a>, int) => option<'a>", - "documentation": {"kind": "markdown", "value": "\n`get(array, index)` returns the element at `index` of `array`.\n\nReturns `None` if the index does not exist in the array. Equivalent to doing `array[index]` in JavaScript.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\n\narray\n->Array.get(0)\n->assertEqual(Some(\"Hello\"))\n\narray\n->Array.get(3)\n->assertEqual(None)\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`get(array, index)` returns the element at `index` of `array`.\n\nReturns `None` if the index does not exist in the array. Equivalent to doing `array[index]` in JavaScript.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\n\narray->Array.get(0) == Some(\"Hello\")\n\narray->Array.get(3) == None\n```\n"} }, { "label": "removeInPlace", "kind": 12, "tags": [], "detail": "(array<'a>, int) => unit", - "documentation": {"kind": "markdown", "value": "\n`removeInPlace(array, index)` removes the item at the specified `index` from `array`.\n\nBeware this will *mutate* the array.\n\n## Examples\n\n```rescript\nlet array = []\narray->Array.removeInPlace(0)\nassertEqual(array, []) // Removing from an empty array does nothing\n\nlet array2 = [\"Hello\", \"Hi\", \"Good bye\"]\narray2->Array.removeInPlace(1)\nassertEqual(array2, [\"Hello\", \"Good bye\"]) // Removes the item at index 1\n```\n "} + "documentation": {"kind": "markdown", "value": "\n`removeInPlace(array, index)` removes the item at the specified `index` from `array`.\n\nBeware this will *mutate* the array.\n\n## Examples\n\n```rescript\nlet array = []\narray->Array.removeInPlace(0)\narray == [] // Removing from an empty array does nothing\n\nlet array2 = [\"Hello\", \"Hi\", \"Good bye\"]\narray2->Array.removeInPlace(1)\narray2 == [\"Hello\", \"Good bye\"] // Removes the item at index 1\n```\n "} }, { "label": "findLastIndexOpt", "kind": 12, "tags": [], "detail": "(array<'a>, 'a => bool) => option", - "documentation": {"kind": "markdown", "value": "\n`findIndexOpt(array, checker)` returns the index of the last element of `array` where the provided `checker` function returns true.\n\nReturns `None` if no item matches.\n\nSee [`Array.findLastIndex`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"hello\", \"world\", \"!\"]\n\narray\n->Array.findLastIndexOpt(item => item->String.includes(\"o\"))\n->assertEqual(Some(1))\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`findIndexOpt(array, checker)` returns the index of the last element of `array` where the provided `checker` function returns true.\n\nReturns `None` if no item matches.\n\nSee [`Array.findLastIndex`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"hello\", \"world\", \"!\"]\n\narray->Array.findLastIndexOpt(item => item->String.includes(\"o\")) == Some(1)\n```\n"} }, { "label": "pushMany", "kind": 12, "tags": [], "detail": "(array<'a>, array<'a>) => unit", - "documentation": {"kind": "markdown", "value": "\n`pushMany(array, itemsArray)` appends many new items to the end of the array.\n\nBeware this will *mutate* the array.\n\nSee [`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push) on MDN.\n\n## Examples\n\n```rescript\nlet someArray = [\"hi\", \"hello\"]\n\nsomeArray->Array.pushMany([\"yay\", \"wehoo\"])\nsomeArray->assertEqual([\"hi\", \"hello\", \"yay\", \"wehoo\"])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`pushMany(array, itemsArray)` appends many new items to the end of the array.\n\nBeware this will *mutate* the array.\n\nSee [`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push) on MDN.\n\n## Examples\n\n```rescript\nlet someArray = [\"hi\", \"hello\"]\n\nsomeArray->Array.pushMany([\"yay\", \"wehoo\"])\nsomeArray == [\"hi\", \"hello\", \"yay\", \"wehoo\"]\n```\n"} }, { "label": "fromIterator", "kind": 12, "tags": [], "detail": "Iterator.t<'a> => array<'a>", - "documentation": {"kind": "markdown", "value": "\n`fromIterator(iterator)` creates an array from the provided `iterator`\n\n## Examples\n\n```rescript\nMap.fromArray([(\"foo\", 1), (\"bar\", 2)])\n->Map.values\n->Array.fromIterator\n->assertEqual([1, 2])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`fromIterator(iterator)` creates an array from the provided `iterator`\n\n## Examples\n\n```rescript\nMap.fromArray([(\"foo\", 1), (\"bar\", 2)])\n->Map.values\n->Array.fromIterator == [1, 2]\n```\n"} }, { "label": "forEach", "kind": 12, @@ -585,7 +585,7 @@ Path Array. "kind": 12, "tags": [], "detail": "(array<'a>, 'a => array<'b>) => array<'b>", - "documentation": {"kind": "markdown", "value": "\n`flatMap(array, mapper)` returns a new array concatenating the arrays returned from running `mapper` on all items in `array`.\n\n## Examples\n\n```rescript\ntype language = ReScript | TypeScript | JavaScript\n\nlet array = [ReScript, TypeScript, JavaScript]\n\narray\n->Array.flatMap(item =>\n switch item {\n | ReScript => [1, 2, 3]\n | TypeScript => [4, 5, 6]\n | JavaScript => [7, 8, 9]\n }\n)\n->assertEqual([1, 2, 3, 4, 5, 6, 7, 8, 9])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`flatMap(array, mapper)` returns a new array concatenating the arrays returned from running `mapper` on all items in `array`.\n\n## Examples\n\n```rescript\ntype language = ReScript | TypeScript | JavaScript\n\nlet array = [ReScript, TypeScript, JavaScript]\n\narray->Array.flatMap(item =>\n switch item {\n | ReScript => [1, 2, 3]\n | TypeScript => [4, 5, 6]\n | JavaScript => [7, 8, 9]\n }\n) == [1, 2, 3, 4, 5, 6, 7, 8, 9]\n```\n"} }, { "label": "fromArrayLike", "kind": 12, @@ -613,19 +613,19 @@ Path Array.m "kind": 12, "tags": [], "detail": "(~length: int, 'a) => array<'a>", - "documentation": {"kind": "markdown", "value": "\n`make(~length, init)` creates an array of length `length` initialized with the value of `init`.\n\n## Examples\n\n```rescript\nArray.make(~length=3, #apple)->assertEqual([#apple, #apple, #apple])\nArray.make(~length=6, 7)->assertEqual([7, 7, 7, 7, 7, 7])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`make(~length, init)` creates an array of length `length` initialized with the value of `init`.\n\n## Examples\n\n```rescript\nArray.make(~length=3, #apple) == [#apple, #apple, #apple]\nArray.make(~length=6, 7) == [7, 7, 7, 7, 7, 7]\n```\n"} }, { "label": "map", "kind": 12, "tags": [], "detail": "(array<'a>, 'a => 'b) => array<'b>", - "documentation": {"kind": "markdown", "value": "\n`map(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray = array->Array.map(greeting => greeting ++ \" to you\")\n\nassertEqual(mappedArray, [\"Hello to you\", \"Hi to you\", \"Good bye to you\"])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`map(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray = array->Array.map(greeting => greeting ++ \" to you\")\n\nmappedArray == [\"Hello to you\", \"Hi to you\", \"Good bye to you\"]\n```\n"} }, { "label": "mapWithIndex", "kind": 12, "tags": [], "detail": "(array<'a>, ('a, int) => 'b) => array<'b>", - "documentation": {"kind": "markdown", "value": "\n`mapWithIndex(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray =\n array->Array.mapWithIndex((greeting, index) =>\n greeting ++ \" at position \" ++ Int.toString(index)\n )\n\nassertEqual(mappedArray, [\"Hello at position 0\", \"Hi at position 1\", \"Good bye at position 2\"])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`mapWithIndex(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray =\n array->Array.mapWithIndex((greeting, index) => greeting ++ \" at position \" ++ Int.toString(index))\n\nmappedArray == [\"Hello at position 0\", \"Hi at position 1\", \"Good bye at position 2\"]\n```\n"} }] Complete src/Completion.res 15:17 @@ -682,13 +682,13 @@ Path m "kind": 12, "tags": [], "detail": "(array<'a>, 'a => 'b) => array<'b>", - "documentation": {"kind": "markdown", "value": "\n`map(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray = array->Array.map(greeting => greeting ++ \" to you\")\n\nassertEqual(mappedArray, [\"Hello to you\", \"Hi to you\", \"Good bye to you\"])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`map(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray = array->Array.map(greeting => greeting ++ \" to you\")\n\nmappedArray == [\"Hello to you\", \"Hi to you\", \"Good bye to you\"]\n```\n"} }, { "label": "Array.mapWithIndex", "kind": 12, "tags": [], "detail": "(array<'a>, ('a, int) => 'b) => array<'b>", - "documentation": {"kind": "markdown", "value": "\n`mapWithIndex(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray =\n array->Array.mapWithIndex((greeting, index) =>\n greeting ++ \" at position \" ++ Int.toString(index)\n )\n\nassertEqual(mappedArray, [\"Hello at position 0\", \"Hi at position 1\", \"Good bye at position 2\"])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`mapWithIndex(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray =\n array->Array.mapWithIndex((greeting, index) => greeting ++ \" at position \" ++ Int.toString(index))\n\nmappedArray == [\"Hello at position 0\", \"Hi at position 1\", \"Good bye at position 2\"]\n```\n"} }] Complete src/Completion.res 29:13 @@ -1999,6 +1999,16 @@ Path Res "modulePath": "RescriptTools_Docgen", "filePath": "src/Completion.res" } + }, { + "label": "RescriptTools_ExtractCodeBlocks", + "kind": 9, + "tags": [], + "detail": "module RescriptTools_ExtractCodeBlocks", + "documentation": null, + "data": { + "modulePath": "RescriptTools_ExtractCodeBlocks", + "filePath": "src/Completion.res" + } }] Complete src/Completion.res 346:57 @@ -2290,13 +2300,13 @@ Path ma "kind": 12, "tags": [], "detail": "(array<'a>, 'a => 'b) => array<'b>", - "documentation": {"kind": "markdown", "value": "\n`map(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray = array->Array.map(greeting => greeting ++ \" to you\")\n\nassertEqual(mappedArray, [\"Hello to you\", \"Hi to you\", \"Good bye to you\"])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`map(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray = array->Array.map(greeting => greeting ++ \" to you\")\n\nmappedArray == [\"Hello to you\", \"Hi to you\", \"Good bye to you\"]\n```\n"} }, { "label": "Array.mapWithIndex", "kind": 12, "tags": [], "detail": "(array<'a>, ('a, int) => 'b) => array<'b>", - "documentation": {"kind": "markdown", "value": "\n`mapWithIndex(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray =\n array->Array.mapWithIndex((greeting, index) =>\n greeting ++ \" at position \" ++ Int.toString(index)\n )\n\nassertEqual(mappedArray, [\"Hello at position 0\", \"Hi at position 1\", \"Good bye at position 2\"])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`mapWithIndex(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray =\n array->Array.mapWithIndex((greeting, index) => greeting ++ \" at position \" ++ Int.toString(index))\n\nmappedArray == [\"Hello at position 0\", \"Hi at position 1\", \"Good bye at position 2\"]\n```\n"} }] Complete src/Completion.res 399:14 @@ -2461,13 +2471,13 @@ Path t "kind": 12, "tags": [1], "detail": "(int, ~digits: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toPrecision` instead\n\n\n`toPrecisionWithPrecision(n, ~digits)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecisionWithPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecisionWithPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\nImplementations are allowed to support larger and smaller values as well.\nECMA-262 only requires a precision of up to 21 significant digits.\n\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: Use `toPrecision` instead\n\n\n`toPrecisionWithPrecision(n, ~digits)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecisionWithPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecisionWithPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\n Implementations are allowed to support larger and smaller values as well.\n ECMA-262 only requires a precision of up to 21 significant digits.\n \n"} }, { "label": "Int.toPrecision", "kind": 12, "tags": [], "detail": "(int, ~digits: int=?) => string", - "documentation": {"kind": "markdown", "value": "\n`toPrecision(n, ~digits=?)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecision(100) // \"100\"\nInt.toPrecision(1) // \"1\"\nInt.toPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\nImplementations are allowed to support larger and smaller values as well.\nECMA-262 only requires a precision of up to 21 significant digits.\n"} + "documentation": {"kind": "markdown", "value": "\n`toPrecision(n, ~digits=?)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecision(100) // \"100\"\nInt.toPrecision(1) // \"1\"\nInt.toPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\n Implementations are allowed to support larger and smaller values as well.\n ECMA-262 only requires a precision of up to 21 significant digits.\n"} }, { "label": "Int.toString", "kind": 12, @@ -2539,13 +2549,13 @@ Path t "kind": 12, "tags": [1], "detail": "(float, ~digits: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toPrecision` instead\n\n\n`toPrecisionWithPrecision(v, ~digits)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits.\nSee [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nFloat.toPrecisionWithPrecision(100.0, ~digits=2) == \"1.0e+2\"\nFloat.toPrecisionWithPrecision(1.0, ~digits=1) == \"1\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\nImplementations are allowed to support larger and smaller values as well.\nECMA-262 only requires a precision of up to 21 significant digits.\n\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: Use `toPrecision` instead\n\n\n`toPrecisionWithPrecision(v, ~digits)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits.\nSee [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nFloat.toPrecisionWithPrecision(100.0, ~digits=2) == \"1.0e+2\"\nFloat.toPrecisionWithPrecision(1.0, ~digits=1) == \"1\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\n Implementations are allowed to support larger and smaller values as well.\n ECMA-262 only requires a precision of up to 21 significant digits.\n \n"} }, { "label": "Float.toPrecision", "kind": 12, "tags": [], "detail": "(float, ~digits: int=?) => string", - "documentation": {"kind": "markdown", "value": "\n`toPrecision(v, ~digits=?)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits.\nSee [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nFloat.toPrecision(100.0) == \"100\"\nFloat.toPrecision(1.0) == \"1\"\nFloat.toPrecision(100.0, ~digits=2) == \"1.0e+2\"\nFloat.toPrecision(1.0, ~digits=1) == \"1\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\nImplementations are allowed to support larger and smaller values as well.\nECMA-262 only requires a precision of up to 21 significant digits.\n"} + "documentation": {"kind": "markdown", "value": "\n`toPrecision(v, ~digits=?)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits.\nSee [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nFloat.toPrecision(100.0) == \"100\"\nFloat.toPrecision(1.0) == \"1\"\nFloat.toPrecision(100.0, ~digits=2) == \"1.0e+2\"\nFloat.toPrecision(1.0, ~digits=1) == \"1\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\n Implementations are allowed to support larger and smaller values as well.\n ECMA-262 only requires a precision of up to 21 significant digits.\n"} }, { "label": "Float.toString", "kind": 12, @@ -2588,13 +2598,13 @@ Path g "kind": 12, "tags": [1], "detail": "result<'a, 'b> => 'a", - "documentation": {"kind": "markdown", "value": "Deprecated: Use 'getOrThrow' instead\n\n\n `getExn(res)`: when `res` is `Ok(n)`, returns `n` when `res` is `Error(m)`, raise an exception\n\n ```res example\n Result.getExn(Result.Ok(42)) == 42\n\n switch Result.getExn(Error(\"Invalid data\")) {\n | exception Not_found => assert(true)\n | _ => assert(false)\n }\n ```\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: Use 'getOrThrow' instead\n\n\n `getExn(res)`: when `res` is `Ok(n)`, returns `n` when `res` is `Error(m)`, raise an exception\n\n ```res example\n Result.getExn(Result.Ok(42)) == 42\n \n switch Result.getExn(Error(\"Invalid data\")) {\n | exception Not_found => assert(true)\n | _ => assert(false)\n }\n ```\n"} }, { "label": "Result.getOrThrow", "kind": 12, "tags": [], "detail": "result<'a, 'b> => 'a", - "documentation": {"kind": "markdown", "value": "\n `getOrThrow(res)`: when `res` is `Ok(n)`, returns `n` when `res` is `Error(m)`, raise an exception\n\n ```res example\n Result.getOrThrow(Result.Ok(42)) == 42\n\n switch Result.getOrThrow(Error(\"Invalid data\")) {\n | exception Not_found => assert(true)\n | _ => assert(false)\n }\n ```\n"} + "documentation": {"kind": "markdown", "value": "\n `getOrThrow(res)`: when `res` is `Ok(n)`, returns `n` when `res` is `Error(m)`, raise an exception\n\n ```res example\n Result.getOrThrow(Result.Ok(42)) == 42\n \n switch Result.getOrThrow(Error(\"Invalid data\")) {\n | exception Not_found => assert(true)\n | _ => assert(false)\n }\n ```\n"} }, { "label": "Result.getOr", "kind": 12, diff --git a/tests/analysis_tests/tests/src/expected/CompletionExpressions.res.txt b/tests/analysis_tests/tests/src/expected/CompletionExpressions.res.txt index 663e00678c..ddd83b7e52 100644 --- a/tests/analysis_tests/tests/src/expected/CompletionExpressions.res.txt +++ b/tests/analysis_tests/tests/src/expected/CompletionExpressions.res.txt @@ -832,7 +832,7 @@ Path fnTakingCallback "kind": 12, "tags": [], "detail": "('a, 'a) => unit", - "documentation": {"kind": "markdown", "value": "\n`assertEqual(a, b)` check if `a` is equal `b`. If not raise a panic exception\n\n## Examples\n\n```rescript\nlist{1, 2}\n->List.tailExn\n->assertEqual(list{2})\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`assertEqual(a, b)` check if `a` is equal `b`. If not raise a panic exception\n\n## Examples\n\n```rescript\nlist{1, 2}->List.tailExn == list{2}\n```\n"} }] Complete src/CompletionExpressions.res 165:22 diff --git a/tests/analysis_tests/tests/src/expected/CompletionInferValues.res.txt b/tests/analysis_tests/tests/src/expected/CompletionInferValues.res.txt index d9fe7877f9..dc885d8485 100644 --- a/tests/analysis_tests/tests/src/expected/CompletionInferValues.res.txt +++ b/tests/analysis_tests/tests/src/expected/CompletionInferValues.res.txt @@ -34,13 +34,13 @@ Path t "kind": 12, "tags": [1], "detail": "(int, ~digits: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toPrecision` instead\n\n\n`toPrecisionWithPrecision(n, ~digits)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecisionWithPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecisionWithPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\nImplementations are allowed to support larger and smaller values as well.\nECMA-262 only requires a precision of up to 21 significant digits.\n\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: Use `toPrecision` instead\n\n\n`toPrecisionWithPrecision(n, ~digits)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecisionWithPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecisionWithPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\n Implementations are allowed to support larger and smaller values as well.\n ECMA-262 only requires a precision of up to 21 significant digits.\n \n"} }, { "label": "Int.toPrecision", "kind": 12, "tags": [], "detail": "(int, ~digits: int=?) => string", - "documentation": {"kind": "markdown", "value": "\n`toPrecision(n, ~digits=?)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecision(100) // \"100\"\nInt.toPrecision(1) // \"1\"\nInt.toPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\nImplementations are allowed to support larger and smaller values as well.\nECMA-262 only requires a precision of up to 21 significant digits.\n"} + "documentation": {"kind": "markdown", "value": "\n`toPrecision(n, ~digits=?)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecision(100) // \"100\"\nInt.toPrecision(1) // \"1\"\nInt.toPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\n Implementations are allowed to support larger and smaller values as well.\n ECMA-262 only requires a precision of up to 21 significant digits.\n"} }, { "label": "Int.toString", "kind": 12, @@ -352,13 +352,13 @@ Path t "kind": 12, "tags": [1], "detail": "(int, ~digits: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toPrecision` instead\n\n\n`toPrecisionWithPrecision(n, ~digits)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecisionWithPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecisionWithPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\nImplementations are allowed to support larger and smaller values as well.\nECMA-262 only requires a precision of up to 21 significant digits.\n\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: Use `toPrecision` instead\n\n\n`toPrecisionWithPrecision(n, ~digits)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecisionWithPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecisionWithPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\n Implementations are allowed to support larger and smaller values as well.\n ECMA-262 only requires a precision of up to 21 significant digits.\n \n"} }, { "label": "Int.toPrecision", "kind": 12, "tags": [], "detail": "(int, ~digits: int=?) => string", - "documentation": {"kind": "markdown", "value": "\n`toPrecision(n, ~digits=?)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecision(100) // \"100\"\nInt.toPrecision(1) // \"1\"\nInt.toPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\nImplementations are allowed to support larger and smaller values as well.\nECMA-262 only requires a precision of up to 21 significant digits.\n"} + "documentation": {"kind": "markdown", "value": "\n`toPrecision(n, ~digits=?)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecision(100) // \"100\"\nInt.toPrecision(1) // \"1\"\nInt.toPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\n Implementations are allowed to support larger and smaller values as well.\n ECMA-262 only requires a precision of up to 21 significant digits.\n"} }, { "label": "Int.toString", "kind": 12, @@ -431,13 +431,13 @@ Path ma "kind": 12, "tags": [], "detail": "(array<'a>, 'a => 'b) => array<'b>", - "documentation": {"kind": "markdown", "value": "\n`map(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray = array->Array.map(greeting => greeting ++ \" to you\")\n\nassertEqual(mappedArray, [\"Hello to you\", \"Hi to you\", \"Good bye to you\"])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`map(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray = array->Array.map(greeting => greeting ++ \" to you\")\n\nmappedArray == [\"Hello to you\", \"Hi to you\", \"Good bye to you\"]\n```\n"} }, { "label": "Array.mapWithIndex", "kind": 12, "tags": [], "detail": "(array<'a>, ('a, int) => 'b) => array<'b>", - "documentation": {"kind": "markdown", "value": "\n`mapWithIndex(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray =\n array->Array.mapWithIndex((greeting, index) =>\n greeting ++ \" at position \" ++ Int.toString(index)\n )\n\nassertEqual(mappedArray, [\"Hello at position 0\", \"Hi at position 1\", \"Good bye at position 2\"])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`mapWithIndex(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray =\n array->Array.mapWithIndex((greeting, index) => greeting ++ \" at position \" ++ Int.toString(index))\n\nmappedArray == [\"Hello at position 0\", \"Hi at position 1\", \"Good bye at position 2\"]\n```\n"} }] Complete src/CompletionInferValues.res 75:78 @@ -571,13 +571,13 @@ Path slic "kind": 12, "tags": [], "detail": "(string, ~start: int, ~end: int) => string", - "documentation": {"kind": "markdown", "value": "\n`slice(str, ~start, ~end)` returns the substring of `str` starting at\ncharacter `start` up to but not including `end`.\n- If either `start` or `end` is negative, then it is evaluated as\n`length(str - start)` or `length(str - end)`.\n- If `end` is greater than the length of `str`, then it is treated as\n`length(str)`.\n- If `start` is greater than `end`, slice returns the empty string.\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n## Examples\n\n```rescript\nString.slice(\"abcdefg\", ~start=2, ~end=5) == \"cde\"\nString.slice(\"abcdefg\", ~start=2, ~end=9) == \"cdefg\"\nString.slice(\"abcdefg\", ~start=-4, ~end=-2) == \"de\"\nString.slice(\"abcdefg\", ~start=5, ~end=1) == \"\"\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`slice(str, ~start, ~end)` returns the substring of `str` starting at\ncharacter `start` up to but not including `end`.\n- If either `start` or `end` is negative, then it is evaluated as\n `length(str - start)` or `length(str - end)`.\n- If `end` is greater than the length of `str`, then it is treated as\n `length(str)`.\n- If `start` is greater than `end`, slice returns the empty string.\n See [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n## Examples\n\n```rescript\nString.slice(\"abcdefg\", ~start=2, ~end=5) == \"cde\"\nString.slice(\"abcdefg\", ~start=2, ~end=9) == \"cdefg\"\nString.slice(\"abcdefg\", ~start=-4, ~end=-2) == \"de\"\nString.slice(\"abcdefg\", ~start=5, ~end=1) == \"\"\n```\n"} }, { "label": "String.sliceToEnd", "kind": 12, "tags": [], "detail": "(string, ~start: int) => string", - "documentation": {"kind": "markdown", "value": "\n`sliceToEnd(str, ~start)` returns the substring of `str` starting at character\n`start` to the end of the string.\n- If `start` is negative, then it is evaluated as `length(str - start)`.\n- If `start` is greater than the length of `str`, then sliceToEnd returns the empty string.\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n## Examples\n\n```rescript\nString.sliceToEnd(\"abcdefg\", ~start=4) == \"efg\"\nString.sliceToEnd(\"abcdefg\", ~start=-2) == \"fg\"\nString.sliceToEnd(\"abcdefg\", ~start=7) == \"\"\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`sliceToEnd(str, ~start)` returns the substring of `str` starting at character\n`start` to the end of the string.\n- If `start` is negative, then it is evaluated as `length(str - start)`.\n- If `start` is greater than the length of `str`, then sliceToEnd returns the empty string.\n See [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n## Examples\n\n```rescript\nString.sliceToEnd(\"abcdefg\", ~start=4) == \"efg\"\nString.sliceToEnd(\"abcdefg\", ~start=-2) == \"fg\"\nString.sliceToEnd(\"abcdefg\", ~start=7) == \"\"\n```\n"} }] Complete src/CompletionInferValues.res 91:82 @@ -694,13 +694,13 @@ Path slic "kind": 12, "tags": [], "detail": "(string, ~start: int, ~end: int) => string", - "documentation": {"kind": "markdown", "value": "\n`slice(str, ~start, ~end)` returns the substring of `str` starting at\ncharacter `start` up to but not including `end`.\n- If either `start` or `end` is negative, then it is evaluated as\n`length(str - start)` or `length(str - end)`.\n- If `end` is greater than the length of `str`, then it is treated as\n`length(str)`.\n- If `start` is greater than `end`, slice returns the empty string.\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n## Examples\n\n```rescript\nString.slice(\"abcdefg\", ~start=2, ~end=5) == \"cde\"\nString.slice(\"abcdefg\", ~start=2, ~end=9) == \"cdefg\"\nString.slice(\"abcdefg\", ~start=-4, ~end=-2) == \"de\"\nString.slice(\"abcdefg\", ~start=5, ~end=1) == \"\"\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`slice(str, ~start, ~end)` returns the substring of `str` starting at\ncharacter `start` up to but not including `end`.\n- If either `start` or `end` is negative, then it is evaluated as\n `length(str - start)` or `length(str - end)`.\n- If `end` is greater than the length of `str`, then it is treated as\n `length(str)`.\n- If `start` is greater than `end`, slice returns the empty string.\n See [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n## Examples\n\n```rescript\nString.slice(\"abcdefg\", ~start=2, ~end=5) == \"cde\"\nString.slice(\"abcdefg\", ~start=2, ~end=9) == \"cdefg\"\nString.slice(\"abcdefg\", ~start=-4, ~end=-2) == \"de\"\nString.slice(\"abcdefg\", ~start=5, ~end=1) == \"\"\n```\n"} }, { "label": "String.sliceToEnd", "kind": 12, "tags": [], "detail": "(string, ~start: int) => string", - "documentation": {"kind": "markdown", "value": "\n`sliceToEnd(str, ~start)` returns the substring of `str` starting at character\n`start` to the end of the string.\n- If `start` is negative, then it is evaluated as `length(str - start)`.\n- If `start` is greater than the length of `str`, then sliceToEnd returns the empty string.\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n## Examples\n\n```rescript\nString.sliceToEnd(\"abcdefg\", ~start=4) == \"efg\"\nString.sliceToEnd(\"abcdefg\", ~start=-2) == \"fg\"\nString.sliceToEnd(\"abcdefg\", ~start=7) == \"\"\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`sliceToEnd(str, ~start)` returns the substring of `str` starting at character\n`start` to the end of the string.\n- If `start` is negative, then it is evaluated as `length(str - start)`.\n- If `start` is greater than the length of `str`, then sliceToEnd returns the empty string.\n See [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n## Examples\n\n```rescript\nString.sliceToEnd(\"abcdefg\", ~start=4) == \"efg\"\nString.sliceToEnd(\"abcdefg\", ~start=-2) == \"fg\"\nString.sliceToEnd(\"abcdefg\", ~start=7) == \"\"\n```\n"} }] Complete src/CompletionInferValues.res 107:89 @@ -723,13 +723,13 @@ Path slic "kind": 12, "tags": [], "detail": "(string, ~start: int, ~end: int) => string", - "documentation": {"kind": "markdown", "value": "\n`slice(str, ~start, ~end)` returns the substring of `str` starting at\ncharacter `start` up to but not including `end`.\n- If either `start` or `end` is negative, then it is evaluated as\n`length(str - start)` or `length(str - end)`.\n- If `end` is greater than the length of `str`, then it is treated as\n`length(str)`.\n- If `start` is greater than `end`, slice returns the empty string.\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n## Examples\n\n```rescript\nString.slice(\"abcdefg\", ~start=2, ~end=5) == \"cde\"\nString.slice(\"abcdefg\", ~start=2, ~end=9) == \"cdefg\"\nString.slice(\"abcdefg\", ~start=-4, ~end=-2) == \"de\"\nString.slice(\"abcdefg\", ~start=5, ~end=1) == \"\"\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`slice(str, ~start, ~end)` returns the substring of `str` starting at\ncharacter `start` up to but not including `end`.\n- If either `start` or `end` is negative, then it is evaluated as\n `length(str - start)` or `length(str - end)`.\n- If `end` is greater than the length of `str`, then it is treated as\n `length(str)`.\n- If `start` is greater than `end`, slice returns the empty string.\n See [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n## Examples\n\n```rescript\nString.slice(\"abcdefg\", ~start=2, ~end=5) == \"cde\"\nString.slice(\"abcdefg\", ~start=2, ~end=9) == \"cdefg\"\nString.slice(\"abcdefg\", ~start=-4, ~end=-2) == \"de\"\nString.slice(\"abcdefg\", ~start=5, ~end=1) == \"\"\n```\n"} }, { "label": "String.sliceToEnd", "kind": 12, "tags": [], "detail": "(string, ~start: int) => string", - "documentation": {"kind": "markdown", "value": "\n`sliceToEnd(str, ~start)` returns the substring of `str` starting at character\n`start` to the end of the string.\n- If `start` is negative, then it is evaluated as `length(str - start)`.\n- If `start` is greater than the length of `str`, then sliceToEnd returns the empty string.\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n## Examples\n\n```rescript\nString.sliceToEnd(\"abcdefg\", ~start=4) == \"efg\"\nString.sliceToEnd(\"abcdefg\", ~start=-2) == \"fg\"\nString.sliceToEnd(\"abcdefg\", ~start=7) == \"\"\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`sliceToEnd(str, ~start)` returns the substring of `str` starting at character\n`start` to the end of the string.\n- If `start` is negative, then it is evaluated as `length(str - start)`.\n- If `start` is greater than the length of `str`, then sliceToEnd returns the empty string.\n See [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n## Examples\n\n```rescript\nString.sliceToEnd(\"abcdefg\", ~start=4) == \"efg\"\nString.sliceToEnd(\"abcdefg\", ~start=-2) == \"fg\"\nString.sliceToEnd(\"abcdefg\", ~start=7) == \"\"\n```\n"} }] Complete src/CompletionInferValues.res 111:80 @@ -752,13 +752,13 @@ Path slic "kind": 12, "tags": [], "detail": "(string, ~start: int, ~end: int) => string", - "documentation": {"kind": "markdown", "value": "\n`slice(str, ~start, ~end)` returns the substring of `str` starting at\ncharacter `start` up to but not including `end`.\n- If either `start` or `end` is negative, then it is evaluated as\n`length(str - start)` or `length(str - end)`.\n- If `end` is greater than the length of `str`, then it is treated as\n`length(str)`.\n- If `start` is greater than `end`, slice returns the empty string.\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n## Examples\n\n```rescript\nString.slice(\"abcdefg\", ~start=2, ~end=5) == \"cde\"\nString.slice(\"abcdefg\", ~start=2, ~end=9) == \"cdefg\"\nString.slice(\"abcdefg\", ~start=-4, ~end=-2) == \"de\"\nString.slice(\"abcdefg\", ~start=5, ~end=1) == \"\"\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`slice(str, ~start, ~end)` returns the substring of `str` starting at\ncharacter `start` up to but not including `end`.\n- If either `start` or `end` is negative, then it is evaluated as\n `length(str - start)` or `length(str - end)`.\n- If `end` is greater than the length of `str`, then it is treated as\n `length(str)`.\n- If `start` is greater than `end`, slice returns the empty string.\n See [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n## Examples\n\n```rescript\nString.slice(\"abcdefg\", ~start=2, ~end=5) == \"cde\"\nString.slice(\"abcdefg\", ~start=2, ~end=9) == \"cdefg\"\nString.slice(\"abcdefg\", ~start=-4, ~end=-2) == \"de\"\nString.slice(\"abcdefg\", ~start=5, ~end=1) == \"\"\n```\n"} }, { "label": "String.sliceToEnd", "kind": 12, "tags": [], "detail": "(string, ~start: int) => string", - "documentation": {"kind": "markdown", "value": "\n`sliceToEnd(str, ~start)` returns the substring of `str` starting at character\n`start` to the end of the string.\n- If `start` is negative, then it is evaluated as `length(str - start)`.\n- If `start` is greater than the length of `str`, then sliceToEnd returns the empty string.\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n## Examples\n\n```rescript\nString.sliceToEnd(\"abcdefg\", ~start=4) == \"efg\"\nString.sliceToEnd(\"abcdefg\", ~start=-2) == \"fg\"\nString.sliceToEnd(\"abcdefg\", ~start=7) == \"\"\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`sliceToEnd(str, ~start)` returns the substring of `str` starting at character\n`start` to the end of the string.\n- If `start` is negative, then it is evaluated as `length(str - start)`.\n- If `start` is greater than the length of `str`, then sliceToEnd returns the empty string.\n See [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n## Examples\n\n```rescript\nString.sliceToEnd(\"abcdefg\", ~start=4) == \"efg\"\nString.sliceToEnd(\"abcdefg\", ~start=-2) == \"fg\"\nString.sliceToEnd(\"abcdefg\", ~start=7) == \"\"\n```\n"} }] Complete src/CompletionInferValues.res 115:53 diff --git a/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt b/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt index f19e643299..42b929877b 100644 --- a/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt +++ b/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt @@ -231,7 +231,7 @@ Path "kind": 12, "tags": [], "detail": "(~min: int=?, ~max: int=?, int) => int", - "documentation": {"kind": "markdown", "value": "\n`clamp(~min=?, ~max=?, value)` returns `value`, optionally bounded by `min` and `max`.\n\nif `max` < `min` returns `min`.\n\n## Examples\n\n```rescript\nInt.clamp(42) == 42\nInt.clamp(42, ~min=50) == 50\nInt.clamp(42, ~max=40) == 40\nInt.clamp(42, ~min=50, ~max=40) == 50\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`clamp(~min=?, ~max=?, value)` returns `value`, optionally bounded by `min` and `max`.\n\nif `max` \\< `min` returns `min`.\n\n## Examples\n\n```rescript\nInt.clamp(42) == 42\nInt.clamp(42, ~min=50) == 50\nInt.clamp(42, ~max=40) == 40\nInt.clamp(42, ~min=50, ~max=40) == 50\n```\n"} }, { "label": "Int.toFixedWithPrecision", "kind": 12, @@ -243,7 +243,7 @@ Path "kind": 12, "tags": [1], "detail": "(int, ~digits: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toPrecision` instead\n\n\n`toPrecisionWithPrecision(n, ~digits)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecisionWithPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecisionWithPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\nImplementations are allowed to support larger and smaller values as well.\nECMA-262 only requires a precision of up to 21 significant digits.\n\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: Use `toPrecision` instead\n\n\n`toPrecisionWithPrecision(n, ~digits)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecisionWithPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecisionWithPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\n Implementations are allowed to support larger and smaller values as well.\n ECMA-262 only requires a precision of up to 21 significant digits.\n \n"} }, { "label": "Int.bitwiseAnd", "kind": 12, @@ -279,7 +279,7 @@ Path "kind": 12, "tags": [], "detail": "(int, ~digits: int=?) => string", - "documentation": {"kind": "markdown", "value": "\n`toPrecision(n, ~digits=?)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecision(100) // \"100\"\nInt.toPrecision(1) // \"1\"\nInt.toPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\nImplementations are allowed to support larger and smaller values as well.\nECMA-262 only requires a precision of up to 21 significant digits.\n"} + "documentation": {"kind": "markdown", "value": "\n`toPrecision(n, ~digits=?)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecision(100) // \"100\"\nInt.toPrecision(1) // \"1\"\nInt.toPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\n Implementations are allowed to support larger and smaller values as well.\n ECMA-262 only requires a precision of up to 21 significant digits.\n"} }, { "label": "Int.range", "kind": 12, @@ -401,7 +401,7 @@ Path "kind": 12, "tags": [], "detail": "(~min: int=?, ~max: int=?, int) => int", - "documentation": {"kind": "markdown", "value": "\n`clamp(~min=?, ~max=?, value)` returns `value`, optionally bounded by `min` and `max`.\n\nif `max` < `min` returns `min`.\n\n## Examples\n\n```rescript\nInt.clamp(42) == 42\nInt.clamp(42, ~min=50) == 50\nInt.clamp(42, ~max=40) == 40\nInt.clamp(42, ~min=50, ~max=40) == 50\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`clamp(~min=?, ~max=?, value)` returns `value`, optionally bounded by `min` and `max`.\n\nif `max` \\< `min` returns `min`.\n\n## Examples\n\n```rescript\nInt.clamp(42) == 42\nInt.clamp(42, ~min=50) == 50\nInt.clamp(42, ~max=40) == 40\nInt.clamp(42, ~min=50, ~max=40) == 50\n```\n"} }, { "label": "Int.toFixedWithPrecision", "kind": 12, @@ -413,7 +413,7 @@ Path "kind": 12, "tags": [1], "detail": "(int, ~digits: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toPrecision` instead\n\n\n`toPrecisionWithPrecision(n, ~digits)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecisionWithPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecisionWithPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\nImplementations are allowed to support larger and smaller values as well.\nECMA-262 only requires a precision of up to 21 significant digits.\n\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: Use `toPrecision` instead\n\n\n`toPrecisionWithPrecision(n, ~digits)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecisionWithPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecisionWithPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\n Implementations are allowed to support larger and smaller values as well.\n ECMA-262 only requires a precision of up to 21 significant digits.\n \n"} }, { "label": "Int.bitwiseAnd", "kind": 12, @@ -449,7 +449,7 @@ Path "kind": 12, "tags": [], "detail": "(int, ~digits: int=?) => string", - "documentation": {"kind": "markdown", "value": "\n`toPrecision(n, ~digits=?)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecision(100) // \"100\"\nInt.toPrecision(1) // \"1\"\nInt.toPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\nImplementations are allowed to support larger and smaller values as well.\nECMA-262 only requires a precision of up to 21 significant digits.\n"} + "documentation": {"kind": "markdown", "value": "\n`toPrecision(n, ~digits=?)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecision(100) // \"100\"\nInt.toPrecision(1) // \"1\"\nInt.toPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\n Implementations are allowed to support larger and smaller values as well.\n ECMA-262 only requires a precision of up to 21 significant digits.\n"} }, { "label": "Int.range", "kind": 12, @@ -549,7 +549,7 @@ Path a "kind": 12, "tags": [], "detail": "(array<'a>, int) => option<'a>", - "documentation": {"kind": "markdown", "value": "\n`at(array, index)`\n\nGet an element by its index. Negative indices count backwards from the last item.\n\n## Examples\n\n```rescript\n[\"a\", \"b\", \"c\"]->Array.at(0)->assertEqual(Some(\"a\"))\n[\"a\", \"b\", \"c\"]->Array.at(2)->assertEqual(Some(\"c\"))\n[\"a\", \"b\", \"c\"]->Array.at(3)->assertEqual(None)\n[\"a\", \"b\", \"c\"]->Array.at(-1)->assertEqual(Some(\"c\"))\n[\"a\", \"b\", \"c\"]->Array.at(-3)->assertEqual(Some(\"a\"))\n[\"a\", \"b\", \"c\"]->Array.at(-4)->assertEqual(None)\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`at(array, index)`\n\nGet an element by its index. Negative indices count backwards from the last item.\n\n## Examples\n\n```rescript\n[\"a\", \"b\", \"c\"]->Array.at(0) == Some(\"a\")\n[\"a\", \"b\", \"c\"]->Array.at(2) == Some(\"c\")\n[\"a\", \"b\", \"c\"]->Array.at(3) == None\n[\"a\", \"b\", \"c\"]->Array.at(-1) == Some(\"c\")\n[\"a\", \"b\", \"c\"]->Array.at(-3) == Some(\"a\")\n[\"a\", \"b\", \"c\"]->Array.at(-4) == None\n```\n"} }] Complete src/CompletionJsx.res 30:12 @@ -790,7 +790,7 @@ Path s "kind": 12, "tags": [], "detail": "(string, RegExp.t) => option", - "documentation": {"kind": "markdown", "value": "\n`searchOpt(str, regexp)`. Like `search`, but return an `option`.\n\n## Examples\n\n```rescript\nString.searchOpt(\"testing 1 2 3\", %re(\"/\\d+/\")) == Some(8)\nString.searchOpt(\"no numbers\", %re(\"/\\d+/\")) == None\n```\n"}, + "documentation": {"kind": "markdown", "value": "\n`searchOpt(str, regexp)`. Like `search`, but return an `option`.\n\n## Examples\n\n```rescript\nString.searchOpt(\"testing 1 2 3\", /\\d+/) == Some(8)\nString.searchOpt(\"no numbers\", /\\d+/) == None\n```\n"}, "sortText": "searchOpt", "insertText": "->String.searchOpt", "additionalTextEdits": [{ @@ -802,7 +802,7 @@ Path s "kind": 12, "tags": [], "detail": "(string, RegExp.t, ~limit: int) => array>", - "documentation": {"kind": "markdown", "value": "\n`splitByRegExpAtMost(str, regexp, ~limit)` splits the given `str` at every\noccurrence of `regexp` and returns an array of the first `limit` resulting\nsubstrings. If `limit` is negative or greater than the number of substrings, the\narray will contain all the substrings.\nSee [`String.split`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split) on MDN.\n\n## Examples\n\n```rescript\nString.splitByRegExpAtMost(\"Hello World. How are you doing?\", / /, ~limit=3) ==\n [Some(\"Hello\"), Some(\"World.\"), Some(\"How\")]\n```\n"}, + "documentation": {"kind": "markdown", "value": "\n`splitByRegExpAtMost(str, regexp, ~limit)` splits the given `str` at every\noccurrence of `regexp` and returns an array of the first `limit` resulting\nsubstrings. If `limit` is negative or greater than the number of substrings, the\narray will contain all the substrings.\nSee [`String.split`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split) on MDN.\n\n## Examples\n\n```rescript\nString.splitByRegExpAtMost(\"Hello World. How are you doing?\", / /, ~limit=3) == [\n Some(\"Hello\"),\n Some(\"World.\"),\n Some(\"How\"),\n ]\n```\n"}, "sortText": "splitByRegExpAtMost", "insertText": "->String.splitByRegExpAtMost", "additionalTextEdits": [{ @@ -814,7 +814,7 @@ Path s "kind": 12, "tags": [], "detail": "(string, ~start: int, ~end: int) => string", - "documentation": {"kind": "markdown", "value": "\n`slice(str, ~start, ~end)` returns the substring of `str` starting at\ncharacter `start` up to but not including `end`.\n- If either `start` or `end` is negative, then it is evaluated as\n`length(str - start)` or `length(str - end)`.\n- If `end` is greater than the length of `str`, then it is treated as\n`length(str)`.\n- If `start` is greater than `end`, slice returns the empty string.\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n## Examples\n\n```rescript\nString.slice(\"abcdefg\", ~start=2, ~end=5) == \"cde\"\nString.slice(\"abcdefg\", ~start=2, ~end=9) == \"cdefg\"\nString.slice(\"abcdefg\", ~start=-4, ~end=-2) == \"de\"\nString.slice(\"abcdefg\", ~start=5, ~end=1) == \"\"\n```\n"}, + "documentation": {"kind": "markdown", "value": "\n`slice(str, ~start, ~end)` returns the substring of `str` starting at\ncharacter `start` up to but not including `end`.\n- If either `start` or `end` is negative, then it is evaluated as\n `length(str - start)` or `length(str - end)`.\n- If `end` is greater than the length of `str`, then it is treated as\n `length(str)`.\n- If `start` is greater than `end`, slice returns the empty string.\n See [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n## Examples\n\n```rescript\nString.slice(\"abcdefg\", ~start=2, ~end=5) == \"cde\"\nString.slice(\"abcdefg\", ~start=2, ~end=9) == \"cdefg\"\nString.slice(\"abcdefg\", ~start=-4, ~end=-2) == \"de\"\nString.slice(\"abcdefg\", ~start=5, ~end=1) == \"\"\n```\n"}, "sortText": "slice", "insertText": "->String.slice", "additionalTextEdits": [{ @@ -862,7 +862,7 @@ Path s "kind": 12, "tags": [], "detail": "(string, ~start: int) => string", - "documentation": {"kind": "markdown", "value": "\n`sliceToEnd(str, ~start)` returns the substring of `str` starting at character\n`start` to the end of the string.\n- If `start` is negative, then it is evaluated as `length(str - start)`.\n- If `start` is greater than the length of `str`, then sliceToEnd returns the empty string.\nSee [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n## Examples\n\n```rescript\nString.sliceToEnd(\"abcdefg\", ~start=4) == \"efg\"\nString.sliceToEnd(\"abcdefg\", ~start=-2) == \"fg\"\nString.sliceToEnd(\"abcdefg\", ~start=7) == \"\"\n```\n"}, + "documentation": {"kind": "markdown", "value": "\n`sliceToEnd(str, ~start)` returns the substring of `str` starting at character\n`start` to the end of the string.\n- If `start` is negative, then it is evaluated as `length(str - start)`.\n- If `start` is greater than the length of `str`, then sliceToEnd returns the empty string.\n See [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n## Examples\n\n```rescript\nString.sliceToEnd(\"abcdefg\", ~start=4) == \"efg\"\nString.sliceToEnd(\"abcdefg\", ~start=-2) == \"fg\"\nString.sliceToEnd(\"abcdefg\", ~start=7) == \"\"\n```\n"}, "sortText": "sliceToEnd", "insertText": "->String.sliceToEnd", "additionalTextEdits": [{ @@ -874,7 +874,7 @@ Path s "kind": 12, "tags": [], "detail": "(string, RegExp.t) => array>", - "documentation": {"kind": "markdown", "value": "\n`splitByRegExp(str, regexp)` splits the given `str` at every occurrence of\n`regexp` and returns an array of the resulting substrings.\nSee [`String.split`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split) on MDN.\n\n## Examples\n\n```rescript\nString.splitByRegExp(\"Jan,Feb,Mar\", %re(\"/,/\")) == [Some(\"Jan\"), Some(\"Feb\"), Some(\"Mar\")]\n```\n"}, + "documentation": {"kind": "markdown", "value": "\n`splitByRegExp(str, regexp)` splits the given `str` at every occurrence of\n`regexp` and returns an array of the resulting substrings.\nSee [`String.split`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split) on MDN.\n\n## Examples\n\n```rescript\nString.splitByRegExp(\"Jan,Feb,Mar\", /,/) == [Some(\"Jan\"), Some(\"Feb\"), Some(\"Mar\")]\n```\n"}, "sortText": "splitByRegExp", "insertText": "->String.splitByRegExp", "additionalTextEdits": [{ @@ -910,7 +910,7 @@ Path s "kind": 12, "tags": [], "detail": "(string, ~start: int, ~end: int) => string", - "documentation": {"kind": "markdown", "value": "\n`substring(str, ~start, ~end)` returns characters `start` up to but not\nincluding end from `str`.\n- If `start` is less than zero, it is treated as zero.\n- If `end` is zero or negative, the empty string is returned.\n- If `start` is greater than `end`, the `start` and `end` points are swapped.\nSee [`String.substring`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring) on MDN.\n\n## Examples\n\n```rescript\nString.substring(\"playground\", ~start=3, ~end=6) == \"ygr\"\nString.substring(\"playground\", ~start=6, ~end=3) == \"ygr\"\nString.substring(\"playground\", ~start=4, ~end=12) == \"ground\"\n```\n"}, + "documentation": {"kind": "markdown", "value": "\n`substring(str, ~start, ~end)` returns characters `start` up to but not\nincluding end from `str`.\n- If `start` is less than zero, it is treated as zero.\n- If `end` is zero or negative, the empty string is returned.\n- If `start` is greater than `end`, the `start` and `end` points are swapped.\n See [`String.substring`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring) on MDN.\n\n## Examples\n\n```rescript\nString.substring(\"playground\", ~start=3, ~end=6) == \"ygr\"\nString.substring(\"playground\", ~start=6, ~end=3) == \"ygr\"\nString.substring(\"playground\", ~start=4, ~end=12) == \"ground\"\n```\n"}, "sortText": "substring", "insertText": "->String.substring", "additionalTextEdits": [{ @@ -922,7 +922,7 @@ Path s "kind": 12, "tags": [], "detail": "(string, RegExp.t) => int", - "documentation": {"kind": "markdown", "value": "\n`search(str, regexp)` returns the starting position of the first match of\n`regexp` in the given `str`, or -1 if there is no match.\nSee [`String.search`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search) on MDN.\n\n## Examples\n\n```rescript\nString.search(\"testing 1 2 3\", %re(\"/\\d+/\")) == 8\nString.search(\"no numbers\", %re(\"/\\d+/\")) == -1\n```\n"}, + "documentation": {"kind": "markdown", "value": "\n`search(str, regexp)` returns the starting position of the first match of\n`regexp` in the given `str`, or -1 if there is no match.\nSee [`String.search`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search) on MDN.\n\n## Examples\n\n```rescript\nString.search(\"testing 1 2 3\", /\\d+/) == 8\nString.search(\"no numbers\", /\\d+/) == -1\n```\n"}, "sortText": "search", "insertText": "->String.search", "additionalTextEdits": [{ diff --git a/tests/analysis_tests/tests/src/expected/CompletionPipeChain.res.txt b/tests/analysis_tests/tests/src/expected/CompletionPipeChain.res.txt index dcf268e218..4fb8e0849f 100644 --- a/tests/analysis_tests/tests/src/expected/CompletionPipeChain.res.txt +++ b/tests/analysis_tests/tests/src/expected/CompletionPipeChain.res.txt @@ -347,13 +347,13 @@ Path t "kind": 12, "tags": [1], "detail": "(int, ~digits: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toPrecision` instead\n\n\n`toPrecisionWithPrecision(n, ~digits)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecisionWithPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecisionWithPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\nImplementations are allowed to support larger and smaller values as well.\nECMA-262 only requires a precision of up to 21 significant digits.\n\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: Use `toPrecision` instead\n\n\n`toPrecisionWithPrecision(n, ~digits)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecisionWithPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecisionWithPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\n Implementations are allowed to support larger and smaller values as well.\n ECMA-262 only requires a precision of up to 21 significant digits.\n \n"} }, { "label": "Int.toPrecision", "kind": 12, "tags": [], "detail": "(int, ~digits: int=?) => string", - "documentation": {"kind": "markdown", "value": "\n`toPrecision(n, ~digits=?)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecision(100) // \"100\"\nInt.toPrecision(1) // \"1\"\nInt.toPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\nImplementations are allowed to support larger and smaller values as well.\nECMA-262 only requires a precision of up to 21 significant digits.\n"} + "documentation": {"kind": "markdown", "value": "\n`toPrecision(n, ~digits=?)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecision(100) // \"100\"\nInt.toPrecision(1) // \"1\"\nInt.toPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\n Implementations are allowed to support larger and smaller values as well.\n ECMA-262 only requires a precision of up to 21 significant digits.\n"} }, { "label": "Int.toString", "kind": 12, diff --git a/tests/analysis_tests/tests/src/expected/Definition.res.txt b/tests/analysis_tests/tests/src/expected/Definition.res.txt index 0734d3c70d..824f03e3c5 100644 --- a/tests/analysis_tests/tests/src/expected/Definition.res.txt +++ b/tests/analysis_tests/tests/src/expected/Definition.res.txt @@ -5,7 +5,7 @@ Definition src/Definition.res 10:23 {"uri": "Definition.res", "range": {"start": {"line": 6, "character": 7}, "end": {"line": 6, "character": 13}}} Hover src/Definition.res 14:14 -{"contents": {"kind": "markdown", "value": "```rescript\n(list<'a>, 'a => 'b) => list<'b>\n```\n---\n\n`map(list, f)` returns a new list with `f` applied to each element of `list`.\n\n## Examples\n\n```rescript\nassertEqual(list{1, 2}->List.map(x => x + 1), list{2, 3})\n```\n"}} +{"contents": {"kind": "markdown", "value": "```rescript\n(list<'a>, 'a => 'b) => list<'b>\n```\n---\n\n`map(list, f)` returns a new list with `f` applied to each element of `list`.\n\n## Examples\n\n```rescript\nlist{1, 2}->List.map(x => x + 1) == list{2, 3}\n```\n"}} Hover src/Definition.res 18:14 {"contents": {"kind": "markdown", "value": "```rescript\n('a => 'b, list<'a>) => list<'b>\n```"}} diff --git a/tests/analysis_tests/tests/src/expected/DotPipeCompletionSpec.res.txt b/tests/analysis_tests/tests/src/expected/DotPipeCompletionSpec.res.txt index 8db5129032..f9947b67ff 100644 --- a/tests/analysis_tests/tests/src/expected/DotPipeCompletionSpec.res.txt +++ b/tests/analysis_tests/tests/src/expected/DotPipeCompletionSpec.res.txt @@ -239,7 +239,7 @@ Path u "kind": 12, "tags": [], "detail": "(array<'a>, array<'a>) => unit", - "documentation": {"kind": "markdown", "value": "\n`unshiftMany(array, itemsArray)` inserts many new items to the start of the array.\n\nBeware this will *mutate* the array.\n\nSee [`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift) on MDN.\n\n## Examples\n\n```rescript\nlet someArray = [\"hi\", \"hello\"]\nsomeArray->Array.unshiftMany([\"yay\", \"wehoo\"])\nsomeArray->assertEqual([\"yay\", \"wehoo\", \"hi\", \"hello\"])\n```\n"}, + "documentation": {"kind": "markdown", "value": "\n`unshiftMany(array, itemsArray)` inserts many new items to the start of the array.\n\nBeware this will *mutate* the array.\n\nSee [`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift) on MDN.\n\n## Examples\n\n```rescript\nlet someArray = [\"hi\", \"hello\"]\nsomeArray->Array.unshiftMany([\"yay\", \"wehoo\"])\nsomeArray == [\"yay\", \"wehoo\", \"hi\", \"hello\"]\n```\n"}, "sortText": "unshiftMany", "insertText": "->Array.unshiftMany", "additionalTextEdits": [{ @@ -251,7 +251,7 @@ Path u "kind": 12, "tags": [], "detail": "(array<'a>, 'a) => unit", - "documentation": {"kind": "markdown", "value": "\n`unshift(array, item)` inserts a new item at the start of the array.\n\nBeware this will *mutate* the array.\n\nSee [`Array.unshift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift) on MDN.\n\n## Examples\n\n```rescript\nlet someArray = [\"hi\", \"hello\"]\nsomeArray->Array.unshift(\"yay\")\nsomeArray->assertEqual([\"yay\", \"hi\", \"hello\"])\n```\n"}, + "documentation": {"kind": "markdown", "value": "\n`unshift(array, item)` inserts a new item at the start of the array.\n\nBeware this will *mutate* the array.\n\nSee [`Array.unshift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift) on MDN.\n\n## Examples\n\n```rescript\nlet someArray = [\"hi\", \"hello\"]\nsomeArray->Array.unshift(\"yay\")\nsomeArray == [\"yay\", \"hi\", \"hello\"]\n```\n"}, "sortText": "unshift", "insertText": "->Array.unshift", "additionalTextEdits": [{ @@ -367,7 +367,7 @@ Path filt "kind": 12, "tags": [], "detail": "(array<'a>, 'a => option<'b>) => array<'b>", - "documentation": {"kind": "markdown", "value": "\n`filterMap(array, fn)`\n\nCalls `fn` for each element and returns a new array containing results of the `fn` calls which are not `None`.\n\n## Examples\n\n```rescript\n[\"Hello\", \"Hi\", \"Good bye\"]\n->Array.filterMap(item =>\n switch item {\n | \"Hello\" => Some(item->String.length)\n | _ => None\n }\n)\n->assertEqual([5])\n\n[1, 2, 3, 4, 5, 6]\n->Array.filterMap(n => mod(n, 2) == 0 ? Some(n * n) : None)\n->assertEqual([4, 16, 36])\n\nArray.filterMap([1, 2, 3, 4, 5, 6], _ => None)->assertEqual([])\n\nArray.filterMap([], n => mod(n, 2) == 0 ? Some(n * n) : None)->assertEqual([])\n```\n"}, + "documentation": {"kind": "markdown", "value": "\n`filterMap(array, fn)`\n\nCalls `fn` for each element and returns a new array containing results of the `fn` calls which are not `None`.\n\n## Examples\n\n```rescript\n[\"Hello\", \"Hi\", \"Good bye\"]->Array.filterMap(item =>\n switch item {\n | \"Hello\" => Some(item->String.length)\n | _ => None\n }\n) == [5]\n\n[1, 2, 3, 4, 5, 6]->Array.filterMap(n => mod(n, 2) == 0 ? Some(n * n) : None) == [4, 16, 36]\n\nArray.filterMap([1, 2, 3, 4, 5, 6], _ => None) == []\n\nArray.filterMap([], n => mod(n, 2) == 0 ? Some(n * n) : None) == []\n```\n"}, "sortText": "filterMap", "insertText": "->Array.filterMap", "additionalTextEdits": [{ @@ -379,7 +379,7 @@ Path filt "kind": 12, "tags": [], "detail": "(array<'a>, 'a => bool) => array<'a>", - "documentation": {"kind": "markdown", "value": "\n`filter(array, checker)` returns a new array containing all elements from `array` for which the provided `checker` function returns true.\n\nSee [`Array.filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) on MDN.\n\n## Examples\n\n```rescript\n[1, 2, 3, 4]\n->Array.filter(num => num > 2)\n->assertEqual([3, 4])\n```\n"}, + "documentation": {"kind": "markdown", "value": "\n`filter(array, checker)` returns a new array containing all elements from `array` for which the provided `checker` function returns true.\n\nSee [`Array.filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) on MDN.\n\n## Examples\n\n```rescript\n[1, 2, 3, 4]->Array.filter(num => num > 2) == [3, 4]\n```\n"}, "sortText": "filter", "insertText": "->Array.filter", "additionalTextEdits": [{ @@ -391,7 +391,7 @@ Path filt "kind": 12, "tags": [], "detail": "(array<'a>, ('a, int) => bool) => array<'a>", - "documentation": {"kind": "markdown", "value": "\n`filterWithIndex(array, checker)` returns a new array containing all elements from `array` for which the provided `checker` function returns true.\n\nSee [`Array.filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) on MDN.\n\n## Examples\n\n```rescript\n[1, 2, 3, 4]\n->Array.filterWithIndex((num, index) => index === 0 || num === 2)\n->assertEqual([1, 2])\n```\n"}, + "documentation": {"kind": "markdown", "value": "\n`filterWithIndex(array, checker)` returns a new array containing all elements from `array` for which the provided `checker` function returns true.\n\nSee [`Array.filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) on MDN.\n\n## Examples\n\n```rescript\n[1, 2, 3, 4]->Array.filterWithIndex((num, index) => index === 0 || num === 2) == [1, 2]\n```\n"}, "sortText": "filterWithIndex", "insertText": "->Array.filterWithIndex", "additionalTextEdits": [{ diff --git a/tests/analysis_tests/tests/src/expected/RecordCompletion.res.txt b/tests/analysis_tests/tests/src/expected/RecordCompletion.res.txt index bef7e1df39..b4587be81a 100644 --- a/tests/analysis_tests/tests/src/expected/RecordCompletion.res.txt +++ b/tests/analysis_tests/tests/src/expected/RecordCompletion.res.txt @@ -21,13 +21,13 @@ Path m "kind": 12, "tags": [], "detail": "(array<'a>, 'a => 'b) => array<'b>", - "documentation": {"kind": "markdown", "value": "\n`map(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray = array->Array.map(greeting => greeting ++ \" to you\")\n\nassertEqual(mappedArray, [\"Hello to you\", \"Hi to you\", \"Good bye to you\"])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`map(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray = array->Array.map(greeting => greeting ++ \" to you\")\n\nmappedArray == [\"Hello to you\", \"Hi to you\", \"Good bye to you\"]\n```\n"} }, { "label": "Array.mapWithIndex", "kind": 12, "tags": [], "detail": "(array<'a>, ('a, int) => 'b) => array<'b>", - "documentation": {"kind": "markdown", "value": "\n`mapWithIndex(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray =\n array->Array.mapWithIndex((greeting, index) =>\n greeting ++ \" at position \" ++ Int.toString(index)\n )\n\nassertEqual(mappedArray, [\"Hello at position 0\", \"Hi at position 1\", \"Good bye at position 2\"])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`mapWithIndex(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray =\n array->Array.mapWithIndex((greeting, index) => greeting ++ \" at position \" ++ Int.toString(index))\n\nmappedArray == [\"Hello at position 0\", \"Hi at position 1\", \"Good bye at position 2\"]\n```\n"} }] Complete src/RecordCompletion.res 11:13 @@ -67,13 +67,13 @@ Path m "kind": 12, "tags": [], "detail": "(array<'a>, 'a => 'b) => array<'b>", - "documentation": {"kind": "markdown", "value": "\n`map(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray = array->Array.map(greeting => greeting ++ \" to you\")\n\nassertEqual(mappedArray, [\"Hello to you\", \"Hi to you\", \"Good bye to you\"])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`map(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray = array->Array.map(greeting => greeting ++ \" to you\")\n\nmappedArray == [\"Hello to you\", \"Hi to you\", \"Good bye to you\"]\n```\n"} }, { "label": "Array.mapWithIndex", "kind": 12, "tags": [], "detail": "(array<'a>, ('a, int) => 'b) => array<'b>", - "documentation": {"kind": "markdown", "value": "\n`mapWithIndex(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray =\n array->Array.mapWithIndex((greeting, index) =>\n greeting ++ \" at position \" ++ Int.toString(index)\n )\n\nassertEqual(mappedArray, [\"Hello at position 0\", \"Hi at position 1\", \"Good bye at position 2\"])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`mapWithIndex(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray =\n array->Array.mapWithIndex((greeting, index) => greeting ++ \" at position \" ++ Int.toString(index))\n\nmappedArray == [\"Hello at position 0\", \"Hi at position 1\", \"Good bye at position 2\"]\n```\n"} }] Complete src/RecordCompletion.res 19:7 diff --git a/tests/analysis_tests/tests/src/expected/RecoveryOnProp.res.txt b/tests/analysis_tests/tests/src/expected/RecoveryOnProp.res.txt index 32cd986e2c..9122d5a48f 100644 --- a/tests/analysis_tests/tests/src/expected/RecoveryOnProp.res.txt +++ b/tests/analysis_tests/tests/src/expected/RecoveryOnProp.res.txt @@ -41,5 +41,15 @@ Path Res "modulePath": "RescriptTools_Docgen", "filePath": "src/RecoveryOnProp.res" } + }, { + "label": "RescriptTools_ExtractCodeBlocks", + "kind": 9, + "tags": [], + "detail": "module RescriptTools_ExtractCodeBlocks", + "documentation": null, + "data": { + "modulePath": "RescriptTools_ExtractCodeBlocks", + "filePath": "src/RecoveryOnProp.res" + } }] diff --git a/tests/analysis_tests/tests/src/expected/SignatureHelp.res.txt b/tests/analysis_tests/tests/src/expected/SignatureHelp.res.txt index f6a030bcaf..cdb8f9a204 100644 --- a/tests/analysis_tests/tests/src/expected/SignatureHelp.res.txt +++ b/tests/analysis_tests/tests/src/expected/SignatureHelp.res.txt @@ -478,7 +478,7 @@ extracted params: "signatures": [{ "label": "(array, int => int) => array", "parameters": [{"label": [0, 11], "documentation": {"kind": "markdown", "value": ""}}, {"label": [13, 23], "documentation": {"kind": "markdown", "value": ""}}], - "documentation": {"kind": "markdown", "value": "\n`map(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray = array->Array.map(greeting => greeting ++ \" to you\")\n\nassertEqual(mappedArray, [\"Hello to you\", \"Hi to you\", \"Good bye to you\"])\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`map(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray = array->Array.map(greeting => greeting ++ \" to you\")\n\nmappedArray == [\"Hello to you\", \"Hi to you\", \"Good bye to you\"]\n```\n"} }], "activeSignature": 0, "activeParameter": 1 From c7eab25e87890f03b013bc0084b6418782a93aaf Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Fri, 11 Jul 2025 14:56:35 +0200 Subject: [PATCH 12/16] fix last remaining format issues in runtime docstrings --- runtime/Belt.res | 49 ++++++++++++++++++------------------------ runtime/Js.res | 17 --------------- runtime/Js_array.res | 27 +---------------------- runtime/Js_bigint.res | 2 +- runtime/Js_string.res | 18 ++++++++-------- runtime/Js_string2.res | 14 ++++++------ 6 files changed, 39 insertions(+), 88 deletions(-) diff --git a/runtime/Belt.res b/runtime/Belt.res index d866766c12..56b56c9a27 100644 --- a/runtime/Belt.res +++ b/runtime/Belt.res @@ -130,16 +130,15 @@ let letters = ["a", "b", "c"] let a = letters[0] // Use a switch statement: -let capitalA = - switch a { - | Some(a) => Some(Js.String.toUpperCase(a)) - | None => None - } +let capitalA = switch a { +| Some(a) => Some(Js.String.toUpperCase(a)) +| None => None +} let k = letters[10] // k == None ``` -With that little bit of tweaking, our code now compiles successfully and is 100% free of runtime errors! +With that little bit of tweaking, our code now compiles successfully and is 100% free of runtime errors\! ### A Special Encoding for Collection Safety @@ -150,31 +149,25 @@ We use a phantom type to solve the problem: ## Examples ```rescript -module Comparable1 = - Belt.Id.MakeComparable( - { - type t = (int, int) - let cmp = ((a0, a1), (b0, b1)) => - switch Pervasives.compare(a0, b0) { - | 0 => Pervasives.compare(a1, b1) - | c => c - } +module Comparable1 = Belt.Id.MakeComparable({ + type t = (int, int) + let cmp = ((a0, a1), (b0, b1)) => + switch Pervasives.compare(a0, b0) { + | 0 => Pervasives.compare(a1, b1) + | c => c } - ) +}) let mySet1 = Belt.Set.make(~id=module(Comparable1)) -module Comparable2 = - Belt.Id.MakeComparable( - { - type t = (int, int) - let cmp = ((a0, a1), (b0, b1)) => - switch Pervasives.compare(a0, b0) { - | 0 => Pervasives.compare(a1, b1) - | c => c - } +module Comparable2 = Belt.Id.MakeComparable({ + type t = (int, int) + let cmp = ((a0, a1), (b0, b1)) => + switch Pervasives.compare(a0, b0) { + | 0 => Pervasives.compare(a1, b1) + | c => c } - ) +}) let mySet2 = Belt.Set.make(~id=module(Comparable2)) ``` @@ -184,8 +177,8 @@ Here, the compiler would infer `mySet1` and `mySet2` having different type, so e ## Examples ```rescript -let mySet1: t<(int, int), Comparable1.identity> -let mySet2: t<(int, int), Comparable2.identity> +let mySet1: t<(int, int), Comparable1.identity> = %todo +let mySet2: t<(int, int), Comparable2.identity> = %todo ``` `Comparable1.identity` and `Comparable2.identity` are not the same using our encoding scheme. diff --git a/runtime/Js.res b/runtime/Js.res index c842a5c259..4bdfdf03d1 100644 --- a/runtime/Js.res +++ b/runtime/Js.res @@ -52,23 +52,6 @@ For more information about these argument orders and the trade-offs between them _Eventually, all modules in the Js namespace are going to be migrated to data-first though._ -In the meantime, there are several options for dealing with the data-last APIs: - -## Examples - -```rescript -/* Js.String (data-last API used with pipe last operator) */ -Js.log(\"2019-11-10\" |> Js.String.split(\"-\")) -Js.log(\"ReScript\" |> Js.String.startsWith(\"Re\")) - -/* Js.String (data-last API used with pipe first operator) */ -Js.log(\"2019-11-10\"->Js.String.split(\"-\", _)) -Js.log(\"ReScript\"->Js.String.startsWith(\"Re\", _)) - -/* Js.String (data-last API used without any piping) */ -Js.log(Js.String.split(\"-\", \"2019-11-10\")) -Js.log(Js.String.startsWith(\"Re\", \"ReScript\")) -``` ## Js.Xxx2 Modules Prefer `Js.Array2` over `Js.Array`, `Js.String2` over `Js.String`, etc. The latters are old modules. diff --git a/runtime/Js_array.res b/runtime/Js_array.res index c7d2429a00..3319d8ede9 100644 --- a/runtime/Js_array.res +++ b/runtime/Js_array.res @@ -26,31 +26,6 @@ Provides bindings to JavaScript’s `Array` functions. These bindings are optimized for pipe-last (`|>`), where the array to be processed is the last parameter in the function. - -Here is an example to find the sum of squares of all even numbers in an array. -Without pipe last, we must call the functions in reverse order: - -## Examples - -```rescript -let isEven = x => mod(x, 2) == 0 -let square = x => x * x -let result = { - open Js.Array - reduce(\"+", 0, map(square, filter(isEven, [5, 2, 3, 4, 1]))) -} -``` - -With pipe last, we call the functions in the “natural” order: - -```rescript -let isEven = x => mod(x, 2) == 0 -let square = x => x * x -let result = { - open Js.Array - [5, 2, 3, 4, 1] |> filter(isEven) |> map(square) |> reduce("+", 0) -} -``` */ @@warning("-103") @@ -1090,7 +1065,7 @@ external unsafe_get: (array<'a>, int) => 'a = "%array_unsafe_get" /** Sets the value at the given position in the array if the position is in bounds. If the index is out of bounds, well, “here there be dragons.“ *This function - modifies the original array.* +modifies the original array.* ## Examples diff --git a/runtime/Js_bigint.res b/runtime/Js_bigint.res index 253daa3bb2..e19daff867 100644 --- a/runtime/Js_bigint.res +++ b/runtime/Js_bigint.res @@ -26,7 +26,7 @@ Js.BigInt.fromStringExn("0o11") try { Js.BigInt.fromStringExn("a") } catch { -| _ => ... +| _ => Console.error("Error parsing bigint") } ``` */ diff --git a/runtime/Js_string.res b/runtime/Js_string.res index 5c00df67ce..a1df479520 100644 --- a/runtime/Js_string.res +++ b/runtime/Js_string.res @@ -140,7 +140,7 @@ external get: (t, int) => t = "" /** `charAt(n, s)` gets the character at index `n` within string `s`. If `n` is negative or greater than the length of `s`, it returns the empty string. If the -string contains characters outside the range \u0000-\uffff, it will return the +string contains characters outside the range \\u0000-\\uffff, it will return the first 16-bit value at that position in the string. See [`String.charAt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt) @@ -336,7 +336,7 @@ let indexOf = (arg1, obj) => indexOf(obj, arg1) /** `indexOfFrom(searchValue, start, str)` returns the position at which `searchValue` was found within `str` starting at character position `start`, or --1 if `searchValue` is not found in that portion of `str`. The return value is +\-1 if `searchValue` is not found in that portion of `str`. The return value is relative to the beginning of the string, no matter where the search started from. @@ -424,7 +424,7 @@ let localeCompare = (arg1, obj) => localeCompare(obj, arg1) /** `match(regexp, str)` matches a `string` against the given `regexp`. If there is no match, it returns `None`. For regular expressions without the g modifier, if - there is a match, the return value is `Some(array)` where the array contains: +there is a match, the return value is `Some(array)` where the array contains: - The entire matched string - Any capture groups if the regexp had parentheses @@ -738,7 +738,7 @@ on MDN. ## Examples ```rescript -Js.String.splitByRe(%re("/\s*[,;]\s*TODO/"), "art; bed , cog ;dad") == [ +Js.String.splitByRe(/\s*[,;]\s*TODO/, "art; bed , cog ;dad") == [ Some("art"), Some("bed"), Some("cog"), @@ -762,15 +762,15 @@ on MDN. ## Examples ```rescript -Js.String.splitByReAtMost(%re("/\s*[,;]\s*TODO/"), ~limit=3, "one: two: three: four") == [ +Js.String.splitByReAtMost(/\s*[,;]\s*TODO/, ~limit=3, "one: two: three: four") == [ Some("one"), Some("two"), Some("three"), ] -Js.String.splitByReAtMost(%re("/\s*[,;]\s*TODO/"), ~limit=0, "one: two: three: four") == [] +Js.String.splitByReAtMost(/\s*[,;]\s*TODO/, ~limit=0, "one: two: three: four") == [] -Js.String.splitByReAtMost(%re("/\s*[,;]\s*TODO/"), ~limit=8, "one: two: three: four") == [ +Js.String.splitByReAtMost(/\s*[,;]\s*TODO/, ~limit=8, "one: two: three: four") == [ Some("one"), Some("two"), Some("three"), @@ -1000,7 +1000,7 @@ on MDN. ## Examples ```rescript -Js.String.anchor("page1", "Page One") == "Page One" +Js.String.anchor("page1", "Page One") == "Page One" ``` */ @send @@ -1018,7 +1018,7 @@ on MDN. ## Examples ```rescript -Js.String.link("page2.html", "Go to page two") == "Go to page two" +Js.String.link("page2.html", "Go to page two") == "Go to page two" ``` */ @send diff --git a/runtime/Js_string2.res b/runtime/Js_string2.res index bd90837608..700b54a0c4 100644 --- a/runtime/Js_string2.res +++ b/runtime/Js_string2.res @@ -145,7 +145,7 @@ external get: (t, int) => t = "" /** `charAt(s, n)` gets the character at index `n` within string `s`. If `n` is negative or greater than the length of `s`, it returns the empty string. If the -string contains characters outside the range \u0000-\uffff, it will return the +string contains characters outside the range \\u0000-\\uffff, it will return the first 16-bit value at that position in the string. See [`String.charAt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt) @@ -331,7 +331,7 @@ external indexOf: (t, t) => int = "indexOf" /** `indexOfFrom(str, searchValue, start)` returns the position at which `searchValue` was found within `str` starting at character position `start`, or --1 if `searchValue` is not found in that portion of `str`. The return value is +\-1 if `searchValue` is not found in that portion of `str`. The return value is relative to the beginning of the string, no matter where the search started from. @@ -415,11 +415,11 @@ external localeCompare: (t, t) => float = "localeCompare" /** `match(str, regexp)` matches a `string` against the given `regexp`. If there is no match, it returns `None`. For regular expressions without the g modifier, if - there is a match, the return value is `Some(array)` where the array contains: +there is a match, the return value is `Some(array)` where the array contains: - The entire matched string - Any capture groups if the regexp had parentheses -For regular expressions with the g modifier, a matched expression returns -`Some(array)` with all the matched substrings and no capture groups. + For regular expressions with the g modifier, a matched expression returns + `Some(array)` with all the matched substrings and no capture groups. See [`String.match`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match) on MDN. @@ -956,7 +956,7 @@ on MDN. ## Examples ```rescript -Js.String2.anchor("Page One", "page1") == "Page One" +Js.String2.anchor("Page One", "page1") == "Page One" ``` */ @send @@ -972,7 +972,7 @@ on MDN. ## Examples ```rescript -Js.String2.link("Go to page two", "page2.html") == "Go to page two" +Js.String2.link("Go to page two", "page2.html") == "Go to page two" ``` */ @send From 2cc3a2211e861d14897b60bd0b05a043e5fc28c1 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Fri, 11 Jul 2025 15:01:06 +0200 Subject: [PATCH 13/16] update analysis test files --- .../tests/src/expected/CompletionJsx.res.txt | 72 +++++++++---------- .../expected/DotPipeCompletionSpec.res.txt | 20 +++--- 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt b/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt index 42b929877b..0e4ad2dc94 100644 --- a/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt +++ b/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt @@ -785,6 +785,30 @@ Path s "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, "newText": "" }] + }, { + "label": "->String.startsWith", + "kind": 12, + "tags": [], + "detail": "(string, string) => bool", + "documentation": {"kind": "markdown", "value": "\n`startsWith(str, substr)` returns `true` if the `str` starts with `substr`,\n`false` otherwise.\nSee [`String.startsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith) on MDN.\n\n## Examples\n\n```rescript\nString.startsWith(\"BuckleScript\", \"Buckle\") == true\nString.startsWith(\"BuckleScript\", \"\") == true\nString.startsWith(\"JavaScript\", \"Buckle\") == false\n```\n"}, + "sortText": "startsWith", + "insertText": "->String.startsWith", + "additionalTextEdits": [{ + "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, + "newText": "" + }] + }, { + "label": "->String.splitAtMost", + "kind": 12, + "tags": [], + "detail": "(string, string, ~limit: int) => array", + "documentation": {"kind": "markdown", "value": "\n`splitAtMost(str, delimiter, ~limit)` splits the given `str` at every\noccurrence of `delimiter` and returns an array of the first `limit` resulting\nsubstrings. If `limit` is negative or greater than the number of substrings,\nthe array will contain all the substrings.\n\n## Examples\n\n```rescript\nString.splitAtMost(\"ant/bee/cat/dog/elk\", \"/\", ~limit=3) == [\"ant\", \"bee\", \"cat\"]\nString.splitAtMost(\"ant/bee/cat/dog/elk\", \"/\", ~limit=0) == []\nString.splitAtMost(\"ant/bee/cat/dog/elk\", \"/\", ~limit=9) == [\"ant\", \"bee\", \"cat\", \"dog\", \"elk\"]\n```\n"}, + "sortText": "splitAtMost", + "insertText": "->String.splitAtMost", + "additionalTextEdits": [{ + "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, + "newText": "" + }] }, { "label": "->String.searchOpt", "kind": 12, @@ -821,42 +845,6 @@ Path s "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, "newText": "" }] - }, { - "label": "->String.substringToEnd", - "kind": 12, - "tags": [], - "detail": "(string, ~start: int) => string", - "documentation": {"kind": "markdown", "value": "\n`substringToEnd(str, ~start)` returns the substring of `str` from position\n`start` to the end.\n- If `start` is less than or equal to zero, the entire string is returned.\n- If `start` is greater than or equal to the length of `str`, the empty string\nis returned.\nSee [`String.substring`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring) on MDN.\n\n## Examples\n\n```rescript\nString.substringToEnd(\"playground\", ~start=4) == \"ground\"\nString.substringToEnd(\"playground\", ~start=-3) == \"playground\"\nString.substringToEnd(\"playground\", ~start=12) == \"\"\n```\n"}, - "sortText": "substringToEnd", - "insertText": "->String.substringToEnd", - "additionalTextEdits": [{ - "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, - "newText": "" - }] - }, { - "label": "->String.startsWith", - "kind": 12, - "tags": [], - "detail": "(string, string) => bool", - "documentation": {"kind": "markdown", "value": "\n`startsWith(str, substr)` returns `true` if the `str` starts with `substr`,\n`false` otherwise.\nSee [`String.startsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith) on MDN.\n\n## Examples\n\n```rescript\nString.startsWith(\"BuckleScript\", \"Buckle\") == true\nString.startsWith(\"BuckleScript\", \"\") == true\nString.startsWith(\"JavaScript\", \"Buckle\") == false\n```\n"}, - "sortText": "startsWith", - "insertText": "->String.startsWith", - "additionalTextEdits": [{ - "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, - "newText": "" - }] - }, { - "label": "->String.splitAtMost", - "kind": 12, - "tags": [], - "detail": "(string, string, ~limit: int) => array", - "documentation": {"kind": "markdown", "value": "\n`splitAtMost(str, delimiter, ~limit)` splits the given `str` at every\noccurrence of `delimiter` and returns an array of the first `limit` resulting\nsubstrings. If `limit` is negative or greater than the number of substrings,\nthe array will contain all the substrings.\n\n## Examples\n\n```rescript\nString.splitAtMost(\"ant/bee/cat/dog/elk\", \"/\", ~limit=3) == [\"ant\", \"bee\", \"cat\"]\nString.splitAtMost(\"ant/bee/cat/dog/elk\", \"/\", ~limit=0) == []\nString.splitAtMost(\"ant/bee/cat/dog/elk\", \"/\", ~limit=9) == [\"ant\", \"bee\", \"cat\", \"dog\", \"elk\"]\n```\n"}, - "sortText": "splitAtMost", - "insertText": "->String.splitAtMost", - "additionalTextEdits": [{ - "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, - "newText": "" - }] }, { "label": "->String.sliceToEnd", "kind": 12, @@ -929,5 +917,17 @@ Path s "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, "newText": "" }] + }, { + "label": "->String.substringToEnd", + "kind": 12, + "tags": [], + "detail": "(string, ~start: int) => string", + "documentation": {"kind": "markdown", "value": "\n`substringToEnd(str, ~start)` returns the substring of `str` from position\n`start` to the end.\n- If `start` is less than or equal to zero, the entire string is returned.\n- If `start` is greater than or equal to the length of `str`, the empty string\n is returned.\n See [`String.substring`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring) on MDN.\n\n## Examples\n\n```rescript\nString.substringToEnd(\"playground\", ~start=4) == \"ground\"\nString.substringToEnd(\"playground\", ~start=-3) == \"playground\"\nString.substringToEnd(\"playground\", ~start=12) == \"\"\n```\n"}, + "sortText": "substringToEnd", + "insertText": "->String.substringToEnd", + "additionalTextEdits": [{ + "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, + "newText": "" + }] }] diff --git a/tests/analysis_tests/tests/src/expected/DotPipeCompletionSpec.res.txt b/tests/analysis_tests/tests/src/expected/DotPipeCompletionSpec.res.txt index f9947b67ff..a230d87fcb 100644 --- a/tests/analysis_tests/tests/src/expected/DotPipeCompletionSpec.res.txt +++ b/tests/analysis_tests/tests/src/expected/DotPipeCompletionSpec.res.txt @@ -418,25 +418,25 @@ Path Array.joinWith Path Stdlib.String.includ Path includ [{ - "label": "->String.includes", + "label": "->String.includesFrom", "kind": 12, "tags": [], - "detail": "(string, string) => bool", - "documentation": {"kind": "markdown", "value": "\n`includes(str, searchValue)` returns `true` if `searchValue` is found anywhere\nwithin `str`, `false` otherwise.\nSee [`String.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) on MDN.\n\n## Examples\n\n```rescript\nString.includes(\"programmer\", \"gram\") == true\nString.includes(\"programmer\", \"er\") == true\nString.includes(\"programmer\", \"pro\") == true\nString.includes(\"programmer.dat\", \"xyz\") == false\n```\n"}, - "sortText": "includes", - "insertText": "->String.includes", + "detail": "(string, string, int) => bool", + "documentation": {"kind": "markdown", "value": "\n`includesFrom(str, searchValue, start)` returns `true` if `searchValue` is found\nanywhere within `str` starting at character number `start` (where 0 is the\nfirst character), `false` otherwise.\nSee [`String.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) on MDN.\n\n## Examples\n\n```rescript\nString.includesFrom(\"programmer\", \"gram\", 1) == true\nString.includesFrom(\"programmer\", \"gram\", 4) == false\nString.includesFrom(`대한민국`, `한`, 1) == true\n```\n"}, + "sortText": "includesFrom", + "insertText": "->String.includesFrom", "additionalTextEdits": [{ "range": {"start": {"line": 89, "character": 55}, "end": {"line": 89, "character": 56}}, "newText": "" }] }, { - "label": "->String.includesFrom", + "label": "->String.includes", "kind": 12, "tags": [], - "detail": "(string, string, int) => bool", - "documentation": {"kind": "markdown", "value": "\n`includesFrom(str, searchValue, start)` returns `true` if `searchValue` is found\nanywhere within `str` starting at character number `start` (where 0 is the\nfirst character), `false` otherwise.\nSee [`String.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) on MDN.\n\n## Examples\n\n```rescript\nString.includesFrom(\"programmer\", \"gram\", 1) == true\nString.includesFrom(\"programmer\", \"gram\", 4) == false\nString.includesFrom(`대한민국`, `한`, 1) == true\n```\n"}, - "sortText": "includesFrom", - "insertText": "->String.includesFrom", + "detail": "(string, string) => bool", + "documentation": {"kind": "markdown", "value": "\n`includes(str, searchValue)` returns `true` if `searchValue` is found anywhere\nwithin `str`, `false` otherwise.\nSee [`String.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) on MDN.\n\n## Examples\n\n```rescript\nString.includes(\"programmer\", \"gram\") == true\nString.includes(\"programmer\", \"er\") == true\nString.includes(\"programmer\", \"pro\") == true\nString.includes(\"programmer.dat\", \"xyz\") == false\n```\n"}, + "sortText": "includes", + "insertText": "->String.includes", "additionalTextEdits": [{ "range": {"start": {"line": 89, "character": 55}, "end": {"line": 89, "character": 56}}, "newText": "" From 242dfa60effdbd9701e8cf3f971b25a4516c73a3 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Fri, 11 Jul 2025 15:08:53 +0200 Subject: [PATCH 14/16] more test output --- .../tests/src/expected/CompletionJsx.res.txt | 72 +++++++++---------- .../expected/DotPipeCompletionSpec.res.txt | 20 +++--- 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt b/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt index 0e4ad2dc94..e9907b0a2b 100644 --- a/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt +++ b/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt @@ -785,30 +785,6 @@ Path s "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, "newText": "" }] - }, { - "label": "->String.startsWith", - "kind": 12, - "tags": [], - "detail": "(string, string) => bool", - "documentation": {"kind": "markdown", "value": "\n`startsWith(str, substr)` returns `true` if the `str` starts with `substr`,\n`false` otherwise.\nSee [`String.startsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith) on MDN.\n\n## Examples\n\n```rescript\nString.startsWith(\"BuckleScript\", \"Buckle\") == true\nString.startsWith(\"BuckleScript\", \"\") == true\nString.startsWith(\"JavaScript\", \"Buckle\") == false\n```\n"}, - "sortText": "startsWith", - "insertText": "->String.startsWith", - "additionalTextEdits": [{ - "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, - "newText": "" - }] - }, { - "label": "->String.splitAtMost", - "kind": 12, - "tags": [], - "detail": "(string, string, ~limit: int) => array", - "documentation": {"kind": "markdown", "value": "\n`splitAtMost(str, delimiter, ~limit)` splits the given `str` at every\noccurrence of `delimiter` and returns an array of the first `limit` resulting\nsubstrings. If `limit` is negative or greater than the number of substrings,\nthe array will contain all the substrings.\n\n## Examples\n\n```rescript\nString.splitAtMost(\"ant/bee/cat/dog/elk\", \"/\", ~limit=3) == [\"ant\", \"bee\", \"cat\"]\nString.splitAtMost(\"ant/bee/cat/dog/elk\", \"/\", ~limit=0) == []\nString.splitAtMost(\"ant/bee/cat/dog/elk\", \"/\", ~limit=9) == [\"ant\", \"bee\", \"cat\", \"dog\", \"elk\"]\n```\n"}, - "sortText": "splitAtMost", - "insertText": "->String.splitAtMost", - "additionalTextEdits": [{ - "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, - "newText": "" - }] }, { "label": "->String.searchOpt", "kind": 12, @@ -845,6 +821,42 @@ Path s "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, "newText": "" }] + }, { + "label": "->String.substringToEnd", + "kind": 12, + "tags": [], + "detail": "(string, ~start: int) => string", + "documentation": {"kind": "markdown", "value": "\n`substringToEnd(str, ~start)` returns the substring of `str` from position\n`start` to the end.\n- If `start` is less than or equal to zero, the entire string is returned.\n- If `start` is greater than or equal to the length of `str`, the empty string\n is returned.\n See [`String.substring`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring) on MDN.\n\n## Examples\n\n```rescript\nString.substringToEnd(\"playground\", ~start=4) == \"ground\"\nString.substringToEnd(\"playground\", ~start=-3) == \"playground\"\nString.substringToEnd(\"playground\", ~start=12) == \"\"\n```\n"}, + "sortText": "substringToEnd", + "insertText": "->String.substringToEnd", + "additionalTextEdits": [{ + "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, + "newText": "" + }] + }, { + "label": "->String.startsWith", + "kind": 12, + "tags": [], + "detail": "(string, string) => bool", + "documentation": {"kind": "markdown", "value": "\n`startsWith(str, substr)` returns `true` if the `str` starts with `substr`,\n`false` otherwise.\nSee [`String.startsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith) on MDN.\n\n## Examples\n\n```rescript\nString.startsWith(\"BuckleScript\", \"Buckle\") == true\nString.startsWith(\"BuckleScript\", \"\") == true\nString.startsWith(\"JavaScript\", \"Buckle\") == false\n```\n"}, + "sortText": "startsWith", + "insertText": "->String.startsWith", + "additionalTextEdits": [{ + "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, + "newText": "" + }] + }, { + "label": "->String.splitAtMost", + "kind": 12, + "tags": [], + "detail": "(string, string, ~limit: int) => array", + "documentation": {"kind": "markdown", "value": "\n`splitAtMost(str, delimiter, ~limit)` splits the given `str` at every\noccurrence of `delimiter` and returns an array of the first `limit` resulting\nsubstrings. If `limit` is negative or greater than the number of substrings,\nthe array will contain all the substrings.\n\n## Examples\n\n```rescript\nString.splitAtMost(\"ant/bee/cat/dog/elk\", \"/\", ~limit=3) == [\"ant\", \"bee\", \"cat\"]\nString.splitAtMost(\"ant/bee/cat/dog/elk\", \"/\", ~limit=0) == []\nString.splitAtMost(\"ant/bee/cat/dog/elk\", \"/\", ~limit=9) == [\"ant\", \"bee\", \"cat\", \"dog\", \"elk\"]\n```\n"}, + "sortText": "splitAtMost", + "insertText": "->String.splitAtMost", + "additionalTextEdits": [{ + "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, + "newText": "" + }] }, { "label": "->String.sliceToEnd", "kind": 12, @@ -917,17 +929,5 @@ Path s "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, "newText": "" }] - }, { - "label": "->String.substringToEnd", - "kind": 12, - "tags": [], - "detail": "(string, ~start: int) => string", - "documentation": {"kind": "markdown", "value": "\n`substringToEnd(str, ~start)` returns the substring of `str` from position\n`start` to the end.\n- If `start` is less than or equal to zero, the entire string is returned.\n- If `start` is greater than or equal to the length of `str`, the empty string\n is returned.\n See [`String.substring`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring) on MDN.\n\n## Examples\n\n```rescript\nString.substringToEnd(\"playground\", ~start=4) == \"ground\"\nString.substringToEnd(\"playground\", ~start=-3) == \"playground\"\nString.substringToEnd(\"playground\", ~start=12) == \"\"\n```\n"}, - "sortText": "substringToEnd", - "insertText": "->String.substringToEnd", - "additionalTextEdits": [{ - "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, - "newText": "" - }] }] diff --git a/tests/analysis_tests/tests/src/expected/DotPipeCompletionSpec.res.txt b/tests/analysis_tests/tests/src/expected/DotPipeCompletionSpec.res.txt index a230d87fcb..f9947b67ff 100644 --- a/tests/analysis_tests/tests/src/expected/DotPipeCompletionSpec.res.txt +++ b/tests/analysis_tests/tests/src/expected/DotPipeCompletionSpec.res.txt @@ -418,25 +418,25 @@ Path Array.joinWith Path Stdlib.String.includ Path includ [{ - "label": "->String.includesFrom", + "label": "->String.includes", "kind": 12, "tags": [], - "detail": "(string, string, int) => bool", - "documentation": {"kind": "markdown", "value": "\n`includesFrom(str, searchValue, start)` returns `true` if `searchValue` is found\nanywhere within `str` starting at character number `start` (where 0 is the\nfirst character), `false` otherwise.\nSee [`String.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) on MDN.\n\n## Examples\n\n```rescript\nString.includesFrom(\"programmer\", \"gram\", 1) == true\nString.includesFrom(\"programmer\", \"gram\", 4) == false\nString.includesFrom(`대한민국`, `한`, 1) == true\n```\n"}, - "sortText": "includesFrom", - "insertText": "->String.includesFrom", + "detail": "(string, string) => bool", + "documentation": {"kind": "markdown", "value": "\n`includes(str, searchValue)` returns `true` if `searchValue` is found anywhere\nwithin `str`, `false` otherwise.\nSee [`String.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) on MDN.\n\n## Examples\n\n```rescript\nString.includes(\"programmer\", \"gram\") == true\nString.includes(\"programmer\", \"er\") == true\nString.includes(\"programmer\", \"pro\") == true\nString.includes(\"programmer.dat\", \"xyz\") == false\n```\n"}, + "sortText": "includes", + "insertText": "->String.includes", "additionalTextEdits": [{ "range": {"start": {"line": 89, "character": 55}, "end": {"line": 89, "character": 56}}, "newText": "" }] }, { - "label": "->String.includes", + "label": "->String.includesFrom", "kind": 12, "tags": [], - "detail": "(string, string) => bool", - "documentation": {"kind": "markdown", "value": "\n`includes(str, searchValue)` returns `true` if `searchValue` is found anywhere\nwithin `str`, `false` otherwise.\nSee [`String.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) on MDN.\n\n## Examples\n\n```rescript\nString.includes(\"programmer\", \"gram\") == true\nString.includes(\"programmer\", \"er\") == true\nString.includes(\"programmer\", \"pro\") == true\nString.includes(\"programmer.dat\", \"xyz\") == false\n```\n"}, - "sortText": "includes", - "insertText": "->String.includes", + "detail": "(string, string, int) => bool", + "documentation": {"kind": "markdown", "value": "\n`includesFrom(str, searchValue, start)` returns `true` if `searchValue` is found\nanywhere within `str` starting at character number `start` (where 0 is the\nfirst character), `false` otherwise.\nSee [`String.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) on MDN.\n\n## Examples\n\n```rescript\nString.includesFrom(\"programmer\", \"gram\", 1) == true\nString.includesFrom(\"programmer\", \"gram\", 4) == false\nString.includesFrom(`대한민국`, `한`, 1) == true\n```\n"}, + "sortText": "includesFrom", + "insertText": "->String.includesFrom", "additionalTextEdits": [{ "range": {"start": {"line": 89, "character": 55}, "end": {"line": 89, "character": 56}}, "newText": "" From 4a971c0c7212e56896c751decfbe3c774e4d5511 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Fri, 11 Jul 2025 15:20:26 +0200 Subject: [PATCH 15/16] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index adf1501b22..bb51e4b097 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ #### :rocket: New Feature - Add experimental command to `rescript-tools` for formatting all ReScript code blocks in markdown. Either in a markdown file directly, or inside of docstrings in ReScript code. https://github.com/rescript-lang/rescript/pull/7598 +- Add experimental command to `rescript-tools` for extracting all ReScript code blocks from markdown, either a md-file directly, or inside of docstrings in ReScript code. https://github.com/rescript-lang/rescript/pull/7623 - Add `String.getSymbolUnsafe` back to Stdlib. https://github.com/rescript-lang/rescript/pull/7626 #### :nail_care: Polish From f8a5a7104266fe35c9b76831ea7df5519a9d1129 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Fri, 11 Jul 2025 19:59:41 +0200 Subject: [PATCH 16/16] fix changelog --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb51e4b097..2b499f6278 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,12 +17,15 @@ - Remove internal/unused `-bs-v` flag. https://github.com/rescript-lang/rescript/pull/7627 - Remove unused `-bs-D` and `-bs-list-conditionals` flags. https://github.com/rescript-lang/rescript/pull/7631 +#### :rocket: New Feature + +- Add experimental command to `rescript-tools` for extracting all ReScript code blocks from markdown, either a md-file directly, or inside of docstrings in ReScript code. https://github.com/rescript-lang/rescript/pull/7623 + # 12.0.0-beta.1 #### :rocket: New Feature - Add experimental command to `rescript-tools` for formatting all ReScript code blocks in markdown. Either in a markdown file directly, or inside of docstrings in ReScript code. https://github.com/rescript-lang/rescript/pull/7598 -- Add experimental command to `rescript-tools` for extracting all ReScript code blocks from markdown, either a md-file directly, or inside of docstrings in ReScript code. https://github.com/rescript-lang/rescript/pull/7623 - Add `String.getSymbolUnsafe` back to Stdlib. https://github.com/rescript-lang/rescript/pull/7626 #### :nail_care: Polish