From 607e6d822e0de12399e3879ff5631974b3e70af7 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Fri, 16 Dec 2022 20:38:38 +0100 Subject: [PATCH 01/11] complete pipe chains --- analysis/src/CompletionFrontEnd.ml | 49 +- analysis/tests/src/CompletionPipeChain.res | 19 + .../src/expected/CompletionPipeChain.res.txt | 1970 +++++++++++++++++ 3 files changed, 2036 insertions(+), 2 deletions(-) create mode 100644 analysis/tests/src/CompletionPipeChain.res create mode 100644 analysis/tests/src/expected/CompletionPipeChain.res.txt diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index bce92250b..d7f12cac5 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -157,6 +157,46 @@ let rec exprToContextPath (e : Parsetree.expression) = | Some contexPath -> Some (CPApply (contexPath, args |> List.map fst))) | _ -> None +let completePipeChain ~(lhs : Parsetree.expression) = + (* Complete the end of pipe chains by reconstructing the pipe chain as a single pipe, + so it can be completed. + Example: + someArray->Js.Array2.filter(v => v > 10)->Js.Array2.map(v => v + 2)-> + will complete as: + Js.Array2.map(someArray->Js.Array2.filter(v => v > 10), v => v + 2)-> + *) + match lhs.pexp_desc with + (* When the left side of the pipe we're completing is a function application. + Example: someArray->Js.Array2.map(v => v + 2)-> *) + | Pexp_apply + ( {pexp_desc = Pexp_ident {txt = Lident "|."}}, + [ + (_, lhs); + (_, {pexp_desc = Pexp_apply (d, args); pexp_loc; pexp_attributes}); + ] ) -> + exprToContextPath + { + pexp_desc = Pexp_apply (d, (Nolabel, lhs) :: args); + pexp_loc; + pexp_attributes; + } + (* When the left side of the pipe we're completing is an identifier application. + Example: someArray->filterAllTheGoodStuff-> *) + | Pexp_apply + ( {pexp_desc = Pexp_ident {txt = Lident "|."}}, + [(_, lhs); (_, {pexp_desc = Pexp_ident id; pexp_loc; pexp_attributes})] + ) -> + exprToContextPath + { + pexp_desc = + Pexp_apply + ( {pexp_desc = Pexp_ident id; pexp_loc; pexp_attributes}, + [(Nolabel, lhs)] ); + pexp_loc; + pexp_attributes; + } + | _ -> None + let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = let offsetNoWhite = skipWhite text (offset - 1) in let posNoWhite = @@ -392,11 +432,16 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text = (Loc.toString expr.pexp_loc) in let setPipeResult ~(lhs : Parsetree.expression) ~id = - match exprToContextPath lhs with + match completePipeChain ~lhs with + | None -> ( + match exprToContextPath lhs with + | Some pipe -> + setResult (Cpath (CPPipe (pipe, id))); + true + | None -> false) | Some pipe -> setResult (Cpath (CPPipe (pipe, id))); true - | None -> false in match expr.pexp_desc with | Pexp_apply diff --git a/analysis/tests/src/CompletionPipeChain.res b/analysis/tests/src/CompletionPipeChain.res new file mode 100644 index 000000000..299936596 --- /dev/null +++ b/analysis/tests/src/CompletionPipeChain.res @@ -0,0 +1,19 @@ +let mapArr = arr => arr->Js.Array2.map(v => v + 2) +let arr = [1, 2, 3] +// let _ = arr-> +// ^com + +// let _ = arr->Js.Array2.map(v => v)-> +// ^com + +// let _ = arr->Js.Array2.filter(v => v)->Js.Array2.filter(v => v)-> +// ^com + +// let _ = arr->Js.Array2.filter(v => v)-> +// ^com + +// let _ = arr->Js.Array2-map(v => v)->Belt.List.fromArray-> +// ^com + +// let _ = arr->Js.Array2-map(v => v)->Belt.List.fromArray->s +// ^com diff --git a/analysis/tests/src/expected/CompletionPipeChain.res.txt b/analysis/tests/src/expected/CompletionPipeChain.res.txt new file mode 100644 index 000000000..703851a24 --- /dev/null +++ b/analysis/tests/src/expected/CompletionPipeChain.res.txt @@ -0,0 +1,1970 @@ +Complete src/CompletionPipeChain.res 2:16 +posCursor:[2:16] posNoWhite:[2:15] Found expr:[2:11->0:-1] +Completable: Cpath Value[arr]-> +[{ + "label": "Js.Array2.mapi", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => 'b) => t<'b>", + "documentation": {"kind": "markdown", "value": "\nApplies the function (the second argument) to each item in the array, returning\na new array. The function acceps two arguments: an item from the array and its\nindex number. The result array does not have to have elements of the same type\nas the input array. See\n[`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)\non MDN.\n\n```res example\n// multiply each item in array by its position\nlet product = (item, index) => item * index\nJs.Array2.mapi([10, 11, 12], product) == [0, 11, 24]\n```\n"} + }, { + "label": "Js.Array2.lastIndexOf", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => int", + "documentation": {"kind": "markdown", "value": "\nReturns the index of the last element in the array that has the given value. If\nthe value is not in the array, returns -1. See\n[`Array.lastIndexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)\non MDN.\n\n```res example\nJs.Array2.lastIndexOf([\"a\", \"b\", \"a\", \"c\"], \"a\") == 2\nJs.Array2.lastIndexOf([\"a\", \"b\", \"a\", \"c\"], \"x\") == -1\n```\n"} + }, { + "label": "Js.Array2.concat", + "kind": 12, + "tags": [], + "detail": "(t<'a>, t<'a>) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nConcatenates the second array argument to the first array argument, returning a\nnew array. The original arrays are not modified. See\n[`Array.concat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)\non MDN.\n\n```res example\nJs.Array2.concat([\"a\", \"b\"], [\"c\", \"d\", \"e\"]) == [\"a\", \"b\", \"c\", \"d\", \"e\"]\n```\n"} + }, { + "label": "Js.Array2.unshiftMany", + "kind": 12, + "tags": [], + "detail": "(t<'a>, array<'a>) => int", + "documentation": {"kind": "markdown", "value": "\nAdds the elements in the second array argument at the beginning of the first\narray argument, returning the new number of elements in the array. *This\nfunction modifies the original array.* See\n[`Array.unshift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)\non MDN.\n\n```res example\nlet arr = [\"d\", \"e\"]\nJs.Array2.unshiftMany(arr, [\"a\", \"b\", \"c\"]) == 5\narr == [\"a\", \"b\", \"c\", \"d\", \"e\"]\n```\n"} + }, { + "label": "Js.Array2.filter", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nApplies the given predicate function (the second argument) to each element in\nthe array; the result is an array of those elements for which the predicate\nfunction returned `true`. See\n[`Array.filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)\non MDN.\n\n```res example\nlet nonEmpty = s => s != \"\"\nJs.Array2.filter([\"abc\", \"\", \"\", \"def\", \"ghi\"], nonEmpty) == [\"abc\", \"def\", \"ghi\"]\n```\n"} + }, { + "label": "Js.Array2.shift", + "kind": 12, + "tags": [], + "detail": "t<'a> => option<'a>", + "documentation": {"kind": "markdown", "value": "\nIf the array is not empty, removes the first element and returns it as\n`Some(value)`; returns `None` if the array is empty. *This function modifies\nthe original array.* See\n[`Array.shift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.shift(arr) == Some(100)\narr == [101, 102, 103, 104]\n\nlet empty: array = []\nJs.Array2.shift(empty) == None\n```\n"} + }, { + "label": "Js.Array2.reduceRight", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('b, 'a) => 'b, 'b) => 'b", + "documentation": {"kind": "markdown", "value": "\nThe `reduceRight()` function takes three parameters: an array, a *reducer\nfunction*, and a beginning accumulator value. The reducer function has two\nparameters: an accumulated value and an element of the array.\n\n`reduceRight()` first calls the reducer function with the beginning value and\nthe last element in the array. The result becomes the new accumulator value,\nwhich is passed in to the reducer function along with the next-to-last element\nin the array. `reduceRight()` proceeds from right to left through the array,\npassing in the result of each stage as the accumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reduceRight()`. See\n[`Array.reduceRight`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight)\non MDN.\n\n**NOTE:** In many cases, `reduce()` and `reduceRight()` give the same result.\nHowever, see the last example here and compare it to the example from\n`reduce()`, where order makes a difference.\n\n```res example\nlet sumOfSquares = (accumulator, item) => accumulator + item * item\n\nJs.Array2.reduceRight([10, 2, 4], sumOfSquares, 0) == 120\nJs.Array2.reduceRight([2.0, 4.0], (acc, item) => item /. acc, 1.0) == 0.5 // 2.0 / (4.0 / 1.0)\n```\n"} + }, { + "label": "Js.Array2.joinWith", + "kind": 12, + "tags": [], + "detail": "(t<'a>, string) => string", + "documentation": {"kind": "markdown", "value": "\nThis function converts each element of the array to a string (via JavaScript)\nand concatenates them, separated by the string given in the first argument,\ninto a single string. See\n[`Array.join`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)\non MDN.\n\n```res example\nJs.Array2.joinWith([\"ant\", \"bee\", \"cat\"], \"--\") == \"ant--bee--cat\"\nJs.Array2.joinWith([\"door\", \"bell\"], \"\") == \"doorbell\"\nJs.Array2.joinWith([2020, 9, 4], \"/\") == \"2020/9/4\"\nJs.Array2.joinWith([2.5, 3.6, 3e-2], \";\") == \"2.5;3.6;0.03\"\n```\n"} + }, { + "label": "Js.Array2.concatMany", + "kind": 12, + "tags": [], + "detail": "(t<'a>, array>) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nThe second argument to `concatMany()` is an array of arrays; these are added at\nthe end of the first argument, returning a new array. See\n[`Array.concat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)\non MDN.\n\n```res example\nJs.Array2.concatMany([\"a\", \"b\", \"c\"], [[\"d\", \"e\"], [\"f\", \"g\", \"h\"]]) == [\n \"a\",\n \"b\",\n \"c\",\n \"d\",\n \"e\",\n \"f\",\n \"g\",\n \"h\",\n ]\n```\n"} + }, { + "label": "Js.Array2.fillInPlace", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nSets all elements of the given array (the first arumgent) to the designated\nvalue (the secon argument), returning the resulting array. *This function\n modifies the original array.*\n\nSee\n[`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.fillInPlace(arr, 99) == [99, 99, 99, 99, 99]\narr == [99, 99, 99, 99, 99]\n```\n"} + }, { + "label": "Js.Array2.isArray", + "kind": 12, + "tags": [], + "detail": "'a => bool", + "documentation": {"kind": "markdown", "value": "\nReturns `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.\n\n```res example\nJs.Array2.isArray([5, 2, 3, 1, 4]) == true\nJs.Array2.isArray(list{5, 2, 3, 1, 4}) == true\nJs.Array2.isArray(\"abcd\") == false\n```\n"} + }, { + "label": "Js.Array2.reduce", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('b, 'a) => 'b, 'b) => 'b", + "documentation": {"kind": "markdown", "value": "\nThe `reduce()` function takes three parameters: an array, a *reducer function*,\nand a beginning accumulator value. The reducer function has two parameters: an\naccumulated value and an element of the array.\n\n`reduce()` first calls the reducer function with the beginning value and the\nfirst element in the array. The result becomes the new accumulator value, which\nis passed in to the reducer function along with the second element in the\narray. `reduce()` proceeds through the array, passing in the result of each\nstage as the accumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reduce()`. See\n[`Array.reduce`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce)\non MDN.\n\n```res example\nlet sumOfSquares = (accumulator, item) => accumulator + item * item\n\nJs.Array2.reduce([10, 2, 4], sumOfSquares, 0) == 120\nJs.Array2.reduce([10, 2, 4], \\\"*\", 1) == 80\nJs.Array2.reduce(\n [\"animal\", \"vegetable\", \"mineral\"],\n (acc, item) => acc + Js.String.length(item),\n 0,\n) == 22 // 6 + 9 + 7\nJs.Array2.reduce([2.0, 4.0], (acc, item) => item /. acc, 1.0) == 2.0 // 4.0 / (2.0 / 1.0)\n```\n"} + }, { + "label": "Js.Array2.copy", + "kind": 12, + "tags": [], + "detail": "t<'a> => t<'a>", + "documentation": {"kind": "markdown", "value": "\nReturns a copy of the entire array. Same as `Js.Array2.Slice(arr, ~start=0,\n~end_=Js.Array2.length(arr))`. See\n[`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\non MDN.\n"} + }, { + "label": "Js.Array2.reducei", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('b, 'a, int) => 'b, 'b) => 'b", + "documentation": {"kind": "markdown", "value": "\nThe `reducei()` function takes three parameters: an array, a *reducer\nfunction*, and a beginning accumulator value. The reducer function has three\nparameters: an accumulated value, an element of the array, and the index of\nthat element.\n\n`reducei()` first calls the reducer function with the beginning value, the\nfirst element in the array, and zero (its index). The result becomes the new\naccumulator value, which is passed to the reducer function along with the\nsecond element in the array and one (its index). `reducei()` proceeds from left\nto right through the array, passing in the result of each stage as the\naccumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reducei()`. See\n[`Array.reduce`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce)\non MDN.\n\n```res example\n// find sum of even-index elements in array\nlet sumOfEvens = (accumulator, item, index) =>\n if mod(index, 2) == 0 {\n accumulator + item\n } else {\n accumulator\n }\n\nJs.Array2.reducei([2, 5, 1, 4, 3], sumOfEvens, 0) == 6\n```\n"} + }, { + "label": "Js.Array2.forEachi", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => unit) => unit", + "documentation": {"kind": "markdown", "value": "\nThe `forEachi()` function applies the function given as the second argument to\neach element in the array. The function you provide takes an item in the array\nand its index number, and returns `unit`. The `forEachi()` function also\nreturns `unit`. You use `forEachi()` when you need to process each element in\nthe array but not return any new array or value; for example, to print the\nitems in an array. See\n[`Array.forEach`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)\non MDN.\n\n```res example\n// display all elements in an array as a numbered list\nJs.Array2.forEachi([\"a\", \"b\", \"c\"], (item, index) => Js.log2(index + 1, item)) == ()\n```\n"} + }, { + "label": "Js.Array2.fillFromInPlace", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a, ~from: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nSets all elements of the given array (the first arumgent) from position `~from`\nto the end to the designated value (the second argument), returning the\nresulting array. *This function modifies the original array.* See\n[`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.fillFromInPlace(arr, 99, ~from=2) == [100, 101, 99, 99, 99]\narr == [100, 101, 99, 99, 99]\n```\n"} + }, { + "label": "Js.Array2.findi", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => bool) => option<'a>", + "documentation": {"kind": "markdown", "value": "\nReturns `Some(value)` for the first element in the array that satisifies the\ngiven predicate function, or `None` if no element satisifies the predicate. The\npredicate function takes an array element and an index as its parameters. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\n// find first positive item at an odd index\nlet positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0\n\nJs.Array2.findi([66, -33, 55, 88, 22], positiveOddElement) == Some(88)\nJs.Array2.findi([66, -33, 55, -88, 22], positiveOddElement) == None\n```\n"} + }, { + "label": "Js.Array2.filteri", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => bool) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nEach element of the given array are passed to the predicate function. The\nreturn value is an array of all those elements for which the predicate function\nreturned `true`.\n\nSee\n[`Array.filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)\non MDN.\n\n```res example\n// keep only positive elements at odd indices\nlet positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0\n\nJs.Array2.filteri([6, 3, 5, 8, 7, -4, 1], positiveOddElement) == [3, 8]\n```\n"} + }, { + "label": "Js.Array2.slice", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~start: int, ~end_: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nReturns a shallow copy of the given array from the `~start` index up to but not\nincluding the `~end_` position. Negative numbers indicate an offset from the\nend of the array. See\n[`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104, 105, 106]\nJs.Array2.slice(arr, ~start=2, ~end_=5) == [102, 103, 104]\nJs.Array2.slice(arr, ~start=-3, ~end_=-1) == [104, 105]\nJs.Array2.slice(arr, ~start=9, ~end_=10) == []\n```\n"} + }, { + "label": "Js.Array2.fromMap", + "kind": 12, + "tags": [], + "detail": "(array_like<'a>, 'a => 'b) => array<'b>", + "documentation": {"kind": "markdown", "value": "\nCreates a new array by applying a function (the second argument) to each item\nin the `array_like` first argument. See\n[`Array.from`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)\non MDN.\n\n```res example\nlet strArr = Js.String.castToArrayLike(\"abcd\")\nlet code = s => Js.String.charCodeAt(0, s)\nJs.Array2.fromMap(strArr, code) == [97.0, 98.0, 99.0, 100.0]\n```\n"} + }, { + "label": "Js.Array2.removeFromInPlace", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~pos: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nRemoves elements from the given array starting at position `~pos` to the end of\nthe array, returning the removed elements. *This function modifies the original\narray.* See\n[`Array.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)\non MDN.\n\n```res example\nlet arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.removeFromInPlace(arr, ~pos=4) == [\"e\", \"f\"]\narr == [\"a\", \"b\", \"c\", \"d\"]\n```\n"} + }, { + "label": "Js.Array2.from", + "kind": 12, + "tags": [], + "detail": "array_like<'a> => array<'a>", + "documentation": {"kind": "markdown", "value": "\nCreates a shallow copy of an array from an array-like object. See\n[`Array.from`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)\non MDN.\n\n```res example\nlet strArr = Js.String.castToArrayLike(\"abcd\")\nJs.Array2.from(strArr) == [\"a\", \"b\", \"c\", \"d\"]\n```\n"} + }, { + "label": "Js.Array2.includes", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => bool", + "documentation": {"kind": "markdown", "value": "\nReturns true if the given value is in the array, `false` otherwise. See\n[`Array.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)\non MDN.\n\n```res example\nJs.Array2.includes([\"a\", \"b\", \"c\"], \"b\") == true\nJs.Array2.includes([\"a\", \"b\", \"c\"], \"x\") == false\n```\n"} + }, { + "label": "Js.Array2.find", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => option<'a>", + "documentation": {"kind": "markdown", "value": "\nReturns `Some(value)` for the first element in the array that satisifies the\ngiven predicate function, or `None` if no element satisifies the predicate. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\n// find first negative element\nJs.Array2.find([33, 22, -55, 77, -44], x => x < 0) == Some(-55)\nJs.Array2.find([33, 22, 55, 77, 44], x => x < 0) == None\n```\n"} + }, { + "label": "Js.Array2.reduceRighti", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('b, 'a, int) => 'b, 'b) => 'b", + "documentation": {"kind": "markdown", "value": "\nThe `reduceRighti()` function takes three parameters: an array, a *reducer\nfunction*, and a beginning accumulator value. The reducer function has three\nparameters: an accumulated value, an element of the array, and the index of\nthat element. `reduceRighti()` first calls the reducer function with the\nbeginning value, the last element in the array, and its index (length of array\nminus one). The result becomes the new accumulator value, which is passed in to\nthe reducer function along with the second element in the array and one (its\nindex). `reduceRighti()` proceeds from right to left through the array, passing\nin the result of each stage as the accumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reduceRighti()`. See\n[`Array.reduceRight`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight)\non MDN.\n\n**NOTE:** In many cases, `reducei()` and `reduceRighti()` give the same result.\nHowever, there are cases where the order in which items are processed makes a\ndifference.\n\n```res example\n// find sum of even-index elements in array\nlet sumOfEvens = (accumulator, item, index) =>\n if mod(index, 2) == 0 {\n accumulator + item\n } else {\n accumulator\n }\n\nJs.Array2.reduceRighti([2, 5, 1, 4, 3], sumOfEvens, 0) == 6\n```\n"} + }, { + "label": "Js.Array2.findIndexi", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => bool) => int", + "documentation": {"kind": "markdown", "value": "\nReturns `Some(value)` for the first element in the array that satisifies the\ngiven predicate function, or `None` if no element satisifies the predicate. The\npredicate function takes an array element and an index as its parameters. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\n// find index of first positive item at an odd index\nlet positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0\n\nJs.Array2.findIndexi([66, -33, 55, 88, 22], positiveOddElement) == 3\nJs.Array2.findIndexi([66, -33, 55, -88, 22], positiveOddElement) == -1\n```\n"} + }, { + "label": "Js.Array2.toLocaleString", + "kind": 12, + "tags": [], + "detail": "t<'a> => string", + "documentation": {"kind": "markdown", "value": "\nConverts the array to a string using the conventions of the current locale.\nEach element is converted to a string using JavaScript. Unlike the JavaScript\n`Array.toLocaleString()`, all elements in a ReasonML array must have the same\ntype. See\n[`Array.toLocaleString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString)\non MDN.\n\n```res example\nJs.Array2.toLocaleString([Js.Date.make()])\n// returns \"3/19/2020, 10:52:11 AM\" for locale en_US.utf8\n// returns \"2020-3-19 10:52:11\" for locale de_DE.utf8\n```\n"} + }, { + "label": "Js.Array2.lastIndexOfFrom", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a, ~from: int) => int", + "documentation": {"kind": "markdown", "value": "\nReturns the index of the last element in the array that has the given value,\nsearching from position `~from` down to the start of the array. If the value is\nnot in the array, returns -1. See\n[`Array.lastIndexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)\non MDN.\n\n```res example\nJs.Array2.lastIndexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\", \"d\"], \"a\", ~from=3) == 2\nJs.Array2.lastIndexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\", \"d\"], \"c\", ~from=2) == -1\n```\n"} + }, { + "label": "Js.Array2.copyWithinFromRange", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~to_: int, ~start: int, ~end_: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nCopies starting at element `~start` in the given array up to but not including\n`~end_` to the designated `~to_` position, returning the resulting array. *This\nfunction modifies the original array.* See\n[`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104, 105]\nJs.Array2.copyWithinFromRange(arr, ~start=2, ~end_=5, ~to_=1) == [100, 102, 103, 104, 104, 105]\narr == [100, 102, 103, 104, 104, 105]\n```\n"} + }, { + "label": "Js.Array2.findIndex", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => int", + "documentation": {"kind": "markdown", "value": "\nReturns the index of the first element in the array that satisifies the given\npredicate function, or -1 if no element satisifies the predicate. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\nJs.Array2.findIndex([33, 22, -55, 77, -44], x => x < 0) == 2\nJs.Array2.findIndex([33, 22, 55, 77, 44], x => x < 0) == -1\n```\n"} + }, { + "label": "Js.Array2.removeCountInPlace", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~pos: int, ~count: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nRemoves `~count` elements from the given array starting at position `~pos`,\nreturning the removed elements. *This function modifies the original array.*\nSee\n[`Array.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)\non MDN.\n\n```res example\nlet arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.removeCountInPlace(arr, ~pos=2, ~count=3) == [\"c\", \"d\", \"e\"]\narr == [\"a\", \"b\", \"f\"]\n```\n"} + }, { + "label": "Js.Array2.reverseInPlace", + "kind": 12, + "tags": [], + "detail": "t<'a> => t<'a>", + "documentation": {"kind": "markdown", "value": "\nReturns an array with the elements of the input array in reverse order. *This\nfunction modifies the original array.* See\n[`Array.reverse`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse)\non MDN.\n\n```res example\nlet arr = [\"ant\", \"bee\", \"cat\"]\nJs.Array2.reverseInPlace(arr) == [\"cat\", \"bee\", \"ant\"]\narr == [\"cat\", \"bee\", \"ant\"]\n```\n"} + }, { + "label": "Js.Array2.every", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => bool", + "documentation": {"kind": "markdown", "value": "\nThe first argument to `every()` is an array. The second argument is a predicate\nfunction that returns a boolean. The `every()` function returns `true` if the\npredicate function is true for all items in the given array. If given an empty\narray, returns `true`. See\n[`Array.every`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)\non MDN.\n\n```res example\nlet isEven = x => mod(x, 2) == 0\nJs.Array2.every([6, 22, 8, 4], isEven) == true\nJs.Array2.every([6, 22, 7, 4], isEven) == false\n```\n"} + }, { + "label": "Js.Array2.length", + "kind": 12, + "tags": [], + "detail": "array<'a> => int", + "documentation": {"kind": "markdown", "value": "\nReturns the number of elements in the array. See\n[`Array.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)\non MDN.\n"} + }, { + "label": "Js.Array2.indexOf", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => int", + "documentation": {"kind": "markdown", "value": "\nReturns the index of the first element in the array that has the given value.\nIf the value is not in the array, returns -1. See\n[`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)\non MDN.\n\n```res example\nJs.Array2.indexOf([100, 101, 102, 103], 102) == 2\nJs.Array2.indexOf([100, 101, 102, 103], 999) == -1\n```\n"} + }, { + "label": "Js.Array2.unshift", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => int", + "documentation": {"kind": "markdown", "value": "\nAdds the given element to the array, returning the new number of elements in\nthe array. *This function modifies the original array.* See\n[`Array.unshift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)\non MDN.\n\n```res example\nlet arr = [\"b\", \"c\", \"d\"]\nJs.Array2.unshift(arr, \"a\") == 4\narr == [\"a\", \"b\", \"c\", \"d\"]\n```\n"} + }, { + "label": "Js.Array2.sortInPlace", + "kind": 12, + "tags": [], + "detail": "t<'a> => t<'a>", + "documentation": {"kind": "markdown", "value": "\nSorts the given array in place and returns the sorted array. JavaScript sorts\nthe array by converting the arguments to UTF-16 strings and sorting them. See\nthe second example with sorting numbers, which does not do a numeric sort.\n*This function modifies the original array.* See\n[`Array.sort`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)\non MDN.\n\n```res example\nlet words = [\"bee\", \"dog\", \"ant\", \"cat\"]\nJs.Array2.sortInPlace(words) == [\"ant\", \"bee\", \"cat\", \"dog\"]\nwords == [\"ant\", \"bee\", \"cat\", \"dog\"]\n\nlet numbers = [3, 30, 10, 1, 20, 2]\nJs.Array2.sortInPlace(numbers) == [1, 10, 2, 20, 3, 30]\nnumbers == [1, 10, 2, 20, 3, 30]\n```\n"} + }, { + "label": "Js.Array2.unsafe_get", + "kind": 12, + "tags": [], + "detail": "(array<'a>, int) => 'a", + "documentation": {"kind": "markdown", "value": "\nReturns the value at the given position in the array if the position is in\nbounds; returns the JavaScript value `undefined` otherwise.\n\n```res example\nlet arr = [100, 101, 102, 103]\nJs.Array2.unsafe_get(arr, 3) == 103\nJs.Array2.unsafe_get(arr, 4) // returns undefined\n```\n"} + }, { + "label": "Js.Array2.some", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => bool", + "documentation": {"kind": "markdown", "value": "\nReturns `true` if the predicate function given as the second argument to\n`some()` returns `true` for any element in the array; `false` otherwise.\n\n```res example\nlet isEven = x => mod(x, 2) == 0\n\nJs.Array2.some([3, 7, 5, 2, 9], isEven) == true\nJs.Array2.some([3, 7, 5, 1, 9], isEven) == false\n```\n"} + }, { + "label": "Js.Array2.map", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => 'b) => t<'b>", + "documentation": {"kind": "markdown", "value": "\nApplies the function (the second argument) to each item in the array, returning\na new array. The result array does not have to have elements of the same type\nas the input array. See\n[`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)\non MDN.\n\n```res example\nJs.Array2.map([12, 4, 8], x => x * x) == [144, 16, 64]\nJs.Array2.map([\"animal\", \"vegetable\", \"mineral\"], Js.String.length) == [6, 9, 7]\n```\n"} + }, { + "label": "Js.Array2.push", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => int", + "documentation": {"kind": "markdown", "value": "\nAppends the given value to the array, returning the number of elements in the\nupdated array. *This function modifies the original array.* See\n[`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)\non MDN.\n\n```res example\nlet arr = [\"ant\", \"bee\", \"cat\"]\nJs.Array2.push(arr, \"dog\") == 4\narr == [\"ant\", \"bee\", \"cat\", \"dog\"]\n```\n"} + }, { + "label": "Js.Array2.fillRangeInPlace", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a, ~start: int, ~end_: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nSets the elements of the given array (the first arumgent) from position\n`~start` up to but not including position `~end_` to the designated value (the\nsecond argument), returning the resulting array. *This function modifies the\noriginal array.* See\n[`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.fillRangeInPlace(arr, 99, ~start=1, ~end_=4) == [100, 99, 99, 99, 104]\narr == [100, 99, 99, 99, 104]\n```\n"} + }, { + "label": "Js.Array2.pop", + "kind": 12, + "tags": [], + "detail": "t<'a> => option<'a>", + "documentation": {"kind": "markdown", "value": "\nIf the array is not empty, removes the last element and returns it as\n`Some(value)`; returns `None` if the array is empty. *This function modifies\nthe original array.* See\n[`Array.pop`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.pop(arr) == Some(104)\narr == [100, 101, 102, 103]\n\nlet empty: array = []\nJs.Array2.pop(empty) == None\n```\n"} + }, { + "label": "Js.Array2.somei", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => bool) => bool", + "documentation": {"kind": "markdown", "value": "\nReturns `true` if the predicate function given as the second argument to\n`somei()` returns `true` for any element in the array; `false` otherwise. The\npredicate function has two arguments: an item from the array and the index\nvalue\n\n```res example\n// Does any string in the array\n// have the same length as its index?\n\nlet sameLength = (str, index) => Js.String.length(str) == index\n\n// \"ef\" has length 2 and is it at index 2\nJs.Array2.somei([\"ab\", \"cd\", \"ef\", \"gh\"], sameLength) == true\n// no item has the same length as its index\nJs.Array2.somei([\"a\", \"bc\", \"def\", \"gh\"], sameLength) == false\n```\n"} + }, { + "label": "Js.Array2.append", + "kind": 12, + "tags": [1], + "detail": "(t<'a>, 'a) => t<'a>", + "documentation": {"kind": "markdown", "value": "Deprecated: `append` is not type-safe. Use `concat` instead.\n\n"} + }, { + "label": "Js.Array2.unsafe_set", + "kind": 12, + "tags": [], + "detail": "(array<'a>, int, 'a) => unit", + "documentation": {"kind": "markdown", "value": "\nSets the value at the given position in the array if the position is in bounds.\nIf the index is out of bounds, well, “here there be dragons.“\n\n*This function modifies the original array.*\n\n```res example\nlet arr = [100, 101, 102, 103]\nJs.Array2.unsafe_set(arr, 3, 99)\n// result is [100, 101, 102, 99];\n\nJs.Array2.unsafe_set(arr, 4, 88)\n// result is [100, 101, 102, 99, 88]\n\nJs.Array2.unsafe_set(arr, 6, 77)\n// result is [100, 101, 102, 99, 88, <1 empty item>, 77]\n\nJs.Array2.unsafe_set(arr, -1, 66)\n// you don't want to know.\n```\n"} + }, { + "label": "Js.Array2.copyWithin", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~to_: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nCopies from the first element in the given array to the designated `~to_`\nposition, returning the resulting array. *This function modifies the original\narray.* See\n[`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.copyWithin(arr, ~to_=2) == [100, 101, 100, 101, 102]\narr == [100, 101, 100, 101, 102]\n```\n"} + }, { + "label": "Js.Array2.everyi", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => bool) => bool", + "documentation": {"kind": "markdown", "value": "\nThe first argument to `everyi()` is an array. The second argument is a\npredicate function with two arguments: an array element and that element’s\nindex; it returns a boolean. The `everyi()` function returns `true` if the\npredicate function is true for all items in the given array. If given an empty\narray, returns `true`. See\n[`Array.every`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)\non MDN.\n\n```res example\n// determine if all even-index items are positive\nlet evenIndexPositive = (item, index) => mod(index, 2) == 0 ? item > 0 : true\n\nJs.Array2.everyi([6, -3, 5, 8], evenIndexPositive) == true\nJs.Array2.everyi([6, 3, -5, 8], evenIndexPositive) == false\n```\n"} + }, { + "label": "Js.Array2.toString", + "kind": 12, + "tags": [], + "detail": "t<'a> => string", + "documentation": {"kind": "markdown", "value": "\nConverts the array to a string. Each element is converted to a string using\nJavaScript. Unlike the JavaScript `Array.toString()`, all elements in a\nReasonML array must have the same type. See\n[`Array.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString)\non MDN.\n\n```res example\nJs.Array2.toString([3.5, 4.6, 7.8]) == \"3.5,4.6,7.8\"\nJs.Array2.toString([\"a\", \"b\", \"c\"]) == \"a,b,c\"\n```\n"} + }, { + "label": "Js.Array2.spliceInPlace", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~pos: int, ~remove: int, ~add: array<'a>) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nStarting at position `~pos`, remove `~remove` elements and then add the\nelements from the `~add` array. Returns an array consisting of the removed\nitems. *This function modifies the original array.* See\n[`Array.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)\non MDN.\n\n```res example\nlet arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.spliceInPlace(arr, ~pos=2, ~remove=2, ~add=[\"x\", \"y\", \"z\"]) == [\"c\", \"d\"]\narr == [\"a\", \"b\", \"x\", \"y\", \"z\", \"e\", \"f\"]\n\nlet arr2 = [\"a\", \"b\", \"c\", \"d\"]\nJs.Array2.spliceInPlace(arr2, ~pos=3, ~remove=0, ~add=[\"x\", \"y\"]) == []\narr2 == [\"a\", \"b\", \"c\", \"x\", \"y\", \"d\"]\n\nlet arr3 = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.spliceInPlace(arr3, ~pos=9, ~remove=2, ~add=[\"x\", \"y\", \"z\"]) == []\narr3 == [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"x\", \"y\", \"z\"]\n```\n"} + }, { + "label": "Js.Array2.pushMany", + "kind": 12, + "tags": [], + "detail": "(t<'a>, array<'a>) => int", + "documentation": {"kind": "markdown", "value": "\nAppends the values from one array (the second argument) to another (the first\nargument), returning the number of elements in the updated array. *This\nfunction modifies the original array.* See\n[`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)\non MDN.\n\n```res example\nlet arr = [\"ant\", \"bee\", \"cat\"]\nJs.Array2.pushMany(arr, [\"dog\", \"elk\"]) == 5\narr == [\"ant\", \"bee\", \"cat\", \"dog\", \"elk\"]\n```\n"} + }, { + "label": "Js.Array2.copyWithinFrom", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~to_: int, ~from: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nCopies starting at element `~from` in the given array to the designated `~to_`\nposition, returning the resulting array. *This function modifies the original\narray.* See\n[`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.copyWithinFrom(arr, ~from=2, ~to_=0) == [102, 103, 104, 103, 104]\narr == [102, 103, 104, 103, 104]\n```\n"} + }, { + "label": "Js.Array2.forEach", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => unit) => unit", + "documentation": {"kind": "markdown", "value": "\nThe `forEach()` function applies the function given as the second argument to\neach element in the array. The function you provide returns `unit`, and the\n`forEach()` function also returns `unit`. You use `forEach()` when you need to\nprocess each element in the array but not return any new array or value; for\nexample, to print the items in an array. See\n[`Array.forEach`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)\non MDN.\n\n```res example\n// display all elements in an array\nJs.Array2.forEach([\"a\", \"b\", \"c\"], x => Js.log(x)) == ()\n```\n"} + }, { + "label": "Js.Array2.sliceFrom", + "kind": 12, + "tags": [], + "detail": "(t<'a>, int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nReturns a shallow copy of the given array from the given index to the end. See\n[`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\non MDN.\n"} + }, { + "label": "Js.Array2.sortInPlaceWith", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, 'a) => int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nSorts the given array in place and returns the sorted array. *This function\n modifies the original array.*\n\nThe first argument to `sortInPlaceWith()` is a function that compares two items\nfrom the array and returns:\n\n* an integer less than zero if the first item is less than the second item *\nzero if the items are equal * an integer greater than zero if the first item is\ngreater than the second item\n\nSee\n[`Array.sort`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)\non MDN.\n\n```res example\n// sort by word length\nlet words = [\"horse\", \"aardvark\", \"dog\", \"camel\"]\nlet byLength = (s1, s2) => Js.String.length(s1) - Js.String.length(s2)\n\nJs.Array2.sortInPlaceWith(words, byLength) == [\"dog\", \"horse\", \"camel\", \"aardvark\"]\n\n// sort in reverse numeric order\nlet numbers = [3, 30, 10, 1, 20, 2]\nlet reverseNumeric = (n1, n2) => n2 - n1\nJs.Array2.sortInPlaceWith(numbers, reverseNumeric) == [30, 20, 10, 3, 2, 1]\n```\n"} + }, { + "label": "Js.Array2.indexOfFrom", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a, ~from: int) => int", + "documentation": {"kind": "markdown", "value": "\nReturns the index of the first element in the array with the given value. The\nsearch starts at position `~from`. See\n[`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)\non MDN.\n\n```res example\nJs.Array2.indexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\"], \"a\", ~from=2) == 2\nJs.Array2.indexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\"], \"a\", ~from=3) == 4\nJs.Array2.indexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\"], \"b\", ~from=2) == -1\n```\n"} + }] + +Complete src/CompletionPipeChain.res 5:39 +posCursor:[5:39] posNoWhite:[5:38] Found expr:[5:11->0:-1] +Completable: Cpath Value[Js, Array2, map](Nolabel, Nolabel)-> +[{ + "label": "Js.Array2.mapi", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => 'b) => t<'b>", + "documentation": {"kind": "markdown", "value": "\nApplies the function (the second argument) to each item in the array, returning\na new array. The function acceps two arguments: an item from the array and its\nindex number. The result array does not have to have elements of the same type\nas the input array. See\n[`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)\non MDN.\n\n```res example\n// multiply each item in array by its position\nlet product = (item, index) => item * index\nJs.Array2.mapi([10, 11, 12], product) == [0, 11, 24]\n```\n"} + }, { + "label": "Js.Array2.lastIndexOf", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => int", + "documentation": {"kind": "markdown", "value": "\nReturns the index of the last element in the array that has the given value. If\nthe value is not in the array, returns -1. See\n[`Array.lastIndexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)\non MDN.\n\n```res example\nJs.Array2.lastIndexOf([\"a\", \"b\", \"a\", \"c\"], \"a\") == 2\nJs.Array2.lastIndexOf([\"a\", \"b\", \"a\", \"c\"], \"x\") == -1\n```\n"} + }, { + "label": "Js.Array2.concat", + "kind": 12, + "tags": [], + "detail": "(t<'a>, t<'a>) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nConcatenates the second array argument to the first array argument, returning a\nnew array. The original arrays are not modified. See\n[`Array.concat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)\non MDN.\n\n```res example\nJs.Array2.concat([\"a\", \"b\"], [\"c\", \"d\", \"e\"]) == [\"a\", \"b\", \"c\", \"d\", \"e\"]\n```\n"} + }, { + "label": "Js.Array2.unshiftMany", + "kind": 12, + "tags": [], + "detail": "(t<'a>, array<'a>) => int", + "documentation": {"kind": "markdown", "value": "\nAdds the elements in the second array argument at the beginning of the first\narray argument, returning the new number of elements in the array. *This\nfunction modifies the original array.* See\n[`Array.unshift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)\non MDN.\n\n```res example\nlet arr = [\"d\", \"e\"]\nJs.Array2.unshiftMany(arr, [\"a\", \"b\", \"c\"]) == 5\narr == [\"a\", \"b\", \"c\", \"d\", \"e\"]\n```\n"} + }, { + "label": "Js.Array2.filter", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nApplies the given predicate function (the second argument) to each element in\nthe array; the result is an array of those elements for which the predicate\nfunction returned `true`. See\n[`Array.filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)\non MDN.\n\n```res example\nlet nonEmpty = s => s != \"\"\nJs.Array2.filter([\"abc\", \"\", \"\", \"def\", \"ghi\"], nonEmpty) == [\"abc\", \"def\", \"ghi\"]\n```\n"} + }, { + "label": "Js.Array2.shift", + "kind": 12, + "tags": [], + "detail": "t<'a> => option<'a>", + "documentation": {"kind": "markdown", "value": "\nIf the array is not empty, removes the first element and returns it as\n`Some(value)`; returns `None` if the array is empty. *This function modifies\nthe original array.* See\n[`Array.shift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.shift(arr) == Some(100)\narr == [101, 102, 103, 104]\n\nlet empty: array = []\nJs.Array2.shift(empty) == None\n```\n"} + }, { + "label": "Js.Array2.reduceRight", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('b, 'a) => 'b, 'b) => 'b", + "documentation": {"kind": "markdown", "value": "\nThe `reduceRight()` function takes three parameters: an array, a *reducer\nfunction*, and a beginning accumulator value. The reducer function has two\nparameters: an accumulated value and an element of the array.\n\n`reduceRight()` first calls the reducer function with the beginning value and\nthe last element in the array. The result becomes the new accumulator value,\nwhich is passed in to the reducer function along with the next-to-last element\nin the array. `reduceRight()` proceeds from right to left through the array,\npassing in the result of each stage as the accumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reduceRight()`. See\n[`Array.reduceRight`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight)\non MDN.\n\n**NOTE:** In many cases, `reduce()` and `reduceRight()` give the same result.\nHowever, see the last example here and compare it to the example from\n`reduce()`, where order makes a difference.\n\n```res example\nlet sumOfSquares = (accumulator, item) => accumulator + item * item\n\nJs.Array2.reduceRight([10, 2, 4], sumOfSquares, 0) == 120\nJs.Array2.reduceRight([2.0, 4.0], (acc, item) => item /. acc, 1.0) == 0.5 // 2.0 / (4.0 / 1.0)\n```\n"} + }, { + "label": "Js.Array2.joinWith", + "kind": 12, + "tags": [], + "detail": "(t<'a>, string) => string", + "documentation": {"kind": "markdown", "value": "\nThis function converts each element of the array to a string (via JavaScript)\nand concatenates them, separated by the string given in the first argument,\ninto a single string. See\n[`Array.join`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)\non MDN.\n\n```res example\nJs.Array2.joinWith([\"ant\", \"bee\", \"cat\"], \"--\") == \"ant--bee--cat\"\nJs.Array2.joinWith([\"door\", \"bell\"], \"\") == \"doorbell\"\nJs.Array2.joinWith([2020, 9, 4], \"/\") == \"2020/9/4\"\nJs.Array2.joinWith([2.5, 3.6, 3e-2], \";\") == \"2.5;3.6;0.03\"\n```\n"} + }, { + "label": "Js.Array2.concatMany", + "kind": 12, + "tags": [], + "detail": "(t<'a>, array>) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nThe second argument to `concatMany()` is an array of arrays; these are added at\nthe end of the first argument, returning a new array. See\n[`Array.concat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)\non MDN.\n\n```res example\nJs.Array2.concatMany([\"a\", \"b\", \"c\"], [[\"d\", \"e\"], [\"f\", \"g\", \"h\"]]) == [\n \"a\",\n \"b\",\n \"c\",\n \"d\",\n \"e\",\n \"f\",\n \"g\",\n \"h\",\n ]\n```\n"} + }, { + "label": "Js.Array2.fillInPlace", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nSets all elements of the given array (the first arumgent) to the designated\nvalue (the secon argument), returning the resulting array. *This function\n modifies the original array.*\n\nSee\n[`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.fillInPlace(arr, 99) == [99, 99, 99, 99, 99]\narr == [99, 99, 99, 99, 99]\n```\n"} + }, { + "label": "Js.Array2.isArray", + "kind": 12, + "tags": [], + "detail": "'a => bool", + "documentation": {"kind": "markdown", "value": "\nReturns `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.\n\n```res example\nJs.Array2.isArray([5, 2, 3, 1, 4]) == true\nJs.Array2.isArray(list{5, 2, 3, 1, 4}) == true\nJs.Array2.isArray(\"abcd\") == false\n```\n"} + }, { + "label": "Js.Array2.reduce", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('b, 'a) => 'b, 'b) => 'b", + "documentation": {"kind": "markdown", "value": "\nThe `reduce()` function takes three parameters: an array, a *reducer function*,\nand a beginning accumulator value. The reducer function has two parameters: an\naccumulated value and an element of the array.\n\n`reduce()` first calls the reducer function with the beginning value and the\nfirst element in the array. The result becomes the new accumulator value, which\nis passed in to the reducer function along with the second element in the\narray. `reduce()` proceeds through the array, passing in the result of each\nstage as the accumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reduce()`. See\n[`Array.reduce`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce)\non MDN.\n\n```res example\nlet sumOfSquares = (accumulator, item) => accumulator + item * item\n\nJs.Array2.reduce([10, 2, 4], sumOfSquares, 0) == 120\nJs.Array2.reduce([10, 2, 4], \\\"*\", 1) == 80\nJs.Array2.reduce(\n [\"animal\", \"vegetable\", \"mineral\"],\n (acc, item) => acc + Js.String.length(item),\n 0,\n) == 22 // 6 + 9 + 7\nJs.Array2.reduce([2.0, 4.0], (acc, item) => item /. acc, 1.0) == 2.0 // 4.0 / (2.0 / 1.0)\n```\n"} + }, { + "label": "Js.Array2.copy", + "kind": 12, + "tags": [], + "detail": "t<'a> => t<'a>", + "documentation": {"kind": "markdown", "value": "\nReturns a copy of the entire array. Same as `Js.Array2.Slice(arr, ~start=0,\n~end_=Js.Array2.length(arr))`. See\n[`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\non MDN.\n"} + }, { + "label": "Js.Array2.reducei", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('b, 'a, int) => 'b, 'b) => 'b", + "documentation": {"kind": "markdown", "value": "\nThe `reducei()` function takes three parameters: an array, a *reducer\nfunction*, and a beginning accumulator value. The reducer function has three\nparameters: an accumulated value, an element of the array, and the index of\nthat element.\n\n`reducei()` first calls the reducer function with the beginning value, the\nfirst element in the array, and zero (its index). The result becomes the new\naccumulator value, which is passed to the reducer function along with the\nsecond element in the array and one (its index). `reducei()` proceeds from left\nto right through the array, passing in the result of each stage as the\naccumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reducei()`. See\n[`Array.reduce`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce)\non MDN.\n\n```res example\n// find sum of even-index elements in array\nlet sumOfEvens = (accumulator, item, index) =>\n if mod(index, 2) == 0 {\n accumulator + item\n } else {\n accumulator\n }\n\nJs.Array2.reducei([2, 5, 1, 4, 3], sumOfEvens, 0) == 6\n```\n"} + }, { + "label": "Js.Array2.forEachi", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => unit) => unit", + "documentation": {"kind": "markdown", "value": "\nThe `forEachi()` function applies the function given as the second argument to\neach element in the array. The function you provide takes an item in the array\nand its index number, and returns `unit`. The `forEachi()` function also\nreturns `unit`. You use `forEachi()` when you need to process each element in\nthe array but not return any new array or value; for example, to print the\nitems in an array. See\n[`Array.forEach`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)\non MDN.\n\n```res example\n// display all elements in an array as a numbered list\nJs.Array2.forEachi([\"a\", \"b\", \"c\"], (item, index) => Js.log2(index + 1, item)) == ()\n```\n"} + }, { + "label": "Js.Array2.fillFromInPlace", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a, ~from: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nSets all elements of the given array (the first arumgent) from position `~from`\nto the end to the designated value (the second argument), returning the\nresulting array. *This function modifies the original array.* See\n[`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.fillFromInPlace(arr, 99, ~from=2) == [100, 101, 99, 99, 99]\narr == [100, 101, 99, 99, 99]\n```\n"} + }, { + "label": "Js.Array2.findi", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => bool) => option<'a>", + "documentation": {"kind": "markdown", "value": "\nReturns `Some(value)` for the first element in the array that satisifies the\ngiven predicate function, or `None` if no element satisifies the predicate. The\npredicate function takes an array element and an index as its parameters. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\n// find first positive item at an odd index\nlet positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0\n\nJs.Array2.findi([66, -33, 55, 88, 22], positiveOddElement) == Some(88)\nJs.Array2.findi([66, -33, 55, -88, 22], positiveOddElement) == None\n```\n"} + }, { + "label": "Js.Array2.filteri", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => bool) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nEach element of the given array are passed to the predicate function. The\nreturn value is an array of all those elements for which the predicate function\nreturned `true`.\n\nSee\n[`Array.filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)\non MDN.\n\n```res example\n// keep only positive elements at odd indices\nlet positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0\n\nJs.Array2.filteri([6, 3, 5, 8, 7, -4, 1], positiveOddElement) == [3, 8]\n```\n"} + }, { + "label": "Js.Array2.slice", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~start: int, ~end_: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nReturns a shallow copy of the given array from the `~start` index up to but not\nincluding the `~end_` position. Negative numbers indicate an offset from the\nend of the array. See\n[`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104, 105, 106]\nJs.Array2.slice(arr, ~start=2, ~end_=5) == [102, 103, 104]\nJs.Array2.slice(arr, ~start=-3, ~end_=-1) == [104, 105]\nJs.Array2.slice(arr, ~start=9, ~end_=10) == []\n```\n"} + }, { + "label": "Js.Array2.fromMap", + "kind": 12, + "tags": [], + "detail": "(array_like<'a>, 'a => 'b) => array<'b>", + "documentation": {"kind": "markdown", "value": "\nCreates a new array by applying a function (the second argument) to each item\nin the `array_like` first argument. See\n[`Array.from`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)\non MDN.\n\n```res example\nlet strArr = Js.String.castToArrayLike(\"abcd\")\nlet code = s => Js.String.charCodeAt(0, s)\nJs.Array2.fromMap(strArr, code) == [97.0, 98.0, 99.0, 100.0]\n```\n"} + }, { + "label": "Js.Array2.removeFromInPlace", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~pos: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nRemoves elements from the given array starting at position `~pos` to the end of\nthe array, returning the removed elements. *This function modifies the original\narray.* See\n[`Array.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)\non MDN.\n\n```res example\nlet arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.removeFromInPlace(arr, ~pos=4) == [\"e\", \"f\"]\narr == [\"a\", \"b\", \"c\", \"d\"]\n```\n"} + }, { + "label": "Js.Array2.from", + "kind": 12, + "tags": [], + "detail": "array_like<'a> => array<'a>", + "documentation": {"kind": "markdown", "value": "\nCreates a shallow copy of an array from an array-like object. See\n[`Array.from`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)\non MDN.\n\n```res example\nlet strArr = Js.String.castToArrayLike(\"abcd\")\nJs.Array2.from(strArr) == [\"a\", \"b\", \"c\", \"d\"]\n```\n"} + }, { + "label": "Js.Array2.includes", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => bool", + "documentation": {"kind": "markdown", "value": "\nReturns true if the given value is in the array, `false` otherwise. See\n[`Array.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)\non MDN.\n\n```res example\nJs.Array2.includes([\"a\", \"b\", \"c\"], \"b\") == true\nJs.Array2.includes([\"a\", \"b\", \"c\"], \"x\") == false\n```\n"} + }, { + "label": "Js.Array2.find", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => option<'a>", + "documentation": {"kind": "markdown", "value": "\nReturns `Some(value)` for the first element in the array that satisifies the\ngiven predicate function, or `None` if no element satisifies the predicate. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\n// find first negative element\nJs.Array2.find([33, 22, -55, 77, -44], x => x < 0) == Some(-55)\nJs.Array2.find([33, 22, 55, 77, 44], x => x < 0) == None\n```\n"} + }, { + "label": "Js.Array2.reduceRighti", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('b, 'a, int) => 'b, 'b) => 'b", + "documentation": {"kind": "markdown", "value": "\nThe `reduceRighti()` function takes three parameters: an array, a *reducer\nfunction*, and a beginning accumulator value. The reducer function has three\nparameters: an accumulated value, an element of the array, and the index of\nthat element. `reduceRighti()` first calls the reducer function with the\nbeginning value, the last element in the array, and its index (length of array\nminus one). The result becomes the new accumulator value, which is passed in to\nthe reducer function along with the second element in the array and one (its\nindex). `reduceRighti()` proceeds from right to left through the array, passing\nin the result of each stage as the accumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reduceRighti()`. See\n[`Array.reduceRight`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight)\non MDN.\n\n**NOTE:** In many cases, `reducei()` and `reduceRighti()` give the same result.\nHowever, there are cases where the order in which items are processed makes a\ndifference.\n\n```res example\n// find sum of even-index elements in array\nlet sumOfEvens = (accumulator, item, index) =>\n if mod(index, 2) == 0 {\n accumulator + item\n } else {\n accumulator\n }\n\nJs.Array2.reduceRighti([2, 5, 1, 4, 3], sumOfEvens, 0) == 6\n```\n"} + }, { + "label": "Js.Array2.findIndexi", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => bool) => int", + "documentation": {"kind": "markdown", "value": "\nReturns `Some(value)` for the first element in the array that satisifies the\ngiven predicate function, or `None` if no element satisifies the predicate. The\npredicate function takes an array element and an index as its parameters. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\n// find index of first positive item at an odd index\nlet positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0\n\nJs.Array2.findIndexi([66, -33, 55, 88, 22], positiveOddElement) == 3\nJs.Array2.findIndexi([66, -33, 55, -88, 22], positiveOddElement) == -1\n```\n"} + }, { + "label": "Js.Array2.toLocaleString", + "kind": 12, + "tags": [], + "detail": "t<'a> => string", + "documentation": {"kind": "markdown", "value": "\nConverts the array to a string using the conventions of the current locale.\nEach element is converted to a string using JavaScript. Unlike the JavaScript\n`Array.toLocaleString()`, all elements in a ReasonML array must have the same\ntype. See\n[`Array.toLocaleString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString)\non MDN.\n\n```res example\nJs.Array2.toLocaleString([Js.Date.make()])\n// returns \"3/19/2020, 10:52:11 AM\" for locale en_US.utf8\n// returns \"2020-3-19 10:52:11\" for locale de_DE.utf8\n```\n"} + }, { + "label": "Js.Array2.lastIndexOfFrom", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a, ~from: int) => int", + "documentation": {"kind": "markdown", "value": "\nReturns the index of the last element in the array that has the given value,\nsearching from position `~from` down to the start of the array. If the value is\nnot in the array, returns -1. See\n[`Array.lastIndexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)\non MDN.\n\n```res example\nJs.Array2.lastIndexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\", \"d\"], \"a\", ~from=3) == 2\nJs.Array2.lastIndexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\", \"d\"], \"c\", ~from=2) == -1\n```\n"} + }, { + "label": "Js.Array2.copyWithinFromRange", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~to_: int, ~start: int, ~end_: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nCopies starting at element `~start` in the given array up to but not including\n`~end_` to the designated `~to_` position, returning the resulting array. *This\nfunction modifies the original array.* See\n[`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104, 105]\nJs.Array2.copyWithinFromRange(arr, ~start=2, ~end_=5, ~to_=1) == [100, 102, 103, 104, 104, 105]\narr == [100, 102, 103, 104, 104, 105]\n```\n"} + }, { + "label": "Js.Array2.findIndex", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => int", + "documentation": {"kind": "markdown", "value": "\nReturns the index of the first element in the array that satisifies the given\npredicate function, or -1 if no element satisifies the predicate. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\nJs.Array2.findIndex([33, 22, -55, 77, -44], x => x < 0) == 2\nJs.Array2.findIndex([33, 22, 55, 77, 44], x => x < 0) == -1\n```\n"} + }, { + "label": "Js.Array2.removeCountInPlace", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~pos: int, ~count: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nRemoves `~count` elements from the given array starting at position `~pos`,\nreturning the removed elements. *This function modifies the original array.*\nSee\n[`Array.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)\non MDN.\n\n```res example\nlet arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.removeCountInPlace(arr, ~pos=2, ~count=3) == [\"c\", \"d\", \"e\"]\narr == [\"a\", \"b\", \"f\"]\n```\n"} + }, { + "label": "Js.Array2.reverseInPlace", + "kind": 12, + "tags": [], + "detail": "t<'a> => t<'a>", + "documentation": {"kind": "markdown", "value": "\nReturns an array with the elements of the input array in reverse order. *This\nfunction modifies the original array.* See\n[`Array.reverse`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse)\non MDN.\n\n```res example\nlet arr = [\"ant\", \"bee\", \"cat\"]\nJs.Array2.reverseInPlace(arr) == [\"cat\", \"bee\", \"ant\"]\narr == [\"cat\", \"bee\", \"ant\"]\n```\n"} + }, { + "label": "Js.Array2.every", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => bool", + "documentation": {"kind": "markdown", "value": "\nThe first argument to `every()` is an array. The second argument is a predicate\nfunction that returns a boolean. The `every()` function returns `true` if the\npredicate function is true for all items in the given array. If given an empty\narray, returns `true`. See\n[`Array.every`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)\non MDN.\n\n```res example\nlet isEven = x => mod(x, 2) == 0\nJs.Array2.every([6, 22, 8, 4], isEven) == true\nJs.Array2.every([6, 22, 7, 4], isEven) == false\n```\n"} + }, { + "label": "Js.Array2.length", + "kind": 12, + "tags": [], + "detail": "array<'a> => int", + "documentation": {"kind": "markdown", "value": "\nReturns the number of elements in the array. See\n[`Array.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)\non MDN.\n"} + }, { + "label": "Js.Array2.indexOf", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => int", + "documentation": {"kind": "markdown", "value": "\nReturns the index of the first element in the array that has the given value.\nIf the value is not in the array, returns -1. See\n[`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)\non MDN.\n\n```res example\nJs.Array2.indexOf([100, 101, 102, 103], 102) == 2\nJs.Array2.indexOf([100, 101, 102, 103], 999) == -1\n```\n"} + }, { + "label": "Js.Array2.unshift", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => int", + "documentation": {"kind": "markdown", "value": "\nAdds the given element to the array, returning the new number of elements in\nthe array. *This function modifies the original array.* See\n[`Array.unshift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)\non MDN.\n\n```res example\nlet arr = [\"b\", \"c\", \"d\"]\nJs.Array2.unshift(arr, \"a\") == 4\narr == [\"a\", \"b\", \"c\", \"d\"]\n```\n"} + }, { + "label": "Js.Array2.sortInPlace", + "kind": 12, + "tags": [], + "detail": "t<'a> => t<'a>", + "documentation": {"kind": "markdown", "value": "\nSorts the given array in place and returns the sorted array. JavaScript sorts\nthe array by converting the arguments to UTF-16 strings and sorting them. See\nthe second example with sorting numbers, which does not do a numeric sort.\n*This function modifies the original array.* See\n[`Array.sort`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)\non MDN.\n\n```res example\nlet words = [\"bee\", \"dog\", \"ant\", \"cat\"]\nJs.Array2.sortInPlace(words) == [\"ant\", \"bee\", \"cat\", \"dog\"]\nwords == [\"ant\", \"bee\", \"cat\", \"dog\"]\n\nlet numbers = [3, 30, 10, 1, 20, 2]\nJs.Array2.sortInPlace(numbers) == [1, 10, 2, 20, 3, 30]\nnumbers == [1, 10, 2, 20, 3, 30]\n```\n"} + }, { + "label": "Js.Array2.unsafe_get", + "kind": 12, + "tags": [], + "detail": "(array<'a>, int) => 'a", + "documentation": {"kind": "markdown", "value": "\nReturns the value at the given position in the array if the position is in\nbounds; returns the JavaScript value `undefined` otherwise.\n\n```res example\nlet arr = [100, 101, 102, 103]\nJs.Array2.unsafe_get(arr, 3) == 103\nJs.Array2.unsafe_get(arr, 4) // returns undefined\n```\n"} + }, { + "label": "Js.Array2.some", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => bool", + "documentation": {"kind": "markdown", "value": "\nReturns `true` if the predicate function given as the second argument to\n`some()` returns `true` for any element in the array; `false` otherwise.\n\n```res example\nlet isEven = x => mod(x, 2) == 0\n\nJs.Array2.some([3, 7, 5, 2, 9], isEven) == true\nJs.Array2.some([3, 7, 5, 1, 9], isEven) == false\n```\n"} + }, { + "label": "Js.Array2.map", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => 'b) => t<'b>", + "documentation": {"kind": "markdown", "value": "\nApplies the function (the second argument) to each item in the array, returning\na new array. The result array does not have to have elements of the same type\nas the input array. See\n[`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)\non MDN.\n\n```res example\nJs.Array2.map([12, 4, 8], x => x * x) == [144, 16, 64]\nJs.Array2.map([\"animal\", \"vegetable\", \"mineral\"], Js.String.length) == [6, 9, 7]\n```\n"} + }, { + "label": "Js.Array2.push", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => int", + "documentation": {"kind": "markdown", "value": "\nAppends the given value to the array, returning the number of elements in the\nupdated array. *This function modifies the original array.* See\n[`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)\non MDN.\n\n```res example\nlet arr = [\"ant\", \"bee\", \"cat\"]\nJs.Array2.push(arr, \"dog\") == 4\narr == [\"ant\", \"bee\", \"cat\", \"dog\"]\n```\n"} + }, { + "label": "Js.Array2.fillRangeInPlace", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a, ~start: int, ~end_: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nSets the elements of the given array (the first arumgent) from position\n`~start` up to but not including position `~end_` to the designated value (the\nsecond argument), returning the resulting array. *This function modifies the\noriginal array.* See\n[`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.fillRangeInPlace(arr, 99, ~start=1, ~end_=4) == [100, 99, 99, 99, 104]\narr == [100, 99, 99, 99, 104]\n```\n"} + }, { + "label": "Js.Array2.pop", + "kind": 12, + "tags": [], + "detail": "t<'a> => option<'a>", + "documentation": {"kind": "markdown", "value": "\nIf the array is not empty, removes the last element and returns it as\n`Some(value)`; returns `None` if the array is empty. *This function modifies\nthe original array.* See\n[`Array.pop`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.pop(arr) == Some(104)\narr == [100, 101, 102, 103]\n\nlet empty: array = []\nJs.Array2.pop(empty) == None\n```\n"} + }, { + "label": "Js.Array2.somei", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => bool) => bool", + "documentation": {"kind": "markdown", "value": "\nReturns `true` if the predicate function given as the second argument to\n`somei()` returns `true` for any element in the array; `false` otherwise. The\npredicate function has two arguments: an item from the array and the index\nvalue\n\n```res example\n// Does any string in the array\n// have the same length as its index?\n\nlet sameLength = (str, index) => Js.String.length(str) == index\n\n// \"ef\" has length 2 and is it at index 2\nJs.Array2.somei([\"ab\", \"cd\", \"ef\", \"gh\"], sameLength) == true\n// no item has the same length as its index\nJs.Array2.somei([\"a\", \"bc\", \"def\", \"gh\"], sameLength) == false\n```\n"} + }, { + "label": "Js.Array2.append", + "kind": 12, + "tags": [1], + "detail": "(t<'a>, 'a) => t<'a>", + "documentation": {"kind": "markdown", "value": "Deprecated: `append` is not type-safe. Use `concat` instead.\n\n"} + }, { + "label": "Js.Array2.unsafe_set", + "kind": 12, + "tags": [], + "detail": "(array<'a>, int, 'a) => unit", + "documentation": {"kind": "markdown", "value": "\nSets the value at the given position in the array if the position is in bounds.\nIf the index is out of bounds, well, “here there be dragons.“\n\n*This function modifies the original array.*\n\n```res example\nlet arr = [100, 101, 102, 103]\nJs.Array2.unsafe_set(arr, 3, 99)\n// result is [100, 101, 102, 99];\n\nJs.Array2.unsafe_set(arr, 4, 88)\n// result is [100, 101, 102, 99, 88]\n\nJs.Array2.unsafe_set(arr, 6, 77)\n// result is [100, 101, 102, 99, 88, <1 empty item>, 77]\n\nJs.Array2.unsafe_set(arr, -1, 66)\n// you don't want to know.\n```\n"} + }, { + "label": "Js.Array2.copyWithin", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~to_: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nCopies from the first element in the given array to the designated `~to_`\nposition, returning the resulting array. *This function modifies the original\narray.* See\n[`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.copyWithin(arr, ~to_=2) == [100, 101, 100, 101, 102]\narr == [100, 101, 100, 101, 102]\n```\n"} + }, { + "label": "Js.Array2.everyi", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => bool) => bool", + "documentation": {"kind": "markdown", "value": "\nThe first argument to `everyi()` is an array. The second argument is a\npredicate function with two arguments: an array element and that element’s\nindex; it returns a boolean. The `everyi()` function returns `true` if the\npredicate function is true for all items in the given array. If given an empty\narray, returns `true`. See\n[`Array.every`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)\non MDN.\n\n```res example\n// determine if all even-index items are positive\nlet evenIndexPositive = (item, index) => mod(index, 2) == 0 ? item > 0 : true\n\nJs.Array2.everyi([6, -3, 5, 8], evenIndexPositive) == true\nJs.Array2.everyi([6, 3, -5, 8], evenIndexPositive) == false\n```\n"} + }, { + "label": "Js.Array2.toString", + "kind": 12, + "tags": [], + "detail": "t<'a> => string", + "documentation": {"kind": "markdown", "value": "\nConverts the array to a string. Each element is converted to a string using\nJavaScript. Unlike the JavaScript `Array.toString()`, all elements in a\nReasonML array must have the same type. See\n[`Array.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString)\non MDN.\n\n```res example\nJs.Array2.toString([3.5, 4.6, 7.8]) == \"3.5,4.6,7.8\"\nJs.Array2.toString([\"a\", \"b\", \"c\"]) == \"a,b,c\"\n```\n"} + }, { + "label": "Js.Array2.spliceInPlace", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~pos: int, ~remove: int, ~add: array<'a>) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nStarting at position `~pos`, remove `~remove` elements and then add the\nelements from the `~add` array. Returns an array consisting of the removed\nitems. *This function modifies the original array.* See\n[`Array.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)\non MDN.\n\n```res example\nlet arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.spliceInPlace(arr, ~pos=2, ~remove=2, ~add=[\"x\", \"y\", \"z\"]) == [\"c\", \"d\"]\narr == [\"a\", \"b\", \"x\", \"y\", \"z\", \"e\", \"f\"]\n\nlet arr2 = [\"a\", \"b\", \"c\", \"d\"]\nJs.Array2.spliceInPlace(arr2, ~pos=3, ~remove=0, ~add=[\"x\", \"y\"]) == []\narr2 == [\"a\", \"b\", \"c\", \"x\", \"y\", \"d\"]\n\nlet arr3 = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.spliceInPlace(arr3, ~pos=9, ~remove=2, ~add=[\"x\", \"y\", \"z\"]) == []\narr3 == [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"x\", \"y\", \"z\"]\n```\n"} + }, { + "label": "Js.Array2.pushMany", + "kind": 12, + "tags": [], + "detail": "(t<'a>, array<'a>) => int", + "documentation": {"kind": "markdown", "value": "\nAppends the values from one array (the second argument) to another (the first\nargument), returning the number of elements in the updated array. *This\nfunction modifies the original array.* See\n[`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)\non MDN.\n\n```res example\nlet arr = [\"ant\", \"bee\", \"cat\"]\nJs.Array2.pushMany(arr, [\"dog\", \"elk\"]) == 5\narr == [\"ant\", \"bee\", \"cat\", \"dog\", \"elk\"]\n```\n"} + }, { + "label": "Js.Array2.copyWithinFrom", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~to_: int, ~from: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nCopies starting at element `~from` in the given array to the designated `~to_`\nposition, returning the resulting array. *This function modifies the original\narray.* See\n[`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.copyWithinFrom(arr, ~from=2, ~to_=0) == [102, 103, 104, 103, 104]\narr == [102, 103, 104, 103, 104]\n```\n"} + }, { + "label": "Js.Array2.forEach", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => unit) => unit", + "documentation": {"kind": "markdown", "value": "\nThe `forEach()` function applies the function given as the second argument to\neach element in the array. The function you provide returns `unit`, and the\n`forEach()` function also returns `unit`. You use `forEach()` when you need to\nprocess each element in the array but not return any new array or value; for\nexample, to print the items in an array. See\n[`Array.forEach`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)\non MDN.\n\n```res example\n// display all elements in an array\nJs.Array2.forEach([\"a\", \"b\", \"c\"], x => Js.log(x)) == ()\n```\n"} + }, { + "label": "Js.Array2.sliceFrom", + "kind": 12, + "tags": [], + "detail": "(t<'a>, int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nReturns a shallow copy of the given array from the given index to the end. See\n[`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\non MDN.\n"} + }, { + "label": "Js.Array2.sortInPlaceWith", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, 'a) => int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nSorts the given array in place and returns the sorted array. *This function\n modifies the original array.*\n\nThe first argument to `sortInPlaceWith()` is a function that compares two items\nfrom the array and returns:\n\n* an integer less than zero if the first item is less than the second item *\nzero if the items are equal * an integer greater than zero if the first item is\ngreater than the second item\n\nSee\n[`Array.sort`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)\non MDN.\n\n```res example\n// sort by word length\nlet words = [\"horse\", \"aardvark\", \"dog\", \"camel\"]\nlet byLength = (s1, s2) => Js.String.length(s1) - Js.String.length(s2)\n\nJs.Array2.sortInPlaceWith(words, byLength) == [\"dog\", \"horse\", \"camel\", \"aardvark\"]\n\n// sort in reverse numeric order\nlet numbers = [3, 30, 10, 1, 20, 2]\nlet reverseNumeric = (n1, n2) => n2 - n1\nJs.Array2.sortInPlaceWith(numbers, reverseNumeric) == [30, 20, 10, 3, 2, 1]\n```\n"} + }, { + "label": "Js.Array2.indexOfFrom", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a, ~from: int) => int", + "documentation": {"kind": "markdown", "value": "\nReturns the index of the first element in the array with the given value. The\nsearch starts at position `~from`. See\n[`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)\non MDN.\n\n```res example\nJs.Array2.indexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\"], \"a\", ~from=2) == 2\nJs.Array2.indexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\"], \"a\", ~from=3) == 4\nJs.Array2.indexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\"], \"b\", ~from=2) == -1\n```\n"} + }] + +Complete src/CompletionPipeChain.res 8:68 +posCursor:[8:68] posNoWhite:[8:67] Found expr:[8:11->0:-1] +Completable: Cpath Value[Js, Array2, filter](Nolabel, Nolabel)-> +[{ + "label": "Js.Array2.mapi", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => 'b) => t<'b>", + "documentation": {"kind": "markdown", "value": "\nApplies the function (the second argument) to each item in the array, returning\na new array. The function acceps two arguments: an item from the array and its\nindex number. The result array does not have to have elements of the same type\nas the input array. See\n[`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)\non MDN.\n\n```res example\n// multiply each item in array by its position\nlet product = (item, index) => item * index\nJs.Array2.mapi([10, 11, 12], product) == [0, 11, 24]\n```\n"} + }, { + "label": "Js.Array2.lastIndexOf", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => int", + "documentation": {"kind": "markdown", "value": "\nReturns the index of the last element in the array that has the given value. If\nthe value is not in the array, returns -1. See\n[`Array.lastIndexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)\non MDN.\n\n```res example\nJs.Array2.lastIndexOf([\"a\", \"b\", \"a\", \"c\"], \"a\") == 2\nJs.Array2.lastIndexOf([\"a\", \"b\", \"a\", \"c\"], \"x\") == -1\n```\n"} + }, { + "label": "Js.Array2.concat", + "kind": 12, + "tags": [], + "detail": "(t<'a>, t<'a>) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nConcatenates the second array argument to the first array argument, returning a\nnew array. The original arrays are not modified. See\n[`Array.concat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)\non MDN.\n\n```res example\nJs.Array2.concat([\"a\", \"b\"], [\"c\", \"d\", \"e\"]) == [\"a\", \"b\", \"c\", \"d\", \"e\"]\n```\n"} + }, { + "label": "Js.Array2.unshiftMany", + "kind": 12, + "tags": [], + "detail": "(t<'a>, array<'a>) => int", + "documentation": {"kind": "markdown", "value": "\nAdds the elements in the second array argument at the beginning of the first\narray argument, returning the new number of elements in the array. *This\nfunction modifies the original array.* See\n[`Array.unshift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)\non MDN.\n\n```res example\nlet arr = [\"d\", \"e\"]\nJs.Array2.unshiftMany(arr, [\"a\", \"b\", \"c\"]) == 5\narr == [\"a\", \"b\", \"c\", \"d\", \"e\"]\n```\n"} + }, { + "label": "Js.Array2.filter", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nApplies the given predicate function (the second argument) to each element in\nthe array; the result is an array of those elements for which the predicate\nfunction returned `true`. See\n[`Array.filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)\non MDN.\n\n```res example\nlet nonEmpty = s => s != \"\"\nJs.Array2.filter([\"abc\", \"\", \"\", \"def\", \"ghi\"], nonEmpty) == [\"abc\", \"def\", \"ghi\"]\n```\n"} + }, { + "label": "Js.Array2.shift", + "kind": 12, + "tags": [], + "detail": "t<'a> => option<'a>", + "documentation": {"kind": "markdown", "value": "\nIf the array is not empty, removes the first element and returns it as\n`Some(value)`; returns `None` if the array is empty. *This function modifies\nthe original array.* See\n[`Array.shift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.shift(arr) == Some(100)\narr == [101, 102, 103, 104]\n\nlet empty: array = []\nJs.Array2.shift(empty) == None\n```\n"} + }, { + "label": "Js.Array2.reduceRight", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('b, 'a) => 'b, 'b) => 'b", + "documentation": {"kind": "markdown", "value": "\nThe `reduceRight()` function takes three parameters: an array, a *reducer\nfunction*, and a beginning accumulator value. The reducer function has two\nparameters: an accumulated value and an element of the array.\n\n`reduceRight()` first calls the reducer function with the beginning value and\nthe last element in the array. The result becomes the new accumulator value,\nwhich is passed in to the reducer function along with the next-to-last element\nin the array. `reduceRight()` proceeds from right to left through the array,\npassing in the result of each stage as the accumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reduceRight()`. See\n[`Array.reduceRight`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight)\non MDN.\n\n**NOTE:** In many cases, `reduce()` and `reduceRight()` give the same result.\nHowever, see the last example here and compare it to the example from\n`reduce()`, where order makes a difference.\n\n```res example\nlet sumOfSquares = (accumulator, item) => accumulator + item * item\n\nJs.Array2.reduceRight([10, 2, 4], sumOfSquares, 0) == 120\nJs.Array2.reduceRight([2.0, 4.0], (acc, item) => item /. acc, 1.0) == 0.5 // 2.0 / (4.0 / 1.0)\n```\n"} + }, { + "label": "Js.Array2.joinWith", + "kind": 12, + "tags": [], + "detail": "(t<'a>, string) => string", + "documentation": {"kind": "markdown", "value": "\nThis function converts each element of the array to a string (via JavaScript)\nand concatenates them, separated by the string given in the first argument,\ninto a single string. See\n[`Array.join`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)\non MDN.\n\n```res example\nJs.Array2.joinWith([\"ant\", \"bee\", \"cat\"], \"--\") == \"ant--bee--cat\"\nJs.Array2.joinWith([\"door\", \"bell\"], \"\") == \"doorbell\"\nJs.Array2.joinWith([2020, 9, 4], \"/\") == \"2020/9/4\"\nJs.Array2.joinWith([2.5, 3.6, 3e-2], \";\") == \"2.5;3.6;0.03\"\n```\n"} + }, { + "label": "Js.Array2.concatMany", + "kind": 12, + "tags": [], + "detail": "(t<'a>, array>) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nThe second argument to `concatMany()` is an array of arrays; these are added at\nthe end of the first argument, returning a new array. See\n[`Array.concat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)\non MDN.\n\n```res example\nJs.Array2.concatMany([\"a\", \"b\", \"c\"], [[\"d\", \"e\"], [\"f\", \"g\", \"h\"]]) == [\n \"a\",\n \"b\",\n \"c\",\n \"d\",\n \"e\",\n \"f\",\n \"g\",\n \"h\",\n ]\n```\n"} + }, { + "label": "Js.Array2.fillInPlace", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nSets all elements of the given array (the first arumgent) to the designated\nvalue (the secon argument), returning the resulting array. *This function\n modifies the original array.*\n\nSee\n[`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.fillInPlace(arr, 99) == [99, 99, 99, 99, 99]\narr == [99, 99, 99, 99, 99]\n```\n"} + }, { + "label": "Js.Array2.isArray", + "kind": 12, + "tags": [], + "detail": "'a => bool", + "documentation": {"kind": "markdown", "value": "\nReturns `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.\n\n```res example\nJs.Array2.isArray([5, 2, 3, 1, 4]) == true\nJs.Array2.isArray(list{5, 2, 3, 1, 4}) == true\nJs.Array2.isArray(\"abcd\") == false\n```\n"} + }, { + "label": "Js.Array2.reduce", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('b, 'a) => 'b, 'b) => 'b", + "documentation": {"kind": "markdown", "value": "\nThe `reduce()` function takes three parameters: an array, a *reducer function*,\nand a beginning accumulator value. The reducer function has two parameters: an\naccumulated value and an element of the array.\n\n`reduce()` first calls the reducer function with the beginning value and the\nfirst element in the array. The result becomes the new accumulator value, which\nis passed in to the reducer function along with the second element in the\narray. `reduce()` proceeds through the array, passing in the result of each\nstage as the accumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reduce()`. See\n[`Array.reduce`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce)\non MDN.\n\n```res example\nlet sumOfSquares = (accumulator, item) => accumulator + item * item\n\nJs.Array2.reduce([10, 2, 4], sumOfSquares, 0) == 120\nJs.Array2.reduce([10, 2, 4], \\\"*\", 1) == 80\nJs.Array2.reduce(\n [\"animal\", \"vegetable\", \"mineral\"],\n (acc, item) => acc + Js.String.length(item),\n 0,\n) == 22 // 6 + 9 + 7\nJs.Array2.reduce([2.0, 4.0], (acc, item) => item /. acc, 1.0) == 2.0 // 4.0 / (2.0 / 1.0)\n```\n"} + }, { + "label": "Js.Array2.copy", + "kind": 12, + "tags": [], + "detail": "t<'a> => t<'a>", + "documentation": {"kind": "markdown", "value": "\nReturns a copy of the entire array. Same as `Js.Array2.Slice(arr, ~start=0,\n~end_=Js.Array2.length(arr))`. See\n[`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\non MDN.\n"} + }, { + "label": "Js.Array2.reducei", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('b, 'a, int) => 'b, 'b) => 'b", + "documentation": {"kind": "markdown", "value": "\nThe `reducei()` function takes three parameters: an array, a *reducer\nfunction*, and a beginning accumulator value. The reducer function has three\nparameters: an accumulated value, an element of the array, and the index of\nthat element.\n\n`reducei()` first calls the reducer function with the beginning value, the\nfirst element in the array, and zero (its index). The result becomes the new\naccumulator value, which is passed to the reducer function along with the\nsecond element in the array and one (its index). `reducei()` proceeds from left\nto right through the array, passing in the result of each stage as the\naccumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reducei()`. See\n[`Array.reduce`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce)\non MDN.\n\n```res example\n// find sum of even-index elements in array\nlet sumOfEvens = (accumulator, item, index) =>\n if mod(index, 2) == 0 {\n accumulator + item\n } else {\n accumulator\n }\n\nJs.Array2.reducei([2, 5, 1, 4, 3], sumOfEvens, 0) == 6\n```\n"} + }, { + "label": "Js.Array2.forEachi", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => unit) => unit", + "documentation": {"kind": "markdown", "value": "\nThe `forEachi()` function applies the function given as the second argument to\neach element in the array. The function you provide takes an item in the array\nand its index number, and returns `unit`. The `forEachi()` function also\nreturns `unit`. You use `forEachi()` when you need to process each element in\nthe array but not return any new array or value; for example, to print the\nitems in an array. See\n[`Array.forEach`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)\non MDN.\n\n```res example\n// display all elements in an array as a numbered list\nJs.Array2.forEachi([\"a\", \"b\", \"c\"], (item, index) => Js.log2(index + 1, item)) == ()\n```\n"} + }, { + "label": "Js.Array2.fillFromInPlace", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a, ~from: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nSets all elements of the given array (the first arumgent) from position `~from`\nto the end to the designated value (the second argument), returning the\nresulting array. *This function modifies the original array.* See\n[`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.fillFromInPlace(arr, 99, ~from=2) == [100, 101, 99, 99, 99]\narr == [100, 101, 99, 99, 99]\n```\n"} + }, { + "label": "Js.Array2.findi", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => bool) => option<'a>", + "documentation": {"kind": "markdown", "value": "\nReturns `Some(value)` for the first element in the array that satisifies the\ngiven predicate function, or `None` if no element satisifies the predicate. The\npredicate function takes an array element and an index as its parameters. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\n// find first positive item at an odd index\nlet positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0\n\nJs.Array2.findi([66, -33, 55, 88, 22], positiveOddElement) == Some(88)\nJs.Array2.findi([66, -33, 55, -88, 22], positiveOddElement) == None\n```\n"} + }, { + "label": "Js.Array2.filteri", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => bool) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nEach element of the given array are passed to the predicate function. The\nreturn value is an array of all those elements for which the predicate function\nreturned `true`.\n\nSee\n[`Array.filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)\non MDN.\n\n```res example\n// keep only positive elements at odd indices\nlet positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0\n\nJs.Array2.filteri([6, 3, 5, 8, 7, -4, 1], positiveOddElement) == [3, 8]\n```\n"} + }, { + "label": "Js.Array2.slice", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~start: int, ~end_: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nReturns a shallow copy of the given array from the `~start` index up to but not\nincluding the `~end_` position. Negative numbers indicate an offset from the\nend of the array. See\n[`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104, 105, 106]\nJs.Array2.slice(arr, ~start=2, ~end_=5) == [102, 103, 104]\nJs.Array2.slice(arr, ~start=-3, ~end_=-1) == [104, 105]\nJs.Array2.slice(arr, ~start=9, ~end_=10) == []\n```\n"} + }, { + "label": "Js.Array2.fromMap", + "kind": 12, + "tags": [], + "detail": "(array_like<'a>, 'a => 'b) => array<'b>", + "documentation": {"kind": "markdown", "value": "\nCreates a new array by applying a function (the second argument) to each item\nin the `array_like` first argument. See\n[`Array.from`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)\non MDN.\n\n```res example\nlet strArr = Js.String.castToArrayLike(\"abcd\")\nlet code = s => Js.String.charCodeAt(0, s)\nJs.Array2.fromMap(strArr, code) == [97.0, 98.0, 99.0, 100.0]\n```\n"} + }, { + "label": "Js.Array2.removeFromInPlace", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~pos: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nRemoves elements from the given array starting at position `~pos` to the end of\nthe array, returning the removed elements. *This function modifies the original\narray.* See\n[`Array.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)\non MDN.\n\n```res example\nlet arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.removeFromInPlace(arr, ~pos=4) == [\"e\", \"f\"]\narr == [\"a\", \"b\", \"c\", \"d\"]\n```\n"} + }, { + "label": "Js.Array2.from", + "kind": 12, + "tags": [], + "detail": "array_like<'a> => array<'a>", + "documentation": {"kind": "markdown", "value": "\nCreates a shallow copy of an array from an array-like object. See\n[`Array.from`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)\non MDN.\n\n```res example\nlet strArr = Js.String.castToArrayLike(\"abcd\")\nJs.Array2.from(strArr) == [\"a\", \"b\", \"c\", \"d\"]\n```\n"} + }, { + "label": "Js.Array2.includes", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => bool", + "documentation": {"kind": "markdown", "value": "\nReturns true if the given value is in the array, `false` otherwise. See\n[`Array.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)\non MDN.\n\n```res example\nJs.Array2.includes([\"a\", \"b\", \"c\"], \"b\") == true\nJs.Array2.includes([\"a\", \"b\", \"c\"], \"x\") == false\n```\n"} + }, { + "label": "Js.Array2.find", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => option<'a>", + "documentation": {"kind": "markdown", "value": "\nReturns `Some(value)` for the first element in the array that satisifies the\ngiven predicate function, or `None` if no element satisifies the predicate. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\n// find first negative element\nJs.Array2.find([33, 22, -55, 77, -44], x => x < 0) == Some(-55)\nJs.Array2.find([33, 22, 55, 77, 44], x => x < 0) == None\n```\n"} + }, { + "label": "Js.Array2.reduceRighti", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('b, 'a, int) => 'b, 'b) => 'b", + "documentation": {"kind": "markdown", "value": "\nThe `reduceRighti()` function takes three parameters: an array, a *reducer\nfunction*, and a beginning accumulator value. The reducer function has three\nparameters: an accumulated value, an element of the array, and the index of\nthat element. `reduceRighti()` first calls the reducer function with the\nbeginning value, the last element in the array, and its index (length of array\nminus one). The result becomes the new accumulator value, which is passed in to\nthe reducer function along with the second element in the array and one (its\nindex). `reduceRighti()` proceeds from right to left through the array, passing\nin the result of each stage as the accumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reduceRighti()`. See\n[`Array.reduceRight`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight)\non MDN.\n\n**NOTE:** In many cases, `reducei()` and `reduceRighti()` give the same result.\nHowever, there are cases where the order in which items are processed makes a\ndifference.\n\n```res example\n// find sum of even-index elements in array\nlet sumOfEvens = (accumulator, item, index) =>\n if mod(index, 2) == 0 {\n accumulator + item\n } else {\n accumulator\n }\n\nJs.Array2.reduceRighti([2, 5, 1, 4, 3], sumOfEvens, 0) == 6\n```\n"} + }, { + "label": "Js.Array2.findIndexi", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => bool) => int", + "documentation": {"kind": "markdown", "value": "\nReturns `Some(value)` for the first element in the array that satisifies the\ngiven predicate function, or `None` if no element satisifies the predicate. The\npredicate function takes an array element and an index as its parameters. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\n// find index of first positive item at an odd index\nlet positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0\n\nJs.Array2.findIndexi([66, -33, 55, 88, 22], positiveOddElement) == 3\nJs.Array2.findIndexi([66, -33, 55, -88, 22], positiveOddElement) == -1\n```\n"} + }, { + "label": "Js.Array2.toLocaleString", + "kind": 12, + "tags": [], + "detail": "t<'a> => string", + "documentation": {"kind": "markdown", "value": "\nConverts the array to a string using the conventions of the current locale.\nEach element is converted to a string using JavaScript. Unlike the JavaScript\n`Array.toLocaleString()`, all elements in a ReasonML array must have the same\ntype. See\n[`Array.toLocaleString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString)\non MDN.\n\n```res example\nJs.Array2.toLocaleString([Js.Date.make()])\n// returns \"3/19/2020, 10:52:11 AM\" for locale en_US.utf8\n// returns \"2020-3-19 10:52:11\" for locale de_DE.utf8\n```\n"} + }, { + "label": "Js.Array2.lastIndexOfFrom", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a, ~from: int) => int", + "documentation": {"kind": "markdown", "value": "\nReturns the index of the last element in the array that has the given value,\nsearching from position `~from` down to the start of the array. If the value is\nnot in the array, returns -1. See\n[`Array.lastIndexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)\non MDN.\n\n```res example\nJs.Array2.lastIndexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\", \"d\"], \"a\", ~from=3) == 2\nJs.Array2.lastIndexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\", \"d\"], \"c\", ~from=2) == -1\n```\n"} + }, { + "label": "Js.Array2.copyWithinFromRange", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~to_: int, ~start: int, ~end_: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nCopies starting at element `~start` in the given array up to but not including\n`~end_` to the designated `~to_` position, returning the resulting array. *This\nfunction modifies the original array.* See\n[`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104, 105]\nJs.Array2.copyWithinFromRange(arr, ~start=2, ~end_=5, ~to_=1) == [100, 102, 103, 104, 104, 105]\narr == [100, 102, 103, 104, 104, 105]\n```\n"} + }, { + "label": "Js.Array2.findIndex", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => int", + "documentation": {"kind": "markdown", "value": "\nReturns the index of the first element in the array that satisifies the given\npredicate function, or -1 if no element satisifies the predicate. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\nJs.Array2.findIndex([33, 22, -55, 77, -44], x => x < 0) == 2\nJs.Array2.findIndex([33, 22, 55, 77, 44], x => x < 0) == -1\n```\n"} + }, { + "label": "Js.Array2.removeCountInPlace", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~pos: int, ~count: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nRemoves `~count` elements from the given array starting at position `~pos`,\nreturning the removed elements. *This function modifies the original array.*\nSee\n[`Array.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)\non MDN.\n\n```res example\nlet arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.removeCountInPlace(arr, ~pos=2, ~count=3) == [\"c\", \"d\", \"e\"]\narr == [\"a\", \"b\", \"f\"]\n```\n"} + }, { + "label": "Js.Array2.reverseInPlace", + "kind": 12, + "tags": [], + "detail": "t<'a> => t<'a>", + "documentation": {"kind": "markdown", "value": "\nReturns an array with the elements of the input array in reverse order. *This\nfunction modifies the original array.* See\n[`Array.reverse`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse)\non MDN.\n\n```res example\nlet arr = [\"ant\", \"bee\", \"cat\"]\nJs.Array2.reverseInPlace(arr) == [\"cat\", \"bee\", \"ant\"]\narr == [\"cat\", \"bee\", \"ant\"]\n```\n"} + }, { + "label": "Js.Array2.every", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => bool", + "documentation": {"kind": "markdown", "value": "\nThe first argument to `every()` is an array. The second argument is a predicate\nfunction that returns a boolean. The `every()` function returns `true` if the\npredicate function is true for all items in the given array. If given an empty\narray, returns `true`. See\n[`Array.every`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)\non MDN.\n\n```res example\nlet isEven = x => mod(x, 2) == 0\nJs.Array2.every([6, 22, 8, 4], isEven) == true\nJs.Array2.every([6, 22, 7, 4], isEven) == false\n```\n"} + }, { + "label": "Js.Array2.length", + "kind": 12, + "tags": [], + "detail": "array<'a> => int", + "documentation": {"kind": "markdown", "value": "\nReturns the number of elements in the array. See\n[`Array.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)\non MDN.\n"} + }, { + "label": "Js.Array2.indexOf", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => int", + "documentation": {"kind": "markdown", "value": "\nReturns the index of the first element in the array that has the given value.\nIf the value is not in the array, returns -1. See\n[`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)\non MDN.\n\n```res example\nJs.Array2.indexOf([100, 101, 102, 103], 102) == 2\nJs.Array2.indexOf([100, 101, 102, 103], 999) == -1\n```\n"} + }, { + "label": "Js.Array2.unshift", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => int", + "documentation": {"kind": "markdown", "value": "\nAdds the given element to the array, returning the new number of elements in\nthe array. *This function modifies the original array.* See\n[`Array.unshift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)\non MDN.\n\n```res example\nlet arr = [\"b\", \"c\", \"d\"]\nJs.Array2.unshift(arr, \"a\") == 4\narr == [\"a\", \"b\", \"c\", \"d\"]\n```\n"} + }, { + "label": "Js.Array2.sortInPlace", + "kind": 12, + "tags": [], + "detail": "t<'a> => t<'a>", + "documentation": {"kind": "markdown", "value": "\nSorts the given array in place and returns the sorted array. JavaScript sorts\nthe array by converting the arguments to UTF-16 strings and sorting them. See\nthe second example with sorting numbers, which does not do a numeric sort.\n*This function modifies the original array.* See\n[`Array.sort`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)\non MDN.\n\n```res example\nlet words = [\"bee\", \"dog\", \"ant\", \"cat\"]\nJs.Array2.sortInPlace(words) == [\"ant\", \"bee\", \"cat\", \"dog\"]\nwords == [\"ant\", \"bee\", \"cat\", \"dog\"]\n\nlet numbers = [3, 30, 10, 1, 20, 2]\nJs.Array2.sortInPlace(numbers) == [1, 10, 2, 20, 3, 30]\nnumbers == [1, 10, 2, 20, 3, 30]\n```\n"} + }, { + "label": "Js.Array2.unsafe_get", + "kind": 12, + "tags": [], + "detail": "(array<'a>, int) => 'a", + "documentation": {"kind": "markdown", "value": "\nReturns the value at the given position in the array if the position is in\nbounds; returns the JavaScript value `undefined` otherwise.\n\n```res example\nlet arr = [100, 101, 102, 103]\nJs.Array2.unsafe_get(arr, 3) == 103\nJs.Array2.unsafe_get(arr, 4) // returns undefined\n```\n"} + }, { + "label": "Js.Array2.some", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => bool", + "documentation": {"kind": "markdown", "value": "\nReturns `true` if the predicate function given as the second argument to\n`some()` returns `true` for any element in the array; `false` otherwise.\n\n```res example\nlet isEven = x => mod(x, 2) == 0\n\nJs.Array2.some([3, 7, 5, 2, 9], isEven) == true\nJs.Array2.some([3, 7, 5, 1, 9], isEven) == false\n```\n"} + }, { + "label": "Js.Array2.map", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => 'b) => t<'b>", + "documentation": {"kind": "markdown", "value": "\nApplies the function (the second argument) to each item in the array, returning\na new array. The result array does not have to have elements of the same type\nas the input array. See\n[`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)\non MDN.\n\n```res example\nJs.Array2.map([12, 4, 8], x => x * x) == [144, 16, 64]\nJs.Array2.map([\"animal\", \"vegetable\", \"mineral\"], Js.String.length) == [6, 9, 7]\n```\n"} + }, { + "label": "Js.Array2.push", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => int", + "documentation": {"kind": "markdown", "value": "\nAppends the given value to the array, returning the number of elements in the\nupdated array. *This function modifies the original array.* See\n[`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)\non MDN.\n\n```res example\nlet arr = [\"ant\", \"bee\", \"cat\"]\nJs.Array2.push(arr, \"dog\") == 4\narr == [\"ant\", \"bee\", \"cat\", \"dog\"]\n```\n"} + }, { + "label": "Js.Array2.fillRangeInPlace", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a, ~start: int, ~end_: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nSets the elements of the given array (the first arumgent) from position\n`~start` up to but not including position `~end_` to the designated value (the\nsecond argument), returning the resulting array. *This function modifies the\noriginal array.* See\n[`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.fillRangeInPlace(arr, 99, ~start=1, ~end_=4) == [100, 99, 99, 99, 104]\narr == [100, 99, 99, 99, 104]\n```\n"} + }, { + "label": "Js.Array2.pop", + "kind": 12, + "tags": [], + "detail": "t<'a> => option<'a>", + "documentation": {"kind": "markdown", "value": "\nIf the array is not empty, removes the last element and returns it as\n`Some(value)`; returns `None` if the array is empty. *This function modifies\nthe original array.* See\n[`Array.pop`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.pop(arr) == Some(104)\narr == [100, 101, 102, 103]\n\nlet empty: array = []\nJs.Array2.pop(empty) == None\n```\n"} + }, { + "label": "Js.Array2.somei", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => bool) => bool", + "documentation": {"kind": "markdown", "value": "\nReturns `true` if the predicate function given as the second argument to\n`somei()` returns `true` for any element in the array; `false` otherwise. The\npredicate function has two arguments: an item from the array and the index\nvalue\n\n```res example\n// Does any string in the array\n// have the same length as its index?\n\nlet sameLength = (str, index) => Js.String.length(str) == index\n\n// \"ef\" has length 2 and is it at index 2\nJs.Array2.somei([\"ab\", \"cd\", \"ef\", \"gh\"], sameLength) == true\n// no item has the same length as its index\nJs.Array2.somei([\"a\", \"bc\", \"def\", \"gh\"], sameLength) == false\n```\n"} + }, { + "label": "Js.Array2.append", + "kind": 12, + "tags": [1], + "detail": "(t<'a>, 'a) => t<'a>", + "documentation": {"kind": "markdown", "value": "Deprecated: `append` is not type-safe. Use `concat` instead.\n\n"} + }, { + "label": "Js.Array2.unsafe_set", + "kind": 12, + "tags": [], + "detail": "(array<'a>, int, 'a) => unit", + "documentation": {"kind": "markdown", "value": "\nSets the value at the given position in the array if the position is in bounds.\nIf the index is out of bounds, well, “here there be dragons.“\n\n*This function modifies the original array.*\n\n```res example\nlet arr = [100, 101, 102, 103]\nJs.Array2.unsafe_set(arr, 3, 99)\n// result is [100, 101, 102, 99];\n\nJs.Array2.unsafe_set(arr, 4, 88)\n// result is [100, 101, 102, 99, 88]\n\nJs.Array2.unsafe_set(arr, 6, 77)\n// result is [100, 101, 102, 99, 88, <1 empty item>, 77]\n\nJs.Array2.unsafe_set(arr, -1, 66)\n// you don't want to know.\n```\n"} + }, { + "label": "Js.Array2.copyWithin", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~to_: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nCopies from the first element in the given array to the designated `~to_`\nposition, returning the resulting array. *This function modifies the original\narray.* See\n[`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.copyWithin(arr, ~to_=2) == [100, 101, 100, 101, 102]\narr == [100, 101, 100, 101, 102]\n```\n"} + }, { + "label": "Js.Array2.everyi", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => bool) => bool", + "documentation": {"kind": "markdown", "value": "\nThe first argument to `everyi()` is an array. The second argument is a\npredicate function with two arguments: an array element and that element’s\nindex; it returns a boolean. The `everyi()` function returns `true` if the\npredicate function is true for all items in the given array. If given an empty\narray, returns `true`. See\n[`Array.every`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)\non MDN.\n\n```res example\n// determine if all even-index items are positive\nlet evenIndexPositive = (item, index) => mod(index, 2) == 0 ? item > 0 : true\n\nJs.Array2.everyi([6, -3, 5, 8], evenIndexPositive) == true\nJs.Array2.everyi([6, 3, -5, 8], evenIndexPositive) == false\n```\n"} + }, { + "label": "Js.Array2.toString", + "kind": 12, + "tags": [], + "detail": "t<'a> => string", + "documentation": {"kind": "markdown", "value": "\nConverts the array to a string. Each element is converted to a string using\nJavaScript. Unlike the JavaScript `Array.toString()`, all elements in a\nReasonML array must have the same type. See\n[`Array.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString)\non MDN.\n\n```res example\nJs.Array2.toString([3.5, 4.6, 7.8]) == \"3.5,4.6,7.8\"\nJs.Array2.toString([\"a\", \"b\", \"c\"]) == \"a,b,c\"\n```\n"} + }, { + "label": "Js.Array2.spliceInPlace", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~pos: int, ~remove: int, ~add: array<'a>) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nStarting at position `~pos`, remove `~remove` elements and then add the\nelements from the `~add` array. Returns an array consisting of the removed\nitems. *This function modifies the original array.* See\n[`Array.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)\non MDN.\n\n```res example\nlet arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.spliceInPlace(arr, ~pos=2, ~remove=2, ~add=[\"x\", \"y\", \"z\"]) == [\"c\", \"d\"]\narr == [\"a\", \"b\", \"x\", \"y\", \"z\", \"e\", \"f\"]\n\nlet arr2 = [\"a\", \"b\", \"c\", \"d\"]\nJs.Array2.spliceInPlace(arr2, ~pos=3, ~remove=0, ~add=[\"x\", \"y\"]) == []\narr2 == [\"a\", \"b\", \"c\", \"x\", \"y\", \"d\"]\n\nlet arr3 = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.spliceInPlace(arr3, ~pos=9, ~remove=2, ~add=[\"x\", \"y\", \"z\"]) == []\narr3 == [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"x\", \"y\", \"z\"]\n```\n"} + }, { + "label": "Js.Array2.pushMany", + "kind": 12, + "tags": [], + "detail": "(t<'a>, array<'a>) => int", + "documentation": {"kind": "markdown", "value": "\nAppends the values from one array (the second argument) to another (the first\nargument), returning the number of elements in the updated array. *This\nfunction modifies the original array.* See\n[`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)\non MDN.\n\n```res example\nlet arr = [\"ant\", \"bee\", \"cat\"]\nJs.Array2.pushMany(arr, [\"dog\", \"elk\"]) == 5\narr == [\"ant\", \"bee\", \"cat\", \"dog\", \"elk\"]\n```\n"} + }, { + "label": "Js.Array2.copyWithinFrom", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~to_: int, ~from: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nCopies starting at element `~from` in the given array to the designated `~to_`\nposition, returning the resulting array. *This function modifies the original\narray.* See\n[`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.copyWithinFrom(arr, ~from=2, ~to_=0) == [102, 103, 104, 103, 104]\narr == [102, 103, 104, 103, 104]\n```\n"} + }, { + "label": "Js.Array2.forEach", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => unit) => unit", + "documentation": {"kind": "markdown", "value": "\nThe `forEach()` function applies the function given as the second argument to\neach element in the array. The function you provide returns `unit`, and the\n`forEach()` function also returns `unit`. You use `forEach()` when you need to\nprocess each element in the array but not return any new array or value; for\nexample, to print the items in an array. See\n[`Array.forEach`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)\non MDN.\n\n```res example\n// display all elements in an array\nJs.Array2.forEach([\"a\", \"b\", \"c\"], x => Js.log(x)) == ()\n```\n"} + }, { + "label": "Js.Array2.sliceFrom", + "kind": 12, + "tags": [], + "detail": "(t<'a>, int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nReturns a shallow copy of the given array from the given index to the end. See\n[`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\non MDN.\n"} + }, { + "label": "Js.Array2.sortInPlaceWith", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, 'a) => int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nSorts the given array in place and returns the sorted array. *This function\n modifies the original array.*\n\nThe first argument to `sortInPlaceWith()` is a function that compares two items\nfrom the array and returns:\n\n* an integer less than zero if the first item is less than the second item *\nzero if the items are equal * an integer greater than zero if the first item is\ngreater than the second item\n\nSee\n[`Array.sort`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)\non MDN.\n\n```res example\n// sort by word length\nlet words = [\"horse\", \"aardvark\", \"dog\", \"camel\"]\nlet byLength = (s1, s2) => Js.String.length(s1) - Js.String.length(s2)\n\nJs.Array2.sortInPlaceWith(words, byLength) == [\"dog\", \"horse\", \"camel\", \"aardvark\"]\n\n// sort in reverse numeric order\nlet numbers = [3, 30, 10, 1, 20, 2]\nlet reverseNumeric = (n1, n2) => n2 - n1\nJs.Array2.sortInPlaceWith(numbers, reverseNumeric) == [30, 20, 10, 3, 2, 1]\n```\n"} + }, { + "label": "Js.Array2.indexOfFrom", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a, ~from: int) => int", + "documentation": {"kind": "markdown", "value": "\nReturns the index of the first element in the array with the given value. The\nsearch starts at position `~from`. See\n[`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)\non MDN.\n\n```res example\nJs.Array2.indexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\"], \"a\", ~from=2) == 2\nJs.Array2.indexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\"], \"a\", ~from=3) == 4\nJs.Array2.indexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\"], \"b\", ~from=2) == -1\n```\n"} + }] + +Complete src/CompletionPipeChain.res 11:42 +posCursor:[11:42] posNoWhite:[11:41] Found expr:[11:11->0:-1] +Completable: Cpath Value[Js, Array2, filter](Nolabel, Nolabel)-> +[{ + "label": "Js.Array2.mapi", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => 'b) => t<'b>", + "documentation": {"kind": "markdown", "value": "\nApplies the function (the second argument) to each item in the array, returning\na new array. The function acceps two arguments: an item from the array and its\nindex number. The result array does not have to have elements of the same type\nas the input array. See\n[`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)\non MDN.\n\n```res example\n// multiply each item in array by its position\nlet product = (item, index) => item * index\nJs.Array2.mapi([10, 11, 12], product) == [0, 11, 24]\n```\n"} + }, { + "label": "Js.Array2.lastIndexOf", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => int", + "documentation": {"kind": "markdown", "value": "\nReturns the index of the last element in the array that has the given value. If\nthe value is not in the array, returns -1. See\n[`Array.lastIndexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)\non MDN.\n\n```res example\nJs.Array2.lastIndexOf([\"a\", \"b\", \"a\", \"c\"], \"a\") == 2\nJs.Array2.lastIndexOf([\"a\", \"b\", \"a\", \"c\"], \"x\") == -1\n```\n"} + }, { + "label": "Js.Array2.concat", + "kind": 12, + "tags": [], + "detail": "(t<'a>, t<'a>) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nConcatenates the second array argument to the first array argument, returning a\nnew array. The original arrays are not modified. See\n[`Array.concat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)\non MDN.\n\n```res example\nJs.Array2.concat([\"a\", \"b\"], [\"c\", \"d\", \"e\"]) == [\"a\", \"b\", \"c\", \"d\", \"e\"]\n```\n"} + }, { + "label": "Js.Array2.unshiftMany", + "kind": 12, + "tags": [], + "detail": "(t<'a>, array<'a>) => int", + "documentation": {"kind": "markdown", "value": "\nAdds the elements in the second array argument at the beginning of the first\narray argument, returning the new number of elements in the array. *This\nfunction modifies the original array.* See\n[`Array.unshift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)\non MDN.\n\n```res example\nlet arr = [\"d\", \"e\"]\nJs.Array2.unshiftMany(arr, [\"a\", \"b\", \"c\"]) == 5\narr == [\"a\", \"b\", \"c\", \"d\", \"e\"]\n```\n"} + }, { + "label": "Js.Array2.filter", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nApplies the given predicate function (the second argument) to each element in\nthe array; the result is an array of those elements for which the predicate\nfunction returned `true`. See\n[`Array.filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)\non MDN.\n\n```res example\nlet nonEmpty = s => s != \"\"\nJs.Array2.filter([\"abc\", \"\", \"\", \"def\", \"ghi\"], nonEmpty) == [\"abc\", \"def\", \"ghi\"]\n```\n"} + }, { + "label": "Js.Array2.shift", + "kind": 12, + "tags": [], + "detail": "t<'a> => option<'a>", + "documentation": {"kind": "markdown", "value": "\nIf the array is not empty, removes the first element and returns it as\n`Some(value)`; returns `None` if the array is empty. *This function modifies\nthe original array.* See\n[`Array.shift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.shift(arr) == Some(100)\narr == [101, 102, 103, 104]\n\nlet empty: array = []\nJs.Array2.shift(empty) == None\n```\n"} + }, { + "label": "Js.Array2.reduceRight", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('b, 'a) => 'b, 'b) => 'b", + "documentation": {"kind": "markdown", "value": "\nThe `reduceRight()` function takes three parameters: an array, a *reducer\nfunction*, and a beginning accumulator value. The reducer function has two\nparameters: an accumulated value and an element of the array.\n\n`reduceRight()` first calls the reducer function with the beginning value and\nthe last element in the array. The result becomes the new accumulator value,\nwhich is passed in to the reducer function along with the next-to-last element\nin the array. `reduceRight()` proceeds from right to left through the array,\npassing in the result of each stage as the accumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reduceRight()`. See\n[`Array.reduceRight`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight)\non MDN.\n\n**NOTE:** In many cases, `reduce()` and `reduceRight()` give the same result.\nHowever, see the last example here and compare it to the example from\n`reduce()`, where order makes a difference.\n\n```res example\nlet sumOfSquares = (accumulator, item) => accumulator + item * item\n\nJs.Array2.reduceRight([10, 2, 4], sumOfSquares, 0) == 120\nJs.Array2.reduceRight([2.0, 4.0], (acc, item) => item /. acc, 1.0) == 0.5 // 2.0 / (4.0 / 1.0)\n```\n"} + }, { + "label": "Js.Array2.joinWith", + "kind": 12, + "tags": [], + "detail": "(t<'a>, string) => string", + "documentation": {"kind": "markdown", "value": "\nThis function converts each element of the array to a string (via JavaScript)\nand concatenates them, separated by the string given in the first argument,\ninto a single string. See\n[`Array.join`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)\non MDN.\n\n```res example\nJs.Array2.joinWith([\"ant\", \"bee\", \"cat\"], \"--\") == \"ant--bee--cat\"\nJs.Array2.joinWith([\"door\", \"bell\"], \"\") == \"doorbell\"\nJs.Array2.joinWith([2020, 9, 4], \"/\") == \"2020/9/4\"\nJs.Array2.joinWith([2.5, 3.6, 3e-2], \";\") == \"2.5;3.6;0.03\"\n```\n"} + }, { + "label": "Js.Array2.concatMany", + "kind": 12, + "tags": [], + "detail": "(t<'a>, array>) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nThe second argument to `concatMany()` is an array of arrays; these are added at\nthe end of the first argument, returning a new array. See\n[`Array.concat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)\non MDN.\n\n```res example\nJs.Array2.concatMany([\"a\", \"b\", \"c\"], [[\"d\", \"e\"], [\"f\", \"g\", \"h\"]]) == [\n \"a\",\n \"b\",\n \"c\",\n \"d\",\n \"e\",\n \"f\",\n \"g\",\n \"h\",\n ]\n```\n"} + }, { + "label": "Js.Array2.fillInPlace", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nSets all elements of the given array (the first arumgent) to the designated\nvalue (the secon argument), returning the resulting array. *This function\n modifies the original array.*\n\nSee\n[`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.fillInPlace(arr, 99) == [99, 99, 99, 99, 99]\narr == [99, 99, 99, 99, 99]\n```\n"} + }, { + "label": "Js.Array2.isArray", + "kind": 12, + "tags": [], + "detail": "'a => bool", + "documentation": {"kind": "markdown", "value": "\nReturns `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.\n\n```res example\nJs.Array2.isArray([5, 2, 3, 1, 4]) == true\nJs.Array2.isArray(list{5, 2, 3, 1, 4}) == true\nJs.Array2.isArray(\"abcd\") == false\n```\n"} + }, { + "label": "Js.Array2.reduce", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('b, 'a) => 'b, 'b) => 'b", + "documentation": {"kind": "markdown", "value": "\nThe `reduce()` function takes three parameters: an array, a *reducer function*,\nand a beginning accumulator value. The reducer function has two parameters: an\naccumulated value and an element of the array.\n\n`reduce()` first calls the reducer function with the beginning value and the\nfirst element in the array. The result becomes the new accumulator value, which\nis passed in to the reducer function along with the second element in the\narray. `reduce()` proceeds through the array, passing in the result of each\nstage as the accumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reduce()`. See\n[`Array.reduce`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce)\non MDN.\n\n```res example\nlet sumOfSquares = (accumulator, item) => accumulator + item * item\n\nJs.Array2.reduce([10, 2, 4], sumOfSquares, 0) == 120\nJs.Array2.reduce([10, 2, 4], \\\"*\", 1) == 80\nJs.Array2.reduce(\n [\"animal\", \"vegetable\", \"mineral\"],\n (acc, item) => acc + Js.String.length(item),\n 0,\n) == 22 // 6 + 9 + 7\nJs.Array2.reduce([2.0, 4.0], (acc, item) => item /. acc, 1.0) == 2.0 // 4.0 / (2.0 / 1.0)\n```\n"} + }, { + "label": "Js.Array2.copy", + "kind": 12, + "tags": [], + "detail": "t<'a> => t<'a>", + "documentation": {"kind": "markdown", "value": "\nReturns a copy of the entire array. Same as `Js.Array2.Slice(arr, ~start=0,\n~end_=Js.Array2.length(arr))`. See\n[`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\non MDN.\n"} + }, { + "label": "Js.Array2.reducei", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('b, 'a, int) => 'b, 'b) => 'b", + "documentation": {"kind": "markdown", "value": "\nThe `reducei()` function takes three parameters: an array, a *reducer\nfunction*, and a beginning accumulator value. The reducer function has three\nparameters: an accumulated value, an element of the array, and the index of\nthat element.\n\n`reducei()` first calls the reducer function with the beginning value, the\nfirst element in the array, and zero (its index). The result becomes the new\naccumulator value, which is passed to the reducer function along with the\nsecond element in the array and one (its index). `reducei()` proceeds from left\nto right through the array, passing in the result of each stage as the\naccumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reducei()`. See\n[`Array.reduce`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce)\non MDN.\n\n```res example\n// find sum of even-index elements in array\nlet sumOfEvens = (accumulator, item, index) =>\n if mod(index, 2) == 0 {\n accumulator + item\n } else {\n accumulator\n }\n\nJs.Array2.reducei([2, 5, 1, 4, 3], sumOfEvens, 0) == 6\n```\n"} + }, { + "label": "Js.Array2.forEachi", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => unit) => unit", + "documentation": {"kind": "markdown", "value": "\nThe `forEachi()` function applies the function given as the second argument to\neach element in the array. The function you provide takes an item in the array\nand its index number, and returns `unit`. The `forEachi()` function also\nreturns `unit`. You use `forEachi()` when you need to process each element in\nthe array but not return any new array or value; for example, to print the\nitems in an array. See\n[`Array.forEach`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)\non MDN.\n\n```res example\n// display all elements in an array as a numbered list\nJs.Array2.forEachi([\"a\", \"b\", \"c\"], (item, index) => Js.log2(index + 1, item)) == ()\n```\n"} + }, { + "label": "Js.Array2.fillFromInPlace", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a, ~from: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nSets all elements of the given array (the first arumgent) from position `~from`\nto the end to the designated value (the second argument), returning the\nresulting array. *This function modifies the original array.* See\n[`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.fillFromInPlace(arr, 99, ~from=2) == [100, 101, 99, 99, 99]\narr == [100, 101, 99, 99, 99]\n```\n"} + }, { + "label": "Js.Array2.findi", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => bool) => option<'a>", + "documentation": {"kind": "markdown", "value": "\nReturns `Some(value)` for the first element in the array that satisifies the\ngiven predicate function, or `None` if no element satisifies the predicate. The\npredicate function takes an array element and an index as its parameters. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\n// find first positive item at an odd index\nlet positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0\n\nJs.Array2.findi([66, -33, 55, 88, 22], positiveOddElement) == Some(88)\nJs.Array2.findi([66, -33, 55, -88, 22], positiveOddElement) == None\n```\n"} + }, { + "label": "Js.Array2.filteri", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => bool) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nEach element of the given array are passed to the predicate function. The\nreturn value is an array of all those elements for which the predicate function\nreturned `true`.\n\nSee\n[`Array.filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)\non MDN.\n\n```res example\n// keep only positive elements at odd indices\nlet positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0\n\nJs.Array2.filteri([6, 3, 5, 8, 7, -4, 1], positiveOddElement) == [3, 8]\n```\n"} + }, { + "label": "Js.Array2.slice", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~start: int, ~end_: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nReturns a shallow copy of the given array from the `~start` index up to but not\nincluding the `~end_` position. Negative numbers indicate an offset from the\nend of the array. See\n[`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104, 105, 106]\nJs.Array2.slice(arr, ~start=2, ~end_=5) == [102, 103, 104]\nJs.Array2.slice(arr, ~start=-3, ~end_=-1) == [104, 105]\nJs.Array2.slice(arr, ~start=9, ~end_=10) == []\n```\n"} + }, { + "label": "Js.Array2.fromMap", + "kind": 12, + "tags": [], + "detail": "(array_like<'a>, 'a => 'b) => array<'b>", + "documentation": {"kind": "markdown", "value": "\nCreates a new array by applying a function (the second argument) to each item\nin the `array_like` first argument. See\n[`Array.from`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)\non MDN.\n\n```res example\nlet strArr = Js.String.castToArrayLike(\"abcd\")\nlet code = s => Js.String.charCodeAt(0, s)\nJs.Array2.fromMap(strArr, code) == [97.0, 98.0, 99.0, 100.0]\n```\n"} + }, { + "label": "Js.Array2.removeFromInPlace", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~pos: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nRemoves elements from the given array starting at position `~pos` to the end of\nthe array, returning the removed elements. *This function modifies the original\narray.* See\n[`Array.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)\non MDN.\n\n```res example\nlet arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.removeFromInPlace(arr, ~pos=4) == [\"e\", \"f\"]\narr == [\"a\", \"b\", \"c\", \"d\"]\n```\n"} + }, { + "label": "Js.Array2.from", + "kind": 12, + "tags": [], + "detail": "array_like<'a> => array<'a>", + "documentation": {"kind": "markdown", "value": "\nCreates a shallow copy of an array from an array-like object. See\n[`Array.from`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)\non MDN.\n\n```res example\nlet strArr = Js.String.castToArrayLike(\"abcd\")\nJs.Array2.from(strArr) == [\"a\", \"b\", \"c\", \"d\"]\n```\n"} + }, { + "label": "Js.Array2.includes", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => bool", + "documentation": {"kind": "markdown", "value": "\nReturns true if the given value is in the array, `false` otherwise. See\n[`Array.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)\non MDN.\n\n```res example\nJs.Array2.includes([\"a\", \"b\", \"c\"], \"b\") == true\nJs.Array2.includes([\"a\", \"b\", \"c\"], \"x\") == false\n```\n"} + }, { + "label": "Js.Array2.find", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => option<'a>", + "documentation": {"kind": "markdown", "value": "\nReturns `Some(value)` for the first element in the array that satisifies the\ngiven predicate function, or `None` if no element satisifies the predicate. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\n// find first negative element\nJs.Array2.find([33, 22, -55, 77, -44], x => x < 0) == Some(-55)\nJs.Array2.find([33, 22, 55, 77, 44], x => x < 0) == None\n```\n"} + }, { + "label": "Js.Array2.reduceRighti", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('b, 'a, int) => 'b, 'b) => 'b", + "documentation": {"kind": "markdown", "value": "\nThe `reduceRighti()` function takes three parameters: an array, a *reducer\nfunction*, and a beginning accumulator value. The reducer function has three\nparameters: an accumulated value, an element of the array, and the index of\nthat element. `reduceRighti()` first calls the reducer function with the\nbeginning value, the last element in the array, and its index (length of array\nminus one). The result becomes the new accumulator value, which is passed in to\nthe reducer function along with the second element in the array and one (its\nindex). `reduceRighti()` proceeds from right to left through the array, passing\nin the result of each stage as the accumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reduceRighti()`. See\n[`Array.reduceRight`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight)\non MDN.\n\n**NOTE:** In many cases, `reducei()` and `reduceRighti()` give the same result.\nHowever, there are cases where the order in which items are processed makes a\ndifference.\n\n```res example\n// find sum of even-index elements in array\nlet sumOfEvens = (accumulator, item, index) =>\n if mod(index, 2) == 0 {\n accumulator + item\n } else {\n accumulator\n }\n\nJs.Array2.reduceRighti([2, 5, 1, 4, 3], sumOfEvens, 0) == 6\n```\n"} + }, { + "label": "Js.Array2.findIndexi", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => bool) => int", + "documentation": {"kind": "markdown", "value": "\nReturns `Some(value)` for the first element in the array that satisifies the\ngiven predicate function, or `None` if no element satisifies the predicate. The\npredicate function takes an array element and an index as its parameters. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\n// find index of first positive item at an odd index\nlet positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0\n\nJs.Array2.findIndexi([66, -33, 55, 88, 22], positiveOddElement) == 3\nJs.Array2.findIndexi([66, -33, 55, -88, 22], positiveOddElement) == -1\n```\n"} + }, { + "label": "Js.Array2.toLocaleString", + "kind": 12, + "tags": [], + "detail": "t<'a> => string", + "documentation": {"kind": "markdown", "value": "\nConverts the array to a string using the conventions of the current locale.\nEach element is converted to a string using JavaScript. Unlike the JavaScript\n`Array.toLocaleString()`, all elements in a ReasonML array must have the same\ntype. See\n[`Array.toLocaleString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString)\non MDN.\n\n```res example\nJs.Array2.toLocaleString([Js.Date.make()])\n// returns \"3/19/2020, 10:52:11 AM\" for locale en_US.utf8\n// returns \"2020-3-19 10:52:11\" for locale de_DE.utf8\n```\n"} + }, { + "label": "Js.Array2.lastIndexOfFrom", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a, ~from: int) => int", + "documentation": {"kind": "markdown", "value": "\nReturns the index of the last element in the array that has the given value,\nsearching from position `~from` down to the start of the array. If the value is\nnot in the array, returns -1. See\n[`Array.lastIndexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)\non MDN.\n\n```res example\nJs.Array2.lastIndexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\", \"d\"], \"a\", ~from=3) == 2\nJs.Array2.lastIndexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\", \"d\"], \"c\", ~from=2) == -1\n```\n"} + }, { + "label": "Js.Array2.copyWithinFromRange", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~to_: int, ~start: int, ~end_: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nCopies starting at element `~start` in the given array up to but not including\n`~end_` to the designated `~to_` position, returning the resulting array. *This\nfunction modifies the original array.* See\n[`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104, 105]\nJs.Array2.copyWithinFromRange(arr, ~start=2, ~end_=5, ~to_=1) == [100, 102, 103, 104, 104, 105]\narr == [100, 102, 103, 104, 104, 105]\n```\n"} + }, { + "label": "Js.Array2.findIndex", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => int", + "documentation": {"kind": "markdown", "value": "\nReturns the index of the first element in the array that satisifies the given\npredicate function, or -1 if no element satisifies the predicate. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\nJs.Array2.findIndex([33, 22, -55, 77, -44], x => x < 0) == 2\nJs.Array2.findIndex([33, 22, 55, 77, 44], x => x < 0) == -1\n```\n"} + }, { + "label": "Js.Array2.removeCountInPlace", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~pos: int, ~count: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nRemoves `~count` elements from the given array starting at position `~pos`,\nreturning the removed elements. *This function modifies the original array.*\nSee\n[`Array.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)\non MDN.\n\n```res example\nlet arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.removeCountInPlace(arr, ~pos=2, ~count=3) == [\"c\", \"d\", \"e\"]\narr == [\"a\", \"b\", \"f\"]\n```\n"} + }, { + "label": "Js.Array2.reverseInPlace", + "kind": 12, + "tags": [], + "detail": "t<'a> => t<'a>", + "documentation": {"kind": "markdown", "value": "\nReturns an array with the elements of the input array in reverse order. *This\nfunction modifies the original array.* See\n[`Array.reverse`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse)\non MDN.\n\n```res example\nlet arr = [\"ant\", \"bee\", \"cat\"]\nJs.Array2.reverseInPlace(arr) == [\"cat\", \"bee\", \"ant\"]\narr == [\"cat\", \"bee\", \"ant\"]\n```\n"} + }, { + "label": "Js.Array2.every", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => bool", + "documentation": {"kind": "markdown", "value": "\nThe first argument to `every()` is an array. The second argument is a predicate\nfunction that returns a boolean. The `every()` function returns `true` if the\npredicate function is true for all items in the given array. If given an empty\narray, returns `true`. See\n[`Array.every`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)\non MDN.\n\n```res example\nlet isEven = x => mod(x, 2) == 0\nJs.Array2.every([6, 22, 8, 4], isEven) == true\nJs.Array2.every([6, 22, 7, 4], isEven) == false\n```\n"} + }, { + "label": "Js.Array2.length", + "kind": 12, + "tags": [], + "detail": "array<'a> => int", + "documentation": {"kind": "markdown", "value": "\nReturns the number of elements in the array. See\n[`Array.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)\non MDN.\n"} + }, { + "label": "Js.Array2.indexOf", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => int", + "documentation": {"kind": "markdown", "value": "\nReturns the index of the first element in the array that has the given value.\nIf the value is not in the array, returns -1. See\n[`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)\non MDN.\n\n```res example\nJs.Array2.indexOf([100, 101, 102, 103], 102) == 2\nJs.Array2.indexOf([100, 101, 102, 103], 999) == -1\n```\n"} + }, { + "label": "Js.Array2.unshift", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => int", + "documentation": {"kind": "markdown", "value": "\nAdds the given element to the array, returning the new number of elements in\nthe array. *This function modifies the original array.* See\n[`Array.unshift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)\non MDN.\n\n```res example\nlet arr = [\"b\", \"c\", \"d\"]\nJs.Array2.unshift(arr, \"a\") == 4\narr == [\"a\", \"b\", \"c\", \"d\"]\n```\n"} + }, { + "label": "Js.Array2.sortInPlace", + "kind": 12, + "tags": [], + "detail": "t<'a> => t<'a>", + "documentation": {"kind": "markdown", "value": "\nSorts the given array in place and returns the sorted array. JavaScript sorts\nthe array by converting the arguments to UTF-16 strings and sorting them. See\nthe second example with sorting numbers, which does not do a numeric sort.\n*This function modifies the original array.* See\n[`Array.sort`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)\non MDN.\n\n```res example\nlet words = [\"bee\", \"dog\", \"ant\", \"cat\"]\nJs.Array2.sortInPlace(words) == [\"ant\", \"bee\", \"cat\", \"dog\"]\nwords == [\"ant\", \"bee\", \"cat\", \"dog\"]\n\nlet numbers = [3, 30, 10, 1, 20, 2]\nJs.Array2.sortInPlace(numbers) == [1, 10, 2, 20, 3, 30]\nnumbers == [1, 10, 2, 20, 3, 30]\n```\n"} + }, { + "label": "Js.Array2.unsafe_get", + "kind": 12, + "tags": [], + "detail": "(array<'a>, int) => 'a", + "documentation": {"kind": "markdown", "value": "\nReturns the value at the given position in the array if the position is in\nbounds; returns the JavaScript value `undefined` otherwise.\n\n```res example\nlet arr = [100, 101, 102, 103]\nJs.Array2.unsafe_get(arr, 3) == 103\nJs.Array2.unsafe_get(arr, 4) // returns undefined\n```\n"} + }, { + "label": "Js.Array2.some", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => bool", + "documentation": {"kind": "markdown", "value": "\nReturns `true` if the predicate function given as the second argument to\n`some()` returns `true` for any element in the array; `false` otherwise.\n\n```res example\nlet isEven = x => mod(x, 2) == 0\n\nJs.Array2.some([3, 7, 5, 2, 9], isEven) == true\nJs.Array2.some([3, 7, 5, 1, 9], isEven) == false\n```\n"} + }, { + "label": "Js.Array2.map", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => 'b) => t<'b>", + "documentation": {"kind": "markdown", "value": "\nApplies the function (the second argument) to each item in the array, returning\na new array. The result array does not have to have elements of the same type\nas the input array. See\n[`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)\non MDN.\n\n```res example\nJs.Array2.map([12, 4, 8], x => x * x) == [144, 16, 64]\nJs.Array2.map([\"animal\", \"vegetable\", \"mineral\"], Js.String.length) == [6, 9, 7]\n```\n"} + }, { + "label": "Js.Array2.push", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => int", + "documentation": {"kind": "markdown", "value": "\nAppends the given value to the array, returning the number of elements in the\nupdated array. *This function modifies the original array.* See\n[`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)\non MDN.\n\n```res example\nlet arr = [\"ant\", \"bee\", \"cat\"]\nJs.Array2.push(arr, \"dog\") == 4\narr == [\"ant\", \"bee\", \"cat\", \"dog\"]\n```\n"} + }, { + "label": "Js.Array2.fillRangeInPlace", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a, ~start: int, ~end_: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nSets the elements of the given array (the first arumgent) from position\n`~start` up to but not including position `~end_` to the designated value (the\nsecond argument), returning the resulting array. *This function modifies the\noriginal array.* See\n[`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.fillRangeInPlace(arr, 99, ~start=1, ~end_=4) == [100, 99, 99, 99, 104]\narr == [100, 99, 99, 99, 104]\n```\n"} + }, { + "label": "Js.Array2.pop", + "kind": 12, + "tags": [], + "detail": "t<'a> => option<'a>", + "documentation": {"kind": "markdown", "value": "\nIf the array is not empty, removes the last element and returns it as\n`Some(value)`; returns `None` if the array is empty. *This function modifies\nthe original array.* See\n[`Array.pop`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.pop(arr) == Some(104)\narr == [100, 101, 102, 103]\n\nlet empty: array = []\nJs.Array2.pop(empty) == None\n```\n"} + }, { + "label": "Js.Array2.somei", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => bool) => bool", + "documentation": {"kind": "markdown", "value": "\nReturns `true` if the predicate function given as the second argument to\n`somei()` returns `true` for any element in the array; `false` otherwise. The\npredicate function has two arguments: an item from the array and the index\nvalue\n\n```res example\n// Does any string in the array\n// have the same length as its index?\n\nlet sameLength = (str, index) => Js.String.length(str) == index\n\n// \"ef\" has length 2 and is it at index 2\nJs.Array2.somei([\"ab\", \"cd\", \"ef\", \"gh\"], sameLength) == true\n// no item has the same length as its index\nJs.Array2.somei([\"a\", \"bc\", \"def\", \"gh\"], sameLength) == false\n```\n"} + }, { + "label": "Js.Array2.append", + "kind": 12, + "tags": [1], + "detail": "(t<'a>, 'a) => t<'a>", + "documentation": {"kind": "markdown", "value": "Deprecated: `append` is not type-safe. Use `concat` instead.\n\n"} + }, { + "label": "Js.Array2.unsafe_set", + "kind": 12, + "tags": [], + "detail": "(array<'a>, int, 'a) => unit", + "documentation": {"kind": "markdown", "value": "\nSets the value at the given position in the array if the position is in bounds.\nIf the index is out of bounds, well, “here there be dragons.“\n\n*This function modifies the original array.*\n\n```res example\nlet arr = [100, 101, 102, 103]\nJs.Array2.unsafe_set(arr, 3, 99)\n// result is [100, 101, 102, 99];\n\nJs.Array2.unsafe_set(arr, 4, 88)\n// result is [100, 101, 102, 99, 88]\n\nJs.Array2.unsafe_set(arr, 6, 77)\n// result is [100, 101, 102, 99, 88, <1 empty item>, 77]\n\nJs.Array2.unsafe_set(arr, -1, 66)\n// you don't want to know.\n```\n"} + }, { + "label": "Js.Array2.copyWithin", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~to_: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nCopies from the first element in the given array to the designated `~to_`\nposition, returning the resulting array. *This function modifies the original\narray.* See\n[`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.copyWithin(arr, ~to_=2) == [100, 101, 100, 101, 102]\narr == [100, 101, 100, 101, 102]\n```\n"} + }, { + "label": "Js.Array2.everyi", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => bool) => bool", + "documentation": {"kind": "markdown", "value": "\nThe first argument to `everyi()` is an array. The second argument is a\npredicate function with two arguments: an array element and that element’s\nindex; it returns a boolean. The `everyi()` function returns `true` if the\npredicate function is true for all items in the given array. If given an empty\narray, returns `true`. See\n[`Array.every`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)\non MDN.\n\n```res example\n// determine if all even-index items are positive\nlet evenIndexPositive = (item, index) => mod(index, 2) == 0 ? item > 0 : true\n\nJs.Array2.everyi([6, -3, 5, 8], evenIndexPositive) == true\nJs.Array2.everyi([6, 3, -5, 8], evenIndexPositive) == false\n```\n"} + }, { + "label": "Js.Array2.toString", + "kind": 12, + "tags": [], + "detail": "t<'a> => string", + "documentation": {"kind": "markdown", "value": "\nConverts the array to a string. Each element is converted to a string using\nJavaScript. Unlike the JavaScript `Array.toString()`, all elements in a\nReasonML array must have the same type. See\n[`Array.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString)\non MDN.\n\n```res example\nJs.Array2.toString([3.5, 4.6, 7.8]) == \"3.5,4.6,7.8\"\nJs.Array2.toString([\"a\", \"b\", \"c\"]) == \"a,b,c\"\n```\n"} + }, { + "label": "Js.Array2.spliceInPlace", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~pos: int, ~remove: int, ~add: array<'a>) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nStarting at position `~pos`, remove `~remove` elements and then add the\nelements from the `~add` array. Returns an array consisting of the removed\nitems. *This function modifies the original array.* See\n[`Array.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)\non MDN.\n\n```res example\nlet arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.spliceInPlace(arr, ~pos=2, ~remove=2, ~add=[\"x\", \"y\", \"z\"]) == [\"c\", \"d\"]\narr == [\"a\", \"b\", \"x\", \"y\", \"z\", \"e\", \"f\"]\n\nlet arr2 = [\"a\", \"b\", \"c\", \"d\"]\nJs.Array2.spliceInPlace(arr2, ~pos=3, ~remove=0, ~add=[\"x\", \"y\"]) == []\narr2 == [\"a\", \"b\", \"c\", \"x\", \"y\", \"d\"]\n\nlet arr3 = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.spliceInPlace(arr3, ~pos=9, ~remove=2, ~add=[\"x\", \"y\", \"z\"]) == []\narr3 == [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"x\", \"y\", \"z\"]\n```\n"} + }, { + "label": "Js.Array2.pushMany", + "kind": 12, + "tags": [], + "detail": "(t<'a>, array<'a>) => int", + "documentation": {"kind": "markdown", "value": "\nAppends the values from one array (the second argument) to another (the first\nargument), returning the number of elements in the updated array. *This\nfunction modifies the original array.* See\n[`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)\non MDN.\n\n```res example\nlet arr = [\"ant\", \"bee\", \"cat\"]\nJs.Array2.pushMany(arr, [\"dog\", \"elk\"]) == 5\narr == [\"ant\", \"bee\", \"cat\", \"dog\", \"elk\"]\n```\n"} + }, { + "label": "Js.Array2.copyWithinFrom", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~to_: int, ~from: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nCopies starting at element `~from` in the given array to the designated `~to_`\nposition, returning the resulting array. *This function modifies the original\narray.* See\n[`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.copyWithinFrom(arr, ~from=2, ~to_=0) == [102, 103, 104, 103, 104]\narr == [102, 103, 104, 103, 104]\n```\n"} + }, { + "label": "Js.Array2.forEach", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => unit) => unit", + "documentation": {"kind": "markdown", "value": "\nThe `forEach()` function applies the function given as the second argument to\neach element in the array. The function you provide returns `unit`, and the\n`forEach()` function also returns `unit`. You use `forEach()` when you need to\nprocess each element in the array but not return any new array or value; for\nexample, to print the items in an array. See\n[`Array.forEach`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)\non MDN.\n\n```res example\n// display all elements in an array\nJs.Array2.forEach([\"a\", \"b\", \"c\"], x => Js.log(x)) == ()\n```\n"} + }, { + "label": "Js.Array2.sliceFrom", + "kind": 12, + "tags": [], + "detail": "(t<'a>, int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nReturns a shallow copy of the given array from the given index to the end. See\n[`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\non MDN.\n"} + }, { + "label": "Js.Array2.sortInPlaceWith", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, 'a) => int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nSorts the given array in place and returns the sorted array. *This function\n modifies the original array.*\n\nThe first argument to `sortInPlaceWith()` is a function that compares two items\nfrom the array and returns:\n\n* an integer less than zero if the first item is less than the second item *\nzero if the items are equal * an integer greater than zero if the first item is\ngreater than the second item\n\nSee\n[`Array.sort`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)\non MDN.\n\n```res example\n// sort by word length\nlet words = [\"horse\", \"aardvark\", \"dog\", \"camel\"]\nlet byLength = (s1, s2) => Js.String.length(s1) - Js.String.length(s2)\n\nJs.Array2.sortInPlaceWith(words, byLength) == [\"dog\", \"horse\", \"camel\", \"aardvark\"]\n\n// sort in reverse numeric order\nlet numbers = [3, 30, 10, 1, 20, 2]\nlet reverseNumeric = (n1, n2) => n2 - n1\nJs.Array2.sortInPlaceWith(numbers, reverseNumeric) == [30, 20, 10, 3, 2, 1]\n```\n"} + }, { + "label": "Js.Array2.indexOfFrom", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a, ~from: int) => int", + "documentation": {"kind": "markdown", "value": "\nReturns the index of the first element in the array with the given value. The\nsearch starts at position `~from`. See\n[`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)\non MDN.\n\n```res example\nJs.Array2.indexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\"], \"a\", ~from=2) == 2\nJs.Array2.indexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\"], \"a\", ~from=3) == 4\nJs.Array2.indexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\"], \"b\", ~from=2) == -1\n```\n"} + }] + +Complete src/CompletionPipeChain.res 14:60 +posCursor:[14:60] posNoWhite:[14:59] Found expr:[14:26->0:-1] +Completable: Cpath Value[Belt, List, fromArray](Nolabel)-> +[{ + "label": "Belt.List.some2", + "kind": 12, + "tags": [], + "detail": "(t<'a>, t<'b>, ('a, 'b) => bool) => bool", + "documentation": {"kind": "markdown", "value": "\n Returns `true` if predicate `pred(a, b)` is true for any pair of elements up\n to the shorter length (i.e. `min(length(firstList), length(secondList))`)\n\n ```res example\n Belt.List.some2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) /* true */\n\n Belt.List.some2(list{}, list{1}, (a, b) => a > b) /* false */\n\n Belt.List.some2(list{2, 3}, list{1}, (a, b) => a > b) /* true */\n\n Belt.List.some2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* true */\n ```\n"} + }, { + "label": "Belt.List.concat", + "kind": 12, + "tags": [], + "detail": "(t<'a>, t<'a>) => t<'a>", + "documentation": {"kind": "markdown", "value": "\n Returns the list obtained by adding `secondList` after `firstList`.\n\n ```res example\n Belt.List.concat(list{1, 2, 3}, list{4, 5}) // list{1, 2, 3, 4, 5}\n ```\n"} + }, { + "label": "Belt.List.mapReverse", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => 'b) => t<'b>", + "documentation": {"kind": "markdown", "value": "\n Equivalent to:\n\n ```res\n map(someList, f)->reverse\n ```\n\n ```res example\n list{3, 4, 5}->Belt.List.mapReverse(x => x * x) /* list{25, 16, 9} */\n ```\n"} + }, { + "label": "Belt.List.keepWithIndex", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => bool) => t<'a>", + "documentation": {"kind": "markdown", "value": "\n Returns a list of all elements in `someList` which satisfy the predicate function `pred`.\n\n ```res example\n let isEven = x => mod(x, 2) == 0\n\n Belt.List.keepWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) /* list{1, 3} */\n ```\n"} + }, { + "label": "Belt.List.getExn", + "kind": 12, + "tags": [], + "detail": "(t<'a>, int) => 'a", + "documentation": {"kind": "markdown", "value": "\n Same as [get](#get), but raises an exception if `index` is larger than the\n length. Use with care.\n\n ```res example\n let abc = list{\"A\", \"B\", \"C\"}\n\n abc->Belt.List.getExn(1) // \"B\"\n\n abc->Belt.List.getExn(4) // Raises an Error\n ```\n"} + }, { + "label": "Belt.List.reduceReverse", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'b, ('b, 'a) => 'b) => 'b", + "documentation": {"kind": "markdown", "value": "\n Works like [reduce](#reduce), except that function `f` is applied to each\n item of `someList` from the last back to the first.\n\n ```res example\n list{1, 2, 3, 4}->Belt.List.reduceReverse(0, (a, b) => a + b) /* 10 */\n\n list{1, 2, 3, 4}->Belt.List.reduceReverse(10, (a, b) => a - b) /* 0 */\n\n list{1, 2, 3, 4}->Belt.List.reduceReverse(list{}, Belt.List.add) // list{1, 2, 3, 4}\n ```\n"} + }, { + "label": "Belt.List.size", + "kind": 12, + "tags": [], + "detail": "t<'a> => int", + "documentation": {"kind": "markdown", "value": " **See** [`length`](##length) "} + }, { + "label": "Belt.List.concatMany", + "kind": 12, + "tags": [], + "detail": "array> => t<'a>", + "documentation": {"kind": "markdown", "value": "\n Returns the list obtained by concatenating all the lists in array `a`, in\n order.\n\n ```res example\n Belt.List.concatMany([list{1, 2, 3}, list{}, list{3}]) // list{1, 2, 3, 3}\n ```\n"} + }, { + "label": "Belt.List.toArray", + "kind": 12, + "tags": [], + "detail": "t<'a> => array<'a>", + "documentation": {"kind": "markdown", "value": "\n Converts the given list to an array.\n\n ```res example\n Belt.List.toArray(list{1, 2, 3}) // [1, 2, 3]\n ```\n"} + }, { + "label": "Belt.List.keepMapU", + "kind": 12, + "tags": [], + "detail": "(t<'a>, (. 'a) => option<'b>) => t<'b>", + "documentation": {"kind": "markdown", "value": " Uncurried version of [keepMap](#keepMap). "} + }, { + "label": "Belt.List.shuffle", + "kind": 12, + "tags": [], + "detail": "t<'a> => t<'a>", + "documentation": {"kind": "markdown", "value": "\n Returns a new list in random order.\n\n ```res example\n Belt.List.shuffle(list{1, 2, 3}) // list{2, 1, 3}\n ```\n"} + }, { + "label": "Belt.List.makeBy", + "kind": 12, + "tags": [], + "detail": "(int, int => 'a) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nReturn a list of length `numItems` with element `i` initialized with `f(i)`.\nReturns an empty list if `numItems` is negative.\n\n```res example\nBelt.List.makeBy(5, i => i) // list{0, 1, 2, 3, 4}\n\nBelt.List.makeBy(5, i => i * i) // list{0, 1, 4, 9, 16}\n```\n"} + }, { + "label": "Belt.List.take", + "kind": 12, + "tags": [], + "detail": "(t<'a>, int) => option>", + "documentation": {"kind": "markdown", "value": "\nReturns a list with the first `n` elements from `someList`, or `None` if `someList` has fewer than `n` elements.\n\n```res example\nlist{1, 2, 3}->Belt.List.take(1) // Some(list{1})\n\nlist{1, 2, 3}->Belt.List.take(2) // Some(list{1, 2})\n\nlist{1, 2, 3}->Belt.List.take(4) // None\n```\n"} + }, { + "label": "Belt.List.hasAssocU", + "kind": 12, + "tags": [], + "detail": "(t<('a, 'c)>, 'b, (. 'a, 'b) => bool) => bool", + "documentation": {"kind": "markdown", "value": " Uncurried version of [hasAssoc](#hasAssoc). "} + }, { + "label": "Belt.List.zip", + "kind": 12, + "tags": [], + "detail": "(t<'a>, t<'b>) => t<('a, 'b)>", + "documentation": {"kind": "markdown", "value": "\n Returns a list of pairs from the two lists with the length of the shorter list.\n\n ```res example\n Belt.List.zip(list{1, 2}, list{3, 4, 5}) // list{(1, 3), (2, 4)}\n ```\n"} + }, { + "label": "Belt.List.reduceReverse2", + "kind": 12, + "tags": [], + "detail": "(t<'a>, t<'b>, 'c, ('c, 'a, 'b) => 'c) => 'c", + "documentation": {"kind": "markdown", "value": "\n Applies `f` to each element of `firstList` and `secondList` from end to\n beginning. Stops with the shorter list. Function `f` has three parameters: an\n “accumulator” which starts with a value of init, an item from `firstList`,\n and an item from `secondList`. `reduce2` returns the final value of the\n accumulator.\n\n ```res example\n Belt.List.reduceReverse2(list{1, 2, 3}, list{4, 5}, 0, (acc, x, y) => acc + x * x + y) /* + (1 * 1 + 4) + (2 * 2 + 5) */\n ```\n"} + }, { + "label": "Belt.List.headExn", + "kind": 12, + "tags": [], + "detail": "t<'a> => 'a", + "documentation": {"kind": "markdown", "value": "\n Same as [head](#head), but raises an exception if `someList` is empty. Use\n with care.\n\n ```res example\n Belt.List.headExn(list{1, 2, 3}) // 1\n\n Belt.List.headExn(list{}) // Raises an Error\n ```\n"} + }, { + "label": "Belt.List.reduceU", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'b, (. 'b, 'a) => 'b) => 'b", + "documentation": {"kind": "markdown", "value": " Uncurried version of [reduce](#reduce). "} + }, { + "label": "Belt.List.cmpU", + "kind": 12, + "tags": [], + "detail": "(t<'a>, t<'a>, (. 'a, 'a) => int) => int", + "documentation": {"kind": "markdown", "value": " Uncurried version of [cmp](#cmp). "} + }, { + "label": "Belt.List.make", + "kind": 12, + "tags": [], + "detail": "(int, 'a) => t<'a>", + "documentation": {"kind": "markdown", "value": "\n Returns a list of length `numItems` with each element filled with value `v`. Returns an empty list if `numItems` is negative.\n\n ```res example\n Belt.List.make(3, 1) // list{1, 1, 1}\n ```\n"} + }, { + "label": "Belt.List.removeAssocU", + "kind": 12, + "tags": [], + "detail": "(t<('a, 'c)>, 'b, (. 'a, 'b) => bool) => t<('a, 'c)>", + "documentation": {"kind": "markdown", "value": " Uncurried version of [removeAssoc](#removeAssoc). "} + }, { + "label": "Belt.List.someU", + "kind": 12, + "tags": [], + "detail": "(t<'a>, (. 'a) => bool) => bool", + "documentation": {"kind": "markdown", "value": " Uncurried version of [some](#some). "} + }, { + "label": "Belt.List.sort", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, 'a) => int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\n Returns a sorted list.\n\n ```res example\n Belt.List.sort(list{5, 4, 9, 3, 7}, (a, b) => a - b) // list{3, 4, 5, 7, 9}\n ```\n"} + }, { + "label": "Belt.List.length", + "kind": 12, + "tags": [], + "detail": "t<'a> => int", + "documentation": {"kind": "markdown", "value": "\n Returns the length of a list.\n\n ```res example\n Belt.List.length(list{1, 2, 3}) // 3\n ```\n"} + }, { + "label": "Belt.List.zipByU", + "kind": 12, + "tags": [], + "detail": "(t<'a>, t<'b>, (. 'a, 'b) => 'c) => t<'c>", + "documentation": {"kind": "markdown", "value": " Uncurried version of [zipBy](#zipBy). "} + }, { + "label": "Belt.List.mapReverse2U", + "kind": 12, + "tags": [], + "detail": "(t<'a>, t<'b>, (. 'a, 'b) => 'c) => t<'c>", + "documentation": {"kind": "markdown", "value": " Uncurried version of [mapReverse2](#mapReverse2). "} + }, { + "label": "Belt.List.every", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => bool", + "documentation": {"kind": "markdown", "value": "\n Returns `true` if all elements satisfy `pred`, where `pred` is a predicate: a function taking an element and returning a bool.\n\n ```res example\n let isBelow10 = value => value < 10\n\n list{1, 9, 8, 2}->Belt.List.every(isBelow10) /* true */\n\n list{1, 99, 8, 2}->Belt.List.every(isBelow10) /* false */\n ```\n"} + }, { + "label": "Belt.List.every2U", + "kind": 12, + "tags": [], + "detail": "(t<'a>, t<'b>, (. 'a, 'b) => bool) => bool", + "documentation": {"kind": "markdown", "value": " Uncurried version of [every2](#every2). "} + }, { + "label": "Belt.List.forEach2U", + "kind": 12, + "tags": [], + "detail": "(t<'a>, t<'b>, (. 'a, 'b) => 'c) => unit", + "documentation": {"kind": "markdown", "value": " Uncurried version of [forEach2](#forEach2). "} + }, { + "label": "Belt.List.setAssocU", + "kind": 12, + "tags": [], + "detail": "(t<('a, 'c)>, 'a, 'c, (. 'a, 'a) => bool) => t<('a, 'c)>", + "documentation": {"kind": "markdown", "value": " Uncurried version of [setAssoc](#setAssoc). "} + }, { + "label": "Belt.List.map", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => 'b) => t<'b>", + "documentation": {"kind": "markdown", "value": "\n Returns a new list with `f` applied to each element of `someList`.\n\n ```res example\n list{1, 2}->Belt.List.map(x => x + 1) // list{3, 4}\n ```\n"} + }, { + "label": "Belt.List.zipBy", + "kind": 12, + "tags": [], + "detail": "(t<'a>, t<'b>, ('a, 'b) => 'c) => t<'c>", + "documentation": {"kind": "markdown", "value": "\n **See:** [zip](#zip)\n\n ```res example\n Belt.List.zipBy(list{1, 2, 3}, list{4, 5}, (a, b) => 2 * a + b) // list{6, 9}\n ```\n"} + }, { + "label": "Belt.List.reduce2", + "kind": 12, + "tags": [], + "detail": "(t<'b>, t<'c>, 'a, ('a, 'b, 'c) => 'a) => 'a", + "documentation": {"kind": "markdown", "value": "\n Applies `f` to each element of `firstList` and `secondList` from beginning to end. Stops with the shorter list. Function `f` has three parameters: an “accumulator” which starts with a value of `initialValue`, an item from `firstList`, and an item from `secondList`. `reduce2` returns the final value of the accumulator.\n\n ```res example\n 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) */\n ```\n"} + }, { + "label": "Belt.List.some2U", + "kind": 12, + "tags": [], + "detail": "(t<'a>, t<'b>, (. 'a, 'b) => bool) => bool", + "documentation": {"kind": "markdown", "value": " Uncurried version of [some2](#some2). "} + }, { + "label": "Belt.List.mapWithIndexU", + "kind": 12, + "tags": [], + "detail": "(t<'a>, (. int, 'a) => 'b) => t<'b>", + "documentation": {"kind": "markdown", "value": " Uncurried version of [mapWithIndex](#mapWithIndex). "} + }, { + "label": "Belt.List.reduceWithIndexU", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'b, (. 'b, 'a, int) => 'b) => 'b", + "documentation": {"kind": "markdown", "value": " Uncurried version of [reduceWithIndex](#reduceWithIndex). "} + }, { + "label": "Belt.List.keep", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => t<'a>", + "documentation": {"kind": "markdown", "value": "\n Returns a list of all elements in `someList` which satisfy the predicate function `pred`.\n\n ```res example\n let isEven = x => mod(x, 2) == 0\n\n Belt.List.keep(list{1, 2, 3, 4}, isEven) /* list{2, 4} */\n\n Belt.List.keep(list{None, Some(2), Some(3), None}, Belt.Option.isSome) /* list{Some(2), Some(3)} */\n ```\n"} + }, { + "label": "Belt.List.forEachU", + "kind": 12, + "tags": [], + "detail": "(t<'a>, (. 'a) => 'b) => unit", + "documentation": {"kind": "markdown", "value": " Uncurried version of [forEach](#forEach). "} + }, { + "label": "Belt.List.every2", + "kind": 12, + "tags": [], + "detail": "(t<'a>, t<'b>, ('a, 'b) => bool) => bool", + "documentation": {"kind": "markdown", "value": "\n Returns `true` if predicate `pred(a, b)` is `true` for all pairs of elements\n up to the shorter length (i.e. `min(length(firstList), length(secondList))`)\n\n ```res example\n Belt.List.every2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) /* true */\n\n Belt.List.every2(list{}, list{1}, (a, b) => a > b) /* true */\n\n Belt.List.every2(list{2, 3}, list{1}, (a, b) => a > b) /* true */\n\n Belt.List.every2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* false */\n ```\n"} + }, { + "label": "Belt.List.mapU", + "kind": 12, + "tags": [], + "detail": "(t<'a>, (. 'a) => 'b) => t<'b>", + "documentation": {"kind": "markdown", "value": " Uncurried version of [map](#map). "} + }, { + "label": "Belt.List.reverse", + "kind": 12, + "tags": [], + "detail": "t<'a> => t<'a>", + "documentation": {"kind": "markdown", "value": "\n Returns a new list whose elements are those of `someList` in reversed order.\n\n ```res example\n Belt.List.reverse(list{1, 2, 3}) /* list{3, 2, 1} */\n ```\n"} + }, { + "label": "Belt.List.cmp", + "kind": 12, + "tags": [], + "detail": "(t<'a>, t<'a>, ('a, 'a) => int) => int", + "documentation": {"kind": "markdown", "value": "\n Compare elements one by one `compareFn(a, b)`. `compareFn` returns a negative number if `a` is \"less than\" `b`, zero if `a` is \"equal to\" `b`, a positive number if `a` is \"greater than\" `b`.\n\n The comparison returns the first non-zero result of `compareFn`, or zero if `compareFn` returns zero for all `a` and `b`.\n\n If all items have compared equal, but `firstList` is exhausted first, return `-1`. (`firstList` is shorter).\n If all items have compared equal, but `secondList` is exhausted first, return `1` (`firstList` is longer).\n\n ```res example\n Belt.List.cmp(list{3}, list{3, 7}, (a, b) => compare(a, b)) /* (-1) */\n\n Belt.List.cmp(list{5, 3}, list{5}, (a, b) => compare(a, b)) /* 1 */\n\n Belt.List.cmp(list{1, 3, 5}, list{1, 4, 2}, (a, b) => compare(a, b)) /* (-1) */\n\n Belt.List.cmp(list{1, 3, 5}, list{1, 2, 3}, (a, b) => compare(a, b)) /* 1 */\n\n Belt.List.cmp(list{1, 3, 5}, list{1, 3, 5}, (a, b) => compare(a, b)) /* 0 */\n ```\n\n **Please note:** The total ordering of List is different from Array,\n for Array, we compare the length first and, only if the lengths are equal, elements one by one.\n For lists, we just compare elements one by one.\n"} + }, { + "label": "Belt.List.eqU", + "kind": 12, + "tags": [], + "detail": "(t<'a>, t<'a>, (. 'a, 'a) => bool) => bool", + "documentation": {"kind": "markdown", "value": " Uncurried version of [eq](#eq). "} + }, { + "label": "Belt.List.sortU", + "kind": 12, + "tags": [], + "detail": "(t<'a>, (. 'a, 'a) => int) => t<'a>", + "documentation": {"kind": "markdown", "value": " Uncurried version of [sort](#sort). "} + }, { + "label": "Belt.List.splitAt", + "kind": 12, + "tags": [], + "detail": "(t<'a>, int) => option<(list<'a>, list<'a>)>", + "documentation": {"kind": "markdown", "value": "\n Split the list `someList` at `index`. Returns `None` when the length of `someList` is less than `index`.\n\n ```res example\n list{\"Hello\", \"World\"}->Belt.List.splitAt(1) // Some((list{\"Hello\"}, list{\"World\"}))\n\n list{0, 1, 2, 3, 4}->Belt.List.splitAt(2) // Some((list{0, 1}, list{2, 3, 4}))\n ```\n"} + }, { + "label": "Belt.List.forEachWithIndexU", + "kind": 12, + "tags": [], + "detail": "(t<'a>, (. int, 'a) => 'b) => unit", + "documentation": {"kind": "markdown", "value": " Uncurried version of [forEachWithIndex](#forEachWithIndex). "} + }, { + "label": "Belt.List.hasU", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'b, (. 'a, 'b) => bool) => bool", + "documentation": {"kind": "markdown", "value": " Uncurried version of [has](#has). "} + }, { + "label": "Belt.List.filter", + "kind": 12, + "tags": [1], + "detail": "(t<'a>, 'a => bool) => t<'a>", + "documentation": {"kind": "markdown", "value": "Deprecated: This function will soon be deprecated. Please, use `List.keep` instead.\n\n\n Returns a list of all elements in `someList` which satisfy the predicate function `pred`.\n\n ```res example\n let isEven = x => mod(x, 2) == 0\n\n Belt.List.filter(list{1, 2, 3, 4}, isEven) /* list{2, 4} */\n\n Belt.List.filter(list{None, Some(2), Some(3), None}, Belt.Option.isSome) /* list{Some(2), Some(3)} */\n ```\n"} + }, { + "label": "Belt.List.reduceReverseU", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'b, (. 'b, 'a) => 'b) => 'b", + "documentation": {"kind": "markdown", "value": " Uncurried version of [reduceReverse](#reduceReverse). "} + }, { + "label": "Belt.List.hasAssoc", + "kind": 12, + "tags": [], + "detail": "(t<('a, 'c)>, 'b, ('a, 'b) => bool) => bool", + "documentation": {"kind": "markdown", "value": "\n Returns `true` if there is a pair in `someList` where the first element equals `k` as per the predicate function `eqFunction`.\n\n ```res example\n list{(1, \"a\"), (2, \"b\"), (3, \"c\")}->Belt.List.hasAssoc(1, (a, b) => a == b) /* true */\n\n list{(9, \"morning\"), (15, \"afternoon\"), (22, \"night\")}\n ->Belt.List.hasAssoc(25, (k, item) => k /* 25 */ == item /* 9, 5, 22 */) /* false */\n ```\n"} + }, { + "label": "Belt.List.forEachWithIndex", + "kind": 12, + "tags": [], + "detail": "(t<'a>, (int, 'a) => 'b) => unit", + "documentation": {"kind": "markdown", "value": "\n Call `f` on each element of `someList` from beginning to end.\n Function `f` takes two arguments: the index starting from 0 and the element from `someList`. `f` returns `unit`.\n\n ```res example\n Belt.List.forEachWithIndex(list{\"a\", \"b\", \"c\"}, (index, x) => {\n Js.log(\"Item \" ++ Belt.Int.toString(index) ++ \" is \" ++ x)\n })\n /*\n prints:\n Item 0 is a\n Item 1 is b\n Item 2 is cc\n */\n ```\n"} + }, { + "label": "Belt.List.reduce", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'b, ('b, 'a) => 'b) => 'b", + "documentation": {"kind": "markdown", "value": "\n Applies `f` to each element of `someList` from beginning to end. Function `f` has two parameters: the item from the list and an “accumulator”, which starts with a value of `initialValue`. reduce returns the final value of the accumulator.\n\n ```res example\n list{1, 2, 3, 4}->Belt.List.reduce(0, (a, b) => a + b) /* 10 */\n\n /* same as */\n\n list{1, 2, 3, 4}->Belt.List.reduce(0, (acc, item) => acc + item) /* 10 */\n ```\n"} + }, { + "label": "Belt.List.add", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => t<'a>", + "documentation": {"kind": "markdown", "value": "\n Adds `value` to the beginning of `someList`.\n\n ```res example\n Belt.List.add(list{2, 3}, 1) // list{1, 2, 3}\n\n Belt.List.add(list{\"World\", \"!\"}, \"Hello\") // list{\"Hello\", \"World\", \"!\"}\n ```\n"} + }, { + "label": "Belt.List.forEach2", + "kind": 12, + "tags": [], + "detail": "(t<'a>, t<'b>, ('a, 'b) => 'c) => unit", + "documentation": {"kind": "markdown", "value": "\n Stops at the length of the shorter list.\n\n ```res example\n Belt.List.forEach2(list{\"Z\", \"Y\"}, list{\"A\", \"B\", \"C\"}, (x, y) => Js.log2(x, y))\n\n /*\n prints:\n \"Z\" \"A\"\n \"Y\" \"B\"\n */\n ```\n"} + }, { + "label": "Belt.List.reduceReverse2U", + "kind": 12, + "tags": [], + "detail": "(t<'a>, t<'b>, 'c, (. 'c, 'a, 'b) => 'c) => 'c", + "documentation": {"kind": "markdown", "value": " Uncurried version of [reduceReverse2](#reduceReverse2). "} + }, { + "label": "Belt.List.cmpByLength", + "kind": 12, + "tags": [], + "detail": "(t<'a>, t<'a>) => int", + "documentation": {"kind": "markdown", "value": "\n Compare two lists solely by length. Returns `-1` if `length(firstList)` is\n less than `length(secondList)`, `0` if `length(firstList)` equals\n `length(secondList)`, and `1` if `length(firstList)` is greater than\n `length(secondList)`.\n\n ```res example\n Belt.List.cmpByLength(list{1, 2}, list{3, 4, 5, 6}) /* -1 */\n\n Belt.List.cmpByLength(list{1, 2, 3}, list{4, 5, 6}) /* = 0 */\n\n Belt.List.cmpByLength(list{1, 2, 3, 4}, list{5, 6}) /* = 1 */\n ```\n"} + }, { + "label": "Belt.List.flatten", + "kind": 12, + "tags": [], + "detail": "t> => t<'a>", + "documentation": {"kind": "markdown", "value": "\n Return the list obtained by concatenating all the lists in list `ls`, in order.\n\n ```res example\n Belt.List.flatten(list{list{1, 2, 3}, list{}, list{3}}) // list{1, 2, 3, 3}\n ```\n"} + }, { + "label": "Belt.List.makeByU", + "kind": 12, + "tags": [], + "detail": "(int, (. int) => 'a) => t<'a>", + "documentation": {"kind": "markdown", "value": " Uncurried version of [makeBy](#makeBy) "} + }, { + "label": "Belt.List.mapReverse2", + "kind": 12, + "tags": [], + "detail": "(t<'a>, t<'b>, ('a, 'b) => 'c) => t<'c>", + "documentation": {"kind": "markdown", "value": "\n Equivalent to: `zipBy(xs, ys, f)->reverse`\n\n ```res example\n\n Belt.List.mapReverse2(list{1, 2, 3}, list{1, 2}, (a, b) => a + b) // list{4, 2}\n ```\n"} + }, { + "label": "Belt.List.getAssoc", + "kind": 12, + "tags": [], + "detail": "(t<('a, 'c)>, 'b, ('a, 'b) => bool) => option<'c>", + "documentation": {"kind": "markdown", "value": "\n Return the second element of a pair in `someList` where the first element equals `k` as per the predicate function `eqFunction`, or `None` if not found.\n\n ```res example\n list{(1, \"a\"), (2, \"b\"), (3, \"c\")}->Belt.List.getAssoc(3, (a, b) => a == b) /* Some(\"c\") */\n\n list{(9, \"morning\"), (15, \"afternoon\"), (22, \"night\")}\n ->Belt.List.getAssoc(15, (k, item) => k /* 15 */ == item /* 9, 5, 22 */)\n /* Some(\"afternoon\") */\n ```\n"} + }, { + "label": "Belt.List.fromArray", + "kind": 12, + "tags": [], + "detail": "array<'a> => t<'a>", + "documentation": {"kind": "markdown", "value": "\n Converts the given array to a list.\n\n ```res example\n Belt.List.fromArray([1, 2, 3]) // list{1, 2, 3}\n ```\n"} + }, { + "label": "Belt.List.reduce2U", + "kind": 12, + "tags": [], + "detail": "(t<'b>, t<'c>, 'a, (. 'a, 'b, 'c) => 'a) => 'a", + "documentation": {"kind": "markdown", "value": " Uncurried version of [reduce2](#reduce2). "} + }, { + "label": "Belt.List.filterWithIndex", + "kind": 12, + "tags": [1], + "detail": "(t<'a>, ('a, int) => bool) => t<'a>", + "documentation": {"kind": "markdown", "value": "Deprecated: This function will soon be deprecated. Please, use `List.keepWithIndex` instead.\n\n\n Returns a list of all elements in `someList` which satisfy the predicate function `pred`.\n\n ```res example\n let isEven = x => mod(x, 2) == 0\n\n Belt.List.filterWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) /* list{1, 3} */\n ```\n"} + }, { + "label": "Belt.List.mapWithIndex", + "kind": 12, + "tags": [], + "detail": "(t<'a>, (int, 'a) => 'b) => t<'b>", + "documentation": {"kind": "markdown", "value": "\n Applies `f` to each element of `someList`.\n Function `f` takes two arguments: the index starting from 0 and the element from `someList`, in that order.\n\n ```res example\n list{1, 2, 3}->Belt.List.mapWithIndex((index, x) => index + x) // list{1, 3, 5}\n ```\n"} + }, { + "label": "Belt.List.keepWithIndexU", + "kind": 12, + "tags": [], + "detail": "(t<'a>, (. 'a, int) => bool) => t<'a>", + "documentation": {"kind": "markdown", "value": " Uncurried version of [keepWithIndex](#keepWithIndex). "} + }, { + "label": "Belt.List.keepMap", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => option<'b>) => t<'b>", + "documentation": {"kind": "markdown", "value": "\n Applies `f` to each element of `someList`. If `f(x)` returns `Some(value)`, then `value` is _kept_ in the resulting list.\n If `f(x)` returns `None`, the element is _not_ retained in the result.\n\n ```res example\n let isEven = x => mod(x, 2) == 0\n\n list{1, 2, 3, 4}\n ->Belt.List.keepMap(x =>\n if (isEven(x)) {\n Some(x)\n } else {\n None\n }\n ) /* list{2, 4} */\n\n list{Some(1), Some(2), None}->Belt.List.keepMap(x => x) /* list{1, 2} */\n ```\n"} + }, { + "label": "Belt.List.reduceWithIndex", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'b, ('b, 'a, int) => 'b) => 'b", + "documentation": {"kind": "markdown", "value": "\n Applies `f` to each element of `someList` from beginning to end. Function `f` has three parameters: the item from the list and an “accumulator”, which starts with a value of `initialValue` and the index of each element. `reduceWithIndex` returns the final value of the accumulator.\n\n ```res example\n list{1, 2, 3, 4}->Belt.List.reduceWithIndex(0, (acc, item, index) => acc + item + index) /* 16 */\n ```\n"} + }, { + "label": "Belt.List.some", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => bool", + "documentation": {"kind": "markdown", "value": "\n Returns `true` if at least _one_ of the elements in `someList` satisfies\n `pred`, where `pred` is a predicate: a function taking an element and\n returning a bool.\n\n ```res example\n let isAbove100 = value => value > 100\n\n list{101, 1, 2, 3}->Belt.List.some(isAbove100) /* true */\n\n list{1, 2, 3, 4}->Belt.List.some(isAbove100) /* false */\n ```\n"} + }, { + "label": "Belt.List.partition", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => (t<'a>, t<'a>)", + "documentation": {"kind": "markdown", "value": "\n 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.\n\n In other words:\n\n ```res\n (elementsThatSatisfies, elementsThatDoesNotSatisfy)\n ```\n\n ```res example\n Belt.List.partition(list{1, 2, 3, 4}, x => x > 2) /* (list{3, 4}, list{1, 2}) */\n ```\n"} + }, { + "label": "Belt.List.getByU", + "kind": 12, + "tags": [], + "detail": "(t<'a>, (. 'a) => bool) => option<'a>", + "documentation": {"kind": "markdown", "value": " Uncurried version of [getBy](#getBy). "} + }, { + "label": "Belt.List.reverseConcat", + "kind": 12, + "tags": [], + "detail": "(t<'a>, t<'a>) => t<'a>", + "documentation": {"kind": "markdown", "value": "\n Equivalent to writing: `concat(reverse(firstList, secondList)`\n\n ```res example\n Belt.List.reverseConcat(list{1, 2}, list{3, 4}) // list{2, 1, 3, 4}\n ```\n"} + }, { + "label": "Belt.List.partitionU", + "kind": 12, + "tags": [], + "detail": "(t<'a>, (. 'a) => bool) => (t<'a>, t<'a>)", + "documentation": {"kind": "markdown", "value": " Uncurried version of [partition](#partition). "} + }, { + "label": "Belt.List.head", + "kind": 12, + "tags": [], + "detail": "t<'a> => option<'a>", + "documentation": {"kind": "markdown", "value": "\n Returns `Some(value)` where `value` is the first element in the list, or\n `None` if `someList` is an empty list.\n\n ```res example\n Belt.List.head(list{}) // None\n Belt.List.head(list{1, 2, 3}) // Some(1)\n ```\n"} + }, { + "label": "Belt.List.get", + "kind": 12, + "tags": [], + "detail": "(t<'a>, int) => option<'a>", + "documentation": {"kind": "markdown", "value": "\n Return the nth element in `someList`, or `None` if `index` is larger than the\n length.\n\n ```res example\n let abc = list{\"A\", \"B\", \"C\"}\n\n abc->Belt.List.get(1) // Some(\"B\")\n\n abc->Belt.List.get(4) // None\n ```\n"} + }, { + "label": "Belt.List.setAssoc", + "kind": 12, + "tags": [], + "detail": "(t<('a, 'c)>, 'a, 'c, ('a, 'a) => bool) => t<('a, 'c)>", + "documentation": {"kind": "markdown", "value": "\n If `k` exists in `someList` by satisfying the `eqFunction` predicate, return a new list with the key and value replaced by the new `k` and `v`; otherwise, return a new list with the pair `k`, `v` added to the head of `someList`.\n\n ```res example\n list{(1, \"a\"), (2, \"b\"), (3, \"c\")}->Belt.List.setAssoc(2, \"x\", (a, b) => a == b) /* list{(1, \"a\"), (2, \"x\"), (3, \"c\")} */\n\n list{(1, \"a\"), (3, \"c\")}->Belt.List.setAssoc(2, \"b\", (a, b) => a == b) /* list{(2, \"b\"), (1, \"a\"), (3, \"c\")} */\n\n list{(9, \"morning\"), (3, \"morning?!\"), (22, \"night\")}\n ->Belt.List.setAssoc(15, \"afternoon\", (a, b) => mod(a, 12) == mod(b, 12))\n /* list{(9, \"morning\"), (15, \"afternoon\"), (22, \"night\")} */\n ```\n\n **Please note**\n\n In the last example, since: `15 mod 12` equals `3 mod 12`\n\n Both the key _and_ the value are replaced in the list.\n"} + }, { + "label": "Belt.List.tail", + "kind": 12, + "tags": [], + "detail": "t<'a> => option>", + "documentation": {"kind": "markdown", "value": "\n Returns `None` if `someList` is empty, otherwise it returns `Some(tail)`\n where `tail` is everything except the first element of `someList`.\n\n ```res example\n Belt.List.tail(list{1, 2, 3}) // Some(list{2, 3})\n\n Belt.List.tail(list{}) // None\n ```\n"} + }, { + "label": "Belt.List.drop", + "kind": 12, + "tags": [], + "detail": "(t<'a>, int) => option>", + "documentation": {"kind": "markdown", "value": "\n Return a new list, dropping the first `n` elements. Returns `None` if `someList` has fewer than `n` elements.\n\n ```res example\n list{1, 2, 3}->Belt.List.drop(2) // Some(list{3})\n\n list{1, 2, 3}->Belt.List.drop(3) // Some(list{})\n\n list{1, 2, 3}->Belt.List.drop(4) // None\n ```\n"} + }, { + "label": "Belt.List.everyU", + "kind": 12, + "tags": [], + "detail": "(t<'a>, (. 'a) => bool) => bool", + "documentation": {"kind": "markdown", "value": " Uncurried version of [every](#every). "} + }, { + "label": "Belt.List.tailExn", + "kind": 12, + "tags": [], + "detail": "t<'a> => t<'a>", + "documentation": {"kind": "markdown", "value": "\n Same as [tail](#tail), but raises an exception if `someList` is empty. Use\n with care.\n\n ```res example\n Belt.List.tailExn(list{1, 2, 3}) // list{2, 3}\n\n Belt.List.tailExn(list{}) // Raises an Error\n ```\n"} + }, { + "label": "Belt.List.mapReverseU", + "kind": 12, + "tags": [], + "detail": "(t<'a>, (. 'a) => 'b) => t<'b>", + "documentation": {"kind": "markdown", "value": " Uncurried version of [mapReverse](#mapReverse). "} + }, { + "label": "Belt.List.unzip", + "kind": 12, + "tags": [], + "detail": "t<('a, 'b)> => (t<'a>, t<'b>)", + "documentation": {"kind": "markdown", "value": "\n Takes a list of pairs and creates a pair of lists. The first list contains all the first items of the pairs; the second list contains all the second items.\n\n ```res example\n Belt.List.unzip(list{(1, 2), (3, 4)}) /* (list{1, 3}, list{2, 4}) */\n\n Belt.List.unzip(list{(\"H\", \"W\"), (\"e\", \"o\"), (\"l\", \"r\"), (\"l\", \"l\"), (\"o\", \"d\"), (\" \", \"!\")})\n /* (list{\"H\", \"e\", \"l\", \"l\", \"o\", \" \"}, list{\"W\", \"o\", \"r\", \"l\", \"d\", \"!\"}) */\n ```\n"} + }, { + "label": "Belt.List.has", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'b, ('a, 'b) => bool) => bool", + "documentation": {"kind": "markdown", "value": "\n Returns `true` if the list contains at least one element for which\n `eqFunction(x)` returns true.\n\n ```res example\n list{1, 2, 3}->Belt.List.has(2, (a, b) => a == b) /* true */\n\n list{1, 2, 3}->Belt.List.has(4, (a, b) => a == b) /* false */\n\n list{(-1), (-2), (-3)}->Belt.List.has(2, (a, b) => abs(a) == abs(b)) /* true */\n ```\n"} + }, { + "label": "Belt.List.forEach", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => 'b) => unit", + "documentation": {"kind": "markdown", "value": "\n Call `f` on each element of `someList` from the beginning to end.\n `f` returns `unit`, so no new array is created. Use `forEach` when you are primarily concerned with repetitively creating side effects.\n\n ```res example\n Belt.List.forEach(list{\"a\", \"b\", \"c\"}, x => Js.log(\"Item: \" ++ x))\n /*\n prints:\n Item: a\n Item: b\n Item: c\n */\n ```\n"} + }, { + "label": "Belt.List.eq", + "kind": 12, + "tags": [], + "detail": "(t<'a>, t<'a>, ('a, 'a) => bool) => bool", + "documentation": {"kind": "markdown", "value": "\n Check equality of `firstList` and `secondList` using `eqElem` for equality on\n elements, where `eqElem` is a function that returns `true` if items `x` and\n `y` meet some criterion for equality, `false` otherwise. eq `false` if length\n of `firstList` and `secondList` are not the same.\n\n ```res example\n Belt.List.eq(list{1, 2, 3}, list{1, 2}, (a, b) => a == b) /* false */\n\n Belt.List.eq(list{1, 2}, list{1, 2}, (a, b) => a == b) /* true */\n\n Belt.List.eq(list{1, 2, 3}, list{(-1), (-2), (-3)}, (a, b) => abs(a) == abs(b)) /* true */\n ```\n"} + }, { + "label": "Belt.List.getBy", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => option<'a>", + "documentation": {"kind": "markdown", "value": "\n Returns `Some(value)` for the first value in `someList` that satisfies the\n predicate function `pred`. Returns `None` if no element satisfies the function.\n\n ```res example\n Belt.List.getBy(list{1, 4, 3, 2}, x => x > 3) /* Some(4) */\n\n Belt.List.getBy(list{1, 4, 3, 2}, x => x > 4) /* None */\n ```\n"} + }, { + "label": "Belt.List.getAssocU", + "kind": 12, + "tags": [], + "detail": "(t<('a, 'c)>, 'b, (. 'a, 'b) => bool) => option<'c>", + "documentation": {"kind": "markdown", "value": " Uncurried version of [getAssoc](#getAssoc). "} + }, { + "label": "Belt.List.keepU", + "kind": 12, + "tags": [], + "detail": "(t<'a>, (. 'a) => bool) => t<'a>", + "documentation": {"kind": "markdown", "value": " Uncurried version of [keep](#keep). "} + }, { + "label": "Belt.List.removeAssoc", + "kind": 12, + "tags": [], + "detail": "(t<('a, 'c)>, 'b, ('a, 'b) => bool) => t<('a, 'c)>", + "documentation": {"kind": "markdown", "value": "\n Return a list after removing the first pair whose first value is `k` per the equality predicate `eqFunction`; if not found, return a new list identical to `someList`.\n\n ```res example\n list{(1, \"a\"), (2, \"b\"), (3, \"c\")}->Belt.List.removeAssoc(1, (a, b) => a == b) /* list{(2, \"b\"), (3, \"c\")} */\n\n list{(9, \"morning\"), (15, \"afternoon\"), (22, \"night\")}\n ->Belt.List.removeAssoc(9, (k, item) => k /* 9 */ == item /* 9, 5, 22 */)\n /* list{(15, \"afternoon\"), (22, \"night\")} */\n ```\n"} + }] + +Complete src/CompletionPipeChain.res 17:61 +posCursor:[17:61] posNoWhite:[17:60] Found expr:[17:11->17:61] +Pexp_apply ...[17:25->17:26] (...[17:11->17:25], ...[17:26->17:61]) +posCursor:[17:61] posNoWhite:[17:60] Found expr:[17:26->17:61] +Completable: Cpath Value[Belt, List, fromArray](Nolabel)->s +[{ + "label": "Belt.List.some2", + "kind": 12, + "tags": [], + "detail": "(t<'a>, t<'b>, ('a, 'b) => bool) => bool", + "documentation": {"kind": "markdown", "value": "\n Returns `true` if predicate `pred(a, b)` is true for any pair of elements up\n to the shorter length (i.e. `min(length(firstList), length(secondList))`)\n\n ```res example\n Belt.List.some2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) /* true */\n\n Belt.List.some2(list{}, list{1}, (a, b) => a > b) /* false */\n\n Belt.List.some2(list{2, 3}, list{1}, (a, b) => a > b) /* true */\n\n Belt.List.some2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* true */\n ```\n"} + }, { + "label": "Belt.List.size", + "kind": 12, + "tags": [], + "detail": "t<'a> => int", + "documentation": {"kind": "markdown", "value": " **See** [`length`](##length) "} + }, { + "label": "Belt.List.shuffle", + "kind": 12, + "tags": [], + "detail": "t<'a> => t<'a>", + "documentation": {"kind": "markdown", "value": "\n Returns a new list in random order.\n\n ```res example\n Belt.List.shuffle(list{1, 2, 3}) // list{2, 1, 3}\n ```\n"} + }, { + "label": "Belt.List.someU", + "kind": 12, + "tags": [], + "detail": "(t<'a>, (. 'a) => bool) => bool", + "documentation": {"kind": "markdown", "value": " Uncurried version of [some](#some). "} + }, { + "label": "Belt.List.sort", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, 'a) => int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\n Returns a sorted list.\n\n ```res example\n Belt.List.sort(list{5, 4, 9, 3, 7}, (a, b) => a - b) // list{3, 4, 5, 7, 9}\n ```\n"} + }, { + "label": "Belt.List.setAssocU", + "kind": 12, + "tags": [], + "detail": "(t<('a, 'c)>, 'a, 'c, (. 'a, 'a) => bool) => t<('a, 'c)>", + "documentation": {"kind": "markdown", "value": " Uncurried version of [setAssoc](#setAssoc). "} + }, { + "label": "Belt.List.some2U", + "kind": 12, + "tags": [], + "detail": "(t<'a>, t<'b>, (. 'a, 'b) => bool) => bool", + "documentation": {"kind": "markdown", "value": " Uncurried version of [some2](#some2). "} + }, { + "label": "Belt.List.sortU", + "kind": 12, + "tags": [], + "detail": "(t<'a>, (. 'a, 'a) => int) => t<'a>", + "documentation": {"kind": "markdown", "value": " Uncurried version of [sort](#sort). "} + }, { + "label": "Belt.List.splitAt", + "kind": 12, + "tags": [], + "detail": "(t<'a>, int) => option<(list<'a>, list<'a>)>", + "documentation": {"kind": "markdown", "value": "\n Split the list `someList` at `index`. Returns `None` when the length of `someList` is less than `index`.\n\n ```res example\n list{\"Hello\", \"World\"}->Belt.List.splitAt(1) // Some((list{\"Hello\"}, list{\"World\"}))\n\n list{0, 1, 2, 3, 4}->Belt.List.splitAt(2) // Some((list{0, 1}, list{2, 3, 4}))\n ```\n"} + }, { + "label": "Belt.List.some", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => bool", + "documentation": {"kind": "markdown", "value": "\n Returns `true` if at least _one_ of the elements in `someList` satisfies\n `pred`, where `pred` is a predicate: a function taking an element and\n returning a bool.\n\n ```res example\n let isAbove100 = value => value > 100\n\n list{101, 1, 2, 3}->Belt.List.some(isAbove100) /* true */\n\n list{1, 2, 3, 4}->Belt.List.some(isAbove100) /* false */\n ```\n"} + }, { + "label": "Belt.List.setAssoc", + "kind": 12, + "tags": [], + "detail": "(t<('a, 'c)>, 'a, 'c, ('a, 'a) => bool) => t<('a, 'c)>", + "documentation": {"kind": "markdown", "value": "\n If `k` exists in `someList` by satisfying the `eqFunction` predicate, return a new list with the key and value replaced by the new `k` and `v`; otherwise, return a new list with the pair `k`, `v` added to the head of `someList`.\n\n ```res example\n list{(1, \"a\"), (2, \"b\"), (3, \"c\")}->Belt.List.setAssoc(2, \"x\", (a, b) => a == b) /* list{(1, \"a\"), (2, \"x\"), (3, \"c\")} */\n\n list{(1, \"a\"), (3, \"c\")}->Belt.List.setAssoc(2, \"b\", (a, b) => a == b) /* list{(2, \"b\"), (1, \"a\"), (3, \"c\")} */\n\n list{(9, \"morning\"), (3, \"morning?!\"), (22, \"night\")}\n ->Belt.List.setAssoc(15, \"afternoon\", (a, b) => mod(a, 12) == mod(b, 12))\n /* list{(9, \"morning\"), (15, \"afternoon\"), (22, \"night\")} */\n ```\n\n **Please note**\n\n In the last example, since: `15 mod 12` equals `3 mod 12`\n\n Both the key _and_ the value are replaced in the list.\n"} + }] + From 465a1be840438a877bed6ba021842fccb756b926 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Sat, 17 Dec 2022 11:08:09 +0100 Subject: [PATCH 02/11] push (broken) self contained example --- analysis/tests/src/CompletionPipeChain.res | 57 +- .../src/expected/CompletionPipeChain.res.txt | 1982 +---------------- 2 files changed, 78 insertions(+), 1961 deletions(-) diff --git a/analysis/tests/src/CompletionPipeChain.res b/analysis/tests/src/CompletionPipeChain.res index 299936596..3864fc278 100644 --- a/analysis/tests/src/CompletionPipeChain.res +++ b/analysis/tests/src/CompletionPipeChain.res @@ -1,19 +1,50 @@ -let mapArr = arr => arr->Js.Array2.map(v => v + 2) -let arr = [1, 2, 3] -// let _ = arr-> +module Integer: { + type t + let increment: (t, int) => t + let decrement: (t, int => int) => t + let make: int => t + let toInt: t => int +} = { + type t = int + let increment = (t, num) => t + num + let decrement = (t, decrementer) => decrementer(t) + let make = t => t + let toInt = t => t +} + +module SuperFloat: { + type t + let fromInteger: Integer.t => t + let toInteger: t => Integer.t +} = { + type t = float + let fromInteger = t => t->Integer.toInt->Belt.Float.fromInt + let toInteger = t => t->Belt.Float.toInt->Integer.make +} + +let toFlt = i => i->SuperFloat.fromInteger +let int = Integer.make(1) +let f = int->Integer.increment(2) +// let _ = int-> // ^com -// let _ = arr->Js.Array2.map(v => v)-> -// ^com +// let _ = int->toFlt-> +// ^com + +// let _ = int->Integer.increment(2)-> +// ^com + +// let _ = Integer.increment(int, 2)-> +// ^com -// let _ = arr->Js.Array2.filter(v => v)->Js.Array2.filter(v => v)-> -// ^com +// let _ = int->Integer.decrement(t => t - 1)-> +// -// let _ = arr->Js.Array2.filter(v => v)-> -// ^com +// let _ = int->Integer.increment(2)->Integer.decrement(t => t - 1)-> +// -// let _ = arr->Js.Array2-map(v => v)->Belt.List.fromArray-> -// ^com +// let _ = int->Integer.increment(2)->SuperFloat.fromInteger-> +// -// let _ = arr->Js.Array2-map(v => v)->Belt.List.fromArray->s -// ^com +// let _ = int->Integer.incremebt(2)->SuperFloat.fromInteger->t +// diff --git a/analysis/tests/src/expected/CompletionPipeChain.res.txt b/analysis/tests/src/expected/CompletionPipeChain.res.txt index 703851a24..35e75e1cc 100644 --- a/analysis/tests/src/expected/CompletionPipeChain.res.txt +++ b/analysis/tests/src/expected/CompletionPipeChain.res.txt @@ -1,1970 +1,56 @@ -Complete src/CompletionPipeChain.res 2:16 -posCursor:[2:16] posNoWhite:[2:15] Found expr:[2:11->0:-1] -Completable: Cpath Value[arr]-> +Complete src/CompletionPipeChain.res 27:16 +posCursor:[27:16] posNoWhite:[27:15] Found expr:[27:11->0:-1] +Completable: Cpath Value[int]-> [{ - "label": "Js.Array2.mapi", + "label": "Integer.toInt", "kind": 12, "tags": [], - "detail": "(t<'a>, ('a, int) => 'b) => t<'b>", - "documentation": {"kind": "markdown", "value": "\nApplies the function (the second argument) to each item in the array, returning\na new array. The function acceps two arguments: an item from the array and its\nindex number. The result array does not have to have elements of the same type\nas the input array. See\n[`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)\non MDN.\n\n```res example\n// multiply each item in array by its position\nlet product = (item, index) => item * index\nJs.Array2.mapi([10, 11, 12], product) == [0, 11, 24]\n```\n"} + "detail": "t => int", + "documentation": null }, { - "label": "Js.Array2.lastIndexOf", + "label": "Integer.increment", "kind": 12, "tags": [], - "detail": "(t<'a>, 'a) => int", - "documentation": {"kind": "markdown", "value": "\nReturns the index of the last element in the array that has the given value. If\nthe value is not in the array, returns -1. See\n[`Array.lastIndexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)\non MDN.\n\n```res example\nJs.Array2.lastIndexOf([\"a\", \"b\", \"a\", \"c\"], \"a\") == 2\nJs.Array2.lastIndexOf([\"a\", \"b\", \"a\", \"c\"], \"x\") == -1\n```\n"} + "detail": "(t, int) => t", + "documentation": null }, { - "label": "Js.Array2.concat", + "label": "Integer.decrement", "kind": 12, "tags": [], - "detail": "(t<'a>, t<'a>) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nConcatenates the second array argument to the first array argument, returning a\nnew array. The original arrays are not modified. See\n[`Array.concat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)\non MDN.\n\n```res example\nJs.Array2.concat([\"a\", \"b\"], [\"c\", \"d\", \"e\"]) == [\"a\", \"b\", \"c\", \"d\", \"e\"]\n```\n"} + "detail": "(t, int => int) => t", + "documentation": null }, { - "label": "Js.Array2.unshiftMany", + "label": "Integer.make", "kind": 12, "tags": [], - "detail": "(t<'a>, array<'a>) => int", - "documentation": {"kind": "markdown", "value": "\nAdds the elements in the second array argument at the beginning of the first\narray argument, returning the new number of elements in the array. *This\nfunction modifies the original array.* See\n[`Array.unshift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)\non MDN.\n\n```res example\nlet arr = [\"d\", \"e\"]\nJs.Array2.unshiftMany(arr, [\"a\", \"b\", \"c\"]) == 5\narr == [\"a\", \"b\", \"c\", \"d\", \"e\"]\n```\n"} - }, { - "label": "Js.Array2.filter", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nApplies the given predicate function (the second argument) to each element in\nthe array; the result is an array of those elements for which the predicate\nfunction returned `true`. See\n[`Array.filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)\non MDN.\n\n```res example\nlet nonEmpty = s => s != \"\"\nJs.Array2.filter([\"abc\", \"\", \"\", \"def\", \"ghi\"], nonEmpty) == [\"abc\", \"def\", \"ghi\"]\n```\n"} - }, { - "label": "Js.Array2.shift", - "kind": 12, - "tags": [], - "detail": "t<'a> => option<'a>", - "documentation": {"kind": "markdown", "value": "\nIf the array is not empty, removes the first element and returns it as\n`Some(value)`; returns `None` if the array is empty. *This function modifies\nthe original array.* See\n[`Array.shift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.shift(arr) == Some(100)\narr == [101, 102, 103, 104]\n\nlet empty: array = []\nJs.Array2.shift(empty) == None\n```\n"} - }, { - "label": "Js.Array2.reduceRight", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('b, 'a) => 'b, 'b) => 'b", - "documentation": {"kind": "markdown", "value": "\nThe `reduceRight()` function takes three parameters: an array, a *reducer\nfunction*, and a beginning accumulator value. The reducer function has two\nparameters: an accumulated value and an element of the array.\n\n`reduceRight()` first calls the reducer function with the beginning value and\nthe last element in the array. The result becomes the new accumulator value,\nwhich is passed in to the reducer function along with the next-to-last element\nin the array. `reduceRight()` proceeds from right to left through the array,\npassing in the result of each stage as the accumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reduceRight()`. See\n[`Array.reduceRight`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight)\non MDN.\n\n**NOTE:** In many cases, `reduce()` and `reduceRight()` give the same result.\nHowever, see the last example here and compare it to the example from\n`reduce()`, where order makes a difference.\n\n```res example\nlet sumOfSquares = (accumulator, item) => accumulator + item * item\n\nJs.Array2.reduceRight([10, 2, 4], sumOfSquares, 0) == 120\nJs.Array2.reduceRight([2.0, 4.0], (acc, item) => item /. acc, 1.0) == 0.5 // 2.0 / (4.0 / 1.0)\n```\n"} - }, { - "label": "Js.Array2.joinWith", - "kind": 12, - "tags": [], - "detail": "(t<'a>, string) => string", - "documentation": {"kind": "markdown", "value": "\nThis function converts each element of the array to a string (via JavaScript)\nand concatenates them, separated by the string given in the first argument,\ninto a single string. See\n[`Array.join`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)\non MDN.\n\n```res example\nJs.Array2.joinWith([\"ant\", \"bee\", \"cat\"], \"--\") == \"ant--bee--cat\"\nJs.Array2.joinWith([\"door\", \"bell\"], \"\") == \"doorbell\"\nJs.Array2.joinWith([2020, 9, 4], \"/\") == \"2020/9/4\"\nJs.Array2.joinWith([2.5, 3.6, 3e-2], \";\") == \"2.5;3.6;0.03\"\n```\n"} - }, { - "label": "Js.Array2.concatMany", - "kind": 12, - "tags": [], - "detail": "(t<'a>, array>) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nThe second argument to `concatMany()` is an array of arrays; these are added at\nthe end of the first argument, returning a new array. See\n[`Array.concat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)\non MDN.\n\n```res example\nJs.Array2.concatMany([\"a\", \"b\", \"c\"], [[\"d\", \"e\"], [\"f\", \"g\", \"h\"]]) == [\n \"a\",\n \"b\",\n \"c\",\n \"d\",\n \"e\",\n \"f\",\n \"g\",\n \"h\",\n ]\n```\n"} - }, { - "label": "Js.Array2.fillInPlace", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nSets all elements of the given array (the first arumgent) to the designated\nvalue (the secon argument), returning the resulting array. *This function\n modifies the original array.*\n\nSee\n[`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.fillInPlace(arr, 99) == [99, 99, 99, 99, 99]\narr == [99, 99, 99, 99, 99]\n```\n"} - }, { - "label": "Js.Array2.isArray", - "kind": 12, - "tags": [], - "detail": "'a => bool", - "documentation": {"kind": "markdown", "value": "\nReturns `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.\n\n```res example\nJs.Array2.isArray([5, 2, 3, 1, 4]) == true\nJs.Array2.isArray(list{5, 2, 3, 1, 4}) == true\nJs.Array2.isArray(\"abcd\") == false\n```\n"} - }, { - "label": "Js.Array2.reduce", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('b, 'a) => 'b, 'b) => 'b", - "documentation": {"kind": "markdown", "value": "\nThe `reduce()` function takes three parameters: an array, a *reducer function*,\nand a beginning accumulator value. The reducer function has two parameters: an\naccumulated value and an element of the array.\n\n`reduce()` first calls the reducer function with the beginning value and the\nfirst element in the array. The result becomes the new accumulator value, which\nis passed in to the reducer function along with the second element in the\narray. `reduce()` proceeds through the array, passing in the result of each\nstage as the accumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reduce()`. See\n[`Array.reduce`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce)\non MDN.\n\n```res example\nlet sumOfSquares = (accumulator, item) => accumulator + item * item\n\nJs.Array2.reduce([10, 2, 4], sumOfSquares, 0) == 120\nJs.Array2.reduce([10, 2, 4], \\\"*\", 1) == 80\nJs.Array2.reduce(\n [\"animal\", \"vegetable\", \"mineral\"],\n (acc, item) => acc + Js.String.length(item),\n 0,\n) == 22 // 6 + 9 + 7\nJs.Array2.reduce([2.0, 4.0], (acc, item) => item /. acc, 1.0) == 2.0 // 4.0 / (2.0 / 1.0)\n```\n"} - }, { - "label": "Js.Array2.copy", - "kind": 12, - "tags": [], - "detail": "t<'a> => t<'a>", - "documentation": {"kind": "markdown", "value": "\nReturns a copy of the entire array. Same as `Js.Array2.Slice(arr, ~start=0,\n~end_=Js.Array2.length(arr))`. See\n[`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\non MDN.\n"} - }, { - "label": "Js.Array2.reducei", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('b, 'a, int) => 'b, 'b) => 'b", - "documentation": {"kind": "markdown", "value": "\nThe `reducei()` function takes three parameters: an array, a *reducer\nfunction*, and a beginning accumulator value. The reducer function has three\nparameters: an accumulated value, an element of the array, and the index of\nthat element.\n\n`reducei()` first calls the reducer function with the beginning value, the\nfirst element in the array, and zero (its index). The result becomes the new\naccumulator value, which is passed to the reducer function along with the\nsecond element in the array and one (its index). `reducei()` proceeds from left\nto right through the array, passing in the result of each stage as the\naccumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reducei()`. See\n[`Array.reduce`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce)\non MDN.\n\n```res example\n// find sum of even-index elements in array\nlet sumOfEvens = (accumulator, item, index) =>\n if mod(index, 2) == 0 {\n accumulator + item\n } else {\n accumulator\n }\n\nJs.Array2.reducei([2, 5, 1, 4, 3], sumOfEvens, 0) == 6\n```\n"} - }, { - "label": "Js.Array2.forEachi", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => unit) => unit", - "documentation": {"kind": "markdown", "value": "\nThe `forEachi()` function applies the function given as the second argument to\neach element in the array. The function you provide takes an item in the array\nand its index number, and returns `unit`. The `forEachi()` function also\nreturns `unit`. You use `forEachi()` when you need to process each element in\nthe array but not return any new array or value; for example, to print the\nitems in an array. See\n[`Array.forEach`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)\non MDN.\n\n```res example\n// display all elements in an array as a numbered list\nJs.Array2.forEachi([\"a\", \"b\", \"c\"], (item, index) => Js.log2(index + 1, item)) == ()\n```\n"} - }, { - "label": "Js.Array2.fillFromInPlace", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a, ~from: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nSets all elements of the given array (the first arumgent) from position `~from`\nto the end to the designated value (the second argument), returning the\nresulting array. *This function modifies the original array.* See\n[`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.fillFromInPlace(arr, 99, ~from=2) == [100, 101, 99, 99, 99]\narr == [100, 101, 99, 99, 99]\n```\n"} - }, { - "label": "Js.Array2.findi", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => bool) => option<'a>", - "documentation": {"kind": "markdown", "value": "\nReturns `Some(value)` for the first element in the array that satisifies the\ngiven predicate function, or `None` if no element satisifies the predicate. The\npredicate function takes an array element and an index as its parameters. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\n// find first positive item at an odd index\nlet positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0\n\nJs.Array2.findi([66, -33, 55, 88, 22], positiveOddElement) == Some(88)\nJs.Array2.findi([66, -33, 55, -88, 22], positiveOddElement) == None\n```\n"} - }, { - "label": "Js.Array2.filteri", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => bool) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nEach element of the given array are passed to the predicate function. The\nreturn value is an array of all those elements for which the predicate function\nreturned `true`.\n\nSee\n[`Array.filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)\non MDN.\n\n```res example\n// keep only positive elements at odd indices\nlet positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0\n\nJs.Array2.filteri([6, 3, 5, 8, 7, -4, 1], positiveOddElement) == [3, 8]\n```\n"} - }, { - "label": "Js.Array2.slice", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~start: int, ~end_: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nReturns a shallow copy of the given array from the `~start` index up to but not\nincluding the `~end_` position. Negative numbers indicate an offset from the\nend of the array. See\n[`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104, 105, 106]\nJs.Array2.slice(arr, ~start=2, ~end_=5) == [102, 103, 104]\nJs.Array2.slice(arr, ~start=-3, ~end_=-1) == [104, 105]\nJs.Array2.slice(arr, ~start=9, ~end_=10) == []\n```\n"} - }, { - "label": "Js.Array2.fromMap", - "kind": 12, - "tags": [], - "detail": "(array_like<'a>, 'a => 'b) => array<'b>", - "documentation": {"kind": "markdown", "value": "\nCreates a new array by applying a function (the second argument) to each item\nin the `array_like` first argument. See\n[`Array.from`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)\non MDN.\n\n```res example\nlet strArr = Js.String.castToArrayLike(\"abcd\")\nlet code = s => Js.String.charCodeAt(0, s)\nJs.Array2.fromMap(strArr, code) == [97.0, 98.0, 99.0, 100.0]\n```\n"} - }, { - "label": "Js.Array2.removeFromInPlace", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~pos: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nRemoves elements from the given array starting at position `~pos` to the end of\nthe array, returning the removed elements. *This function modifies the original\narray.* See\n[`Array.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)\non MDN.\n\n```res example\nlet arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.removeFromInPlace(arr, ~pos=4) == [\"e\", \"f\"]\narr == [\"a\", \"b\", \"c\", \"d\"]\n```\n"} - }, { - "label": "Js.Array2.from", - "kind": 12, - "tags": [], - "detail": "array_like<'a> => array<'a>", - "documentation": {"kind": "markdown", "value": "\nCreates a shallow copy of an array from an array-like object. See\n[`Array.from`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)\non MDN.\n\n```res example\nlet strArr = Js.String.castToArrayLike(\"abcd\")\nJs.Array2.from(strArr) == [\"a\", \"b\", \"c\", \"d\"]\n```\n"} - }, { - "label": "Js.Array2.includes", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a) => bool", - "documentation": {"kind": "markdown", "value": "\nReturns true if the given value is in the array, `false` otherwise. See\n[`Array.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)\non MDN.\n\n```res example\nJs.Array2.includes([\"a\", \"b\", \"c\"], \"b\") == true\nJs.Array2.includes([\"a\", \"b\", \"c\"], \"x\") == false\n```\n"} - }, { - "label": "Js.Array2.find", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => option<'a>", - "documentation": {"kind": "markdown", "value": "\nReturns `Some(value)` for the first element in the array that satisifies the\ngiven predicate function, or `None` if no element satisifies the predicate. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\n// find first negative element\nJs.Array2.find([33, 22, -55, 77, -44], x => x < 0) == Some(-55)\nJs.Array2.find([33, 22, 55, 77, 44], x => x < 0) == None\n```\n"} - }, { - "label": "Js.Array2.reduceRighti", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('b, 'a, int) => 'b, 'b) => 'b", - "documentation": {"kind": "markdown", "value": "\nThe `reduceRighti()` function takes three parameters: an array, a *reducer\nfunction*, and a beginning accumulator value. The reducer function has three\nparameters: an accumulated value, an element of the array, and the index of\nthat element. `reduceRighti()` first calls the reducer function with the\nbeginning value, the last element in the array, and its index (length of array\nminus one). The result becomes the new accumulator value, which is passed in to\nthe reducer function along with the second element in the array and one (its\nindex). `reduceRighti()` proceeds from right to left through the array, passing\nin the result of each stage as the accumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reduceRighti()`. See\n[`Array.reduceRight`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight)\non MDN.\n\n**NOTE:** In many cases, `reducei()` and `reduceRighti()` give the same result.\nHowever, there are cases where the order in which items are processed makes a\ndifference.\n\n```res example\n// find sum of even-index elements in array\nlet sumOfEvens = (accumulator, item, index) =>\n if mod(index, 2) == 0 {\n accumulator + item\n } else {\n accumulator\n }\n\nJs.Array2.reduceRighti([2, 5, 1, 4, 3], sumOfEvens, 0) == 6\n```\n"} - }, { - "label": "Js.Array2.findIndexi", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => bool) => int", - "documentation": {"kind": "markdown", "value": "\nReturns `Some(value)` for the first element in the array that satisifies the\ngiven predicate function, or `None` if no element satisifies the predicate. The\npredicate function takes an array element and an index as its parameters. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\n// find index of first positive item at an odd index\nlet positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0\n\nJs.Array2.findIndexi([66, -33, 55, 88, 22], positiveOddElement) == 3\nJs.Array2.findIndexi([66, -33, 55, -88, 22], positiveOddElement) == -1\n```\n"} - }, { - "label": "Js.Array2.toLocaleString", - "kind": 12, - "tags": [], - "detail": "t<'a> => string", - "documentation": {"kind": "markdown", "value": "\nConverts the array to a string using the conventions of the current locale.\nEach element is converted to a string using JavaScript. Unlike the JavaScript\n`Array.toLocaleString()`, all elements in a ReasonML array must have the same\ntype. See\n[`Array.toLocaleString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString)\non MDN.\n\n```res example\nJs.Array2.toLocaleString([Js.Date.make()])\n// returns \"3/19/2020, 10:52:11 AM\" for locale en_US.utf8\n// returns \"2020-3-19 10:52:11\" for locale de_DE.utf8\n```\n"} - }, { - "label": "Js.Array2.lastIndexOfFrom", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a, ~from: int) => int", - "documentation": {"kind": "markdown", "value": "\nReturns the index of the last element in the array that has the given value,\nsearching from position `~from` down to the start of the array. If the value is\nnot in the array, returns -1. See\n[`Array.lastIndexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)\non MDN.\n\n```res example\nJs.Array2.lastIndexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\", \"d\"], \"a\", ~from=3) == 2\nJs.Array2.lastIndexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\", \"d\"], \"c\", ~from=2) == -1\n```\n"} - }, { - "label": "Js.Array2.copyWithinFromRange", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~to_: int, ~start: int, ~end_: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nCopies starting at element `~start` in the given array up to but not including\n`~end_` to the designated `~to_` position, returning the resulting array. *This\nfunction modifies the original array.* See\n[`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104, 105]\nJs.Array2.copyWithinFromRange(arr, ~start=2, ~end_=5, ~to_=1) == [100, 102, 103, 104, 104, 105]\narr == [100, 102, 103, 104, 104, 105]\n```\n"} - }, { - "label": "Js.Array2.findIndex", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => int", - "documentation": {"kind": "markdown", "value": "\nReturns the index of the first element in the array that satisifies the given\npredicate function, or -1 if no element satisifies the predicate. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\nJs.Array2.findIndex([33, 22, -55, 77, -44], x => x < 0) == 2\nJs.Array2.findIndex([33, 22, 55, 77, 44], x => x < 0) == -1\n```\n"} - }, { - "label": "Js.Array2.removeCountInPlace", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~pos: int, ~count: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nRemoves `~count` elements from the given array starting at position `~pos`,\nreturning the removed elements. *This function modifies the original array.*\nSee\n[`Array.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)\non MDN.\n\n```res example\nlet arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.removeCountInPlace(arr, ~pos=2, ~count=3) == [\"c\", \"d\", \"e\"]\narr == [\"a\", \"b\", \"f\"]\n```\n"} - }, { - "label": "Js.Array2.reverseInPlace", - "kind": 12, - "tags": [], - "detail": "t<'a> => t<'a>", - "documentation": {"kind": "markdown", "value": "\nReturns an array with the elements of the input array in reverse order. *This\nfunction modifies the original array.* See\n[`Array.reverse`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse)\non MDN.\n\n```res example\nlet arr = [\"ant\", \"bee\", \"cat\"]\nJs.Array2.reverseInPlace(arr) == [\"cat\", \"bee\", \"ant\"]\narr == [\"cat\", \"bee\", \"ant\"]\n```\n"} - }, { - "label": "Js.Array2.every", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => bool", - "documentation": {"kind": "markdown", "value": "\nThe first argument to `every()` is an array. The second argument is a predicate\nfunction that returns a boolean. The `every()` function returns `true` if the\npredicate function is true for all items in the given array. If given an empty\narray, returns `true`. See\n[`Array.every`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)\non MDN.\n\n```res example\nlet isEven = x => mod(x, 2) == 0\nJs.Array2.every([6, 22, 8, 4], isEven) == true\nJs.Array2.every([6, 22, 7, 4], isEven) == false\n```\n"} - }, { - "label": "Js.Array2.length", - "kind": 12, - "tags": [], - "detail": "array<'a> => int", - "documentation": {"kind": "markdown", "value": "\nReturns the number of elements in the array. See\n[`Array.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)\non MDN.\n"} - }, { - "label": "Js.Array2.indexOf", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a) => int", - "documentation": {"kind": "markdown", "value": "\nReturns the index of the first element in the array that has the given value.\nIf the value is not in the array, returns -1. See\n[`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)\non MDN.\n\n```res example\nJs.Array2.indexOf([100, 101, 102, 103], 102) == 2\nJs.Array2.indexOf([100, 101, 102, 103], 999) == -1\n```\n"} - }, { - "label": "Js.Array2.unshift", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a) => int", - "documentation": {"kind": "markdown", "value": "\nAdds the given element to the array, returning the new number of elements in\nthe array. *This function modifies the original array.* See\n[`Array.unshift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)\non MDN.\n\n```res example\nlet arr = [\"b\", \"c\", \"d\"]\nJs.Array2.unshift(arr, \"a\") == 4\narr == [\"a\", \"b\", \"c\", \"d\"]\n```\n"} - }, { - "label": "Js.Array2.sortInPlace", - "kind": 12, - "tags": [], - "detail": "t<'a> => t<'a>", - "documentation": {"kind": "markdown", "value": "\nSorts the given array in place and returns the sorted array. JavaScript sorts\nthe array by converting the arguments to UTF-16 strings and sorting them. See\nthe second example with sorting numbers, which does not do a numeric sort.\n*This function modifies the original array.* See\n[`Array.sort`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)\non MDN.\n\n```res example\nlet words = [\"bee\", \"dog\", \"ant\", \"cat\"]\nJs.Array2.sortInPlace(words) == [\"ant\", \"bee\", \"cat\", \"dog\"]\nwords == [\"ant\", \"bee\", \"cat\", \"dog\"]\n\nlet numbers = [3, 30, 10, 1, 20, 2]\nJs.Array2.sortInPlace(numbers) == [1, 10, 2, 20, 3, 30]\nnumbers == [1, 10, 2, 20, 3, 30]\n```\n"} - }, { - "label": "Js.Array2.unsafe_get", - "kind": 12, - "tags": [], - "detail": "(array<'a>, int) => 'a", - "documentation": {"kind": "markdown", "value": "\nReturns the value at the given position in the array if the position is in\nbounds; returns the JavaScript value `undefined` otherwise.\n\n```res example\nlet arr = [100, 101, 102, 103]\nJs.Array2.unsafe_get(arr, 3) == 103\nJs.Array2.unsafe_get(arr, 4) // returns undefined\n```\n"} - }, { - "label": "Js.Array2.some", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => bool", - "documentation": {"kind": "markdown", "value": "\nReturns `true` if the predicate function given as the second argument to\n`some()` returns `true` for any element in the array; `false` otherwise.\n\n```res example\nlet isEven = x => mod(x, 2) == 0\n\nJs.Array2.some([3, 7, 5, 2, 9], isEven) == true\nJs.Array2.some([3, 7, 5, 1, 9], isEven) == false\n```\n"} - }, { - "label": "Js.Array2.map", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => 'b) => t<'b>", - "documentation": {"kind": "markdown", "value": "\nApplies the function (the second argument) to each item in the array, returning\na new array. The result array does not have to have elements of the same type\nas the input array. See\n[`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)\non MDN.\n\n```res example\nJs.Array2.map([12, 4, 8], x => x * x) == [144, 16, 64]\nJs.Array2.map([\"animal\", \"vegetable\", \"mineral\"], Js.String.length) == [6, 9, 7]\n```\n"} - }, { - "label": "Js.Array2.push", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a) => int", - "documentation": {"kind": "markdown", "value": "\nAppends the given value to the array, returning the number of elements in the\nupdated array. *This function modifies the original array.* See\n[`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)\non MDN.\n\n```res example\nlet arr = [\"ant\", \"bee\", \"cat\"]\nJs.Array2.push(arr, \"dog\") == 4\narr == [\"ant\", \"bee\", \"cat\", \"dog\"]\n```\n"} - }, { - "label": "Js.Array2.fillRangeInPlace", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a, ~start: int, ~end_: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nSets the elements of the given array (the first arumgent) from position\n`~start` up to but not including position `~end_` to the designated value (the\nsecond argument), returning the resulting array. *This function modifies the\noriginal array.* See\n[`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.fillRangeInPlace(arr, 99, ~start=1, ~end_=4) == [100, 99, 99, 99, 104]\narr == [100, 99, 99, 99, 104]\n```\n"} - }, { - "label": "Js.Array2.pop", - "kind": 12, - "tags": [], - "detail": "t<'a> => option<'a>", - "documentation": {"kind": "markdown", "value": "\nIf the array is not empty, removes the last element and returns it as\n`Some(value)`; returns `None` if the array is empty. *This function modifies\nthe original array.* See\n[`Array.pop`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.pop(arr) == Some(104)\narr == [100, 101, 102, 103]\n\nlet empty: array = []\nJs.Array2.pop(empty) == None\n```\n"} - }, { - "label": "Js.Array2.somei", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => bool) => bool", - "documentation": {"kind": "markdown", "value": "\nReturns `true` if the predicate function given as the second argument to\n`somei()` returns `true` for any element in the array; `false` otherwise. The\npredicate function has two arguments: an item from the array and the index\nvalue\n\n```res example\n// Does any string in the array\n// have the same length as its index?\n\nlet sameLength = (str, index) => Js.String.length(str) == index\n\n// \"ef\" has length 2 and is it at index 2\nJs.Array2.somei([\"ab\", \"cd\", \"ef\", \"gh\"], sameLength) == true\n// no item has the same length as its index\nJs.Array2.somei([\"a\", \"bc\", \"def\", \"gh\"], sameLength) == false\n```\n"} - }, { - "label": "Js.Array2.append", - "kind": 12, - "tags": [1], - "detail": "(t<'a>, 'a) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: `append` is not type-safe. Use `concat` instead.\n\n"} - }, { - "label": "Js.Array2.unsafe_set", - "kind": 12, - "tags": [], - "detail": "(array<'a>, int, 'a) => unit", - "documentation": {"kind": "markdown", "value": "\nSets the value at the given position in the array if the position is in bounds.\nIf the index is out of bounds, well, “here there be dragons.“\n\n*This function modifies the original array.*\n\n```res example\nlet arr = [100, 101, 102, 103]\nJs.Array2.unsafe_set(arr, 3, 99)\n// result is [100, 101, 102, 99];\n\nJs.Array2.unsafe_set(arr, 4, 88)\n// result is [100, 101, 102, 99, 88]\n\nJs.Array2.unsafe_set(arr, 6, 77)\n// result is [100, 101, 102, 99, 88, <1 empty item>, 77]\n\nJs.Array2.unsafe_set(arr, -1, 66)\n// you don't want to know.\n```\n"} - }, { - "label": "Js.Array2.copyWithin", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~to_: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nCopies from the first element in the given array to the designated `~to_`\nposition, returning the resulting array. *This function modifies the original\narray.* See\n[`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.copyWithin(arr, ~to_=2) == [100, 101, 100, 101, 102]\narr == [100, 101, 100, 101, 102]\n```\n"} - }, { - "label": "Js.Array2.everyi", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => bool) => bool", - "documentation": {"kind": "markdown", "value": "\nThe first argument to `everyi()` is an array. The second argument is a\npredicate function with two arguments: an array element and that element’s\nindex; it returns a boolean. The `everyi()` function returns `true` if the\npredicate function is true for all items in the given array. If given an empty\narray, returns `true`. See\n[`Array.every`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)\non MDN.\n\n```res example\n// determine if all even-index items are positive\nlet evenIndexPositive = (item, index) => mod(index, 2) == 0 ? item > 0 : true\n\nJs.Array2.everyi([6, -3, 5, 8], evenIndexPositive) == true\nJs.Array2.everyi([6, 3, -5, 8], evenIndexPositive) == false\n```\n"} - }, { - "label": "Js.Array2.toString", - "kind": 12, - "tags": [], - "detail": "t<'a> => string", - "documentation": {"kind": "markdown", "value": "\nConverts the array to a string. Each element is converted to a string using\nJavaScript. Unlike the JavaScript `Array.toString()`, all elements in a\nReasonML array must have the same type. See\n[`Array.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString)\non MDN.\n\n```res example\nJs.Array2.toString([3.5, 4.6, 7.8]) == \"3.5,4.6,7.8\"\nJs.Array2.toString([\"a\", \"b\", \"c\"]) == \"a,b,c\"\n```\n"} - }, { - "label": "Js.Array2.spliceInPlace", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~pos: int, ~remove: int, ~add: array<'a>) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nStarting at position `~pos`, remove `~remove` elements and then add the\nelements from the `~add` array. Returns an array consisting of the removed\nitems. *This function modifies the original array.* See\n[`Array.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)\non MDN.\n\n```res example\nlet arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.spliceInPlace(arr, ~pos=2, ~remove=2, ~add=[\"x\", \"y\", \"z\"]) == [\"c\", \"d\"]\narr == [\"a\", \"b\", \"x\", \"y\", \"z\", \"e\", \"f\"]\n\nlet arr2 = [\"a\", \"b\", \"c\", \"d\"]\nJs.Array2.spliceInPlace(arr2, ~pos=3, ~remove=0, ~add=[\"x\", \"y\"]) == []\narr2 == [\"a\", \"b\", \"c\", \"x\", \"y\", \"d\"]\n\nlet arr3 = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.spliceInPlace(arr3, ~pos=9, ~remove=2, ~add=[\"x\", \"y\", \"z\"]) == []\narr3 == [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"x\", \"y\", \"z\"]\n```\n"} - }, { - "label": "Js.Array2.pushMany", - "kind": 12, - "tags": [], - "detail": "(t<'a>, array<'a>) => int", - "documentation": {"kind": "markdown", "value": "\nAppends the values from one array (the second argument) to another (the first\nargument), returning the number of elements in the updated array. *This\nfunction modifies the original array.* See\n[`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)\non MDN.\n\n```res example\nlet arr = [\"ant\", \"bee\", \"cat\"]\nJs.Array2.pushMany(arr, [\"dog\", \"elk\"]) == 5\narr == [\"ant\", \"bee\", \"cat\", \"dog\", \"elk\"]\n```\n"} - }, { - "label": "Js.Array2.copyWithinFrom", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~to_: int, ~from: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nCopies starting at element `~from` in the given array to the designated `~to_`\nposition, returning the resulting array. *This function modifies the original\narray.* See\n[`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.copyWithinFrom(arr, ~from=2, ~to_=0) == [102, 103, 104, 103, 104]\narr == [102, 103, 104, 103, 104]\n```\n"} - }, { - "label": "Js.Array2.forEach", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => unit) => unit", - "documentation": {"kind": "markdown", "value": "\nThe `forEach()` function applies the function given as the second argument to\neach element in the array. The function you provide returns `unit`, and the\n`forEach()` function also returns `unit`. You use `forEach()` when you need to\nprocess each element in the array but not return any new array or value; for\nexample, to print the items in an array. See\n[`Array.forEach`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)\non MDN.\n\n```res example\n// display all elements in an array\nJs.Array2.forEach([\"a\", \"b\", \"c\"], x => Js.log(x)) == ()\n```\n"} - }, { - "label": "Js.Array2.sliceFrom", - "kind": 12, - "tags": [], - "detail": "(t<'a>, int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nReturns a shallow copy of the given array from the given index to the end. See\n[`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\non MDN.\n"} - }, { - "label": "Js.Array2.sortInPlaceWith", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, 'a) => int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nSorts the given array in place and returns the sorted array. *This function\n modifies the original array.*\n\nThe first argument to `sortInPlaceWith()` is a function that compares two items\nfrom the array and returns:\n\n* an integer less than zero if the first item is less than the second item *\nzero if the items are equal * an integer greater than zero if the first item is\ngreater than the second item\n\nSee\n[`Array.sort`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)\non MDN.\n\n```res example\n// sort by word length\nlet words = [\"horse\", \"aardvark\", \"dog\", \"camel\"]\nlet byLength = (s1, s2) => Js.String.length(s1) - Js.String.length(s2)\n\nJs.Array2.sortInPlaceWith(words, byLength) == [\"dog\", \"horse\", \"camel\", \"aardvark\"]\n\n// sort in reverse numeric order\nlet numbers = [3, 30, 10, 1, 20, 2]\nlet reverseNumeric = (n1, n2) => n2 - n1\nJs.Array2.sortInPlaceWith(numbers, reverseNumeric) == [30, 20, 10, 3, 2, 1]\n```\n"} - }, { - "label": "Js.Array2.indexOfFrom", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a, ~from: int) => int", - "documentation": {"kind": "markdown", "value": "\nReturns the index of the first element in the array with the given value. The\nsearch starts at position `~from`. See\n[`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)\non MDN.\n\n```res example\nJs.Array2.indexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\"], \"a\", ~from=2) == 2\nJs.Array2.indexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\"], \"a\", ~from=3) == 4\nJs.Array2.indexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\"], \"b\", ~from=2) == -1\n```\n"} - }] - -Complete src/CompletionPipeChain.res 5:39 -posCursor:[5:39] posNoWhite:[5:38] Found expr:[5:11->0:-1] -Completable: Cpath Value[Js, Array2, map](Nolabel, Nolabel)-> -[{ - "label": "Js.Array2.mapi", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => 'b) => t<'b>", - "documentation": {"kind": "markdown", "value": "\nApplies the function (the second argument) to each item in the array, returning\na new array. The function acceps two arguments: an item from the array and its\nindex number. The result array does not have to have elements of the same type\nas the input array. See\n[`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)\non MDN.\n\n```res example\n// multiply each item in array by its position\nlet product = (item, index) => item * index\nJs.Array2.mapi([10, 11, 12], product) == [0, 11, 24]\n```\n"} - }, { - "label": "Js.Array2.lastIndexOf", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a) => int", - "documentation": {"kind": "markdown", "value": "\nReturns the index of the last element in the array that has the given value. If\nthe value is not in the array, returns -1. See\n[`Array.lastIndexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)\non MDN.\n\n```res example\nJs.Array2.lastIndexOf([\"a\", \"b\", \"a\", \"c\"], \"a\") == 2\nJs.Array2.lastIndexOf([\"a\", \"b\", \"a\", \"c\"], \"x\") == -1\n```\n"} - }, { - "label": "Js.Array2.concat", - "kind": 12, - "tags": [], - "detail": "(t<'a>, t<'a>) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nConcatenates the second array argument to the first array argument, returning a\nnew array. The original arrays are not modified. See\n[`Array.concat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)\non MDN.\n\n```res example\nJs.Array2.concat([\"a\", \"b\"], [\"c\", \"d\", \"e\"]) == [\"a\", \"b\", \"c\", \"d\", \"e\"]\n```\n"} - }, { - "label": "Js.Array2.unshiftMany", - "kind": 12, - "tags": [], - "detail": "(t<'a>, array<'a>) => int", - "documentation": {"kind": "markdown", "value": "\nAdds the elements in the second array argument at the beginning of the first\narray argument, returning the new number of elements in the array. *This\nfunction modifies the original array.* See\n[`Array.unshift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)\non MDN.\n\n```res example\nlet arr = [\"d\", \"e\"]\nJs.Array2.unshiftMany(arr, [\"a\", \"b\", \"c\"]) == 5\narr == [\"a\", \"b\", \"c\", \"d\", \"e\"]\n```\n"} - }, { - "label": "Js.Array2.filter", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nApplies the given predicate function (the second argument) to each element in\nthe array; the result is an array of those elements for which the predicate\nfunction returned `true`. See\n[`Array.filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)\non MDN.\n\n```res example\nlet nonEmpty = s => s != \"\"\nJs.Array2.filter([\"abc\", \"\", \"\", \"def\", \"ghi\"], nonEmpty) == [\"abc\", \"def\", \"ghi\"]\n```\n"} - }, { - "label": "Js.Array2.shift", - "kind": 12, - "tags": [], - "detail": "t<'a> => option<'a>", - "documentation": {"kind": "markdown", "value": "\nIf the array is not empty, removes the first element and returns it as\n`Some(value)`; returns `None` if the array is empty. *This function modifies\nthe original array.* See\n[`Array.shift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.shift(arr) == Some(100)\narr == [101, 102, 103, 104]\n\nlet empty: array = []\nJs.Array2.shift(empty) == None\n```\n"} - }, { - "label": "Js.Array2.reduceRight", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('b, 'a) => 'b, 'b) => 'b", - "documentation": {"kind": "markdown", "value": "\nThe `reduceRight()` function takes three parameters: an array, a *reducer\nfunction*, and a beginning accumulator value. The reducer function has two\nparameters: an accumulated value and an element of the array.\n\n`reduceRight()` first calls the reducer function with the beginning value and\nthe last element in the array. The result becomes the new accumulator value,\nwhich is passed in to the reducer function along with the next-to-last element\nin the array. `reduceRight()` proceeds from right to left through the array,\npassing in the result of each stage as the accumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reduceRight()`. See\n[`Array.reduceRight`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight)\non MDN.\n\n**NOTE:** In many cases, `reduce()` and `reduceRight()` give the same result.\nHowever, see the last example here and compare it to the example from\n`reduce()`, where order makes a difference.\n\n```res example\nlet sumOfSquares = (accumulator, item) => accumulator + item * item\n\nJs.Array2.reduceRight([10, 2, 4], sumOfSquares, 0) == 120\nJs.Array2.reduceRight([2.0, 4.0], (acc, item) => item /. acc, 1.0) == 0.5 // 2.0 / (4.0 / 1.0)\n```\n"} - }, { - "label": "Js.Array2.joinWith", - "kind": 12, - "tags": [], - "detail": "(t<'a>, string) => string", - "documentation": {"kind": "markdown", "value": "\nThis function converts each element of the array to a string (via JavaScript)\nand concatenates them, separated by the string given in the first argument,\ninto a single string. See\n[`Array.join`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)\non MDN.\n\n```res example\nJs.Array2.joinWith([\"ant\", \"bee\", \"cat\"], \"--\") == \"ant--bee--cat\"\nJs.Array2.joinWith([\"door\", \"bell\"], \"\") == \"doorbell\"\nJs.Array2.joinWith([2020, 9, 4], \"/\") == \"2020/9/4\"\nJs.Array2.joinWith([2.5, 3.6, 3e-2], \";\") == \"2.5;3.6;0.03\"\n```\n"} - }, { - "label": "Js.Array2.concatMany", - "kind": 12, - "tags": [], - "detail": "(t<'a>, array>) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nThe second argument to `concatMany()` is an array of arrays; these are added at\nthe end of the first argument, returning a new array. See\n[`Array.concat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)\non MDN.\n\n```res example\nJs.Array2.concatMany([\"a\", \"b\", \"c\"], [[\"d\", \"e\"], [\"f\", \"g\", \"h\"]]) == [\n \"a\",\n \"b\",\n \"c\",\n \"d\",\n \"e\",\n \"f\",\n \"g\",\n \"h\",\n ]\n```\n"} - }, { - "label": "Js.Array2.fillInPlace", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nSets all elements of the given array (the first arumgent) to the designated\nvalue (the secon argument), returning the resulting array. *This function\n modifies the original array.*\n\nSee\n[`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.fillInPlace(arr, 99) == [99, 99, 99, 99, 99]\narr == [99, 99, 99, 99, 99]\n```\n"} - }, { - "label": "Js.Array2.isArray", - "kind": 12, - "tags": [], - "detail": "'a => bool", - "documentation": {"kind": "markdown", "value": "\nReturns `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.\n\n```res example\nJs.Array2.isArray([5, 2, 3, 1, 4]) == true\nJs.Array2.isArray(list{5, 2, 3, 1, 4}) == true\nJs.Array2.isArray(\"abcd\") == false\n```\n"} - }, { - "label": "Js.Array2.reduce", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('b, 'a) => 'b, 'b) => 'b", - "documentation": {"kind": "markdown", "value": "\nThe `reduce()` function takes three parameters: an array, a *reducer function*,\nand a beginning accumulator value. The reducer function has two parameters: an\naccumulated value and an element of the array.\n\n`reduce()` first calls the reducer function with the beginning value and the\nfirst element in the array. The result becomes the new accumulator value, which\nis passed in to the reducer function along with the second element in the\narray. `reduce()` proceeds through the array, passing in the result of each\nstage as the accumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reduce()`. See\n[`Array.reduce`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce)\non MDN.\n\n```res example\nlet sumOfSquares = (accumulator, item) => accumulator + item * item\n\nJs.Array2.reduce([10, 2, 4], sumOfSquares, 0) == 120\nJs.Array2.reduce([10, 2, 4], \\\"*\", 1) == 80\nJs.Array2.reduce(\n [\"animal\", \"vegetable\", \"mineral\"],\n (acc, item) => acc + Js.String.length(item),\n 0,\n) == 22 // 6 + 9 + 7\nJs.Array2.reduce([2.0, 4.0], (acc, item) => item /. acc, 1.0) == 2.0 // 4.0 / (2.0 / 1.0)\n```\n"} - }, { - "label": "Js.Array2.copy", - "kind": 12, - "tags": [], - "detail": "t<'a> => t<'a>", - "documentation": {"kind": "markdown", "value": "\nReturns a copy of the entire array. Same as `Js.Array2.Slice(arr, ~start=0,\n~end_=Js.Array2.length(arr))`. See\n[`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\non MDN.\n"} - }, { - "label": "Js.Array2.reducei", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('b, 'a, int) => 'b, 'b) => 'b", - "documentation": {"kind": "markdown", "value": "\nThe `reducei()` function takes three parameters: an array, a *reducer\nfunction*, and a beginning accumulator value. The reducer function has three\nparameters: an accumulated value, an element of the array, and the index of\nthat element.\n\n`reducei()` first calls the reducer function with the beginning value, the\nfirst element in the array, and zero (its index). The result becomes the new\naccumulator value, which is passed to the reducer function along with the\nsecond element in the array and one (its index). `reducei()` proceeds from left\nto right through the array, passing in the result of each stage as the\naccumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reducei()`. See\n[`Array.reduce`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce)\non MDN.\n\n```res example\n// find sum of even-index elements in array\nlet sumOfEvens = (accumulator, item, index) =>\n if mod(index, 2) == 0 {\n accumulator + item\n } else {\n accumulator\n }\n\nJs.Array2.reducei([2, 5, 1, 4, 3], sumOfEvens, 0) == 6\n```\n"} - }, { - "label": "Js.Array2.forEachi", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => unit) => unit", - "documentation": {"kind": "markdown", "value": "\nThe `forEachi()` function applies the function given as the second argument to\neach element in the array. The function you provide takes an item in the array\nand its index number, and returns `unit`. The `forEachi()` function also\nreturns `unit`. You use `forEachi()` when you need to process each element in\nthe array but not return any new array or value; for example, to print the\nitems in an array. See\n[`Array.forEach`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)\non MDN.\n\n```res example\n// display all elements in an array as a numbered list\nJs.Array2.forEachi([\"a\", \"b\", \"c\"], (item, index) => Js.log2(index + 1, item)) == ()\n```\n"} - }, { - "label": "Js.Array2.fillFromInPlace", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a, ~from: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nSets all elements of the given array (the first arumgent) from position `~from`\nto the end to the designated value (the second argument), returning the\nresulting array. *This function modifies the original array.* See\n[`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.fillFromInPlace(arr, 99, ~from=2) == [100, 101, 99, 99, 99]\narr == [100, 101, 99, 99, 99]\n```\n"} - }, { - "label": "Js.Array2.findi", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => bool) => option<'a>", - "documentation": {"kind": "markdown", "value": "\nReturns `Some(value)` for the first element in the array that satisifies the\ngiven predicate function, or `None` if no element satisifies the predicate. The\npredicate function takes an array element and an index as its parameters. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\n// find first positive item at an odd index\nlet positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0\n\nJs.Array2.findi([66, -33, 55, 88, 22], positiveOddElement) == Some(88)\nJs.Array2.findi([66, -33, 55, -88, 22], positiveOddElement) == None\n```\n"} - }, { - "label": "Js.Array2.filteri", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => bool) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nEach element of the given array are passed to the predicate function. The\nreturn value is an array of all those elements for which the predicate function\nreturned `true`.\n\nSee\n[`Array.filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)\non MDN.\n\n```res example\n// keep only positive elements at odd indices\nlet positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0\n\nJs.Array2.filteri([6, 3, 5, 8, 7, -4, 1], positiveOddElement) == [3, 8]\n```\n"} - }, { - "label": "Js.Array2.slice", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~start: int, ~end_: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nReturns a shallow copy of the given array from the `~start` index up to but not\nincluding the `~end_` position. Negative numbers indicate an offset from the\nend of the array. See\n[`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104, 105, 106]\nJs.Array2.slice(arr, ~start=2, ~end_=5) == [102, 103, 104]\nJs.Array2.slice(arr, ~start=-3, ~end_=-1) == [104, 105]\nJs.Array2.slice(arr, ~start=9, ~end_=10) == []\n```\n"} - }, { - "label": "Js.Array2.fromMap", - "kind": 12, - "tags": [], - "detail": "(array_like<'a>, 'a => 'b) => array<'b>", - "documentation": {"kind": "markdown", "value": "\nCreates a new array by applying a function (the second argument) to each item\nin the `array_like` first argument. See\n[`Array.from`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)\non MDN.\n\n```res example\nlet strArr = Js.String.castToArrayLike(\"abcd\")\nlet code = s => Js.String.charCodeAt(0, s)\nJs.Array2.fromMap(strArr, code) == [97.0, 98.0, 99.0, 100.0]\n```\n"} - }, { - "label": "Js.Array2.removeFromInPlace", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~pos: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nRemoves elements from the given array starting at position `~pos` to the end of\nthe array, returning the removed elements. *This function modifies the original\narray.* See\n[`Array.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)\non MDN.\n\n```res example\nlet arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.removeFromInPlace(arr, ~pos=4) == [\"e\", \"f\"]\narr == [\"a\", \"b\", \"c\", \"d\"]\n```\n"} - }, { - "label": "Js.Array2.from", - "kind": 12, - "tags": [], - "detail": "array_like<'a> => array<'a>", - "documentation": {"kind": "markdown", "value": "\nCreates a shallow copy of an array from an array-like object. See\n[`Array.from`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)\non MDN.\n\n```res example\nlet strArr = Js.String.castToArrayLike(\"abcd\")\nJs.Array2.from(strArr) == [\"a\", \"b\", \"c\", \"d\"]\n```\n"} - }, { - "label": "Js.Array2.includes", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a) => bool", - "documentation": {"kind": "markdown", "value": "\nReturns true if the given value is in the array, `false` otherwise. See\n[`Array.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)\non MDN.\n\n```res example\nJs.Array2.includes([\"a\", \"b\", \"c\"], \"b\") == true\nJs.Array2.includes([\"a\", \"b\", \"c\"], \"x\") == false\n```\n"} - }, { - "label": "Js.Array2.find", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => option<'a>", - "documentation": {"kind": "markdown", "value": "\nReturns `Some(value)` for the first element in the array that satisifies the\ngiven predicate function, or `None` if no element satisifies the predicate. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\n// find first negative element\nJs.Array2.find([33, 22, -55, 77, -44], x => x < 0) == Some(-55)\nJs.Array2.find([33, 22, 55, 77, 44], x => x < 0) == None\n```\n"} - }, { - "label": "Js.Array2.reduceRighti", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('b, 'a, int) => 'b, 'b) => 'b", - "documentation": {"kind": "markdown", "value": "\nThe `reduceRighti()` function takes three parameters: an array, a *reducer\nfunction*, and a beginning accumulator value. The reducer function has three\nparameters: an accumulated value, an element of the array, and the index of\nthat element. `reduceRighti()` first calls the reducer function with the\nbeginning value, the last element in the array, and its index (length of array\nminus one). The result becomes the new accumulator value, which is passed in to\nthe reducer function along with the second element in the array and one (its\nindex). `reduceRighti()` proceeds from right to left through the array, passing\nin the result of each stage as the accumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reduceRighti()`. See\n[`Array.reduceRight`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight)\non MDN.\n\n**NOTE:** In many cases, `reducei()` and `reduceRighti()` give the same result.\nHowever, there are cases where the order in which items are processed makes a\ndifference.\n\n```res example\n// find sum of even-index elements in array\nlet sumOfEvens = (accumulator, item, index) =>\n if mod(index, 2) == 0 {\n accumulator + item\n } else {\n accumulator\n }\n\nJs.Array2.reduceRighti([2, 5, 1, 4, 3], sumOfEvens, 0) == 6\n```\n"} - }, { - "label": "Js.Array2.findIndexi", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => bool) => int", - "documentation": {"kind": "markdown", "value": "\nReturns `Some(value)` for the first element in the array that satisifies the\ngiven predicate function, or `None` if no element satisifies the predicate. The\npredicate function takes an array element and an index as its parameters. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\n// find index of first positive item at an odd index\nlet positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0\n\nJs.Array2.findIndexi([66, -33, 55, 88, 22], positiveOddElement) == 3\nJs.Array2.findIndexi([66, -33, 55, -88, 22], positiveOddElement) == -1\n```\n"} - }, { - "label": "Js.Array2.toLocaleString", - "kind": 12, - "tags": [], - "detail": "t<'a> => string", - "documentation": {"kind": "markdown", "value": "\nConverts the array to a string using the conventions of the current locale.\nEach element is converted to a string using JavaScript. Unlike the JavaScript\n`Array.toLocaleString()`, all elements in a ReasonML array must have the same\ntype. See\n[`Array.toLocaleString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString)\non MDN.\n\n```res example\nJs.Array2.toLocaleString([Js.Date.make()])\n// returns \"3/19/2020, 10:52:11 AM\" for locale en_US.utf8\n// returns \"2020-3-19 10:52:11\" for locale de_DE.utf8\n```\n"} - }, { - "label": "Js.Array2.lastIndexOfFrom", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a, ~from: int) => int", - "documentation": {"kind": "markdown", "value": "\nReturns the index of the last element in the array that has the given value,\nsearching from position `~from` down to the start of the array. If the value is\nnot in the array, returns -1. See\n[`Array.lastIndexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)\non MDN.\n\n```res example\nJs.Array2.lastIndexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\", \"d\"], \"a\", ~from=3) == 2\nJs.Array2.lastIndexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\", \"d\"], \"c\", ~from=2) == -1\n```\n"} - }, { - "label": "Js.Array2.copyWithinFromRange", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~to_: int, ~start: int, ~end_: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nCopies starting at element `~start` in the given array up to but not including\n`~end_` to the designated `~to_` position, returning the resulting array. *This\nfunction modifies the original array.* See\n[`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104, 105]\nJs.Array2.copyWithinFromRange(arr, ~start=2, ~end_=5, ~to_=1) == [100, 102, 103, 104, 104, 105]\narr == [100, 102, 103, 104, 104, 105]\n```\n"} - }, { - "label": "Js.Array2.findIndex", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => int", - "documentation": {"kind": "markdown", "value": "\nReturns the index of the first element in the array that satisifies the given\npredicate function, or -1 if no element satisifies the predicate. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\nJs.Array2.findIndex([33, 22, -55, 77, -44], x => x < 0) == 2\nJs.Array2.findIndex([33, 22, 55, 77, 44], x => x < 0) == -1\n```\n"} - }, { - "label": "Js.Array2.removeCountInPlace", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~pos: int, ~count: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nRemoves `~count` elements from the given array starting at position `~pos`,\nreturning the removed elements. *This function modifies the original array.*\nSee\n[`Array.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)\non MDN.\n\n```res example\nlet arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.removeCountInPlace(arr, ~pos=2, ~count=3) == [\"c\", \"d\", \"e\"]\narr == [\"a\", \"b\", \"f\"]\n```\n"} - }, { - "label": "Js.Array2.reverseInPlace", - "kind": 12, - "tags": [], - "detail": "t<'a> => t<'a>", - "documentation": {"kind": "markdown", "value": "\nReturns an array with the elements of the input array in reverse order. *This\nfunction modifies the original array.* See\n[`Array.reverse`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse)\non MDN.\n\n```res example\nlet arr = [\"ant\", \"bee\", \"cat\"]\nJs.Array2.reverseInPlace(arr) == [\"cat\", \"bee\", \"ant\"]\narr == [\"cat\", \"bee\", \"ant\"]\n```\n"} - }, { - "label": "Js.Array2.every", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => bool", - "documentation": {"kind": "markdown", "value": "\nThe first argument to `every()` is an array. The second argument is a predicate\nfunction that returns a boolean. The `every()` function returns `true` if the\npredicate function is true for all items in the given array. If given an empty\narray, returns `true`. See\n[`Array.every`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)\non MDN.\n\n```res example\nlet isEven = x => mod(x, 2) == 0\nJs.Array2.every([6, 22, 8, 4], isEven) == true\nJs.Array2.every([6, 22, 7, 4], isEven) == false\n```\n"} - }, { - "label": "Js.Array2.length", - "kind": 12, - "tags": [], - "detail": "array<'a> => int", - "documentation": {"kind": "markdown", "value": "\nReturns the number of elements in the array. See\n[`Array.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)\non MDN.\n"} - }, { - "label": "Js.Array2.indexOf", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a) => int", - "documentation": {"kind": "markdown", "value": "\nReturns the index of the first element in the array that has the given value.\nIf the value is not in the array, returns -1. See\n[`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)\non MDN.\n\n```res example\nJs.Array2.indexOf([100, 101, 102, 103], 102) == 2\nJs.Array2.indexOf([100, 101, 102, 103], 999) == -1\n```\n"} - }, { - "label": "Js.Array2.unshift", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a) => int", - "documentation": {"kind": "markdown", "value": "\nAdds the given element to the array, returning the new number of elements in\nthe array. *This function modifies the original array.* See\n[`Array.unshift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)\non MDN.\n\n```res example\nlet arr = [\"b\", \"c\", \"d\"]\nJs.Array2.unshift(arr, \"a\") == 4\narr == [\"a\", \"b\", \"c\", \"d\"]\n```\n"} - }, { - "label": "Js.Array2.sortInPlace", - "kind": 12, - "tags": [], - "detail": "t<'a> => t<'a>", - "documentation": {"kind": "markdown", "value": "\nSorts the given array in place and returns the sorted array. JavaScript sorts\nthe array by converting the arguments to UTF-16 strings and sorting them. See\nthe second example with sorting numbers, which does not do a numeric sort.\n*This function modifies the original array.* See\n[`Array.sort`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)\non MDN.\n\n```res example\nlet words = [\"bee\", \"dog\", \"ant\", \"cat\"]\nJs.Array2.sortInPlace(words) == [\"ant\", \"bee\", \"cat\", \"dog\"]\nwords == [\"ant\", \"bee\", \"cat\", \"dog\"]\n\nlet numbers = [3, 30, 10, 1, 20, 2]\nJs.Array2.sortInPlace(numbers) == [1, 10, 2, 20, 3, 30]\nnumbers == [1, 10, 2, 20, 3, 30]\n```\n"} - }, { - "label": "Js.Array2.unsafe_get", - "kind": 12, - "tags": [], - "detail": "(array<'a>, int) => 'a", - "documentation": {"kind": "markdown", "value": "\nReturns the value at the given position in the array if the position is in\nbounds; returns the JavaScript value `undefined` otherwise.\n\n```res example\nlet arr = [100, 101, 102, 103]\nJs.Array2.unsafe_get(arr, 3) == 103\nJs.Array2.unsafe_get(arr, 4) // returns undefined\n```\n"} - }, { - "label": "Js.Array2.some", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => bool", - "documentation": {"kind": "markdown", "value": "\nReturns `true` if the predicate function given as the second argument to\n`some()` returns `true` for any element in the array; `false` otherwise.\n\n```res example\nlet isEven = x => mod(x, 2) == 0\n\nJs.Array2.some([3, 7, 5, 2, 9], isEven) == true\nJs.Array2.some([3, 7, 5, 1, 9], isEven) == false\n```\n"} - }, { - "label": "Js.Array2.map", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => 'b) => t<'b>", - "documentation": {"kind": "markdown", "value": "\nApplies the function (the second argument) to each item in the array, returning\na new array. The result array does not have to have elements of the same type\nas the input array. See\n[`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)\non MDN.\n\n```res example\nJs.Array2.map([12, 4, 8], x => x * x) == [144, 16, 64]\nJs.Array2.map([\"animal\", \"vegetable\", \"mineral\"], Js.String.length) == [6, 9, 7]\n```\n"} - }, { - "label": "Js.Array2.push", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a) => int", - "documentation": {"kind": "markdown", "value": "\nAppends the given value to the array, returning the number of elements in the\nupdated array. *This function modifies the original array.* See\n[`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)\non MDN.\n\n```res example\nlet arr = [\"ant\", \"bee\", \"cat\"]\nJs.Array2.push(arr, \"dog\") == 4\narr == [\"ant\", \"bee\", \"cat\", \"dog\"]\n```\n"} - }, { - "label": "Js.Array2.fillRangeInPlace", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a, ~start: int, ~end_: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nSets the elements of the given array (the first arumgent) from position\n`~start` up to but not including position `~end_` to the designated value (the\nsecond argument), returning the resulting array. *This function modifies the\noriginal array.* See\n[`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.fillRangeInPlace(arr, 99, ~start=1, ~end_=4) == [100, 99, 99, 99, 104]\narr == [100, 99, 99, 99, 104]\n```\n"} - }, { - "label": "Js.Array2.pop", - "kind": 12, - "tags": [], - "detail": "t<'a> => option<'a>", - "documentation": {"kind": "markdown", "value": "\nIf the array is not empty, removes the last element and returns it as\n`Some(value)`; returns `None` if the array is empty. *This function modifies\nthe original array.* See\n[`Array.pop`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.pop(arr) == Some(104)\narr == [100, 101, 102, 103]\n\nlet empty: array = []\nJs.Array2.pop(empty) == None\n```\n"} - }, { - "label": "Js.Array2.somei", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => bool) => bool", - "documentation": {"kind": "markdown", "value": "\nReturns `true` if the predicate function given as the second argument to\n`somei()` returns `true` for any element in the array; `false` otherwise. The\npredicate function has two arguments: an item from the array and the index\nvalue\n\n```res example\n// Does any string in the array\n// have the same length as its index?\n\nlet sameLength = (str, index) => Js.String.length(str) == index\n\n// \"ef\" has length 2 and is it at index 2\nJs.Array2.somei([\"ab\", \"cd\", \"ef\", \"gh\"], sameLength) == true\n// no item has the same length as its index\nJs.Array2.somei([\"a\", \"bc\", \"def\", \"gh\"], sameLength) == false\n```\n"} - }, { - "label": "Js.Array2.append", - "kind": 12, - "tags": [1], - "detail": "(t<'a>, 'a) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: `append` is not type-safe. Use `concat` instead.\n\n"} - }, { - "label": "Js.Array2.unsafe_set", - "kind": 12, - "tags": [], - "detail": "(array<'a>, int, 'a) => unit", - "documentation": {"kind": "markdown", "value": "\nSets the value at the given position in the array if the position is in bounds.\nIf the index is out of bounds, well, “here there be dragons.“\n\n*This function modifies the original array.*\n\n```res example\nlet arr = [100, 101, 102, 103]\nJs.Array2.unsafe_set(arr, 3, 99)\n// result is [100, 101, 102, 99];\n\nJs.Array2.unsafe_set(arr, 4, 88)\n// result is [100, 101, 102, 99, 88]\n\nJs.Array2.unsafe_set(arr, 6, 77)\n// result is [100, 101, 102, 99, 88, <1 empty item>, 77]\n\nJs.Array2.unsafe_set(arr, -1, 66)\n// you don't want to know.\n```\n"} - }, { - "label": "Js.Array2.copyWithin", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~to_: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nCopies from the first element in the given array to the designated `~to_`\nposition, returning the resulting array. *This function modifies the original\narray.* See\n[`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.copyWithin(arr, ~to_=2) == [100, 101, 100, 101, 102]\narr == [100, 101, 100, 101, 102]\n```\n"} - }, { - "label": "Js.Array2.everyi", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => bool) => bool", - "documentation": {"kind": "markdown", "value": "\nThe first argument to `everyi()` is an array. The second argument is a\npredicate function with two arguments: an array element and that element’s\nindex; it returns a boolean. The `everyi()` function returns `true` if the\npredicate function is true for all items in the given array. If given an empty\narray, returns `true`. See\n[`Array.every`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)\non MDN.\n\n```res example\n// determine if all even-index items are positive\nlet evenIndexPositive = (item, index) => mod(index, 2) == 0 ? item > 0 : true\n\nJs.Array2.everyi([6, -3, 5, 8], evenIndexPositive) == true\nJs.Array2.everyi([6, 3, -5, 8], evenIndexPositive) == false\n```\n"} - }, { - "label": "Js.Array2.toString", - "kind": 12, - "tags": [], - "detail": "t<'a> => string", - "documentation": {"kind": "markdown", "value": "\nConverts the array to a string. Each element is converted to a string using\nJavaScript. Unlike the JavaScript `Array.toString()`, all elements in a\nReasonML array must have the same type. See\n[`Array.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString)\non MDN.\n\n```res example\nJs.Array2.toString([3.5, 4.6, 7.8]) == \"3.5,4.6,7.8\"\nJs.Array2.toString([\"a\", \"b\", \"c\"]) == \"a,b,c\"\n```\n"} - }, { - "label": "Js.Array2.spliceInPlace", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~pos: int, ~remove: int, ~add: array<'a>) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nStarting at position `~pos`, remove `~remove` elements and then add the\nelements from the `~add` array. Returns an array consisting of the removed\nitems. *This function modifies the original array.* See\n[`Array.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)\non MDN.\n\n```res example\nlet arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.spliceInPlace(arr, ~pos=2, ~remove=2, ~add=[\"x\", \"y\", \"z\"]) == [\"c\", \"d\"]\narr == [\"a\", \"b\", \"x\", \"y\", \"z\", \"e\", \"f\"]\n\nlet arr2 = [\"a\", \"b\", \"c\", \"d\"]\nJs.Array2.spliceInPlace(arr2, ~pos=3, ~remove=0, ~add=[\"x\", \"y\"]) == []\narr2 == [\"a\", \"b\", \"c\", \"x\", \"y\", \"d\"]\n\nlet arr3 = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.spliceInPlace(arr3, ~pos=9, ~remove=2, ~add=[\"x\", \"y\", \"z\"]) == []\narr3 == [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"x\", \"y\", \"z\"]\n```\n"} - }, { - "label": "Js.Array2.pushMany", - "kind": 12, - "tags": [], - "detail": "(t<'a>, array<'a>) => int", - "documentation": {"kind": "markdown", "value": "\nAppends the values from one array (the second argument) to another (the first\nargument), returning the number of elements in the updated array. *This\nfunction modifies the original array.* See\n[`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)\non MDN.\n\n```res example\nlet arr = [\"ant\", \"bee\", \"cat\"]\nJs.Array2.pushMany(arr, [\"dog\", \"elk\"]) == 5\narr == [\"ant\", \"bee\", \"cat\", \"dog\", \"elk\"]\n```\n"} - }, { - "label": "Js.Array2.copyWithinFrom", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~to_: int, ~from: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nCopies starting at element `~from` in the given array to the designated `~to_`\nposition, returning the resulting array. *This function modifies the original\narray.* See\n[`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.copyWithinFrom(arr, ~from=2, ~to_=0) == [102, 103, 104, 103, 104]\narr == [102, 103, 104, 103, 104]\n```\n"} - }, { - "label": "Js.Array2.forEach", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => unit) => unit", - "documentation": {"kind": "markdown", "value": "\nThe `forEach()` function applies the function given as the second argument to\neach element in the array. The function you provide returns `unit`, and the\n`forEach()` function also returns `unit`. You use `forEach()` when you need to\nprocess each element in the array but not return any new array or value; for\nexample, to print the items in an array. See\n[`Array.forEach`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)\non MDN.\n\n```res example\n// display all elements in an array\nJs.Array2.forEach([\"a\", \"b\", \"c\"], x => Js.log(x)) == ()\n```\n"} - }, { - "label": "Js.Array2.sliceFrom", - "kind": 12, - "tags": [], - "detail": "(t<'a>, int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nReturns a shallow copy of the given array from the given index to the end. See\n[`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\non MDN.\n"} - }, { - "label": "Js.Array2.sortInPlaceWith", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, 'a) => int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nSorts the given array in place and returns the sorted array. *This function\n modifies the original array.*\n\nThe first argument to `sortInPlaceWith()` is a function that compares two items\nfrom the array and returns:\n\n* an integer less than zero if the first item is less than the second item *\nzero if the items are equal * an integer greater than zero if the first item is\ngreater than the second item\n\nSee\n[`Array.sort`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)\non MDN.\n\n```res example\n// sort by word length\nlet words = [\"horse\", \"aardvark\", \"dog\", \"camel\"]\nlet byLength = (s1, s2) => Js.String.length(s1) - Js.String.length(s2)\n\nJs.Array2.sortInPlaceWith(words, byLength) == [\"dog\", \"horse\", \"camel\", \"aardvark\"]\n\n// sort in reverse numeric order\nlet numbers = [3, 30, 10, 1, 20, 2]\nlet reverseNumeric = (n1, n2) => n2 - n1\nJs.Array2.sortInPlaceWith(numbers, reverseNumeric) == [30, 20, 10, 3, 2, 1]\n```\n"} - }, { - "label": "Js.Array2.indexOfFrom", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a, ~from: int) => int", - "documentation": {"kind": "markdown", "value": "\nReturns the index of the first element in the array with the given value. The\nsearch starts at position `~from`. See\n[`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)\non MDN.\n\n```res example\nJs.Array2.indexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\"], \"a\", ~from=2) == 2\nJs.Array2.indexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\"], \"a\", ~from=3) == 4\nJs.Array2.indexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\"], \"b\", ~from=2) == -1\n```\n"} - }] - -Complete src/CompletionPipeChain.res 8:68 -posCursor:[8:68] posNoWhite:[8:67] Found expr:[8:11->0:-1] -Completable: Cpath Value[Js, Array2, filter](Nolabel, Nolabel)-> -[{ - "label": "Js.Array2.mapi", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => 'b) => t<'b>", - "documentation": {"kind": "markdown", "value": "\nApplies the function (the second argument) to each item in the array, returning\na new array. The function acceps two arguments: an item from the array and its\nindex number. The result array does not have to have elements of the same type\nas the input array. See\n[`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)\non MDN.\n\n```res example\n// multiply each item in array by its position\nlet product = (item, index) => item * index\nJs.Array2.mapi([10, 11, 12], product) == [0, 11, 24]\n```\n"} - }, { - "label": "Js.Array2.lastIndexOf", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a) => int", - "documentation": {"kind": "markdown", "value": "\nReturns the index of the last element in the array that has the given value. If\nthe value is not in the array, returns -1. See\n[`Array.lastIndexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)\non MDN.\n\n```res example\nJs.Array2.lastIndexOf([\"a\", \"b\", \"a\", \"c\"], \"a\") == 2\nJs.Array2.lastIndexOf([\"a\", \"b\", \"a\", \"c\"], \"x\") == -1\n```\n"} - }, { - "label": "Js.Array2.concat", - "kind": 12, - "tags": [], - "detail": "(t<'a>, t<'a>) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nConcatenates the second array argument to the first array argument, returning a\nnew array. The original arrays are not modified. See\n[`Array.concat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)\non MDN.\n\n```res example\nJs.Array2.concat([\"a\", \"b\"], [\"c\", \"d\", \"e\"]) == [\"a\", \"b\", \"c\", \"d\", \"e\"]\n```\n"} - }, { - "label": "Js.Array2.unshiftMany", - "kind": 12, - "tags": [], - "detail": "(t<'a>, array<'a>) => int", - "documentation": {"kind": "markdown", "value": "\nAdds the elements in the second array argument at the beginning of the first\narray argument, returning the new number of elements in the array. *This\nfunction modifies the original array.* See\n[`Array.unshift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)\non MDN.\n\n```res example\nlet arr = [\"d\", \"e\"]\nJs.Array2.unshiftMany(arr, [\"a\", \"b\", \"c\"]) == 5\narr == [\"a\", \"b\", \"c\", \"d\", \"e\"]\n```\n"} - }, { - "label": "Js.Array2.filter", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nApplies the given predicate function (the second argument) to each element in\nthe array; the result is an array of those elements for which the predicate\nfunction returned `true`. See\n[`Array.filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)\non MDN.\n\n```res example\nlet nonEmpty = s => s != \"\"\nJs.Array2.filter([\"abc\", \"\", \"\", \"def\", \"ghi\"], nonEmpty) == [\"abc\", \"def\", \"ghi\"]\n```\n"} - }, { - "label": "Js.Array2.shift", - "kind": 12, - "tags": [], - "detail": "t<'a> => option<'a>", - "documentation": {"kind": "markdown", "value": "\nIf the array is not empty, removes the first element and returns it as\n`Some(value)`; returns `None` if the array is empty. *This function modifies\nthe original array.* See\n[`Array.shift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.shift(arr) == Some(100)\narr == [101, 102, 103, 104]\n\nlet empty: array = []\nJs.Array2.shift(empty) == None\n```\n"} - }, { - "label": "Js.Array2.reduceRight", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('b, 'a) => 'b, 'b) => 'b", - "documentation": {"kind": "markdown", "value": "\nThe `reduceRight()` function takes three parameters: an array, a *reducer\nfunction*, and a beginning accumulator value. The reducer function has two\nparameters: an accumulated value and an element of the array.\n\n`reduceRight()` first calls the reducer function with the beginning value and\nthe last element in the array. The result becomes the new accumulator value,\nwhich is passed in to the reducer function along with the next-to-last element\nin the array. `reduceRight()` proceeds from right to left through the array,\npassing in the result of each stage as the accumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reduceRight()`. See\n[`Array.reduceRight`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight)\non MDN.\n\n**NOTE:** In many cases, `reduce()` and `reduceRight()` give the same result.\nHowever, see the last example here and compare it to the example from\n`reduce()`, where order makes a difference.\n\n```res example\nlet sumOfSquares = (accumulator, item) => accumulator + item * item\n\nJs.Array2.reduceRight([10, 2, 4], sumOfSquares, 0) == 120\nJs.Array2.reduceRight([2.0, 4.0], (acc, item) => item /. acc, 1.0) == 0.5 // 2.0 / (4.0 / 1.0)\n```\n"} - }, { - "label": "Js.Array2.joinWith", - "kind": 12, - "tags": [], - "detail": "(t<'a>, string) => string", - "documentation": {"kind": "markdown", "value": "\nThis function converts each element of the array to a string (via JavaScript)\nand concatenates them, separated by the string given in the first argument,\ninto a single string. See\n[`Array.join`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)\non MDN.\n\n```res example\nJs.Array2.joinWith([\"ant\", \"bee\", \"cat\"], \"--\") == \"ant--bee--cat\"\nJs.Array2.joinWith([\"door\", \"bell\"], \"\") == \"doorbell\"\nJs.Array2.joinWith([2020, 9, 4], \"/\") == \"2020/9/4\"\nJs.Array2.joinWith([2.5, 3.6, 3e-2], \";\") == \"2.5;3.6;0.03\"\n```\n"} - }, { - "label": "Js.Array2.concatMany", - "kind": 12, - "tags": [], - "detail": "(t<'a>, array>) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nThe second argument to `concatMany()` is an array of arrays; these are added at\nthe end of the first argument, returning a new array. See\n[`Array.concat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)\non MDN.\n\n```res example\nJs.Array2.concatMany([\"a\", \"b\", \"c\"], [[\"d\", \"e\"], [\"f\", \"g\", \"h\"]]) == [\n \"a\",\n \"b\",\n \"c\",\n \"d\",\n \"e\",\n \"f\",\n \"g\",\n \"h\",\n ]\n```\n"} - }, { - "label": "Js.Array2.fillInPlace", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nSets all elements of the given array (the first arumgent) to the designated\nvalue (the secon argument), returning the resulting array. *This function\n modifies the original array.*\n\nSee\n[`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.fillInPlace(arr, 99) == [99, 99, 99, 99, 99]\narr == [99, 99, 99, 99, 99]\n```\n"} - }, { - "label": "Js.Array2.isArray", - "kind": 12, - "tags": [], - "detail": "'a => bool", - "documentation": {"kind": "markdown", "value": "\nReturns `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.\n\n```res example\nJs.Array2.isArray([5, 2, 3, 1, 4]) == true\nJs.Array2.isArray(list{5, 2, 3, 1, 4}) == true\nJs.Array2.isArray(\"abcd\") == false\n```\n"} - }, { - "label": "Js.Array2.reduce", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('b, 'a) => 'b, 'b) => 'b", - "documentation": {"kind": "markdown", "value": "\nThe `reduce()` function takes three parameters: an array, a *reducer function*,\nand a beginning accumulator value. The reducer function has two parameters: an\naccumulated value and an element of the array.\n\n`reduce()` first calls the reducer function with the beginning value and the\nfirst element in the array. The result becomes the new accumulator value, which\nis passed in to the reducer function along with the second element in the\narray. `reduce()` proceeds through the array, passing in the result of each\nstage as the accumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reduce()`. See\n[`Array.reduce`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce)\non MDN.\n\n```res example\nlet sumOfSquares = (accumulator, item) => accumulator + item * item\n\nJs.Array2.reduce([10, 2, 4], sumOfSquares, 0) == 120\nJs.Array2.reduce([10, 2, 4], \\\"*\", 1) == 80\nJs.Array2.reduce(\n [\"animal\", \"vegetable\", \"mineral\"],\n (acc, item) => acc + Js.String.length(item),\n 0,\n) == 22 // 6 + 9 + 7\nJs.Array2.reduce([2.0, 4.0], (acc, item) => item /. acc, 1.0) == 2.0 // 4.0 / (2.0 / 1.0)\n```\n"} - }, { - "label": "Js.Array2.copy", - "kind": 12, - "tags": [], - "detail": "t<'a> => t<'a>", - "documentation": {"kind": "markdown", "value": "\nReturns a copy of the entire array. Same as `Js.Array2.Slice(arr, ~start=0,\n~end_=Js.Array2.length(arr))`. See\n[`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\non MDN.\n"} - }, { - "label": "Js.Array2.reducei", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('b, 'a, int) => 'b, 'b) => 'b", - "documentation": {"kind": "markdown", "value": "\nThe `reducei()` function takes three parameters: an array, a *reducer\nfunction*, and a beginning accumulator value. The reducer function has three\nparameters: an accumulated value, an element of the array, and the index of\nthat element.\n\n`reducei()` first calls the reducer function with the beginning value, the\nfirst element in the array, and zero (its index). The result becomes the new\naccumulator value, which is passed to the reducer function along with the\nsecond element in the array and one (its index). `reducei()` proceeds from left\nto right through the array, passing in the result of each stage as the\naccumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reducei()`. See\n[`Array.reduce`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce)\non MDN.\n\n```res example\n// find sum of even-index elements in array\nlet sumOfEvens = (accumulator, item, index) =>\n if mod(index, 2) == 0 {\n accumulator + item\n } else {\n accumulator\n }\n\nJs.Array2.reducei([2, 5, 1, 4, 3], sumOfEvens, 0) == 6\n```\n"} - }, { - "label": "Js.Array2.forEachi", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => unit) => unit", - "documentation": {"kind": "markdown", "value": "\nThe `forEachi()` function applies the function given as the second argument to\neach element in the array. The function you provide takes an item in the array\nand its index number, and returns `unit`. The `forEachi()` function also\nreturns `unit`. You use `forEachi()` when you need to process each element in\nthe array but not return any new array or value; for example, to print the\nitems in an array. See\n[`Array.forEach`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)\non MDN.\n\n```res example\n// display all elements in an array as a numbered list\nJs.Array2.forEachi([\"a\", \"b\", \"c\"], (item, index) => Js.log2(index + 1, item)) == ()\n```\n"} - }, { - "label": "Js.Array2.fillFromInPlace", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a, ~from: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nSets all elements of the given array (the first arumgent) from position `~from`\nto the end to the designated value (the second argument), returning the\nresulting array. *This function modifies the original array.* See\n[`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.fillFromInPlace(arr, 99, ~from=2) == [100, 101, 99, 99, 99]\narr == [100, 101, 99, 99, 99]\n```\n"} - }, { - "label": "Js.Array2.findi", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => bool) => option<'a>", - "documentation": {"kind": "markdown", "value": "\nReturns `Some(value)` for the first element in the array that satisifies the\ngiven predicate function, or `None` if no element satisifies the predicate. The\npredicate function takes an array element and an index as its parameters. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\n// find first positive item at an odd index\nlet positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0\n\nJs.Array2.findi([66, -33, 55, 88, 22], positiveOddElement) == Some(88)\nJs.Array2.findi([66, -33, 55, -88, 22], positiveOddElement) == None\n```\n"} - }, { - "label": "Js.Array2.filteri", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => bool) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nEach element of the given array are passed to the predicate function. The\nreturn value is an array of all those elements for which the predicate function\nreturned `true`.\n\nSee\n[`Array.filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)\non MDN.\n\n```res example\n// keep only positive elements at odd indices\nlet positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0\n\nJs.Array2.filteri([6, 3, 5, 8, 7, -4, 1], positiveOddElement) == [3, 8]\n```\n"} - }, { - "label": "Js.Array2.slice", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~start: int, ~end_: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nReturns a shallow copy of the given array from the `~start` index up to but not\nincluding the `~end_` position. Negative numbers indicate an offset from the\nend of the array. See\n[`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104, 105, 106]\nJs.Array2.slice(arr, ~start=2, ~end_=5) == [102, 103, 104]\nJs.Array2.slice(arr, ~start=-3, ~end_=-1) == [104, 105]\nJs.Array2.slice(arr, ~start=9, ~end_=10) == []\n```\n"} - }, { - "label": "Js.Array2.fromMap", - "kind": 12, - "tags": [], - "detail": "(array_like<'a>, 'a => 'b) => array<'b>", - "documentation": {"kind": "markdown", "value": "\nCreates a new array by applying a function (the second argument) to each item\nin the `array_like` first argument. See\n[`Array.from`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)\non MDN.\n\n```res example\nlet strArr = Js.String.castToArrayLike(\"abcd\")\nlet code = s => Js.String.charCodeAt(0, s)\nJs.Array2.fromMap(strArr, code) == [97.0, 98.0, 99.0, 100.0]\n```\n"} - }, { - "label": "Js.Array2.removeFromInPlace", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~pos: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nRemoves elements from the given array starting at position `~pos` to the end of\nthe array, returning the removed elements. *This function modifies the original\narray.* See\n[`Array.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)\non MDN.\n\n```res example\nlet arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.removeFromInPlace(arr, ~pos=4) == [\"e\", \"f\"]\narr == [\"a\", \"b\", \"c\", \"d\"]\n```\n"} - }, { - "label": "Js.Array2.from", - "kind": 12, - "tags": [], - "detail": "array_like<'a> => array<'a>", - "documentation": {"kind": "markdown", "value": "\nCreates a shallow copy of an array from an array-like object. See\n[`Array.from`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)\non MDN.\n\n```res example\nlet strArr = Js.String.castToArrayLike(\"abcd\")\nJs.Array2.from(strArr) == [\"a\", \"b\", \"c\", \"d\"]\n```\n"} - }, { - "label": "Js.Array2.includes", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a) => bool", - "documentation": {"kind": "markdown", "value": "\nReturns true if the given value is in the array, `false` otherwise. See\n[`Array.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)\non MDN.\n\n```res example\nJs.Array2.includes([\"a\", \"b\", \"c\"], \"b\") == true\nJs.Array2.includes([\"a\", \"b\", \"c\"], \"x\") == false\n```\n"} - }, { - "label": "Js.Array2.find", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => option<'a>", - "documentation": {"kind": "markdown", "value": "\nReturns `Some(value)` for the first element in the array that satisifies the\ngiven predicate function, or `None` if no element satisifies the predicate. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\n// find first negative element\nJs.Array2.find([33, 22, -55, 77, -44], x => x < 0) == Some(-55)\nJs.Array2.find([33, 22, 55, 77, 44], x => x < 0) == None\n```\n"} - }, { - "label": "Js.Array2.reduceRighti", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('b, 'a, int) => 'b, 'b) => 'b", - "documentation": {"kind": "markdown", "value": "\nThe `reduceRighti()` function takes three parameters: an array, a *reducer\nfunction*, and a beginning accumulator value. The reducer function has three\nparameters: an accumulated value, an element of the array, and the index of\nthat element. `reduceRighti()` first calls the reducer function with the\nbeginning value, the last element in the array, and its index (length of array\nminus one). The result becomes the new accumulator value, which is passed in to\nthe reducer function along with the second element in the array and one (its\nindex). `reduceRighti()` proceeds from right to left through the array, passing\nin the result of each stage as the accumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reduceRighti()`. See\n[`Array.reduceRight`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight)\non MDN.\n\n**NOTE:** In many cases, `reducei()` and `reduceRighti()` give the same result.\nHowever, there are cases where the order in which items are processed makes a\ndifference.\n\n```res example\n// find sum of even-index elements in array\nlet sumOfEvens = (accumulator, item, index) =>\n if mod(index, 2) == 0 {\n accumulator + item\n } else {\n accumulator\n }\n\nJs.Array2.reduceRighti([2, 5, 1, 4, 3], sumOfEvens, 0) == 6\n```\n"} - }, { - "label": "Js.Array2.findIndexi", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => bool) => int", - "documentation": {"kind": "markdown", "value": "\nReturns `Some(value)` for the first element in the array that satisifies the\ngiven predicate function, or `None` if no element satisifies the predicate. The\npredicate function takes an array element and an index as its parameters. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\n// find index of first positive item at an odd index\nlet positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0\n\nJs.Array2.findIndexi([66, -33, 55, 88, 22], positiveOddElement) == 3\nJs.Array2.findIndexi([66, -33, 55, -88, 22], positiveOddElement) == -1\n```\n"} - }, { - "label": "Js.Array2.toLocaleString", - "kind": 12, - "tags": [], - "detail": "t<'a> => string", - "documentation": {"kind": "markdown", "value": "\nConverts the array to a string using the conventions of the current locale.\nEach element is converted to a string using JavaScript. Unlike the JavaScript\n`Array.toLocaleString()`, all elements in a ReasonML array must have the same\ntype. See\n[`Array.toLocaleString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString)\non MDN.\n\n```res example\nJs.Array2.toLocaleString([Js.Date.make()])\n// returns \"3/19/2020, 10:52:11 AM\" for locale en_US.utf8\n// returns \"2020-3-19 10:52:11\" for locale de_DE.utf8\n```\n"} - }, { - "label": "Js.Array2.lastIndexOfFrom", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a, ~from: int) => int", - "documentation": {"kind": "markdown", "value": "\nReturns the index of the last element in the array that has the given value,\nsearching from position `~from` down to the start of the array. If the value is\nnot in the array, returns -1. See\n[`Array.lastIndexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)\non MDN.\n\n```res example\nJs.Array2.lastIndexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\", \"d\"], \"a\", ~from=3) == 2\nJs.Array2.lastIndexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\", \"d\"], \"c\", ~from=2) == -1\n```\n"} - }, { - "label": "Js.Array2.copyWithinFromRange", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~to_: int, ~start: int, ~end_: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nCopies starting at element `~start` in the given array up to but not including\n`~end_` to the designated `~to_` position, returning the resulting array. *This\nfunction modifies the original array.* See\n[`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104, 105]\nJs.Array2.copyWithinFromRange(arr, ~start=2, ~end_=5, ~to_=1) == [100, 102, 103, 104, 104, 105]\narr == [100, 102, 103, 104, 104, 105]\n```\n"} - }, { - "label": "Js.Array2.findIndex", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => int", - "documentation": {"kind": "markdown", "value": "\nReturns the index of the first element in the array that satisifies the given\npredicate function, or -1 if no element satisifies the predicate. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\nJs.Array2.findIndex([33, 22, -55, 77, -44], x => x < 0) == 2\nJs.Array2.findIndex([33, 22, 55, 77, 44], x => x < 0) == -1\n```\n"} - }, { - "label": "Js.Array2.removeCountInPlace", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~pos: int, ~count: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nRemoves `~count` elements from the given array starting at position `~pos`,\nreturning the removed elements. *This function modifies the original array.*\nSee\n[`Array.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)\non MDN.\n\n```res example\nlet arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.removeCountInPlace(arr, ~pos=2, ~count=3) == [\"c\", \"d\", \"e\"]\narr == [\"a\", \"b\", \"f\"]\n```\n"} - }, { - "label": "Js.Array2.reverseInPlace", - "kind": 12, - "tags": [], - "detail": "t<'a> => t<'a>", - "documentation": {"kind": "markdown", "value": "\nReturns an array with the elements of the input array in reverse order. *This\nfunction modifies the original array.* See\n[`Array.reverse`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse)\non MDN.\n\n```res example\nlet arr = [\"ant\", \"bee\", \"cat\"]\nJs.Array2.reverseInPlace(arr) == [\"cat\", \"bee\", \"ant\"]\narr == [\"cat\", \"bee\", \"ant\"]\n```\n"} - }, { - "label": "Js.Array2.every", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => bool", - "documentation": {"kind": "markdown", "value": "\nThe first argument to `every()` is an array. The second argument is a predicate\nfunction that returns a boolean. The `every()` function returns `true` if the\npredicate function is true for all items in the given array. If given an empty\narray, returns `true`. See\n[`Array.every`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)\non MDN.\n\n```res example\nlet isEven = x => mod(x, 2) == 0\nJs.Array2.every([6, 22, 8, 4], isEven) == true\nJs.Array2.every([6, 22, 7, 4], isEven) == false\n```\n"} - }, { - "label": "Js.Array2.length", - "kind": 12, - "tags": [], - "detail": "array<'a> => int", - "documentation": {"kind": "markdown", "value": "\nReturns the number of elements in the array. See\n[`Array.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)\non MDN.\n"} - }, { - "label": "Js.Array2.indexOf", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a) => int", - "documentation": {"kind": "markdown", "value": "\nReturns the index of the first element in the array that has the given value.\nIf the value is not in the array, returns -1. See\n[`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)\non MDN.\n\n```res example\nJs.Array2.indexOf([100, 101, 102, 103], 102) == 2\nJs.Array2.indexOf([100, 101, 102, 103], 999) == -1\n```\n"} - }, { - "label": "Js.Array2.unshift", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a) => int", - "documentation": {"kind": "markdown", "value": "\nAdds the given element to the array, returning the new number of elements in\nthe array. *This function modifies the original array.* See\n[`Array.unshift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)\non MDN.\n\n```res example\nlet arr = [\"b\", \"c\", \"d\"]\nJs.Array2.unshift(arr, \"a\") == 4\narr == [\"a\", \"b\", \"c\", \"d\"]\n```\n"} - }, { - "label": "Js.Array2.sortInPlace", - "kind": 12, - "tags": [], - "detail": "t<'a> => t<'a>", - "documentation": {"kind": "markdown", "value": "\nSorts the given array in place and returns the sorted array. JavaScript sorts\nthe array by converting the arguments to UTF-16 strings and sorting them. See\nthe second example with sorting numbers, which does not do a numeric sort.\n*This function modifies the original array.* See\n[`Array.sort`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)\non MDN.\n\n```res example\nlet words = [\"bee\", \"dog\", \"ant\", \"cat\"]\nJs.Array2.sortInPlace(words) == [\"ant\", \"bee\", \"cat\", \"dog\"]\nwords == [\"ant\", \"bee\", \"cat\", \"dog\"]\n\nlet numbers = [3, 30, 10, 1, 20, 2]\nJs.Array2.sortInPlace(numbers) == [1, 10, 2, 20, 3, 30]\nnumbers == [1, 10, 2, 20, 3, 30]\n```\n"} - }, { - "label": "Js.Array2.unsafe_get", - "kind": 12, - "tags": [], - "detail": "(array<'a>, int) => 'a", - "documentation": {"kind": "markdown", "value": "\nReturns the value at the given position in the array if the position is in\nbounds; returns the JavaScript value `undefined` otherwise.\n\n```res example\nlet arr = [100, 101, 102, 103]\nJs.Array2.unsafe_get(arr, 3) == 103\nJs.Array2.unsafe_get(arr, 4) // returns undefined\n```\n"} - }, { - "label": "Js.Array2.some", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => bool", - "documentation": {"kind": "markdown", "value": "\nReturns `true` if the predicate function given as the second argument to\n`some()` returns `true` for any element in the array; `false` otherwise.\n\n```res example\nlet isEven = x => mod(x, 2) == 0\n\nJs.Array2.some([3, 7, 5, 2, 9], isEven) == true\nJs.Array2.some([3, 7, 5, 1, 9], isEven) == false\n```\n"} - }, { - "label": "Js.Array2.map", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => 'b) => t<'b>", - "documentation": {"kind": "markdown", "value": "\nApplies the function (the second argument) to each item in the array, returning\na new array. The result array does not have to have elements of the same type\nas the input array. See\n[`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)\non MDN.\n\n```res example\nJs.Array2.map([12, 4, 8], x => x * x) == [144, 16, 64]\nJs.Array2.map([\"animal\", \"vegetable\", \"mineral\"], Js.String.length) == [6, 9, 7]\n```\n"} - }, { - "label": "Js.Array2.push", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a) => int", - "documentation": {"kind": "markdown", "value": "\nAppends the given value to the array, returning the number of elements in the\nupdated array. *This function modifies the original array.* See\n[`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)\non MDN.\n\n```res example\nlet arr = [\"ant\", \"bee\", \"cat\"]\nJs.Array2.push(arr, \"dog\") == 4\narr == [\"ant\", \"bee\", \"cat\", \"dog\"]\n```\n"} - }, { - "label": "Js.Array2.fillRangeInPlace", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a, ~start: int, ~end_: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nSets the elements of the given array (the first arumgent) from position\n`~start` up to but not including position `~end_` to the designated value (the\nsecond argument), returning the resulting array. *This function modifies the\noriginal array.* See\n[`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.fillRangeInPlace(arr, 99, ~start=1, ~end_=4) == [100, 99, 99, 99, 104]\narr == [100, 99, 99, 99, 104]\n```\n"} - }, { - "label": "Js.Array2.pop", - "kind": 12, - "tags": [], - "detail": "t<'a> => option<'a>", - "documentation": {"kind": "markdown", "value": "\nIf the array is not empty, removes the last element and returns it as\n`Some(value)`; returns `None` if the array is empty. *This function modifies\nthe original array.* See\n[`Array.pop`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.pop(arr) == Some(104)\narr == [100, 101, 102, 103]\n\nlet empty: array = []\nJs.Array2.pop(empty) == None\n```\n"} - }, { - "label": "Js.Array2.somei", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => bool) => bool", - "documentation": {"kind": "markdown", "value": "\nReturns `true` if the predicate function given as the second argument to\n`somei()` returns `true` for any element in the array; `false` otherwise. The\npredicate function has two arguments: an item from the array and the index\nvalue\n\n```res example\n// Does any string in the array\n// have the same length as its index?\n\nlet sameLength = (str, index) => Js.String.length(str) == index\n\n// \"ef\" has length 2 and is it at index 2\nJs.Array2.somei([\"ab\", \"cd\", \"ef\", \"gh\"], sameLength) == true\n// no item has the same length as its index\nJs.Array2.somei([\"a\", \"bc\", \"def\", \"gh\"], sameLength) == false\n```\n"} - }, { - "label": "Js.Array2.append", - "kind": 12, - "tags": [1], - "detail": "(t<'a>, 'a) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: `append` is not type-safe. Use `concat` instead.\n\n"} - }, { - "label": "Js.Array2.unsafe_set", - "kind": 12, - "tags": [], - "detail": "(array<'a>, int, 'a) => unit", - "documentation": {"kind": "markdown", "value": "\nSets the value at the given position in the array if the position is in bounds.\nIf the index is out of bounds, well, “here there be dragons.“\n\n*This function modifies the original array.*\n\n```res example\nlet arr = [100, 101, 102, 103]\nJs.Array2.unsafe_set(arr, 3, 99)\n// result is [100, 101, 102, 99];\n\nJs.Array2.unsafe_set(arr, 4, 88)\n// result is [100, 101, 102, 99, 88]\n\nJs.Array2.unsafe_set(arr, 6, 77)\n// result is [100, 101, 102, 99, 88, <1 empty item>, 77]\n\nJs.Array2.unsafe_set(arr, -1, 66)\n// you don't want to know.\n```\n"} - }, { - "label": "Js.Array2.copyWithin", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~to_: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nCopies from the first element in the given array to the designated `~to_`\nposition, returning the resulting array. *This function modifies the original\narray.* See\n[`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.copyWithin(arr, ~to_=2) == [100, 101, 100, 101, 102]\narr == [100, 101, 100, 101, 102]\n```\n"} - }, { - "label": "Js.Array2.everyi", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => bool) => bool", - "documentation": {"kind": "markdown", "value": "\nThe first argument to `everyi()` is an array. The second argument is a\npredicate function with two arguments: an array element and that element’s\nindex; it returns a boolean. The `everyi()` function returns `true` if the\npredicate function is true for all items in the given array. If given an empty\narray, returns `true`. See\n[`Array.every`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)\non MDN.\n\n```res example\n// determine if all even-index items are positive\nlet evenIndexPositive = (item, index) => mod(index, 2) == 0 ? item > 0 : true\n\nJs.Array2.everyi([6, -3, 5, 8], evenIndexPositive) == true\nJs.Array2.everyi([6, 3, -5, 8], evenIndexPositive) == false\n```\n"} - }, { - "label": "Js.Array2.toString", - "kind": 12, - "tags": [], - "detail": "t<'a> => string", - "documentation": {"kind": "markdown", "value": "\nConverts the array to a string. Each element is converted to a string using\nJavaScript. Unlike the JavaScript `Array.toString()`, all elements in a\nReasonML array must have the same type. See\n[`Array.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString)\non MDN.\n\n```res example\nJs.Array2.toString([3.5, 4.6, 7.8]) == \"3.5,4.6,7.8\"\nJs.Array2.toString([\"a\", \"b\", \"c\"]) == \"a,b,c\"\n```\n"} - }, { - "label": "Js.Array2.spliceInPlace", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~pos: int, ~remove: int, ~add: array<'a>) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nStarting at position `~pos`, remove `~remove` elements and then add the\nelements from the `~add` array. Returns an array consisting of the removed\nitems. *This function modifies the original array.* See\n[`Array.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)\non MDN.\n\n```res example\nlet arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.spliceInPlace(arr, ~pos=2, ~remove=2, ~add=[\"x\", \"y\", \"z\"]) == [\"c\", \"d\"]\narr == [\"a\", \"b\", \"x\", \"y\", \"z\", \"e\", \"f\"]\n\nlet arr2 = [\"a\", \"b\", \"c\", \"d\"]\nJs.Array2.spliceInPlace(arr2, ~pos=3, ~remove=0, ~add=[\"x\", \"y\"]) == []\narr2 == [\"a\", \"b\", \"c\", \"x\", \"y\", \"d\"]\n\nlet arr3 = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.spliceInPlace(arr3, ~pos=9, ~remove=2, ~add=[\"x\", \"y\", \"z\"]) == []\narr3 == [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"x\", \"y\", \"z\"]\n```\n"} - }, { - "label": "Js.Array2.pushMany", - "kind": 12, - "tags": [], - "detail": "(t<'a>, array<'a>) => int", - "documentation": {"kind": "markdown", "value": "\nAppends the values from one array (the second argument) to another (the first\nargument), returning the number of elements in the updated array. *This\nfunction modifies the original array.* See\n[`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)\non MDN.\n\n```res example\nlet arr = [\"ant\", \"bee\", \"cat\"]\nJs.Array2.pushMany(arr, [\"dog\", \"elk\"]) == 5\narr == [\"ant\", \"bee\", \"cat\", \"dog\", \"elk\"]\n```\n"} - }, { - "label": "Js.Array2.copyWithinFrom", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~to_: int, ~from: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nCopies starting at element `~from` in the given array to the designated `~to_`\nposition, returning the resulting array. *This function modifies the original\narray.* See\n[`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.copyWithinFrom(arr, ~from=2, ~to_=0) == [102, 103, 104, 103, 104]\narr == [102, 103, 104, 103, 104]\n```\n"} - }, { - "label": "Js.Array2.forEach", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => unit) => unit", - "documentation": {"kind": "markdown", "value": "\nThe `forEach()` function applies the function given as the second argument to\neach element in the array. The function you provide returns `unit`, and the\n`forEach()` function also returns `unit`. You use `forEach()` when you need to\nprocess each element in the array but not return any new array or value; for\nexample, to print the items in an array. See\n[`Array.forEach`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)\non MDN.\n\n```res example\n// display all elements in an array\nJs.Array2.forEach([\"a\", \"b\", \"c\"], x => Js.log(x)) == ()\n```\n"} - }, { - "label": "Js.Array2.sliceFrom", - "kind": 12, - "tags": [], - "detail": "(t<'a>, int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nReturns a shallow copy of the given array from the given index to the end. See\n[`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\non MDN.\n"} - }, { - "label": "Js.Array2.sortInPlaceWith", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, 'a) => int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nSorts the given array in place and returns the sorted array. *This function\n modifies the original array.*\n\nThe first argument to `sortInPlaceWith()` is a function that compares two items\nfrom the array and returns:\n\n* an integer less than zero if the first item is less than the second item *\nzero if the items are equal * an integer greater than zero if the first item is\ngreater than the second item\n\nSee\n[`Array.sort`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)\non MDN.\n\n```res example\n// sort by word length\nlet words = [\"horse\", \"aardvark\", \"dog\", \"camel\"]\nlet byLength = (s1, s2) => Js.String.length(s1) - Js.String.length(s2)\n\nJs.Array2.sortInPlaceWith(words, byLength) == [\"dog\", \"horse\", \"camel\", \"aardvark\"]\n\n// sort in reverse numeric order\nlet numbers = [3, 30, 10, 1, 20, 2]\nlet reverseNumeric = (n1, n2) => n2 - n1\nJs.Array2.sortInPlaceWith(numbers, reverseNumeric) == [30, 20, 10, 3, 2, 1]\n```\n"} - }, { - "label": "Js.Array2.indexOfFrom", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a, ~from: int) => int", - "documentation": {"kind": "markdown", "value": "\nReturns the index of the first element in the array with the given value. The\nsearch starts at position `~from`. See\n[`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)\non MDN.\n\n```res example\nJs.Array2.indexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\"], \"a\", ~from=2) == 2\nJs.Array2.indexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\"], \"a\", ~from=3) == 4\nJs.Array2.indexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\"], \"b\", ~from=2) == -1\n```\n"} - }] - -Complete src/CompletionPipeChain.res 11:42 -posCursor:[11:42] posNoWhite:[11:41] Found expr:[11:11->0:-1] -Completable: Cpath Value[Js, Array2, filter](Nolabel, Nolabel)-> -[{ - "label": "Js.Array2.mapi", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => 'b) => t<'b>", - "documentation": {"kind": "markdown", "value": "\nApplies the function (the second argument) to each item in the array, returning\na new array. The function acceps two arguments: an item from the array and its\nindex number. The result array does not have to have elements of the same type\nas the input array. See\n[`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)\non MDN.\n\n```res example\n// multiply each item in array by its position\nlet product = (item, index) => item * index\nJs.Array2.mapi([10, 11, 12], product) == [0, 11, 24]\n```\n"} - }, { - "label": "Js.Array2.lastIndexOf", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a) => int", - "documentation": {"kind": "markdown", "value": "\nReturns the index of the last element in the array that has the given value. If\nthe value is not in the array, returns -1. See\n[`Array.lastIndexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)\non MDN.\n\n```res example\nJs.Array2.lastIndexOf([\"a\", \"b\", \"a\", \"c\"], \"a\") == 2\nJs.Array2.lastIndexOf([\"a\", \"b\", \"a\", \"c\"], \"x\") == -1\n```\n"} - }, { - "label": "Js.Array2.concat", - "kind": 12, - "tags": [], - "detail": "(t<'a>, t<'a>) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nConcatenates the second array argument to the first array argument, returning a\nnew array. The original arrays are not modified. See\n[`Array.concat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)\non MDN.\n\n```res example\nJs.Array2.concat([\"a\", \"b\"], [\"c\", \"d\", \"e\"]) == [\"a\", \"b\", \"c\", \"d\", \"e\"]\n```\n"} - }, { - "label": "Js.Array2.unshiftMany", - "kind": 12, - "tags": [], - "detail": "(t<'a>, array<'a>) => int", - "documentation": {"kind": "markdown", "value": "\nAdds the elements in the second array argument at the beginning of the first\narray argument, returning the new number of elements in the array. *This\nfunction modifies the original array.* See\n[`Array.unshift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)\non MDN.\n\n```res example\nlet arr = [\"d\", \"e\"]\nJs.Array2.unshiftMany(arr, [\"a\", \"b\", \"c\"]) == 5\narr == [\"a\", \"b\", \"c\", \"d\", \"e\"]\n```\n"} - }, { - "label": "Js.Array2.filter", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nApplies the given predicate function (the second argument) to each element in\nthe array; the result is an array of those elements for which the predicate\nfunction returned `true`. See\n[`Array.filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)\non MDN.\n\n```res example\nlet nonEmpty = s => s != \"\"\nJs.Array2.filter([\"abc\", \"\", \"\", \"def\", \"ghi\"], nonEmpty) == [\"abc\", \"def\", \"ghi\"]\n```\n"} - }, { - "label": "Js.Array2.shift", - "kind": 12, - "tags": [], - "detail": "t<'a> => option<'a>", - "documentation": {"kind": "markdown", "value": "\nIf the array is not empty, removes the first element and returns it as\n`Some(value)`; returns `None` if the array is empty. *This function modifies\nthe original array.* See\n[`Array.shift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.shift(arr) == Some(100)\narr == [101, 102, 103, 104]\n\nlet empty: array = []\nJs.Array2.shift(empty) == None\n```\n"} - }, { - "label": "Js.Array2.reduceRight", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('b, 'a) => 'b, 'b) => 'b", - "documentation": {"kind": "markdown", "value": "\nThe `reduceRight()` function takes three parameters: an array, a *reducer\nfunction*, and a beginning accumulator value. The reducer function has two\nparameters: an accumulated value and an element of the array.\n\n`reduceRight()` first calls the reducer function with the beginning value and\nthe last element in the array. The result becomes the new accumulator value,\nwhich is passed in to the reducer function along with the next-to-last element\nin the array. `reduceRight()` proceeds from right to left through the array,\npassing in the result of each stage as the accumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reduceRight()`. See\n[`Array.reduceRight`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight)\non MDN.\n\n**NOTE:** In many cases, `reduce()` and `reduceRight()` give the same result.\nHowever, see the last example here and compare it to the example from\n`reduce()`, where order makes a difference.\n\n```res example\nlet sumOfSquares = (accumulator, item) => accumulator + item * item\n\nJs.Array2.reduceRight([10, 2, 4], sumOfSquares, 0) == 120\nJs.Array2.reduceRight([2.0, 4.0], (acc, item) => item /. acc, 1.0) == 0.5 // 2.0 / (4.0 / 1.0)\n```\n"} - }, { - "label": "Js.Array2.joinWith", - "kind": 12, - "tags": [], - "detail": "(t<'a>, string) => string", - "documentation": {"kind": "markdown", "value": "\nThis function converts each element of the array to a string (via JavaScript)\nand concatenates them, separated by the string given in the first argument,\ninto a single string. See\n[`Array.join`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)\non MDN.\n\n```res example\nJs.Array2.joinWith([\"ant\", \"bee\", \"cat\"], \"--\") == \"ant--bee--cat\"\nJs.Array2.joinWith([\"door\", \"bell\"], \"\") == \"doorbell\"\nJs.Array2.joinWith([2020, 9, 4], \"/\") == \"2020/9/4\"\nJs.Array2.joinWith([2.5, 3.6, 3e-2], \";\") == \"2.5;3.6;0.03\"\n```\n"} - }, { - "label": "Js.Array2.concatMany", - "kind": 12, - "tags": [], - "detail": "(t<'a>, array>) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nThe second argument to `concatMany()` is an array of arrays; these are added at\nthe end of the first argument, returning a new array. See\n[`Array.concat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)\non MDN.\n\n```res example\nJs.Array2.concatMany([\"a\", \"b\", \"c\"], [[\"d\", \"e\"], [\"f\", \"g\", \"h\"]]) == [\n \"a\",\n \"b\",\n \"c\",\n \"d\",\n \"e\",\n \"f\",\n \"g\",\n \"h\",\n ]\n```\n"} - }, { - "label": "Js.Array2.fillInPlace", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nSets all elements of the given array (the first arumgent) to the designated\nvalue (the secon argument), returning the resulting array. *This function\n modifies the original array.*\n\nSee\n[`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.fillInPlace(arr, 99) == [99, 99, 99, 99, 99]\narr == [99, 99, 99, 99, 99]\n```\n"} - }, { - "label": "Js.Array2.isArray", - "kind": 12, - "tags": [], - "detail": "'a => bool", - "documentation": {"kind": "markdown", "value": "\nReturns `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.\n\n```res example\nJs.Array2.isArray([5, 2, 3, 1, 4]) == true\nJs.Array2.isArray(list{5, 2, 3, 1, 4}) == true\nJs.Array2.isArray(\"abcd\") == false\n```\n"} - }, { - "label": "Js.Array2.reduce", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('b, 'a) => 'b, 'b) => 'b", - "documentation": {"kind": "markdown", "value": "\nThe `reduce()` function takes three parameters: an array, a *reducer function*,\nand a beginning accumulator value. The reducer function has two parameters: an\naccumulated value and an element of the array.\n\n`reduce()` first calls the reducer function with the beginning value and the\nfirst element in the array. The result becomes the new accumulator value, which\nis passed in to the reducer function along with the second element in the\narray. `reduce()` proceeds through the array, passing in the result of each\nstage as the accumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reduce()`. See\n[`Array.reduce`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce)\non MDN.\n\n```res example\nlet sumOfSquares = (accumulator, item) => accumulator + item * item\n\nJs.Array2.reduce([10, 2, 4], sumOfSquares, 0) == 120\nJs.Array2.reduce([10, 2, 4], \\\"*\", 1) == 80\nJs.Array2.reduce(\n [\"animal\", \"vegetable\", \"mineral\"],\n (acc, item) => acc + Js.String.length(item),\n 0,\n) == 22 // 6 + 9 + 7\nJs.Array2.reduce([2.0, 4.0], (acc, item) => item /. acc, 1.0) == 2.0 // 4.0 / (2.0 / 1.0)\n```\n"} - }, { - "label": "Js.Array2.copy", - "kind": 12, - "tags": [], - "detail": "t<'a> => t<'a>", - "documentation": {"kind": "markdown", "value": "\nReturns a copy of the entire array. Same as `Js.Array2.Slice(arr, ~start=0,\n~end_=Js.Array2.length(arr))`. See\n[`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\non MDN.\n"} - }, { - "label": "Js.Array2.reducei", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('b, 'a, int) => 'b, 'b) => 'b", - "documentation": {"kind": "markdown", "value": "\nThe `reducei()` function takes three parameters: an array, a *reducer\nfunction*, and a beginning accumulator value. The reducer function has three\nparameters: an accumulated value, an element of the array, and the index of\nthat element.\n\n`reducei()` first calls the reducer function with the beginning value, the\nfirst element in the array, and zero (its index). The result becomes the new\naccumulator value, which is passed to the reducer function along with the\nsecond element in the array and one (its index). `reducei()` proceeds from left\nto right through the array, passing in the result of each stage as the\naccumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reducei()`. See\n[`Array.reduce`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce)\non MDN.\n\n```res example\n// find sum of even-index elements in array\nlet sumOfEvens = (accumulator, item, index) =>\n if mod(index, 2) == 0 {\n accumulator + item\n } else {\n accumulator\n }\n\nJs.Array2.reducei([2, 5, 1, 4, 3], sumOfEvens, 0) == 6\n```\n"} - }, { - "label": "Js.Array2.forEachi", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => unit) => unit", - "documentation": {"kind": "markdown", "value": "\nThe `forEachi()` function applies the function given as the second argument to\neach element in the array. The function you provide takes an item in the array\nand its index number, and returns `unit`. The `forEachi()` function also\nreturns `unit`. You use `forEachi()` when you need to process each element in\nthe array but not return any new array or value; for example, to print the\nitems in an array. See\n[`Array.forEach`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)\non MDN.\n\n```res example\n// display all elements in an array as a numbered list\nJs.Array2.forEachi([\"a\", \"b\", \"c\"], (item, index) => Js.log2(index + 1, item)) == ()\n```\n"} - }, { - "label": "Js.Array2.fillFromInPlace", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a, ~from: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nSets all elements of the given array (the first arumgent) from position `~from`\nto the end to the designated value (the second argument), returning the\nresulting array. *This function modifies the original array.* See\n[`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.fillFromInPlace(arr, 99, ~from=2) == [100, 101, 99, 99, 99]\narr == [100, 101, 99, 99, 99]\n```\n"} - }, { - "label": "Js.Array2.findi", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => bool) => option<'a>", - "documentation": {"kind": "markdown", "value": "\nReturns `Some(value)` for the first element in the array that satisifies the\ngiven predicate function, or `None` if no element satisifies the predicate. The\npredicate function takes an array element and an index as its parameters. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\n// find first positive item at an odd index\nlet positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0\n\nJs.Array2.findi([66, -33, 55, 88, 22], positiveOddElement) == Some(88)\nJs.Array2.findi([66, -33, 55, -88, 22], positiveOddElement) == None\n```\n"} - }, { - "label": "Js.Array2.filteri", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => bool) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nEach element of the given array are passed to the predicate function. The\nreturn value is an array of all those elements for which the predicate function\nreturned `true`.\n\nSee\n[`Array.filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)\non MDN.\n\n```res example\n// keep only positive elements at odd indices\nlet positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0\n\nJs.Array2.filteri([6, 3, 5, 8, 7, -4, 1], positiveOddElement) == [3, 8]\n```\n"} - }, { - "label": "Js.Array2.slice", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~start: int, ~end_: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nReturns a shallow copy of the given array from the `~start` index up to but not\nincluding the `~end_` position. Negative numbers indicate an offset from the\nend of the array. See\n[`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104, 105, 106]\nJs.Array2.slice(arr, ~start=2, ~end_=5) == [102, 103, 104]\nJs.Array2.slice(arr, ~start=-3, ~end_=-1) == [104, 105]\nJs.Array2.slice(arr, ~start=9, ~end_=10) == []\n```\n"} - }, { - "label": "Js.Array2.fromMap", - "kind": 12, - "tags": [], - "detail": "(array_like<'a>, 'a => 'b) => array<'b>", - "documentation": {"kind": "markdown", "value": "\nCreates a new array by applying a function (the second argument) to each item\nin the `array_like` first argument. See\n[`Array.from`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)\non MDN.\n\n```res example\nlet strArr = Js.String.castToArrayLike(\"abcd\")\nlet code = s => Js.String.charCodeAt(0, s)\nJs.Array2.fromMap(strArr, code) == [97.0, 98.0, 99.0, 100.0]\n```\n"} - }, { - "label": "Js.Array2.removeFromInPlace", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~pos: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nRemoves elements from the given array starting at position `~pos` to the end of\nthe array, returning the removed elements. *This function modifies the original\narray.* See\n[`Array.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)\non MDN.\n\n```res example\nlet arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.removeFromInPlace(arr, ~pos=4) == [\"e\", \"f\"]\narr == [\"a\", \"b\", \"c\", \"d\"]\n```\n"} - }, { - "label": "Js.Array2.from", - "kind": 12, - "tags": [], - "detail": "array_like<'a> => array<'a>", - "documentation": {"kind": "markdown", "value": "\nCreates a shallow copy of an array from an array-like object. See\n[`Array.from`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)\non MDN.\n\n```res example\nlet strArr = Js.String.castToArrayLike(\"abcd\")\nJs.Array2.from(strArr) == [\"a\", \"b\", \"c\", \"d\"]\n```\n"} - }, { - "label": "Js.Array2.includes", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a) => bool", - "documentation": {"kind": "markdown", "value": "\nReturns true if the given value is in the array, `false` otherwise. See\n[`Array.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)\non MDN.\n\n```res example\nJs.Array2.includes([\"a\", \"b\", \"c\"], \"b\") == true\nJs.Array2.includes([\"a\", \"b\", \"c\"], \"x\") == false\n```\n"} - }, { - "label": "Js.Array2.find", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => option<'a>", - "documentation": {"kind": "markdown", "value": "\nReturns `Some(value)` for the first element in the array that satisifies the\ngiven predicate function, or `None` if no element satisifies the predicate. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\n// find first negative element\nJs.Array2.find([33, 22, -55, 77, -44], x => x < 0) == Some(-55)\nJs.Array2.find([33, 22, 55, 77, 44], x => x < 0) == None\n```\n"} - }, { - "label": "Js.Array2.reduceRighti", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('b, 'a, int) => 'b, 'b) => 'b", - "documentation": {"kind": "markdown", "value": "\nThe `reduceRighti()` function takes three parameters: an array, a *reducer\nfunction*, and a beginning accumulator value. The reducer function has three\nparameters: an accumulated value, an element of the array, and the index of\nthat element. `reduceRighti()` first calls the reducer function with the\nbeginning value, the last element in the array, and its index (length of array\nminus one). The result becomes the new accumulator value, which is passed in to\nthe reducer function along with the second element in the array and one (its\nindex). `reduceRighti()` proceeds from right to left through the array, passing\nin the result of each stage as the accumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reduceRighti()`. See\n[`Array.reduceRight`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight)\non MDN.\n\n**NOTE:** In many cases, `reducei()` and `reduceRighti()` give the same result.\nHowever, there are cases where the order in which items are processed makes a\ndifference.\n\n```res example\n// find sum of even-index elements in array\nlet sumOfEvens = (accumulator, item, index) =>\n if mod(index, 2) == 0 {\n accumulator + item\n } else {\n accumulator\n }\n\nJs.Array2.reduceRighti([2, 5, 1, 4, 3], sumOfEvens, 0) == 6\n```\n"} - }, { - "label": "Js.Array2.findIndexi", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => bool) => int", - "documentation": {"kind": "markdown", "value": "\nReturns `Some(value)` for the first element in the array that satisifies the\ngiven predicate function, or `None` if no element satisifies the predicate. The\npredicate function takes an array element and an index as its parameters. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\n// find index of first positive item at an odd index\nlet positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0\n\nJs.Array2.findIndexi([66, -33, 55, 88, 22], positiveOddElement) == 3\nJs.Array2.findIndexi([66, -33, 55, -88, 22], positiveOddElement) == -1\n```\n"} - }, { - "label": "Js.Array2.toLocaleString", - "kind": 12, - "tags": [], - "detail": "t<'a> => string", - "documentation": {"kind": "markdown", "value": "\nConverts the array to a string using the conventions of the current locale.\nEach element is converted to a string using JavaScript. Unlike the JavaScript\n`Array.toLocaleString()`, all elements in a ReasonML array must have the same\ntype. See\n[`Array.toLocaleString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString)\non MDN.\n\n```res example\nJs.Array2.toLocaleString([Js.Date.make()])\n// returns \"3/19/2020, 10:52:11 AM\" for locale en_US.utf8\n// returns \"2020-3-19 10:52:11\" for locale de_DE.utf8\n```\n"} - }, { - "label": "Js.Array2.lastIndexOfFrom", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a, ~from: int) => int", - "documentation": {"kind": "markdown", "value": "\nReturns the index of the last element in the array that has the given value,\nsearching from position `~from` down to the start of the array. If the value is\nnot in the array, returns -1. See\n[`Array.lastIndexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)\non MDN.\n\n```res example\nJs.Array2.lastIndexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\", \"d\"], \"a\", ~from=3) == 2\nJs.Array2.lastIndexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\", \"d\"], \"c\", ~from=2) == -1\n```\n"} - }, { - "label": "Js.Array2.copyWithinFromRange", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~to_: int, ~start: int, ~end_: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nCopies starting at element `~start` in the given array up to but not including\n`~end_` to the designated `~to_` position, returning the resulting array. *This\nfunction modifies the original array.* See\n[`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104, 105]\nJs.Array2.copyWithinFromRange(arr, ~start=2, ~end_=5, ~to_=1) == [100, 102, 103, 104, 104, 105]\narr == [100, 102, 103, 104, 104, 105]\n```\n"} - }, { - "label": "Js.Array2.findIndex", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => int", - "documentation": {"kind": "markdown", "value": "\nReturns the index of the first element in the array that satisifies the given\npredicate function, or -1 if no element satisifies the predicate. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\nJs.Array2.findIndex([33, 22, -55, 77, -44], x => x < 0) == 2\nJs.Array2.findIndex([33, 22, 55, 77, 44], x => x < 0) == -1\n```\n"} - }, { - "label": "Js.Array2.removeCountInPlace", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~pos: int, ~count: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nRemoves `~count` elements from the given array starting at position `~pos`,\nreturning the removed elements. *This function modifies the original array.*\nSee\n[`Array.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)\non MDN.\n\n```res example\nlet arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.removeCountInPlace(arr, ~pos=2, ~count=3) == [\"c\", \"d\", \"e\"]\narr == [\"a\", \"b\", \"f\"]\n```\n"} - }, { - "label": "Js.Array2.reverseInPlace", - "kind": 12, - "tags": [], - "detail": "t<'a> => t<'a>", - "documentation": {"kind": "markdown", "value": "\nReturns an array with the elements of the input array in reverse order. *This\nfunction modifies the original array.* See\n[`Array.reverse`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse)\non MDN.\n\n```res example\nlet arr = [\"ant\", \"bee\", \"cat\"]\nJs.Array2.reverseInPlace(arr) == [\"cat\", \"bee\", \"ant\"]\narr == [\"cat\", \"bee\", \"ant\"]\n```\n"} - }, { - "label": "Js.Array2.every", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => bool", - "documentation": {"kind": "markdown", "value": "\nThe first argument to `every()` is an array. The second argument is a predicate\nfunction that returns a boolean. The `every()` function returns `true` if the\npredicate function is true for all items in the given array. If given an empty\narray, returns `true`. See\n[`Array.every`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)\non MDN.\n\n```res example\nlet isEven = x => mod(x, 2) == 0\nJs.Array2.every([6, 22, 8, 4], isEven) == true\nJs.Array2.every([6, 22, 7, 4], isEven) == false\n```\n"} - }, { - "label": "Js.Array2.length", - "kind": 12, - "tags": [], - "detail": "array<'a> => int", - "documentation": {"kind": "markdown", "value": "\nReturns the number of elements in the array. See\n[`Array.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)\non MDN.\n"} - }, { - "label": "Js.Array2.indexOf", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a) => int", - "documentation": {"kind": "markdown", "value": "\nReturns the index of the first element in the array that has the given value.\nIf the value is not in the array, returns -1. See\n[`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)\non MDN.\n\n```res example\nJs.Array2.indexOf([100, 101, 102, 103], 102) == 2\nJs.Array2.indexOf([100, 101, 102, 103], 999) == -1\n```\n"} - }, { - "label": "Js.Array2.unshift", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a) => int", - "documentation": {"kind": "markdown", "value": "\nAdds the given element to the array, returning the new number of elements in\nthe array. *This function modifies the original array.* See\n[`Array.unshift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)\non MDN.\n\n```res example\nlet arr = [\"b\", \"c\", \"d\"]\nJs.Array2.unshift(arr, \"a\") == 4\narr == [\"a\", \"b\", \"c\", \"d\"]\n```\n"} - }, { - "label": "Js.Array2.sortInPlace", - "kind": 12, - "tags": [], - "detail": "t<'a> => t<'a>", - "documentation": {"kind": "markdown", "value": "\nSorts the given array in place and returns the sorted array. JavaScript sorts\nthe array by converting the arguments to UTF-16 strings and sorting them. See\nthe second example with sorting numbers, which does not do a numeric sort.\n*This function modifies the original array.* See\n[`Array.sort`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)\non MDN.\n\n```res example\nlet words = [\"bee\", \"dog\", \"ant\", \"cat\"]\nJs.Array2.sortInPlace(words) == [\"ant\", \"bee\", \"cat\", \"dog\"]\nwords == [\"ant\", \"bee\", \"cat\", \"dog\"]\n\nlet numbers = [3, 30, 10, 1, 20, 2]\nJs.Array2.sortInPlace(numbers) == [1, 10, 2, 20, 3, 30]\nnumbers == [1, 10, 2, 20, 3, 30]\n```\n"} - }, { - "label": "Js.Array2.unsafe_get", - "kind": 12, - "tags": [], - "detail": "(array<'a>, int) => 'a", - "documentation": {"kind": "markdown", "value": "\nReturns the value at the given position in the array if the position is in\nbounds; returns the JavaScript value `undefined` otherwise.\n\n```res example\nlet arr = [100, 101, 102, 103]\nJs.Array2.unsafe_get(arr, 3) == 103\nJs.Array2.unsafe_get(arr, 4) // returns undefined\n```\n"} - }, { - "label": "Js.Array2.some", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => bool", - "documentation": {"kind": "markdown", "value": "\nReturns `true` if the predicate function given as the second argument to\n`some()` returns `true` for any element in the array; `false` otherwise.\n\n```res example\nlet isEven = x => mod(x, 2) == 0\n\nJs.Array2.some([3, 7, 5, 2, 9], isEven) == true\nJs.Array2.some([3, 7, 5, 1, 9], isEven) == false\n```\n"} - }, { - "label": "Js.Array2.map", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => 'b) => t<'b>", - "documentation": {"kind": "markdown", "value": "\nApplies the function (the second argument) to each item in the array, returning\na new array. The result array does not have to have elements of the same type\nas the input array. See\n[`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)\non MDN.\n\n```res example\nJs.Array2.map([12, 4, 8], x => x * x) == [144, 16, 64]\nJs.Array2.map([\"animal\", \"vegetable\", \"mineral\"], Js.String.length) == [6, 9, 7]\n```\n"} - }, { - "label": "Js.Array2.push", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a) => int", - "documentation": {"kind": "markdown", "value": "\nAppends the given value to the array, returning the number of elements in the\nupdated array. *This function modifies the original array.* See\n[`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)\non MDN.\n\n```res example\nlet arr = [\"ant\", \"bee\", \"cat\"]\nJs.Array2.push(arr, \"dog\") == 4\narr == [\"ant\", \"bee\", \"cat\", \"dog\"]\n```\n"} - }, { - "label": "Js.Array2.fillRangeInPlace", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a, ~start: int, ~end_: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nSets the elements of the given array (the first arumgent) from position\n`~start` up to but not including position `~end_` to the designated value (the\nsecond argument), returning the resulting array. *This function modifies the\noriginal array.* See\n[`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.fillRangeInPlace(arr, 99, ~start=1, ~end_=4) == [100, 99, 99, 99, 104]\narr == [100, 99, 99, 99, 104]\n```\n"} - }, { - "label": "Js.Array2.pop", - "kind": 12, - "tags": [], - "detail": "t<'a> => option<'a>", - "documentation": {"kind": "markdown", "value": "\nIf the array is not empty, removes the last element and returns it as\n`Some(value)`; returns `None` if the array is empty. *This function modifies\nthe original array.* See\n[`Array.pop`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.pop(arr) == Some(104)\narr == [100, 101, 102, 103]\n\nlet empty: array = []\nJs.Array2.pop(empty) == None\n```\n"} - }, { - "label": "Js.Array2.somei", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => bool) => bool", - "documentation": {"kind": "markdown", "value": "\nReturns `true` if the predicate function given as the second argument to\n`somei()` returns `true` for any element in the array; `false` otherwise. The\npredicate function has two arguments: an item from the array and the index\nvalue\n\n```res example\n// Does any string in the array\n// have the same length as its index?\n\nlet sameLength = (str, index) => Js.String.length(str) == index\n\n// \"ef\" has length 2 and is it at index 2\nJs.Array2.somei([\"ab\", \"cd\", \"ef\", \"gh\"], sameLength) == true\n// no item has the same length as its index\nJs.Array2.somei([\"a\", \"bc\", \"def\", \"gh\"], sameLength) == false\n```\n"} - }, { - "label": "Js.Array2.append", - "kind": 12, - "tags": [1], - "detail": "(t<'a>, 'a) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: `append` is not type-safe. Use `concat` instead.\n\n"} - }, { - "label": "Js.Array2.unsafe_set", - "kind": 12, - "tags": [], - "detail": "(array<'a>, int, 'a) => unit", - "documentation": {"kind": "markdown", "value": "\nSets the value at the given position in the array if the position is in bounds.\nIf the index is out of bounds, well, “here there be dragons.“\n\n*This function modifies the original array.*\n\n```res example\nlet arr = [100, 101, 102, 103]\nJs.Array2.unsafe_set(arr, 3, 99)\n// result is [100, 101, 102, 99];\n\nJs.Array2.unsafe_set(arr, 4, 88)\n// result is [100, 101, 102, 99, 88]\n\nJs.Array2.unsafe_set(arr, 6, 77)\n// result is [100, 101, 102, 99, 88, <1 empty item>, 77]\n\nJs.Array2.unsafe_set(arr, -1, 66)\n// you don't want to know.\n```\n"} - }, { - "label": "Js.Array2.copyWithin", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~to_: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nCopies from the first element in the given array to the designated `~to_`\nposition, returning the resulting array. *This function modifies the original\narray.* See\n[`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.copyWithin(arr, ~to_=2) == [100, 101, 100, 101, 102]\narr == [100, 101, 100, 101, 102]\n```\n"} - }, { - "label": "Js.Array2.everyi", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => bool) => bool", - "documentation": {"kind": "markdown", "value": "\nThe first argument to `everyi()` is an array. The second argument is a\npredicate function with two arguments: an array element and that element’s\nindex; it returns a boolean. The `everyi()` function returns `true` if the\npredicate function is true for all items in the given array. If given an empty\narray, returns `true`. See\n[`Array.every`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)\non MDN.\n\n```res example\n// determine if all even-index items are positive\nlet evenIndexPositive = (item, index) => mod(index, 2) == 0 ? item > 0 : true\n\nJs.Array2.everyi([6, -3, 5, 8], evenIndexPositive) == true\nJs.Array2.everyi([6, 3, -5, 8], evenIndexPositive) == false\n```\n"} - }, { - "label": "Js.Array2.toString", - "kind": 12, - "tags": [], - "detail": "t<'a> => string", - "documentation": {"kind": "markdown", "value": "\nConverts the array to a string. Each element is converted to a string using\nJavaScript. Unlike the JavaScript `Array.toString()`, all elements in a\nReasonML array must have the same type. See\n[`Array.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString)\non MDN.\n\n```res example\nJs.Array2.toString([3.5, 4.6, 7.8]) == \"3.5,4.6,7.8\"\nJs.Array2.toString([\"a\", \"b\", \"c\"]) == \"a,b,c\"\n```\n"} - }, { - "label": "Js.Array2.spliceInPlace", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~pos: int, ~remove: int, ~add: array<'a>) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nStarting at position `~pos`, remove `~remove` elements and then add the\nelements from the `~add` array. Returns an array consisting of the removed\nitems. *This function modifies the original array.* See\n[`Array.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)\non MDN.\n\n```res example\nlet arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.spliceInPlace(arr, ~pos=2, ~remove=2, ~add=[\"x\", \"y\", \"z\"]) == [\"c\", \"d\"]\narr == [\"a\", \"b\", \"x\", \"y\", \"z\", \"e\", \"f\"]\n\nlet arr2 = [\"a\", \"b\", \"c\", \"d\"]\nJs.Array2.spliceInPlace(arr2, ~pos=3, ~remove=0, ~add=[\"x\", \"y\"]) == []\narr2 == [\"a\", \"b\", \"c\", \"x\", \"y\", \"d\"]\n\nlet arr3 = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.spliceInPlace(arr3, ~pos=9, ~remove=2, ~add=[\"x\", \"y\", \"z\"]) == []\narr3 == [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"x\", \"y\", \"z\"]\n```\n"} - }, { - "label": "Js.Array2.pushMany", - "kind": 12, - "tags": [], - "detail": "(t<'a>, array<'a>) => int", - "documentation": {"kind": "markdown", "value": "\nAppends the values from one array (the second argument) to another (the first\nargument), returning the number of elements in the updated array. *This\nfunction modifies the original array.* See\n[`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)\non MDN.\n\n```res example\nlet arr = [\"ant\", \"bee\", \"cat\"]\nJs.Array2.pushMany(arr, [\"dog\", \"elk\"]) == 5\narr == [\"ant\", \"bee\", \"cat\", \"dog\", \"elk\"]\n```\n"} - }, { - "label": "Js.Array2.copyWithinFrom", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~to_: int, ~from: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nCopies starting at element `~from` in the given array to the designated `~to_`\nposition, returning the resulting array. *This function modifies the original\narray.* See\n[`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.copyWithinFrom(arr, ~from=2, ~to_=0) == [102, 103, 104, 103, 104]\narr == [102, 103, 104, 103, 104]\n```\n"} - }, { - "label": "Js.Array2.forEach", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => unit) => unit", - "documentation": {"kind": "markdown", "value": "\nThe `forEach()` function applies the function given as the second argument to\neach element in the array. The function you provide returns `unit`, and the\n`forEach()` function also returns `unit`. You use `forEach()` when you need to\nprocess each element in the array but not return any new array or value; for\nexample, to print the items in an array. See\n[`Array.forEach`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)\non MDN.\n\n```res example\n// display all elements in an array\nJs.Array2.forEach([\"a\", \"b\", \"c\"], x => Js.log(x)) == ()\n```\n"} - }, { - "label": "Js.Array2.sliceFrom", - "kind": 12, - "tags": [], - "detail": "(t<'a>, int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nReturns a shallow copy of the given array from the given index to the end. See\n[`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\non MDN.\n"} - }, { - "label": "Js.Array2.sortInPlaceWith", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, 'a) => int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nSorts the given array in place and returns the sorted array. *This function\n modifies the original array.*\n\nThe first argument to `sortInPlaceWith()` is a function that compares two items\nfrom the array and returns:\n\n* an integer less than zero if the first item is less than the second item *\nzero if the items are equal * an integer greater than zero if the first item is\ngreater than the second item\n\nSee\n[`Array.sort`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)\non MDN.\n\n```res example\n// sort by word length\nlet words = [\"horse\", \"aardvark\", \"dog\", \"camel\"]\nlet byLength = (s1, s2) => Js.String.length(s1) - Js.String.length(s2)\n\nJs.Array2.sortInPlaceWith(words, byLength) == [\"dog\", \"horse\", \"camel\", \"aardvark\"]\n\n// sort in reverse numeric order\nlet numbers = [3, 30, 10, 1, 20, 2]\nlet reverseNumeric = (n1, n2) => n2 - n1\nJs.Array2.sortInPlaceWith(numbers, reverseNumeric) == [30, 20, 10, 3, 2, 1]\n```\n"} - }, { - "label": "Js.Array2.indexOfFrom", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a, ~from: int) => int", - "documentation": {"kind": "markdown", "value": "\nReturns the index of the first element in the array with the given value. The\nsearch starts at position `~from`. See\n[`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)\non MDN.\n\n```res example\nJs.Array2.indexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\"], \"a\", ~from=2) == 2\nJs.Array2.indexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\"], \"a\", ~from=3) == 4\nJs.Array2.indexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\"], \"b\", ~from=2) == -1\n```\n"} - }] - -Complete src/CompletionPipeChain.res 14:60 -posCursor:[14:60] posNoWhite:[14:59] Found expr:[14:26->0:-1] -Completable: Cpath Value[Belt, List, fromArray](Nolabel)-> -[{ - "label": "Belt.List.some2", - "kind": 12, - "tags": [], - "detail": "(t<'a>, t<'b>, ('a, 'b) => bool) => bool", - "documentation": {"kind": "markdown", "value": "\n Returns `true` if predicate `pred(a, b)` is true for any pair of elements up\n to the shorter length (i.e. `min(length(firstList), length(secondList))`)\n\n ```res example\n Belt.List.some2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) /* true */\n\n Belt.List.some2(list{}, list{1}, (a, b) => a > b) /* false */\n\n Belt.List.some2(list{2, 3}, list{1}, (a, b) => a > b) /* true */\n\n Belt.List.some2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* true */\n ```\n"} - }, { - "label": "Belt.List.concat", - "kind": 12, - "tags": [], - "detail": "(t<'a>, t<'a>) => t<'a>", - "documentation": {"kind": "markdown", "value": "\n Returns the list obtained by adding `secondList` after `firstList`.\n\n ```res example\n Belt.List.concat(list{1, 2, 3}, list{4, 5}) // list{1, 2, 3, 4, 5}\n ```\n"} - }, { - "label": "Belt.List.mapReverse", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => 'b) => t<'b>", - "documentation": {"kind": "markdown", "value": "\n Equivalent to:\n\n ```res\n map(someList, f)->reverse\n ```\n\n ```res example\n list{3, 4, 5}->Belt.List.mapReverse(x => x * x) /* list{25, 16, 9} */\n ```\n"} - }, { - "label": "Belt.List.keepWithIndex", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => bool) => t<'a>", - "documentation": {"kind": "markdown", "value": "\n Returns a list of all elements in `someList` which satisfy the predicate function `pred`.\n\n ```res example\n let isEven = x => mod(x, 2) == 0\n\n Belt.List.keepWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) /* list{1, 3} */\n ```\n"} - }, { - "label": "Belt.List.getExn", - "kind": 12, - "tags": [], - "detail": "(t<'a>, int) => 'a", - "documentation": {"kind": "markdown", "value": "\n Same as [get](#get), but raises an exception if `index` is larger than the\n length. Use with care.\n\n ```res example\n let abc = list{\"A\", \"B\", \"C\"}\n\n abc->Belt.List.getExn(1) // \"B\"\n\n abc->Belt.List.getExn(4) // Raises an Error\n ```\n"} - }, { - "label": "Belt.List.reduceReverse", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'b, ('b, 'a) => 'b) => 'b", - "documentation": {"kind": "markdown", "value": "\n Works like [reduce](#reduce), except that function `f` is applied to each\n item of `someList` from the last back to the first.\n\n ```res example\n list{1, 2, 3, 4}->Belt.List.reduceReverse(0, (a, b) => a + b) /* 10 */\n\n list{1, 2, 3, 4}->Belt.List.reduceReverse(10, (a, b) => a - b) /* 0 */\n\n list{1, 2, 3, 4}->Belt.List.reduceReverse(list{}, Belt.List.add) // list{1, 2, 3, 4}\n ```\n"} - }, { - "label": "Belt.List.size", - "kind": 12, - "tags": [], - "detail": "t<'a> => int", - "documentation": {"kind": "markdown", "value": " **See** [`length`](##length) "} - }, { - "label": "Belt.List.concatMany", - "kind": 12, - "tags": [], - "detail": "array> => t<'a>", - "documentation": {"kind": "markdown", "value": "\n Returns the list obtained by concatenating all the lists in array `a`, in\n order.\n\n ```res example\n Belt.List.concatMany([list{1, 2, 3}, list{}, list{3}]) // list{1, 2, 3, 3}\n ```\n"} - }, { - "label": "Belt.List.toArray", - "kind": 12, - "tags": [], - "detail": "t<'a> => array<'a>", - "documentation": {"kind": "markdown", "value": "\n Converts the given list to an array.\n\n ```res example\n Belt.List.toArray(list{1, 2, 3}) // [1, 2, 3]\n ```\n"} - }, { - "label": "Belt.List.keepMapU", - "kind": 12, - "tags": [], - "detail": "(t<'a>, (. 'a) => option<'b>) => t<'b>", - "documentation": {"kind": "markdown", "value": " Uncurried version of [keepMap](#keepMap). "} - }, { - "label": "Belt.List.shuffle", - "kind": 12, - "tags": [], - "detail": "t<'a> => t<'a>", - "documentation": {"kind": "markdown", "value": "\n Returns a new list in random order.\n\n ```res example\n Belt.List.shuffle(list{1, 2, 3}) // list{2, 1, 3}\n ```\n"} - }, { - "label": "Belt.List.makeBy", - "kind": 12, - "tags": [], - "detail": "(int, int => 'a) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nReturn a list of length `numItems` with element `i` initialized with `f(i)`.\nReturns an empty list if `numItems` is negative.\n\n```res example\nBelt.List.makeBy(5, i => i) // list{0, 1, 2, 3, 4}\n\nBelt.List.makeBy(5, i => i * i) // list{0, 1, 4, 9, 16}\n```\n"} - }, { - "label": "Belt.List.take", - "kind": 12, - "tags": [], - "detail": "(t<'a>, int) => option>", - "documentation": {"kind": "markdown", "value": "\nReturns a list with the first `n` elements from `someList`, or `None` if `someList` has fewer than `n` elements.\n\n```res example\nlist{1, 2, 3}->Belt.List.take(1) // Some(list{1})\n\nlist{1, 2, 3}->Belt.List.take(2) // Some(list{1, 2})\n\nlist{1, 2, 3}->Belt.List.take(4) // None\n```\n"} - }, { - "label": "Belt.List.hasAssocU", - "kind": 12, - "tags": [], - "detail": "(t<('a, 'c)>, 'b, (. 'a, 'b) => bool) => bool", - "documentation": {"kind": "markdown", "value": " Uncurried version of [hasAssoc](#hasAssoc). "} - }, { - "label": "Belt.List.zip", - "kind": 12, - "tags": [], - "detail": "(t<'a>, t<'b>) => t<('a, 'b)>", - "documentation": {"kind": "markdown", "value": "\n Returns a list of pairs from the two lists with the length of the shorter list.\n\n ```res example\n Belt.List.zip(list{1, 2}, list{3, 4, 5}) // list{(1, 3), (2, 4)}\n ```\n"} - }, { - "label": "Belt.List.reduceReverse2", - "kind": 12, - "tags": [], - "detail": "(t<'a>, t<'b>, 'c, ('c, 'a, 'b) => 'c) => 'c", - "documentation": {"kind": "markdown", "value": "\n Applies `f` to each element of `firstList` and `secondList` from end to\n beginning. Stops with the shorter list. Function `f` has three parameters: an\n “accumulator” which starts with a value of init, an item from `firstList`,\n and an item from `secondList`. `reduce2` returns the final value of the\n accumulator.\n\n ```res example\n Belt.List.reduceReverse2(list{1, 2, 3}, list{4, 5}, 0, (acc, x, y) => acc + x * x + y) /* + (1 * 1 + 4) + (2 * 2 + 5) */\n ```\n"} - }, { - "label": "Belt.List.headExn", - "kind": 12, - "tags": [], - "detail": "t<'a> => 'a", - "documentation": {"kind": "markdown", "value": "\n Same as [head](#head), but raises an exception if `someList` is empty. Use\n with care.\n\n ```res example\n Belt.List.headExn(list{1, 2, 3}) // 1\n\n Belt.List.headExn(list{}) // Raises an Error\n ```\n"} - }, { - "label": "Belt.List.reduceU", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'b, (. 'b, 'a) => 'b) => 'b", - "documentation": {"kind": "markdown", "value": " Uncurried version of [reduce](#reduce). "} - }, { - "label": "Belt.List.cmpU", - "kind": 12, - "tags": [], - "detail": "(t<'a>, t<'a>, (. 'a, 'a) => int) => int", - "documentation": {"kind": "markdown", "value": " Uncurried version of [cmp](#cmp). "} - }, { - "label": "Belt.List.make", - "kind": 12, - "tags": [], - "detail": "(int, 'a) => t<'a>", - "documentation": {"kind": "markdown", "value": "\n Returns a list of length `numItems` with each element filled with value `v`. Returns an empty list if `numItems` is negative.\n\n ```res example\n Belt.List.make(3, 1) // list{1, 1, 1}\n ```\n"} - }, { - "label": "Belt.List.removeAssocU", - "kind": 12, - "tags": [], - "detail": "(t<('a, 'c)>, 'b, (. 'a, 'b) => bool) => t<('a, 'c)>", - "documentation": {"kind": "markdown", "value": " Uncurried version of [removeAssoc](#removeAssoc). "} - }, { - "label": "Belt.List.someU", - "kind": 12, - "tags": [], - "detail": "(t<'a>, (. 'a) => bool) => bool", - "documentation": {"kind": "markdown", "value": " Uncurried version of [some](#some). "} - }, { - "label": "Belt.List.sort", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, 'a) => int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\n Returns a sorted list.\n\n ```res example\n Belt.List.sort(list{5, 4, 9, 3, 7}, (a, b) => a - b) // list{3, 4, 5, 7, 9}\n ```\n"} - }, { - "label": "Belt.List.length", - "kind": 12, - "tags": [], - "detail": "t<'a> => int", - "documentation": {"kind": "markdown", "value": "\n Returns the length of a list.\n\n ```res example\n Belt.List.length(list{1, 2, 3}) // 3\n ```\n"} - }, { - "label": "Belt.List.zipByU", - "kind": 12, - "tags": [], - "detail": "(t<'a>, t<'b>, (. 'a, 'b) => 'c) => t<'c>", - "documentation": {"kind": "markdown", "value": " Uncurried version of [zipBy](#zipBy). "} - }, { - "label": "Belt.List.mapReverse2U", - "kind": 12, - "tags": [], - "detail": "(t<'a>, t<'b>, (. 'a, 'b) => 'c) => t<'c>", - "documentation": {"kind": "markdown", "value": " Uncurried version of [mapReverse2](#mapReverse2). "} - }, { - "label": "Belt.List.every", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => bool", - "documentation": {"kind": "markdown", "value": "\n Returns `true` if all elements satisfy `pred`, where `pred` is a predicate: a function taking an element and returning a bool.\n\n ```res example\n let isBelow10 = value => value < 10\n\n list{1, 9, 8, 2}->Belt.List.every(isBelow10) /* true */\n\n list{1, 99, 8, 2}->Belt.List.every(isBelow10) /* false */\n ```\n"} - }, { - "label": "Belt.List.every2U", - "kind": 12, - "tags": [], - "detail": "(t<'a>, t<'b>, (. 'a, 'b) => bool) => bool", - "documentation": {"kind": "markdown", "value": " Uncurried version of [every2](#every2). "} - }, { - "label": "Belt.List.forEach2U", - "kind": 12, - "tags": [], - "detail": "(t<'a>, t<'b>, (. 'a, 'b) => 'c) => unit", - "documentation": {"kind": "markdown", "value": " Uncurried version of [forEach2](#forEach2). "} - }, { - "label": "Belt.List.setAssocU", - "kind": 12, - "tags": [], - "detail": "(t<('a, 'c)>, 'a, 'c, (. 'a, 'a) => bool) => t<('a, 'c)>", - "documentation": {"kind": "markdown", "value": " Uncurried version of [setAssoc](#setAssoc). "} - }, { - "label": "Belt.List.map", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => 'b) => t<'b>", - "documentation": {"kind": "markdown", "value": "\n Returns a new list with `f` applied to each element of `someList`.\n\n ```res example\n list{1, 2}->Belt.List.map(x => x + 1) // list{3, 4}\n ```\n"} - }, { - "label": "Belt.List.zipBy", - "kind": 12, - "tags": [], - "detail": "(t<'a>, t<'b>, ('a, 'b) => 'c) => t<'c>", - "documentation": {"kind": "markdown", "value": "\n **See:** [zip](#zip)\n\n ```res example\n Belt.List.zipBy(list{1, 2, 3}, list{4, 5}, (a, b) => 2 * a + b) // list{6, 9}\n ```\n"} - }, { - "label": "Belt.List.reduce2", - "kind": 12, - "tags": [], - "detail": "(t<'b>, t<'c>, 'a, ('a, 'b, 'c) => 'a) => 'a", - "documentation": {"kind": "markdown", "value": "\n Applies `f` to each element of `firstList` and `secondList` from beginning to end. Stops with the shorter list. Function `f` has three parameters: an “accumulator” which starts with a value of `initialValue`, an item from `firstList`, and an item from `secondList`. `reduce2` returns the final value of the accumulator.\n\n ```res example\n 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) */\n ```\n"} - }, { - "label": "Belt.List.some2U", - "kind": 12, - "tags": [], - "detail": "(t<'a>, t<'b>, (. 'a, 'b) => bool) => bool", - "documentation": {"kind": "markdown", "value": " Uncurried version of [some2](#some2). "} - }, { - "label": "Belt.List.mapWithIndexU", - "kind": 12, - "tags": [], - "detail": "(t<'a>, (. int, 'a) => 'b) => t<'b>", - "documentation": {"kind": "markdown", "value": " Uncurried version of [mapWithIndex](#mapWithIndex). "} - }, { - "label": "Belt.List.reduceWithIndexU", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'b, (. 'b, 'a, int) => 'b) => 'b", - "documentation": {"kind": "markdown", "value": " Uncurried version of [reduceWithIndex](#reduceWithIndex). "} - }, { - "label": "Belt.List.keep", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => t<'a>", - "documentation": {"kind": "markdown", "value": "\n Returns a list of all elements in `someList` which satisfy the predicate function `pred`.\n\n ```res example\n let isEven = x => mod(x, 2) == 0\n\n Belt.List.keep(list{1, 2, 3, 4}, isEven) /* list{2, 4} */\n\n Belt.List.keep(list{None, Some(2), Some(3), None}, Belt.Option.isSome) /* list{Some(2), Some(3)} */\n ```\n"} - }, { - "label": "Belt.List.forEachU", - "kind": 12, - "tags": [], - "detail": "(t<'a>, (. 'a) => 'b) => unit", - "documentation": {"kind": "markdown", "value": " Uncurried version of [forEach](#forEach). "} - }, { - "label": "Belt.List.every2", - "kind": 12, - "tags": [], - "detail": "(t<'a>, t<'b>, ('a, 'b) => bool) => bool", - "documentation": {"kind": "markdown", "value": "\n Returns `true` if predicate `pred(a, b)` is `true` for all pairs of elements\n up to the shorter length (i.e. `min(length(firstList), length(secondList))`)\n\n ```res example\n Belt.List.every2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) /* true */\n\n Belt.List.every2(list{}, list{1}, (a, b) => a > b) /* true */\n\n Belt.List.every2(list{2, 3}, list{1}, (a, b) => a > b) /* true */\n\n Belt.List.every2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* false */\n ```\n"} - }, { - "label": "Belt.List.mapU", - "kind": 12, - "tags": [], - "detail": "(t<'a>, (. 'a) => 'b) => t<'b>", - "documentation": {"kind": "markdown", "value": " Uncurried version of [map](#map). "} - }, { - "label": "Belt.List.reverse", - "kind": 12, - "tags": [], - "detail": "t<'a> => t<'a>", - "documentation": {"kind": "markdown", "value": "\n Returns a new list whose elements are those of `someList` in reversed order.\n\n ```res example\n Belt.List.reverse(list{1, 2, 3}) /* list{3, 2, 1} */\n ```\n"} - }, { - "label": "Belt.List.cmp", - "kind": 12, - "tags": [], - "detail": "(t<'a>, t<'a>, ('a, 'a) => int) => int", - "documentation": {"kind": "markdown", "value": "\n Compare elements one by one `compareFn(a, b)`. `compareFn` returns a negative number if `a` is \"less than\" `b`, zero if `a` is \"equal to\" `b`, a positive number if `a` is \"greater than\" `b`.\n\n The comparison returns the first non-zero result of `compareFn`, or zero if `compareFn` returns zero for all `a` and `b`.\n\n If all items have compared equal, but `firstList` is exhausted first, return `-1`. (`firstList` is shorter).\n If all items have compared equal, but `secondList` is exhausted first, return `1` (`firstList` is longer).\n\n ```res example\n Belt.List.cmp(list{3}, list{3, 7}, (a, b) => compare(a, b)) /* (-1) */\n\n Belt.List.cmp(list{5, 3}, list{5}, (a, b) => compare(a, b)) /* 1 */\n\n Belt.List.cmp(list{1, 3, 5}, list{1, 4, 2}, (a, b) => compare(a, b)) /* (-1) */\n\n Belt.List.cmp(list{1, 3, 5}, list{1, 2, 3}, (a, b) => compare(a, b)) /* 1 */\n\n Belt.List.cmp(list{1, 3, 5}, list{1, 3, 5}, (a, b) => compare(a, b)) /* 0 */\n ```\n\n **Please note:** The total ordering of List is different from Array,\n for Array, we compare the length first and, only if the lengths are equal, elements one by one.\n For lists, we just compare elements one by one.\n"} - }, { - "label": "Belt.List.eqU", - "kind": 12, - "tags": [], - "detail": "(t<'a>, t<'a>, (. 'a, 'a) => bool) => bool", - "documentation": {"kind": "markdown", "value": " Uncurried version of [eq](#eq). "} - }, { - "label": "Belt.List.sortU", - "kind": 12, - "tags": [], - "detail": "(t<'a>, (. 'a, 'a) => int) => t<'a>", - "documentation": {"kind": "markdown", "value": " Uncurried version of [sort](#sort). "} - }, { - "label": "Belt.List.splitAt", - "kind": 12, - "tags": [], - "detail": "(t<'a>, int) => option<(list<'a>, list<'a>)>", - "documentation": {"kind": "markdown", "value": "\n Split the list `someList` at `index`. Returns `None` when the length of `someList` is less than `index`.\n\n ```res example\n list{\"Hello\", \"World\"}->Belt.List.splitAt(1) // Some((list{\"Hello\"}, list{\"World\"}))\n\n list{0, 1, 2, 3, 4}->Belt.List.splitAt(2) // Some((list{0, 1}, list{2, 3, 4}))\n ```\n"} - }, { - "label": "Belt.List.forEachWithIndexU", - "kind": 12, - "tags": [], - "detail": "(t<'a>, (. int, 'a) => 'b) => unit", - "documentation": {"kind": "markdown", "value": " Uncurried version of [forEachWithIndex](#forEachWithIndex). "} - }, { - "label": "Belt.List.hasU", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'b, (. 'a, 'b) => bool) => bool", - "documentation": {"kind": "markdown", "value": " Uncurried version of [has](#has). "} - }, { - "label": "Belt.List.filter", - "kind": 12, - "tags": [1], - "detail": "(t<'a>, 'a => bool) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: This function will soon be deprecated. Please, use `List.keep` instead.\n\n\n Returns a list of all elements in `someList` which satisfy the predicate function `pred`.\n\n ```res example\n let isEven = x => mod(x, 2) == 0\n\n Belt.List.filter(list{1, 2, 3, 4}, isEven) /* list{2, 4} */\n\n Belt.List.filter(list{None, Some(2), Some(3), None}, Belt.Option.isSome) /* list{Some(2), Some(3)} */\n ```\n"} - }, { - "label": "Belt.List.reduceReverseU", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'b, (. 'b, 'a) => 'b) => 'b", - "documentation": {"kind": "markdown", "value": " Uncurried version of [reduceReverse](#reduceReverse). "} - }, { - "label": "Belt.List.hasAssoc", - "kind": 12, - "tags": [], - "detail": "(t<('a, 'c)>, 'b, ('a, 'b) => bool) => bool", - "documentation": {"kind": "markdown", "value": "\n Returns `true` if there is a pair in `someList` where the first element equals `k` as per the predicate function `eqFunction`.\n\n ```res example\n list{(1, \"a\"), (2, \"b\"), (3, \"c\")}->Belt.List.hasAssoc(1, (a, b) => a == b) /* true */\n\n list{(9, \"morning\"), (15, \"afternoon\"), (22, \"night\")}\n ->Belt.List.hasAssoc(25, (k, item) => k /* 25 */ == item /* 9, 5, 22 */) /* false */\n ```\n"} - }, { - "label": "Belt.List.forEachWithIndex", - "kind": 12, - "tags": [], - "detail": "(t<'a>, (int, 'a) => 'b) => unit", - "documentation": {"kind": "markdown", "value": "\n Call `f` on each element of `someList` from beginning to end.\n Function `f` takes two arguments: the index starting from 0 and the element from `someList`. `f` returns `unit`.\n\n ```res example\n Belt.List.forEachWithIndex(list{\"a\", \"b\", \"c\"}, (index, x) => {\n Js.log(\"Item \" ++ Belt.Int.toString(index) ++ \" is \" ++ x)\n })\n /*\n prints:\n Item 0 is a\n Item 1 is b\n Item 2 is cc\n */\n ```\n"} - }, { - "label": "Belt.List.reduce", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'b, ('b, 'a) => 'b) => 'b", - "documentation": {"kind": "markdown", "value": "\n Applies `f` to each element of `someList` from beginning to end. Function `f` has two parameters: the item from the list and an “accumulator”, which starts with a value of `initialValue`. reduce returns the final value of the accumulator.\n\n ```res example\n list{1, 2, 3, 4}->Belt.List.reduce(0, (a, b) => a + b) /* 10 */\n\n /* same as */\n\n list{1, 2, 3, 4}->Belt.List.reduce(0, (acc, item) => acc + item) /* 10 */\n ```\n"} - }, { - "label": "Belt.List.add", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a) => t<'a>", - "documentation": {"kind": "markdown", "value": "\n Adds `value` to the beginning of `someList`.\n\n ```res example\n Belt.List.add(list{2, 3}, 1) // list{1, 2, 3}\n\n Belt.List.add(list{\"World\", \"!\"}, \"Hello\") // list{\"Hello\", \"World\", \"!\"}\n ```\n"} - }, { - "label": "Belt.List.forEach2", - "kind": 12, - "tags": [], - "detail": "(t<'a>, t<'b>, ('a, 'b) => 'c) => unit", - "documentation": {"kind": "markdown", "value": "\n Stops at the length of the shorter list.\n\n ```res example\n Belt.List.forEach2(list{\"Z\", \"Y\"}, list{\"A\", \"B\", \"C\"}, (x, y) => Js.log2(x, y))\n\n /*\n prints:\n \"Z\" \"A\"\n \"Y\" \"B\"\n */\n ```\n"} - }, { - "label": "Belt.List.reduceReverse2U", - "kind": 12, - "tags": [], - "detail": "(t<'a>, t<'b>, 'c, (. 'c, 'a, 'b) => 'c) => 'c", - "documentation": {"kind": "markdown", "value": " Uncurried version of [reduceReverse2](#reduceReverse2). "} - }, { - "label": "Belt.List.cmpByLength", - "kind": 12, - "tags": [], - "detail": "(t<'a>, t<'a>) => int", - "documentation": {"kind": "markdown", "value": "\n Compare two lists solely by length. Returns `-1` if `length(firstList)` is\n less than `length(secondList)`, `0` if `length(firstList)` equals\n `length(secondList)`, and `1` if `length(firstList)` is greater than\n `length(secondList)`.\n\n ```res example\n Belt.List.cmpByLength(list{1, 2}, list{3, 4, 5, 6}) /* -1 */\n\n Belt.List.cmpByLength(list{1, 2, 3}, list{4, 5, 6}) /* = 0 */\n\n Belt.List.cmpByLength(list{1, 2, 3, 4}, list{5, 6}) /* = 1 */\n ```\n"} - }, { - "label": "Belt.List.flatten", - "kind": 12, - "tags": [], - "detail": "t> => t<'a>", - "documentation": {"kind": "markdown", "value": "\n Return the list obtained by concatenating all the lists in list `ls`, in order.\n\n ```res example\n Belt.List.flatten(list{list{1, 2, 3}, list{}, list{3}}) // list{1, 2, 3, 3}\n ```\n"} - }, { - "label": "Belt.List.makeByU", - "kind": 12, - "tags": [], - "detail": "(int, (. int) => 'a) => t<'a>", - "documentation": {"kind": "markdown", "value": " Uncurried version of [makeBy](#makeBy) "} - }, { - "label": "Belt.List.mapReverse2", - "kind": 12, - "tags": [], - "detail": "(t<'a>, t<'b>, ('a, 'b) => 'c) => t<'c>", - "documentation": {"kind": "markdown", "value": "\n Equivalent to: `zipBy(xs, ys, f)->reverse`\n\n ```res example\n\n Belt.List.mapReverse2(list{1, 2, 3}, list{1, 2}, (a, b) => a + b) // list{4, 2}\n ```\n"} - }, { - "label": "Belt.List.getAssoc", - "kind": 12, - "tags": [], - "detail": "(t<('a, 'c)>, 'b, ('a, 'b) => bool) => option<'c>", - "documentation": {"kind": "markdown", "value": "\n Return the second element of a pair in `someList` where the first element equals `k` as per the predicate function `eqFunction`, or `None` if not found.\n\n ```res example\n list{(1, \"a\"), (2, \"b\"), (3, \"c\")}->Belt.List.getAssoc(3, (a, b) => a == b) /* Some(\"c\") */\n\n list{(9, \"morning\"), (15, \"afternoon\"), (22, \"night\")}\n ->Belt.List.getAssoc(15, (k, item) => k /* 15 */ == item /* 9, 5, 22 */)\n /* Some(\"afternoon\") */\n ```\n"} - }, { - "label": "Belt.List.fromArray", - "kind": 12, - "tags": [], - "detail": "array<'a> => t<'a>", - "documentation": {"kind": "markdown", "value": "\n Converts the given array to a list.\n\n ```res example\n Belt.List.fromArray([1, 2, 3]) // list{1, 2, 3}\n ```\n"} - }, { - "label": "Belt.List.reduce2U", - "kind": 12, - "tags": [], - "detail": "(t<'b>, t<'c>, 'a, (. 'a, 'b, 'c) => 'a) => 'a", - "documentation": {"kind": "markdown", "value": " Uncurried version of [reduce2](#reduce2). "} - }, { - "label": "Belt.List.filterWithIndex", - "kind": 12, - "tags": [1], - "detail": "(t<'a>, ('a, int) => bool) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: This function will soon be deprecated. Please, use `List.keepWithIndex` instead.\n\n\n Returns a list of all elements in `someList` which satisfy the predicate function `pred`.\n\n ```res example\n let isEven = x => mod(x, 2) == 0\n\n Belt.List.filterWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) /* list{1, 3} */\n ```\n"} - }, { - "label": "Belt.List.mapWithIndex", - "kind": 12, - "tags": [], - "detail": "(t<'a>, (int, 'a) => 'b) => t<'b>", - "documentation": {"kind": "markdown", "value": "\n Applies `f` to each element of `someList`.\n Function `f` takes two arguments: the index starting from 0 and the element from `someList`, in that order.\n\n ```res example\n list{1, 2, 3}->Belt.List.mapWithIndex((index, x) => index + x) // list{1, 3, 5}\n ```\n"} - }, { - "label": "Belt.List.keepWithIndexU", - "kind": 12, - "tags": [], - "detail": "(t<'a>, (. 'a, int) => bool) => t<'a>", - "documentation": {"kind": "markdown", "value": " Uncurried version of [keepWithIndex](#keepWithIndex). "} - }, { - "label": "Belt.List.keepMap", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => option<'b>) => t<'b>", - "documentation": {"kind": "markdown", "value": "\n Applies `f` to each element of `someList`. If `f(x)` returns `Some(value)`, then `value` is _kept_ in the resulting list.\n If `f(x)` returns `None`, the element is _not_ retained in the result.\n\n ```res example\n let isEven = x => mod(x, 2) == 0\n\n list{1, 2, 3, 4}\n ->Belt.List.keepMap(x =>\n if (isEven(x)) {\n Some(x)\n } else {\n None\n }\n ) /* list{2, 4} */\n\n list{Some(1), Some(2), None}->Belt.List.keepMap(x => x) /* list{1, 2} */\n ```\n"} - }, { - "label": "Belt.List.reduceWithIndex", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'b, ('b, 'a, int) => 'b) => 'b", - "documentation": {"kind": "markdown", "value": "\n Applies `f` to each element of `someList` from beginning to end. Function `f` has three parameters: the item from the list and an “accumulator”, which starts with a value of `initialValue` and the index of each element. `reduceWithIndex` returns the final value of the accumulator.\n\n ```res example\n list{1, 2, 3, 4}->Belt.List.reduceWithIndex(0, (acc, item, index) => acc + item + index) /* 16 */\n ```\n"} - }, { - "label": "Belt.List.some", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => bool", - "documentation": {"kind": "markdown", "value": "\n Returns `true` if at least _one_ of the elements in `someList` satisfies\n `pred`, where `pred` is a predicate: a function taking an element and\n returning a bool.\n\n ```res example\n let isAbove100 = value => value > 100\n\n list{101, 1, 2, 3}->Belt.List.some(isAbove100) /* true */\n\n list{1, 2, 3, 4}->Belt.List.some(isAbove100) /* false */\n ```\n"} - }, { - "label": "Belt.List.partition", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => (t<'a>, t<'a>)", - "documentation": {"kind": "markdown", "value": "\n 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.\n\n In other words:\n\n ```res\n (elementsThatSatisfies, elementsThatDoesNotSatisfy)\n ```\n\n ```res example\n Belt.List.partition(list{1, 2, 3, 4}, x => x > 2) /* (list{3, 4}, list{1, 2}) */\n ```\n"} - }, { - "label": "Belt.List.getByU", - "kind": 12, - "tags": [], - "detail": "(t<'a>, (. 'a) => bool) => option<'a>", - "documentation": {"kind": "markdown", "value": " Uncurried version of [getBy](#getBy). "} - }, { - "label": "Belt.List.reverseConcat", - "kind": 12, - "tags": [], - "detail": "(t<'a>, t<'a>) => t<'a>", - "documentation": {"kind": "markdown", "value": "\n Equivalent to writing: `concat(reverse(firstList, secondList)`\n\n ```res example\n Belt.List.reverseConcat(list{1, 2}, list{3, 4}) // list{2, 1, 3, 4}\n ```\n"} - }, { - "label": "Belt.List.partitionU", - "kind": 12, - "tags": [], - "detail": "(t<'a>, (. 'a) => bool) => (t<'a>, t<'a>)", - "documentation": {"kind": "markdown", "value": " Uncurried version of [partition](#partition). "} - }, { - "label": "Belt.List.head", - "kind": 12, - "tags": [], - "detail": "t<'a> => option<'a>", - "documentation": {"kind": "markdown", "value": "\n Returns `Some(value)` where `value` is the first element in the list, or\n `None` if `someList` is an empty list.\n\n ```res example\n Belt.List.head(list{}) // None\n Belt.List.head(list{1, 2, 3}) // Some(1)\n ```\n"} - }, { - "label": "Belt.List.get", - "kind": 12, - "tags": [], - "detail": "(t<'a>, int) => option<'a>", - "documentation": {"kind": "markdown", "value": "\n Return the nth element in `someList`, or `None` if `index` is larger than the\n length.\n\n ```res example\n let abc = list{\"A\", \"B\", \"C\"}\n\n abc->Belt.List.get(1) // Some(\"B\")\n\n abc->Belt.List.get(4) // None\n ```\n"} - }, { - "label": "Belt.List.setAssoc", - "kind": 12, - "tags": [], - "detail": "(t<('a, 'c)>, 'a, 'c, ('a, 'a) => bool) => t<('a, 'c)>", - "documentation": {"kind": "markdown", "value": "\n If `k` exists in `someList` by satisfying the `eqFunction` predicate, return a new list with the key and value replaced by the new `k` and `v`; otherwise, return a new list with the pair `k`, `v` added to the head of `someList`.\n\n ```res example\n list{(1, \"a\"), (2, \"b\"), (3, \"c\")}->Belt.List.setAssoc(2, \"x\", (a, b) => a == b) /* list{(1, \"a\"), (2, \"x\"), (3, \"c\")} */\n\n list{(1, \"a\"), (3, \"c\")}->Belt.List.setAssoc(2, \"b\", (a, b) => a == b) /* list{(2, \"b\"), (1, \"a\"), (3, \"c\")} */\n\n list{(9, \"morning\"), (3, \"morning?!\"), (22, \"night\")}\n ->Belt.List.setAssoc(15, \"afternoon\", (a, b) => mod(a, 12) == mod(b, 12))\n /* list{(9, \"morning\"), (15, \"afternoon\"), (22, \"night\")} */\n ```\n\n **Please note**\n\n In the last example, since: `15 mod 12` equals `3 mod 12`\n\n Both the key _and_ the value are replaced in the list.\n"} - }, { - "label": "Belt.List.tail", - "kind": 12, - "tags": [], - "detail": "t<'a> => option>", - "documentation": {"kind": "markdown", "value": "\n Returns `None` if `someList` is empty, otherwise it returns `Some(tail)`\n where `tail` is everything except the first element of `someList`.\n\n ```res example\n Belt.List.tail(list{1, 2, 3}) // Some(list{2, 3})\n\n Belt.List.tail(list{}) // None\n ```\n"} - }, { - "label": "Belt.List.drop", - "kind": 12, - "tags": [], - "detail": "(t<'a>, int) => option>", - "documentation": {"kind": "markdown", "value": "\n Return a new list, dropping the first `n` elements. Returns `None` if `someList` has fewer than `n` elements.\n\n ```res example\n list{1, 2, 3}->Belt.List.drop(2) // Some(list{3})\n\n list{1, 2, 3}->Belt.List.drop(3) // Some(list{})\n\n list{1, 2, 3}->Belt.List.drop(4) // None\n ```\n"} - }, { - "label": "Belt.List.everyU", - "kind": 12, - "tags": [], - "detail": "(t<'a>, (. 'a) => bool) => bool", - "documentation": {"kind": "markdown", "value": " Uncurried version of [every](#every). "} - }, { - "label": "Belt.List.tailExn", - "kind": 12, - "tags": [], - "detail": "t<'a> => t<'a>", - "documentation": {"kind": "markdown", "value": "\n Same as [tail](#tail), but raises an exception if `someList` is empty. Use\n with care.\n\n ```res example\n Belt.List.tailExn(list{1, 2, 3}) // list{2, 3}\n\n Belt.List.tailExn(list{}) // Raises an Error\n ```\n"} - }, { - "label": "Belt.List.mapReverseU", - "kind": 12, - "tags": [], - "detail": "(t<'a>, (. 'a) => 'b) => t<'b>", - "documentation": {"kind": "markdown", "value": " Uncurried version of [mapReverse](#mapReverse). "} - }, { - "label": "Belt.List.unzip", - "kind": 12, - "tags": [], - "detail": "t<('a, 'b)> => (t<'a>, t<'b>)", - "documentation": {"kind": "markdown", "value": "\n Takes a list of pairs and creates a pair of lists. The first list contains all the first items of the pairs; the second list contains all the second items.\n\n ```res example\n Belt.List.unzip(list{(1, 2), (3, 4)}) /* (list{1, 3}, list{2, 4}) */\n\n Belt.List.unzip(list{(\"H\", \"W\"), (\"e\", \"o\"), (\"l\", \"r\"), (\"l\", \"l\"), (\"o\", \"d\"), (\" \", \"!\")})\n /* (list{\"H\", \"e\", \"l\", \"l\", \"o\", \" \"}, list{\"W\", \"o\", \"r\", \"l\", \"d\", \"!\"}) */\n ```\n"} - }, { - "label": "Belt.List.has", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'b, ('a, 'b) => bool) => bool", - "documentation": {"kind": "markdown", "value": "\n Returns `true` if the list contains at least one element for which\n `eqFunction(x)` returns true.\n\n ```res example\n list{1, 2, 3}->Belt.List.has(2, (a, b) => a == b) /* true */\n\n list{1, 2, 3}->Belt.List.has(4, (a, b) => a == b) /* false */\n\n list{(-1), (-2), (-3)}->Belt.List.has(2, (a, b) => abs(a) == abs(b)) /* true */\n ```\n"} - }, { - "label": "Belt.List.forEach", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => 'b) => unit", - "documentation": {"kind": "markdown", "value": "\n Call `f` on each element of `someList` from the beginning to end.\n `f` returns `unit`, so no new array is created. Use `forEach` when you are primarily concerned with repetitively creating side effects.\n\n ```res example\n Belt.List.forEach(list{\"a\", \"b\", \"c\"}, x => Js.log(\"Item: \" ++ x))\n /*\n prints:\n Item: a\n Item: b\n Item: c\n */\n ```\n"} - }, { - "label": "Belt.List.eq", - "kind": 12, - "tags": [], - "detail": "(t<'a>, t<'a>, ('a, 'a) => bool) => bool", - "documentation": {"kind": "markdown", "value": "\n Check equality of `firstList` and `secondList` using `eqElem` for equality on\n elements, where `eqElem` is a function that returns `true` if items `x` and\n `y` meet some criterion for equality, `false` otherwise. eq `false` if length\n of `firstList` and `secondList` are not the same.\n\n ```res example\n Belt.List.eq(list{1, 2, 3}, list{1, 2}, (a, b) => a == b) /* false */\n\n Belt.List.eq(list{1, 2}, list{1, 2}, (a, b) => a == b) /* true */\n\n Belt.List.eq(list{1, 2, 3}, list{(-1), (-2), (-3)}, (a, b) => abs(a) == abs(b)) /* true */\n ```\n"} - }, { - "label": "Belt.List.getBy", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => option<'a>", - "documentation": {"kind": "markdown", "value": "\n Returns `Some(value)` for the first value in `someList` that satisfies the\n predicate function `pred`. Returns `None` if no element satisfies the function.\n\n ```res example\n Belt.List.getBy(list{1, 4, 3, 2}, x => x > 3) /* Some(4) */\n\n Belt.List.getBy(list{1, 4, 3, 2}, x => x > 4) /* None */\n ```\n"} - }, { - "label": "Belt.List.getAssocU", - "kind": 12, - "tags": [], - "detail": "(t<('a, 'c)>, 'b, (. 'a, 'b) => bool) => option<'c>", - "documentation": {"kind": "markdown", "value": " Uncurried version of [getAssoc](#getAssoc). "} - }, { - "label": "Belt.List.keepU", - "kind": 12, - "tags": [], - "detail": "(t<'a>, (. 'a) => bool) => t<'a>", - "documentation": {"kind": "markdown", "value": " Uncurried version of [keep](#keep). "} - }, { - "label": "Belt.List.removeAssoc", - "kind": 12, - "tags": [], - "detail": "(t<('a, 'c)>, 'b, ('a, 'b) => bool) => t<('a, 'c)>", - "documentation": {"kind": "markdown", "value": "\n Return a list after removing the first pair whose first value is `k` per the equality predicate `eqFunction`; if not found, return a new list identical to `someList`.\n\n ```res example\n list{(1, \"a\"), (2, \"b\"), (3, \"c\")}->Belt.List.removeAssoc(1, (a, b) => a == b) /* list{(2, \"b\"), (3, \"c\")} */\n\n list{(9, \"morning\"), (15, \"afternoon\"), (22, \"night\")}\n ->Belt.List.removeAssoc(9, (k, item) => k /* 9 */ == item /* 9, 5, 22 */)\n /* list{(15, \"afternoon\"), (22, \"night\")} */\n ```\n"} + "detail": "int => t", + "documentation": null }] -Complete src/CompletionPipeChain.res 17:61 -posCursor:[17:61] posNoWhite:[17:60] Found expr:[17:11->17:61] -Pexp_apply ...[17:25->17:26] (...[17:11->17:25], ...[17:26->17:61]) -posCursor:[17:61] posNoWhite:[17:60] Found expr:[17:26->17:61] -Completable: Cpath Value[Belt, List, fromArray](Nolabel)->s +Complete src/CompletionPipeChain.res 30:23 +posCursor:[30:23] posNoWhite:[30:22] Found expr:[30:11->0:-1] +Completable: Cpath Value[toFlt](Nolabel)-> [{ - "label": "Belt.List.some2", - "kind": 12, - "tags": [], - "detail": "(t<'a>, t<'b>, ('a, 'b) => bool) => bool", - "documentation": {"kind": "markdown", "value": "\n Returns `true` if predicate `pred(a, b)` is true for any pair of elements up\n to the shorter length (i.e. `min(length(firstList), length(secondList))`)\n\n ```res example\n Belt.List.some2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) /* true */\n\n Belt.List.some2(list{}, list{1}, (a, b) => a > b) /* false */\n\n Belt.List.some2(list{2, 3}, list{1}, (a, b) => a > b) /* true */\n\n Belt.List.some2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* true */\n ```\n"} - }, { - "label": "Belt.List.size", - "kind": 12, - "tags": [], - "detail": "t<'a> => int", - "documentation": {"kind": "markdown", "value": " **See** [`length`](##length) "} - }, { - "label": "Belt.List.shuffle", - "kind": 12, - "tags": [], - "detail": "t<'a> => t<'a>", - "documentation": {"kind": "markdown", "value": "\n Returns a new list in random order.\n\n ```res example\n Belt.List.shuffle(list{1, 2, 3}) // list{2, 1, 3}\n ```\n"} - }, { - "label": "Belt.List.someU", - "kind": 12, - "tags": [], - "detail": "(t<'a>, (. 'a) => bool) => bool", - "documentation": {"kind": "markdown", "value": " Uncurried version of [some](#some). "} - }, { - "label": "Belt.List.sort", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, 'a) => int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\n Returns a sorted list.\n\n ```res example\n Belt.List.sort(list{5, 4, 9, 3, 7}, (a, b) => a - b) // list{3, 4, 5, 7, 9}\n ```\n"} - }, { - "label": "Belt.List.setAssocU", - "kind": 12, - "tags": [], - "detail": "(t<('a, 'c)>, 'a, 'c, (. 'a, 'a) => bool) => t<('a, 'c)>", - "documentation": {"kind": "markdown", "value": " Uncurried version of [setAssoc](#setAssoc). "} - }, { - "label": "Belt.List.some2U", - "kind": 12, - "tags": [], - "detail": "(t<'a>, t<'b>, (. 'a, 'b) => bool) => bool", - "documentation": {"kind": "markdown", "value": " Uncurried version of [some2](#some2). "} - }, { - "label": "Belt.List.sortU", + "label": "SuperFloat.fromInteger", "kind": 12, "tags": [], - "detail": "(t<'a>, (. 'a, 'a) => int) => t<'a>", - "documentation": {"kind": "markdown", "value": " Uncurried version of [sort](#sort). "} + "detail": "Integer.t => t", + "documentation": null }, { - "label": "Belt.List.splitAt", + "label": "SuperFloat.toInteger", "kind": 12, "tags": [], - "detail": "(t<'a>, int) => option<(list<'a>, list<'a>)>", - "documentation": {"kind": "markdown", "value": "\n Split the list `someList` at `index`. Returns `None` when the length of `someList` is less than `index`.\n\n ```res example\n list{\"Hello\", \"World\"}->Belt.List.splitAt(1) // Some((list{\"Hello\"}, list{\"World\"}))\n\n list{0, 1, 2, 3, 4}->Belt.List.splitAt(2) // Some((list{0, 1}, list{2, 3, 4}))\n ```\n"} - }, { - "label": "Belt.List.some", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => bool", - "documentation": {"kind": "markdown", "value": "\n Returns `true` if at least _one_ of the elements in `someList` satisfies\n `pred`, where `pred` is a predicate: a function taking an element and\n returning a bool.\n\n ```res example\n let isAbove100 = value => value > 100\n\n list{101, 1, 2, 3}->Belt.List.some(isAbove100) /* true */\n\n list{1, 2, 3, 4}->Belt.List.some(isAbove100) /* false */\n ```\n"} - }, { - "label": "Belt.List.setAssoc", - "kind": 12, - "tags": [], - "detail": "(t<('a, 'c)>, 'a, 'c, ('a, 'a) => bool) => t<('a, 'c)>", - "documentation": {"kind": "markdown", "value": "\n If `k` exists in `someList` by satisfying the `eqFunction` predicate, return a new list with the key and value replaced by the new `k` and `v`; otherwise, return a new list with the pair `k`, `v` added to the head of `someList`.\n\n ```res example\n list{(1, \"a\"), (2, \"b\"), (3, \"c\")}->Belt.List.setAssoc(2, \"x\", (a, b) => a == b) /* list{(1, \"a\"), (2, \"x\"), (3, \"c\")} */\n\n list{(1, \"a\"), (3, \"c\")}->Belt.List.setAssoc(2, \"b\", (a, b) => a == b) /* list{(2, \"b\"), (1, \"a\"), (3, \"c\")} */\n\n list{(9, \"morning\"), (3, \"morning?!\"), (22, \"night\")}\n ->Belt.List.setAssoc(15, \"afternoon\", (a, b) => mod(a, 12) == mod(b, 12))\n /* list{(9, \"morning\"), (15, \"afternoon\"), (22, \"night\")} */\n ```\n\n **Please note**\n\n In the last example, since: `15 mod 12` equals `3 mod 12`\n\n Both the key _and_ the value are replaced in the list.\n"} + "detail": "t => Integer.t", + "documentation": null }] +Complete src/CompletionPipeChain.res 33:38 +posCursor:[33:38] posNoWhite:[33:37] Found expr:[33:11->0:-1] +Completable: Cpath Value[Integer, increment](Nolabel, Nolabel)-> +[] + +Complete src/CompletionPipeChain.res 36:38 +posCursor:[36:38] posNoWhite:[36:37] Found expr:[36:11->0:-1] +Completable: Cpath Value[Integer, increment](Nolabel, Nolabel)-> +[] + From de9123d8eddcd8d725a7b0d1d966e546f33dbb39 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Sat, 17 Dec 2022 18:19:50 +0100 Subject: [PATCH 03/11] attempt to fix completing pipe application --- analysis/src/CompletionBackEnd.ml | 51 +++++-- analysis/src/Hover.ml | 2 +- analysis/src/SharedTypes.ml | 16 +- analysis/tests/src/CompletionPipeChain.res | 10 +- .../src/expected/CompletionPipeChain.res.txt | 138 +++++++++++++++++- 5 files changed, 193 insertions(+), 24 deletions(-) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index b7240a297..6b6e143c7 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -562,6 +562,7 @@ let completionForExporteds iterExported getDeclared ~prefix ~exact ~env with deprecated = declared.deprecated; docstring = declared.docstring; + modulePath = ModulePath.toPathWithoutTip declared.modulePath; } :: !res | _ -> ()); @@ -1152,9 +1153,12 @@ let completionToItem {Completion.name; deprecated; docstring; kind} = ~deprecated ~detail:(detail name kind) ~docstring let completionsGetTypeEnv = function - | {Completion.kind = Value typ; env} :: _ -> Some (typ, env) - | {Completion.kind = ObjLabel typ; env} :: _ -> Some (typ, env) - | {Completion.kind = Field ({typ}, _); env} :: _ -> Some (typ, env) + | {Completion.kind = Value typ; env; modulePath} :: _ -> + Some (typ, env, modulePath) + | {Completion.kind = ObjLabel typ; env; modulePath} :: _ -> + Some (typ, env, modulePath) + | {Completion.kind = Field ({typ}, _); env; modulePath} :: _ -> + Some (typ, env, modulePath) | _ -> None let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos @@ -1185,7 +1189,7 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos ~env ~exact:true ~scope |> completionsGetTypeEnv with - | Some (typ, env) -> ( + | Some (typ, env, modulePath) -> ( let rec reconstructFunctionType args tRet = match args with | [] -> tRet @@ -1216,7 +1220,10 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos | args, tRet when args <> [] -> let args = processApply args labels in let retType = reconstructFunctionType args tRet in - [Completion.create ~name:"dummy" ~env ~kind:(Completion.Value retType)] + [ + Completion.createWithModulePath ~name:"dummy" ~env + ~kind:(Completion.Value retType) ~modulePath; + ] | _ -> []) | None -> []) | CPField (CPId (path, Module), fieldName) -> @@ -1231,19 +1238,20 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos ~env ~exact:true ~scope |> completionsGetTypeEnv with - | Some (typ, env) -> ( + | Some (typ, env, modulePath) -> ( match typ |> extractRecordType ~env ~package with | Some (env, fields, typDecl) -> fields |> Utils.filterMap (fun field -> if checkName field.fname.txt ~prefix:fieldName ~exact then Some - (Completion.create ~name:field.fname.txt ~env + (Completion.createWithModulePath ~name:field.fname.txt ~env ~kind: (Completion.Field ( field, typDecl.item.decl - |> Shared.declToString typDecl.name.txt ))) + |> Shared.declToString typDecl.name.txt )) + ~modulePath) else None) | None -> []) | None -> []) @@ -1254,7 +1262,7 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos ~env ~exact:true ~scope |> completionsGetTypeEnv with - | Some (typ, env) -> ( + | Some (typ, env, modulePath) -> ( match typ |> extractObjectType ~env ~package with | Some (env, tObj) -> let rec getFields (texp : Types.type_expr) = @@ -1270,8 +1278,8 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos |> Utils.filterMap (fun (field, typ) -> if checkName field ~prefix:label ~exact then Some - (Completion.create ~name:field ~env - ~kind:(Completion.ObjLabel typ)) + (Completion.createWithModulePath ~name:field ~env + ~kind:(Completion.ObjLabel typ) ~modulePath) else None) | None -> []) | None -> []) @@ -1282,7 +1290,7 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos ~env ~exact:true ~scope |> completionsGetTypeEnv with - | Some (typ, _envNotUsed) -> ( + | Some (typ, env, completionItemModulePath) -> ( let { arrayModulePath; optionModulePath; @@ -1375,7 +1383,20 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos env (* Restore original env for the completion after x->foo()... *); }) - | [] -> []) + | [] -> + let completions = + completionItemModulePath @ [funNamePrefix] + |> getCompletionsForPath ~completionContext:Value ~exact:false + ~package ~opens ~allFiles ~pos ~env ~scope + in + completions + |> List.map (fun (completion : Completion.t) -> + { + completion with + name = completion.name; + env + (* Restore original env for the completion after x->foo()... *); + })) | None -> []) | None -> []) @@ -1438,7 +1459,7 @@ let processCompletable ~debug ~package ~scope ~env ~pos ~forHover | Cjsx (componentPath, prefix, identsSeen) -> let labels = match componentPath @ ["make"] |> findTypeOfValue with - | Some (typ, make_env) -> + | Some (typ, make_env, _) -> let rec getFieldsV3 (texp : Types.type_expr) = match texp.desc with | Tfield (name, _, t1, t2) -> @@ -1774,7 +1795,7 @@ Note: The `@react.component` decorator requires the react-jsx config to be set i ~env ~exact:true ~scope |> completionsGetTypeEnv with - | Some (typ, _env) -> + | Some (typ, _env, _) -> if debug then Printf.printf "Found type for function %s\n" (typ |> Shared.typeToString); diff --git a/analysis/src/Hover.ml b/analysis/src/Hover.ml index 599852273..adc54fc07 100644 --- a/analysis/src/Hover.ml +++ b/analysis/src/Hover.ml @@ -152,7 +152,7 @@ let getHoverViaCompletions ~debug ~path ~pos ~currentFile ~forHover Some (Protocol.stringifyHover (String.concat "\n\n" parts)) | _ -> ( match CompletionBackEnd.completionsGetTypeEnv completions with - | Some (typ, _env) -> + | Some (typ, _env, _) -> let typeString, _docstring = hoverWithExpandedTypes ~docstring:"" ~file ~package ~supportsMarkdownLinks typ diff --git a/analysis/src/SharedTypes.ml b/analysis/src/SharedTypes.ml index 549c5ea32..07daefb3f 100644 --- a/analysis/src/SharedTypes.ml +++ b/analysis/src/SharedTypes.ml @@ -22,6 +22,16 @@ module ModulePath = struct | NotVisible -> current in loop modulePath [tipName] + + let toPathWithoutTip modulePath : path = + let rec loop modulePath current = + match modulePath with + | File _ -> current + | IncludedModule (_, inner) -> loop inner current + | ExportedModule {name; modulePath = inner} -> loop inner (name :: current) + | NotVisible -> current + in + loop modulePath [] end type field = {stamp: int; fname: string Location.loc; typ: Types.type_expr} @@ -253,10 +263,14 @@ module Completion = struct deprecated: string option; docstring: string list; kind: kind; + modulePath: string list; } let create ~name ~kind ~env = - {name; env; deprecated = None; docstring = []; kind} + {name; env; deprecated = None; docstring = []; kind; modulePath = []} + + let createWithModulePath ~name ~kind ~env ~modulePath = + {name; env; deprecated = None; docstring = []; kind; modulePath} (* https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion *) (* https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#completionItemKind *) diff --git a/analysis/tests/src/CompletionPipeChain.res b/analysis/tests/src/CompletionPipeChain.res index 3864fc278..d4384ded0 100644 --- a/analysis/tests/src/CompletionPipeChain.res +++ b/analysis/tests/src/CompletionPipeChain.res @@ -38,13 +38,13 @@ let f = int->Integer.increment(2) // ^com // let _ = int->Integer.decrement(t => t - 1)-> -// +// ^com // let _ = int->Integer.increment(2)->Integer.decrement(t => t - 1)-> -// +// ^com // let _ = int->Integer.increment(2)->SuperFloat.fromInteger-> -// +// ^com -// let _ = int->Integer.incremebt(2)->SuperFloat.fromInteger->t -// +// let _ = int->Integer.increment(2)->SuperFloat.fromInteger->t +// ^com diff --git a/analysis/tests/src/expected/CompletionPipeChain.res.txt b/analysis/tests/src/expected/CompletionPipeChain.res.txt index 35e75e1cc..bb0ac7635 100644 --- a/analysis/tests/src/expected/CompletionPipeChain.res.txt +++ b/analysis/tests/src/expected/CompletionPipeChain.res.txt @@ -47,10 +47,144 @@ Completable: Cpath Value[toFlt](Nolabel)-> Complete src/CompletionPipeChain.res 33:38 posCursor:[33:38] posNoWhite:[33:37] Found expr:[33:11->0:-1] Completable: Cpath Value[Integer, increment](Nolabel, Nolabel)-> -[] +[{ + "label": "toInt", + "kind": 12, + "tags": [], + "detail": "t => int", + "documentation": null + }, { + "label": "increment", + "kind": 12, + "tags": [], + "detail": "(t, int) => t", + "documentation": null + }, { + "label": "decrement", + "kind": 12, + "tags": [], + "detail": "(t, int => int) => t", + "documentation": null + }, { + "label": "make", + "kind": 12, + "tags": [], + "detail": "int => t", + "documentation": null + }] Complete src/CompletionPipeChain.res 36:38 posCursor:[36:38] posNoWhite:[36:37] Found expr:[36:11->0:-1] Completable: Cpath Value[Integer, increment](Nolabel, Nolabel)-> -[] +[{ + "label": "toInt", + "kind": 12, + "tags": [], + "detail": "t => int", + "documentation": null + }, { + "label": "increment", + "kind": 12, + "tags": [], + "detail": "(t, int) => t", + "documentation": null + }, { + "label": "decrement", + "kind": 12, + "tags": [], + "detail": "(t, int => int) => t", + "documentation": null + }, { + "label": "make", + "kind": 12, + "tags": [], + "detail": "int => t", + "documentation": null + }] + +Complete src/CompletionPipeChain.res 39:47 +posCursor:[39:47] posNoWhite:[39:46] Found expr:[39:11->0:-1] +Completable: Cpath Value[Integer, decrement](Nolabel, Nolabel)-> +[{ + "label": "toInt", + "kind": 12, + "tags": [], + "detail": "t => int", + "documentation": null + }, { + "label": "increment", + "kind": 12, + "tags": [], + "detail": "(t, int) => t", + "documentation": null + }, { + "label": "decrement", + "kind": 12, + "tags": [], + "detail": "(t, int => int) => t", + "documentation": null + }, { + "label": "make", + "kind": 12, + "tags": [], + "detail": "int => t", + "documentation": null + }] + +Complete src/CompletionPipeChain.res 42:69 +posCursor:[42:69] posNoWhite:[42:68] Found expr:[42:11->0:-1] +Completable: Cpath Value[Integer, decrement](Nolabel, Nolabel)-> +[{ + "label": "toInt", + "kind": 12, + "tags": [], + "detail": "t => int", + "documentation": null + }, { + "label": "increment", + "kind": 12, + "tags": [], + "detail": "(t, int) => t", + "documentation": null + }, { + "label": "decrement", + "kind": 12, + "tags": [], + "detail": "(t, int => int) => t", + "documentation": null + }, { + "label": "make", + "kind": 12, + "tags": [], + "detail": "int => t", + "documentation": null + }] + +Complete src/CompletionPipeChain.res 45:62 +posCursor:[45:62] posNoWhite:[45:61] Found expr:[45:11->0:-1] +Completable: Cpath Value[SuperFloat, fromInteger](Nolabel)-> +[{ + "label": "fromInteger", + "kind": 12, + "tags": [], + "detail": "Integer.t => t", + "documentation": null + }, { + "label": "toInteger", + "kind": 12, + "tags": [], + "detail": "t => Integer.t", + "documentation": null + }] + +Complete src/CompletionPipeChain.res 48:63 +posCursor:[48:63] posNoWhite:[48:62] Found expr:[48:11->48:63] +Completable: Cpath Value[SuperFloat, fromInteger](Nolabel)->t +[{ + "label": "toInteger", + "kind": 12, + "tags": [], + "detail": "t => Integer.t", + "documentation": null + }] From d0246a4b587b49c3b0c8c83bf45608e9fa14ee82 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Sat, 17 Dec 2022 22:02:45 +0100 Subject: [PATCH 04/11] fix completing uncompiled across files --- analysis/src/CompletionBackEnd.ml | 4 +- analysis/tests/src/CompletionPipeChain.res | 6 +++ analysis/tests/src/CompletionSupport.res | 6 +++ .../src/expected/CompletionPipeChain.res.txt | 46 +++++++++++++++++++ .../src/expected/CompletionSupport.res.txt | 0 5 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 analysis/tests/src/CompletionSupport.res create mode 100644 analysis/tests/src/expected/CompletionSupport.res.txt diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index 6b6e143c7..40497fe6b 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -562,7 +562,9 @@ let completionForExporteds iterExported getDeclared ~prefix ~exact ~env with deprecated = declared.deprecated; docstring = declared.docstring; - modulePath = ModulePath.toPathWithoutTip declared.modulePath; + modulePath = + [env.file.moduleName] + @ ModulePath.toPathWithoutTip declared.modulePath; } :: !res | _ -> ()); diff --git a/analysis/tests/src/CompletionPipeChain.res b/analysis/tests/src/CompletionPipeChain.res index d4384ded0..17b8949d8 100644 --- a/analysis/tests/src/CompletionPipeChain.res +++ b/analysis/tests/src/CompletionPipeChain.res @@ -48,3 +48,9 @@ let f = int->Integer.increment(2) // let _ = int->Integer.increment(2)->SuperFloat.fromInteger->t // ^com + +// let _ = int->Integer.increment(2)->Integer.toInt->CompletionSupport.Test.make-> +// ^com + +// let _ = CompletionSupport.Test.make(1)->CompletionSupport.Test.addSelf(2)-> +// ^com diff --git a/analysis/tests/src/CompletionSupport.res b/analysis/tests/src/CompletionSupport.res new file mode 100644 index 000000000..371ca57b1 --- /dev/null +++ b/analysis/tests/src/CompletionSupport.res @@ -0,0 +1,6 @@ +module Test = { + type t = {name: int} + let add = (ax: t) => ax.name + 1 + let addSelf = (ax: t) => {name: ax.name + 1} + let make = (name: int): t => {name: name} +} diff --git a/analysis/tests/src/expected/CompletionPipeChain.res.txt b/analysis/tests/src/expected/CompletionPipeChain.res.txt index bb0ac7635..cdb88fe1e 100644 --- a/analysis/tests/src/expected/CompletionPipeChain.res.txt +++ b/analysis/tests/src/expected/CompletionPipeChain.res.txt @@ -188,3 +188,49 @@ Completable: Cpath Value[SuperFloat, fromInteger](Nolabel)->t "documentation": null }] +Complete src/CompletionPipeChain.res 51:82 +posCursor:[51:82] posNoWhite:[51:81] Found expr:[51:11->0:-1] +Completable: Cpath Value[CompletionSupport, Test, make](Nolabel)-> +[{ + "label": "add", + "kind": 12, + "tags": [], + "detail": "t => int", + "documentation": null + }, { + "label": "addSelf", + "kind": 12, + "tags": [], + "detail": "t => t", + "documentation": null + }, { + "label": "make", + "kind": 12, + "tags": [], + "detail": "int => t", + "documentation": null + }] + +Complete src/CompletionPipeChain.res 54:78 +posCursor:[54:78] posNoWhite:[54:77] Found expr:[54:11->0:-1] +Completable: Cpath Value[CompletionSupport, Test, addSelf](Nolabel, Nolabel)-> +[{ + "label": "add", + "kind": 12, + "tags": [], + "detail": "t => int", + "documentation": null + }, { + "label": "addSelf", + "kind": 12, + "tags": [], + "detail": "t => t", + "documentation": null + }, { + "label": "make", + "kind": 12, + "tags": [], + "detail": "int => t", + "documentation": null + }] + diff --git a/analysis/tests/src/expected/CompletionSupport.res.txt b/analysis/tests/src/expected/CompletionSupport.res.txt new file mode 100644 index 000000000..e69de29bb From fbc777df0e8addfe52df88801a9ff0dadec91302 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Sat, 17 Dec 2022 22:19:03 +0100 Subject: [PATCH 05/11] properly qualify completion items --- analysis/src/CompletionBackEnd.ml | 22 +++++++- .../src/expected/CompletionPipeChain.res.txt | 50 +++++++++---------- 2 files changed, 45 insertions(+), 27 deletions(-) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index 40497fe6b..4eff8e778 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -1292,7 +1292,7 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos ~env ~exact:true ~scope |> completionsGetTypeEnv with - | Some (typ, env, completionItemModulePath) -> ( + | Some (typ, _envFromCompletion, completionItemModulePath) -> ( let { arrayModulePath; optionModulePath; @@ -1386,6 +1386,24 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos (* Restore original env for the completion after x->foo()... *); }) | [] -> + (* Module paths coming directly from a completion item is prefixed with + file module name it was found in. We pluck that off here if the env + we're in is the same as the completion item was found in. This ensures + that a correct qualified path can be produced. *) + let modulePath = + match completionItemModulePath with + | topModule :: rest when topModule = env.file.moduleName -> rest + | modulePath -> modulePath + in + let modulePathMinusOpens = + modulePath + |> removeRawOpens package.opens + |> removeRawOpens rawOpens |> String.concat "." + in + let completionName name = + if modulePathMinusOpens = "" then name + else modulePathMinusOpens ^ "." ^ name + in let completions = completionItemModulePath @ [funNamePrefix] |> getCompletionsForPath ~completionContext:Value ~exact:false @@ -1395,7 +1413,7 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos |> List.map (fun (completion : Completion.t) -> { completion with - name = completion.name; + name = completionName completion.name; env (* Restore original env for the completion after x->foo()... *); })) diff --git a/analysis/tests/src/expected/CompletionPipeChain.res.txt b/analysis/tests/src/expected/CompletionPipeChain.res.txt index cdb88fe1e..3df39da0b 100644 --- a/analysis/tests/src/expected/CompletionPipeChain.res.txt +++ b/analysis/tests/src/expected/CompletionPipeChain.res.txt @@ -48,25 +48,25 @@ Complete src/CompletionPipeChain.res 33:38 posCursor:[33:38] posNoWhite:[33:37] Found expr:[33:11->0:-1] Completable: Cpath Value[Integer, increment](Nolabel, Nolabel)-> [{ - "label": "toInt", + "label": "Integer.toInt", "kind": 12, "tags": [], "detail": "t => int", "documentation": null }, { - "label": "increment", + "label": "Integer.increment", "kind": 12, "tags": [], "detail": "(t, int) => t", "documentation": null }, { - "label": "decrement", + "label": "Integer.decrement", "kind": 12, "tags": [], "detail": "(t, int => int) => t", "documentation": null }, { - "label": "make", + "label": "Integer.make", "kind": 12, "tags": [], "detail": "int => t", @@ -77,25 +77,25 @@ Complete src/CompletionPipeChain.res 36:38 posCursor:[36:38] posNoWhite:[36:37] Found expr:[36:11->0:-1] Completable: Cpath Value[Integer, increment](Nolabel, Nolabel)-> [{ - "label": "toInt", + "label": "Integer.toInt", "kind": 12, "tags": [], "detail": "t => int", "documentation": null }, { - "label": "increment", + "label": "Integer.increment", "kind": 12, "tags": [], "detail": "(t, int) => t", "documentation": null }, { - "label": "decrement", + "label": "Integer.decrement", "kind": 12, "tags": [], "detail": "(t, int => int) => t", "documentation": null }, { - "label": "make", + "label": "Integer.make", "kind": 12, "tags": [], "detail": "int => t", @@ -106,25 +106,25 @@ Complete src/CompletionPipeChain.res 39:47 posCursor:[39:47] posNoWhite:[39:46] Found expr:[39:11->0:-1] Completable: Cpath Value[Integer, decrement](Nolabel, Nolabel)-> [{ - "label": "toInt", + "label": "Integer.toInt", "kind": 12, "tags": [], "detail": "t => int", "documentation": null }, { - "label": "increment", + "label": "Integer.increment", "kind": 12, "tags": [], "detail": "(t, int) => t", "documentation": null }, { - "label": "decrement", + "label": "Integer.decrement", "kind": 12, "tags": [], "detail": "(t, int => int) => t", "documentation": null }, { - "label": "make", + "label": "Integer.make", "kind": 12, "tags": [], "detail": "int => t", @@ -135,25 +135,25 @@ Complete src/CompletionPipeChain.res 42:69 posCursor:[42:69] posNoWhite:[42:68] Found expr:[42:11->0:-1] Completable: Cpath Value[Integer, decrement](Nolabel, Nolabel)-> [{ - "label": "toInt", + "label": "Integer.toInt", "kind": 12, "tags": [], "detail": "t => int", "documentation": null }, { - "label": "increment", + "label": "Integer.increment", "kind": 12, "tags": [], "detail": "(t, int) => t", "documentation": null }, { - "label": "decrement", + "label": "Integer.decrement", "kind": 12, "tags": [], "detail": "(t, int => int) => t", "documentation": null }, { - "label": "make", + "label": "Integer.make", "kind": 12, "tags": [], "detail": "int => t", @@ -164,13 +164,13 @@ Complete src/CompletionPipeChain.res 45:62 posCursor:[45:62] posNoWhite:[45:61] Found expr:[45:11->0:-1] Completable: Cpath Value[SuperFloat, fromInteger](Nolabel)-> [{ - "label": "fromInteger", + "label": "SuperFloat.fromInteger", "kind": 12, "tags": [], "detail": "Integer.t => t", "documentation": null }, { - "label": "toInteger", + "label": "SuperFloat.toInteger", "kind": 12, "tags": [], "detail": "t => Integer.t", @@ -181,7 +181,7 @@ Complete src/CompletionPipeChain.res 48:63 posCursor:[48:63] posNoWhite:[48:62] Found expr:[48:11->48:63] Completable: Cpath Value[SuperFloat, fromInteger](Nolabel)->t [{ - "label": "toInteger", + "label": "SuperFloat.toInteger", "kind": 12, "tags": [], "detail": "t => Integer.t", @@ -192,19 +192,19 @@ Complete src/CompletionPipeChain.res 51:82 posCursor:[51:82] posNoWhite:[51:81] Found expr:[51:11->0:-1] Completable: Cpath Value[CompletionSupport, Test, make](Nolabel)-> [{ - "label": "add", + "label": "CompletionSupport.Test.add", "kind": 12, "tags": [], "detail": "t => int", "documentation": null }, { - "label": "addSelf", + "label": "CompletionSupport.Test.addSelf", "kind": 12, "tags": [], "detail": "t => t", "documentation": null }, { - "label": "make", + "label": "CompletionSupport.Test.make", "kind": 12, "tags": [], "detail": "int => t", @@ -215,19 +215,19 @@ Complete src/CompletionPipeChain.res 54:78 posCursor:[54:78] posNoWhite:[54:77] Found expr:[54:11->0:-1] Completable: Cpath Value[CompletionSupport, Test, addSelf](Nolabel, Nolabel)-> [{ - "label": "add", + "label": "CompletionSupport.Test.add", "kind": 12, "tags": [], "detail": "t => int", "documentation": null }, { - "label": "addSelf", + "label": "CompletionSupport.Test.addSelf", "kind": 12, "tags": [], "detail": "t => t", "documentation": null }, { - "label": "make", + "label": "CompletionSupport.Test.make", "kind": 12, "tags": [], "detail": "int => t", From 7f5b3c5804de2313a0bebb7c3ec570384678baab Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Sat, 17 Dec 2022 22:33:59 +0100 Subject: [PATCH 06/11] more sane way of ensuring the file module name gets picked up --- analysis/src/CompletionBackEnd.ml | 6 ++---- analysis/src/SharedTypes.ml | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index 4eff8e778..c2384f46c 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -562,9 +562,7 @@ let completionForExporteds iterExported getDeclared ~prefix ~exact ~env with deprecated = declared.deprecated; docstring = declared.docstring; - modulePath = - [env.file.moduleName] - @ ModulePath.toPathWithoutTip declared.modulePath; + modulePath = ModulePath.toFullPath declared.modulePath; } :: !res | _ -> ()); @@ -1292,7 +1290,7 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos ~env ~exact:true ~scope |> completionsGetTypeEnv with - | Some (typ, _envFromCompletion, completionItemModulePath) -> ( + | Some (typ, _envFromCompletionItem, completionItemModulePath) -> ( let { arrayModulePath; optionModulePath; diff --git a/analysis/src/SharedTypes.ml b/analysis/src/SharedTypes.ml index 07daefb3f..fc6fb8b1e 100644 --- a/analysis/src/SharedTypes.ml +++ b/analysis/src/SharedTypes.ml @@ -23,10 +23,10 @@ module ModulePath = struct in loop modulePath [tipName] - let toPathWithoutTip modulePath : path = + let toFullPath modulePath : path = let rec loop modulePath current = match modulePath with - | File _ -> current + | File (_, fileModule) -> fileModule :: current | IncludedModule (_, inner) -> loop inner current | ExportedModule {name; modulePath = inner} -> loop inner (name :: current) | NotVisible -> current From ac73cad0a77b109bb3f95865ec52b7f93d67fe3a Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Mon, 19 Dec 2022 18:21:33 +0100 Subject: [PATCH 07/11] Small refactor, and store modulePath verbatim. --- analysis/src/CompletionBackEnd.ml | 30 +++++++++++++++--------------- analysis/src/SharedTypes.ml | 4 ++-- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index c2384f46c..9bae7d336 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -562,7 +562,7 @@ let completionForExporteds iterExported getDeclared ~prefix ~exact ~env with deprecated = declared.deprecated; docstring = declared.docstring; - modulePath = ModulePath.toFullPath declared.modulePath; + modulePath = declared.modulePath; } :: !res | _ -> ()); @@ -1358,20 +1358,20 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos | [] -> modulePath in match lhsPath with - | Some modulePath -> ( - match modulePath with + | Some lhsPath -> ( + match lhsPath with | _ :: _ -> - let modulePathMinusOpens = - modulePath + let lhsPathMinusOpens = + lhsPath |> removeRawOpens package.opens |> removeRawOpens rawOpens |> String.concat "." in let completionName name = - if modulePathMinusOpens = "" then name - else modulePathMinusOpens ^ "." ^ name + if lhsPathMinusOpens = "" then name + else lhsPathMinusOpens ^ "." ^ name in let completions = - modulePath @ [funNamePrefix] + lhsPath @ [funNamePrefix] |> getCompletionsForPath ~completionContext:Value ~exact:false ~package ~opens ~allFiles ~pos ~env ~scope in @@ -1388,22 +1388,22 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos file module name it was found in. We pluck that off here if the env we're in is the same as the completion item was found in. This ensures that a correct qualified path can be produced. *) - let modulePath = - match completionItemModulePath with + let completionPath = + match ModulePath.toFullPath completionItemModulePath with | topModule :: rest when topModule = env.file.moduleName -> rest | modulePath -> modulePath in - let modulePathMinusOpens = - modulePath + let completionPathMinusOpens = + completionPath |> removeRawOpens package.opens |> removeRawOpens rawOpens |> String.concat "." in let completionName name = - if modulePathMinusOpens = "" then name - else modulePathMinusOpens ^ "." ^ name + if completionPathMinusOpens = "" then name + else completionPathMinusOpens ^ "." ^ name in let completions = - completionItemModulePath @ [funNamePrefix] + completionPath @ [funNamePrefix] |> getCompletionsForPath ~completionContext:Value ~exact:false ~package ~opens ~allFiles ~pos ~env ~scope in diff --git a/analysis/src/SharedTypes.ml b/analysis/src/SharedTypes.ml index fc6fb8b1e..b38ecb001 100644 --- a/analysis/src/SharedTypes.ml +++ b/analysis/src/SharedTypes.ml @@ -263,11 +263,11 @@ module Completion = struct deprecated: string option; docstring: string list; kind: kind; - modulePath: string list; + modulePath: ModulePath.t; } let create ~name ~kind ~env = - {name; env; deprecated = None; docstring = []; kind; modulePath = []} + {name; env; deprecated = None; docstring = []; kind; modulePath = NotVisible} let createWithModulePath ~name ~kind ~env ~modulePath = {name; env; deprecated = None; docstring = []; kind; modulePath} From d358399dd8d67096f5bf23589051ac1ed3aeb92e Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Mon, 19 Dec 2022 18:47:49 +0100 Subject: [PATCH 08/11] Put all the logic to find the completionPath in one place. --- analysis/src/CompletionBackEnd.ml | 152 +++++++++++++----------------- 1 file changed, 66 insertions(+), 86 deletions(-) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index 9bae7d336..6826ddb97 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -1303,30 +1303,28 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos } = package.builtInCompletionModules in - let getModulePath path = - let rec loop (path : Path.t) = - match path with - | Pident id -> [Ident.name id] - | Pdot (p, s, _) -> s :: loop p - | Papply _ -> [] - in + let getBuiltinTypePath path = + match path with + | Path.Pident id when Ident.name id = "array" -> Some arrayModulePath + | Path.Pident id when Ident.name id = "option" -> Some optionModulePath + | Path.Pident id when Ident.name id = "string" -> Some stringModulePath + | Path.Pident id when Ident.name id = "int" -> Some intModulePath + | Path.Pident id when Ident.name id = "float" -> Some floatModulePath + | Path.Pident id when Ident.name id = "promise" -> + Some promiseModulePath + | Path.Pident id when Ident.name id = "list" -> Some listModulePath + | Path.Pident id when Ident.name id = "result" -> Some resultModulePath + | Path.Pident id when Ident.name id = "lazy_t" -> Some ["Lazy"] + | Path.Pident id when Ident.name id = "char" -> Some ["Char"] + | _ -> None + in + let rec expandPath (path : Path.t) = match path with - | Path.Pident id when Ident.name id = "array" -> arrayModulePath - | Path.Pident id when Ident.name id = "option" -> optionModulePath - | Path.Pident id when Ident.name id = "string" -> stringModulePath - | Path.Pident id when Ident.name id = "int" -> intModulePath - | Path.Pident id when Ident.name id = "float" -> floatModulePath - | Path.Pident id when Ident.name id = "promise" -> promiseModulePath - | Path.Pident id when Ident.name id = "list" -> listModulePath - | Path.Pident id when Ident.name id = "result" -> resultModulePath - | Path.Pident id when Ident.name id = "lazy_t" -> ["Lazy"] - | Path.Pident id when Ident.name id = "char" -> ["Char"] - | _ -> ( - match loop path with - | _ :: rest -> List.rev rest - | [] -> []) + | Pident id -> [Ident.name id] + | Pdot (p, s, _) -> s :: expandPath p + | Papply _ -> [] in - let getConstrPath typ = + let getTypePath typ = match typ.Types.desc with | Tconstr (path, _typeArgs, _) | Tlink {desc = Tconstr (path, _typeArgs, _)} @@ -1335,12 +1333,6 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos Some path | _ -> None in - let fromType typ = - match getConstrPath typ with - | None -> None - | Some path -> Some (getModulePath path) - in - let lhsPath = fromType typ in let rec removeRawOpen rawOpen modulePath = match (rawOpen, modulePath) with | [_], _ -> Some modulePath @@ -1357,64 +1349,52 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos | Some mp -> mp) | [] -> modulePath in - match lhsPath with - | Some lhsPath -> ( - match lhsPath with - | _ :: _ -> - let lhsPathMinusOpens = - lhsPath - |> removeRawOpens package.opens - |> removeRawOpens rawOpens |> String.concat "." - in - let completionName name = - if lhsPathMinusOpens = "" then name - else lhsPathMinusOpens ^ "." ^ name - in - let completions = - lhsPath @ [funNamePrefix] - |> getCompletionsForPath ~completionContext:Value ~exact:false - ~package ~opens ~allFiles ~pos ~env ~scope - in - completions - |> List.map (fun (completion : Completion.t) -> - { - completion with - name = completionName completion.name; - env - (* Restore original env for the completion after x->foo()... *); - }) - | [] -> - (* Module paths coming directly from a completion item is prefixed with - file module name it was found in. We pluck that off here if the env - we're in is the same as the completion item was found in. This ensures - that a correct qualified path can be produced. *) - let completionPath = - match ModulePath.toFullPath completionItemModulePath with - | topModule :: rest when topModule = env.file.moduleName -> rest - | modulePath -> modulePath - in - let completionPathMinusOpens = - completionPath - |> removeRawOpens package.opens - |> removeRawOpens rawOpens |> String.concat "." - in - let completionName name = - if completionPathMinusOpens = "" then name - else completionPathMinusOpens ^ "." ^ name - in - let completions = - completionPath @ [funNamePrefix] - |> getCompletionsForPath ~completionContext:Value ~exact:false - ~package ~opens ~allFiles ~pos ~env ~scope - in - completions - |> List.map (fun (completion : Completion.t) -> - { - completion with - name = completionName completion.name; - env - (* Restore original env for the completion after x->foo()... *); - })) + let completionPath = + match getTypePath typ with + | Some typePath -> ( + match getBuiltinTypePath typePath with + | Some path -> Some path + | None -> ( + match expandPath typePath with + | _ :: rest when rest <> [] -> + (* Assume a non-empty type path is coming from the compiler and + can be used as-is. *) + Some (List.rev rest) + | _ -> ( + (* Module paths coming directly from a completion item is prefixed with + file module name it was found in. We pluck that off here if the env + we're in is the same as the completion item was found in. This ensures + that a correct qualified path can be produced. *) + match ModulePath.toFullPath completionItemModulePath with + | topModule :: rest when topModule = env.file.moduleName -> + Some rest + | path -> Some path))) + | None -> None + in + match completionPath with + | Some completionPath -> + let completionPathMinusOpens = + completionPath + |> removeRawOpens package.opens + |> removeRawOpens rawOpens |> String.concat "." + in + let completionName name = + if completionPathMinusOpens = "" then name + else completionPathMinusOpens ^ "." ^ name + in + let completions = + completionPath @ [funNamePrefix] + |> getCompletionsForPath ~completionContext:Value ~exact:false + ~package ~opens ~allFiles ~pos ~env ~scope + in + completions + |> List.map (fun (completion : Completion.t) -> + { + completion with + name = completionName completion.name; + env + (* Restore original env for the completion after x->foo()... *); + }) | None -> []) | None -> []) From 7f6c21cebcdb6af47e57fd3b256b7e4e16c6e856 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Wed, 21 Dec 2022 09:51:59 +0100 Subject: [PATCH 09/11] Add path to QueryEnv and remove it from Completion. --- analysis/src/CompletionBackEnd.ml | 54 ++++++++++++--------------- analysis/src/Hover.ml | 2 +- analysis/src/ProcessCmt.ml | 61 +++++++++++++++++-------------- analysis/src/ResolvePath.ml | 3 +- analysis/src/SharedTypes.ml | 37 +++++++++---------- 5 files changed, 77 insertions(+), 80 deletions(-) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index 6826ddb97..4e0b46af6 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -562,7 +562,6 @@ let completionForExporteds iterExported getDeclared ~prefix ~exact ~env with deprecated = declared.deprecated; docstring = declared.docstring; - modulePath = declared.modulePath; } :: !res | _ -> ()); @@ -1153,12 +1152,9 @@ let completionToItem {Completion.name; deprecated; docstring; kind} = ~deprecated ~detail:(detail name kind) ~docstring let completionsGetTypeEnv = function - | {Completion.kind = Value typ; env; modulePath} :: _ -> - Some (typ, env, modulePath) - | {Completion.kind = ObjLabel typ; env; modulePath} :: _ -> - Some (typ, env, modulePath) - | {Completion.kind = Field ({typ}, _); env; modulePath} :: _ -> - Some (typ, env, modulePath) + | {Completion.kind = Value typ; env} :: _ -> Some (typ, env) + | {Completion.kind = ObjLabel typ; env} :: _ -> Some (typ, env) + | {Completion.kind = Field ({typ}, _); env} :: _ -> Some (typ, env) | _ -> None let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos @@ -1189,7 +1185,7 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos ~env ~exact:true ~scope |> completionsGetTypeEnv with - | Some (typ, env, modulePath) -> ( + | Some (typ, env) -> ( let rec reconstructFunctionType args tRet = match args with | [] -> tRet @@ -1220,10 +1216,7 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos | args, tRet when args <> [] -> let args = processApply args labels in let retType = reconstructFunctionType args tRet in - [ - Completion.createWithModulePath ~name:"dummy" ~env - ~kind:(Completion.Value retType) ~modulePath; - ] + [Completion.create ~name:"dummy" ~env ~kind:(Completion.Value retType)] | _ -> []) | None -> []) | CPField (CPId (path, Module), fieldName) -> @@ -1238,20 +1231,19 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos ~env ~exact:true ~scope |> completionsGetTypeEnv with - | Some (typ, env, modulePath) -> ( + | Some (typ, env) -> ( match typ |> extractRecordType ~env ~package with | Some (env, fields, typDecl) -> fields |> Utils.filterMap (fun field -> if checkName field.fname.txt ~prefix:fieldName ~exact then Some - (Completion.createWithModulePath ~name:field.fname.txt ~env + (Completion.create ~name:field.fname.txt ~env ~kind: (Completion.Field ( field, typDecl.item.decl - |> Shared.declToString typDecl.name.txt )) - ~modulePath) + |> Shared.declToString typDecl.name.txt ))) else None) | None -> []) | None -> []) @@ -1262,7 +1254,7 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos ~env ~exact:true ~scope |> completionsGetTypeEnv with - | Some (typ, env, modulePath) -> ( + | Some (typ, env) -> ( match typ |> extractObjectType ~env ~package with | Some (env, tObj) -> let rec getFields (texp : Types.type_expr) = @@ -1278,8 +1270,8 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos |> Utils.filterMap (fun (field, typ) -> if checkName field ~prefix:label ~exact then Some - (Completion.createWithModulePath ~name:field ~env - ~kind:(Completion.ObjLabel typ) ~modulePath) + (Completion.create ~name:field ~env + ~kind:(Completion.ObjLabel typ)) else None) | None -> []) | None -> []) @@ -1290,7 +1282,7 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos ~env ~exact:true ~scope |> completionsGetTypeEnv with - | Some (typ, _envFromCompletionItem, completionItemModulePath) -> ( + | Some (typ, envFromCompletionItem) -> ( let { arrayModulePath; optionModulePath; @@ -1360,15 +1352,15 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos (* Assume a non-empty type path is coming from the compiler and can be used as-is. *) Some (List.rev rest) - | _ -> ( - (* Module paths coming directly from a completion item is prefixed with - file module name it was found in. We pluck that off here if the env - we're in is the same as the completion item was found in. This ensures - that a correct qualified path can be produced. *) - match ModulePath.toFullPath completionItemModulePath with - | topModule :: rest when topModule = env.file.moduleName -> - Some rest - | path -> Some path))) + | _ -> + (* Get the path from the comletion environment *) + let pathFromEnv = + let path = envFromCompletionItem.path in + if env.file.moduleName = envFromCompletionItem.file.moduleName + then path + else envFromCompletionItem.file.moduleName :: path + in + Some pathFromEnv)) | None -> None in match completionPath with @@ -1457,7 +1449,7 @@ let processCompletable ~debug ~package ~scope ~env ~pos ~forHover | Cjsx (componentPath, prefix, identsSeen) -> let labels = match componentPath @ ["make"] |> findTypeOfValue with - | Some (typ, make_env, _) -> + | Some (typ, make_env) -> let rec getFieldsV3 (texp : Types.type_expr) = match texp.desc with | Tfield (name, _, t1, t2) -> @@ -1793,7 +1785,7 @@ Note: The `@react.component` decorator requires the react-jsx config to be set i ~env ~exact:true ~scope |> completionsGetTypeEnv with - | Some (typ, _env, _) -> + | Some (typ, _env) -> if debug then Printf.printf "Found type for function %s\n" (typ |> Shared.typeToString); diff --git a/analysis/src/Hover.ml b/analysis/src/Hover.ml index adc54fc07..599852273 100644 --- a/analysis/src/Hover.ml +++ b/analysis/src/Hover.ml @@ -152,7 +152,7 @@ let getHoverViaCompletions ~debug ~path ~pos ~currentFile ~forHover Some (Protocol.stringifyHover (String.concat "\n\n" parts)) | _ -> ( match CompletionBackEnd.completionsGetTypeEnv completions with - | Some (typ, _env, _) -> + | Some (typ, _env) -> let typeString, _docstring = hoverWithExpandedTypes ~docstring:"" ~file ~package ~supportsMarkdownLinks typ diff --git a/analysis/src/ProcessCmt.ml b/analysis/src/ProcessCmt.ml index b005cf2fe..dab690758 100644 --- a/analysis/src/ProcessCmt.ml +++ b/analysis/src/ProcessCmt.ml @@ -104,10 +104,11 @@ let rec forTypeSignatureItem ~(env : SharedTypes.Env.t) ~(exported : Exported.t) in [{Module.kind = Type (declared.item, recStatus); name = declared.name.txt}] | Sig_module (ident, {md_type; md_attributes; md_loc}, _) -> + let name = Ident.name ident in let declared = addDeclared ~extent:md_loc - ~item:(forTypeModule env md_type) - ~name:(Location.mkloc (Ident.name ident) md_loc) + ~item:(forTypeModule ~name ~env md_type) + ~name:(Location.mkloc name md_loc) ~stamp:(Ident.binding_time ident) ~env md_attributes (Exported.add exported Exported.Module) Stamps.addModule @@ -115,22 +116,22 @@ let rec forTypeSignatureItem ~(env : SharedTypes.Env.t) ~(exported : Exported.t) [{Module.kind = Module declared.item; name = declared.name.txt}] | _ -> [] -and forTypeSignature env signature = +and forTypeSignature ~name ~env signature = let exported = Exported.init () in let items = List.fold_right (fun item items -> forTypeSignatureItem ~env ~exported item @ items) signature [] in - {Module.docstring = []; exported; items} + {Module.name; docstring = []; exported; items} -and forTypeModule env moduleType = +and forTypeModule ~name ~env moduleType = match moduleType with | Types.Mty_ident path -> Ident path | Mty_alias (_ (* 402 *), path) -> Ident path - | Mty_signature signature -> Structure (forTypeSignature env signature) + | Mty_signature signature -> Structure (forTypeSignature ~name ~env signature) | Mty_functor (_argIdent, _argType, resultType) -> - forTypeModule env resultType + forTypeModule ~name ~env resultType let getModuleTypePath mod_desc = match mod_desc with @@ -249,7 +250,11 @@ let rec forSignatureItem ~env ~(exported : Exported.t) decl |> forTypeDeclaration ~env ~exported ~recStatus) | Tsig_module {md_id; md_attributes; md_loc; md_name = name; md_type = {mty_type}} -> - let item = forTypeModule (env |> Env.addModule ~name:name.txt) mty_type in + let item = + forTypeModule ~name:name.txt + ~env:(env |> Env.addModule ~name:name.txt) + mty_type + in let declared = addDeclared ~item ~name ~extent:md_loc ~stamp:(Ident.binding_time md_id) ~env md_attributes @@ -279,7 +284,7 @@ let rec forSignatureItem ~env ~(exported : Exported.t) (* TODO: process other things here *) | _ -> [] -let forSignature ~env sigItems = +let forSignature ~name ~env sigItems = let exported = Exported.init () in let items = sigItems |> List.map (forSignatureItem ~env ~exported) |> List.flatten @@ -294,13 +299,13 @@ let forSignature ~env sigItems = | None -> [] | Some d -> [d] in - {Module.docstring; exported; items} + {Module.name; docstring; exported; items} -let forTreeModuleType ~env {Typedtree.mty_desc} = +let forTreeModuleType ~name ~env {Typedtree.mty_desc} = match mty_desc with | Tmty_ident _ -> None | Tmty_signature {sig_items} -> - let contents = forSignature ~env sig_items in + let contents = forSignature ~name ~env sig_items in Some (Module.Structure contents) | _ -> None @@ -352,7 +357,7 @@ let rec forStructureItem ~env ~(exported : Exported.t) item = (String.length name.txt >= 6 && (String.sub name.txt 0 6 = "local_") [@doesNotRaise]) (* %%private generates a dummy module called local_... *) -> - let item = forModule env mod_desc name.txt in + let item = forModule ~env mod_desc name.txt in let declared = addDeclared ~item ~name ~extent:mb_loc ~stamp:(Ident.binding_time mb_id) ~env mb_attributes @@ -375,7 +380,7 @@ let rec forStructureItem ~env ~(exported : Exported.t) item = mtd_loc; } -> let env = env |> Env.addModuleType ~name:name.txt in - let modTypeItem = forTypeModule env modType in + let modTypeItem = forTypeModule ~name:name.txt ~env modType in let declared = addDeclared ~item:modTypeItem ~name ~extent:mtd_loc ~stamp:(Ident.binding_time mtd_id) @@ -418,18 +423,18 @@ let rec forStructureItem ~env ~(exported : Exported.t) item = decl |> forTypeDeclaration ~env ~exported ~recStatus) | _ -> [] -and forModule env mod_desc moduleName = +and forModule ~env mod_desc moduleName = match mod_desc with | Tmod_ident (path, _lident) -> Ident path | Tmod_structure structure -> let env = env |> Env.addModule ~name:moduleName in - let contents = forStructure ~env structure.str_items in + let contents = forStructure ~name:moduleName ~env structure.str_items in Structure contents | Tmod_functor (ident, argName, maybeType, resultExpr) -> (match maybeType with | None -> () | Some t -> ( - match forTreeModuleType ~env t with + match forTreeModuleType ~name:argName.txt ~env t with | None -> () | Some kind -> let stamp = Ident.binding_time ident in @@ -438,20 +443,20 @@ and forModule env mod_desc moduleName = ~extent:t.Typedtree.mty_loc ~stamp ~modulePath:NotVisible false [] in Stamps.addModule env.stamps stamp declared)); - forModule env resultExpr.mod_desc moduleName + forModule ~env resultExpr.mod_desc moduleName | Tmod_apply (functor_, _arg, _coercion) -> - forModule env functor_.mod_desc moduleName + forModule ~env functor_.mod_desc moduleName | Tmod_unpack (_expr, moduleType) -> let env = env |> Env.addModule ~name:moduleName in - forTypeModule env moduleType + forTypeModule ~name:moduleName ~env moduleType | Tmod_constraint (expr, typ, _constraint, _coercion) -> (* TODO do this better I think *) - let modKind = forModule env expr.mod_desc moduleName in + let modKind = forModule ~env expr.mod_desc moduleName in let env = env |> Env.addModule ~name:moduleName in - let modTypeKind = forTypeModule env typ in + let modTypeKind = forTypeModule ~name:moduleName ~env typ in Constraint (modKind, modTypeKind) -and forStructure ~env strItems = +and forStructure ~name ~env strItems = let exported = Exported.init () in let items = List.fold_right @@ -468,7 +473,7 @@ and forStructure ~env strItems = | None -> [] | Some d -> [d] in - {docstring; exported; items} + {Module.name; docstring; exported; items} let fileForCmtInfos ~moduleName ~uri ({cmt_modname; cmt_annots} : Cmt_format.cmt_infos) = @@ -486,7 +491,7 @@ let fileForCmtInfos ~moduleName ~uri | _ -> None) |> List.concat in - let structure = forStructure ~env items in + let structure = forStructure ~name:moduleName ~env items in {File.uri; moduleName = cmt_modname; stamps = env.stamps; structure} | Partial_interface parts -> let items = @@ -498,13 +503,13 @@ let fileForCmtInfos ~moduleName ~uri | _ -> None) |> List.concat in - let structure = forSignature ~env items in + let structure = forSignature ~name:moduleName ~env items in {uri; moduleName = cmt_modname; stamps = env.stamps; structure} | Implementation structure -> - let structure = forStructure ~env structure.str_items in + let structure = forStructure ~name:moduleName ~env structure.str_items in {uri; moduleName = cmt_modname; stamps = env.stamps; structure} | Interface signature -> - let structure = forSignature ~env signature.sig_items in + let structure = forSignature ~name:moduleName ~env signature.sig_items in {uri; moduleName = cmt_modname; stamps = env.stamps; structure} | _ -> File.create moduleName uri diff --git a/analysis/src/ResolvePath.ml b/analysis/src/ResolvePath.ml index dc930a7e7..877e273fe 100644 --- a/analysis/src/ResolvePath.ml +++ b/analysis/src/ResolvePath.ml @@ -46,7 +46,8 @@ and resolvePathInner ~(env : QueryEnv.t) ~path = and findInModule ~(env : QueryEnv.t) module_ path = match module_ with - | Structure {exported} -> resolvePathInner ~env:{env with exported} ~path + | Structure structure -> + resolvePathInner ~env:(QueryEnv.enterStructure env structure) ~path | Constraint (_, module1) -> findInModule ~env module1 path | Ident modulePath -> ( let stamp, moduleName, fullPath = joinPaths modulePath path in diff --git a/analysis/src/SharedTypes.ml b/analysis/src/SharedTypes.ml index b38ecb001..e5ee97e9f 100644 --- a/analysis/src/SharedTypes.ml +++ b/analysis/src/SharedTypes.ml @@ -22,16 +22,6 @@ module ModulePath = struct | NotVisible -> current in loop modulePath [tipName] - - let toFullPath modulePath : path = - let rec loop modulePath current = - match modulePath with - | File (_, fileModule) -> fileModule :: current - | IncludedModule (_, inner) -> loop inner current - | ExportedModule {name; modulePath = inner} -> loop inner (name :: current) - | NotVisible -> current - in - loop modulePath [] end type field = {stamp: int; fname: string Location.loc; typ: Types.type_expr} @@ -115,6 +105,7 @@ module Module = struct and item = {kind: kind; name: string} and structure = { + name: string; docstring: string list; exported: Exported.t; items: item list; @@ -236,14 +227,26 @@ module File = struct uri; stamps = Stamps.init (); moduleName; - structure = {docstring = []; exported = Exported.init (); items = []}; + structure = + { + name = moduleName; + docstring = []; + exported = Exported.init (); + items = []; + }; } end -module QueryEnv = struct - type t = {file: File.t; exported: Exported.t} +module QueryEnv : sig + type t = private {file: File.t; exported: Exported.t; path: path} + val fromFile : File.t -> t + val enterStructure : t -> Module.structure -> t +end = struct + type t = {file: File.t; exported: Exported.t; path: path} - let fromFile file = {file; exported = file.structure.exported} + let fromFile file = {file; exported = file.structure.exported; path = []} + let enterStructure env (structure : Module.structure) = + {env with exported = structure.exported; path = structure.name :: env.path} end module Completion = struct @@ -263,14 +266,10 @@ module Completion = struct deprecated: string option; docstring: string list; kind: kind; - modulePath: ModulePath.t; } let create ~name ~kind ~env = - {name; env; deprecated = None; docstring = []; kind; modulePath = NotVisible} - - let createWithModulePath ~name ~kind ~env ~modulePath = - {name; env; deprecated = None; docstring = []; kind; modulePath} + {name; env; deprecated = None; docstring = []; kind} (* https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion *) (* https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#completionItemKind *) From a69092dd53fbcf2da64aad01af87ec83624a7a5c Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Wed, 21 Dec 2022 10:37:38 +0100 Subject: [PATCH 10/11] example of 'false positive', trigger pipe completion when we should not --- analysis/tests/src/CompletionPipeChain.res | 4 + .../src/expected/CompletionPipeChain.res.txt | 341 ++++++++++++++++++ 2 files changed, 345 insertions(+) diff --git a/analysis/tests/src/CompletionPipeChain.res b/analysis/tests/src/CompletionPipeChain.res index 17b8949d8..59c1af258 100644 --- a/analysis/tests/src/CompletionPipeChain.res +++ b/analysis/tests/src/CompletionPipeChain.res @@ -54,3 +54,7 @@ let f = int->Integer.increment(2) // let _ = CompletionSupport.Test.make(1)->CompletionSupport.Test.addSelf(2)-> // ^com + +let _ = [123]->Js.Array2.forEach(v => Js.log(v)) +// -> +// ^com diff --git a/analysis/tests/src/expected/CompletionPipeChain.res.txt b/analysis/tests/src/expected/CompletionPipeChain.res.txt index 3df39da0b..d951e3a19 100644 --- a/analysis/tests/src/expected/CompletionPipeChain.res.txt +++ b/analysis/tests/src/expected/CompletionPipeChain.res.txt @@ -234,3 +234,344 @@ Completable: Cpath Value[CompletionSupport, Test, addSelf](Nolabel, Nolabel)-> "documentation": null }] +Complete src/CompletionPipeChain.res 58:5 +posCursor:[58:5] posNoWhite:[58:4] Found expr:[57:8->0:-1] +Completable: Cpath Value[Js, Array2, forEach](Nolabel, Nolabel)-> +[{ + "label": "Js_array2.mapi", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => 'b) => t<'b>", + "documentation": {"kind": "markdown", "value": "\nApplies the function (the second argument) to each item in the array, returning\na new array. The function acceps two arguments: an item from the array and its\nindex number. The result array does not have to have elements of the same type\nas the input array. See\n[`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)\non MDN.\n\n```res example\n// multiply each item in array by its position\nlet product = (item, index) => item * index\nJs.Array2.mapi([10, 11, 12], product) == [0, 11, 24]\n```\n"} + }, { + "label": "Js_array2.lastIndexOf", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => int", + "documentation": {"kind": "markdown", "value": "\nReturns the index of the last element in the array that has the given value. If\nthe value is not in the array, returns -1. See\n[`Array.lastIndexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)\non MDN.\n\n```res example\nJs.Array2.lastIndexOf([\"a\", \"b\", \"a\", \"c\"], \"a\") == 2\nJs.Array2.lastIndexOf([\"a\", \"b\", \"a\", \"c\"], \"x\") == -1\n```\n"} + }, { + "label": "Js_array2.concat", + "kind": 12, + "tags": [], + "detail": "(t<'a>, t<'a>) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nConcatenates the second array argument to the first array argument, returning a\nnew array. The original arrays are not modified. See\n[`Array.concat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)\non MDN.\n\n```res example\nJs.Array2.concat([\"a\", \"b\"], [\"c\", \"d\", \"e\"]) == [\"a\", \"b\", \"c\", \"d\", \"e\"]\n```\n"} + }, { + "label": "Js_array2.unshiftMany", + "kind": 12, + "tags": [], + "detail": "(t<'a>, array<'a>) => int", + "documentation": {"kind": "markdown", "value": "\nAdds the elements in the second array argument at the beginning of the first\narray argument, returning the new number of elements in the array. *This\nfunction modifies the original array.* See\n[`Array.unshift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)\non MDN.\n\n```res example\nlet arr = [\"d\", \"e\"]\nJs.Array2.unshiftMany(arr, [\"a\", \"b\", \"c\"]) == 5\narr == [\"a\", \"b\", \"c\", \"d\", \"e\"]\n```\n"} + }, { + "label": "Js_array2.filter", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nApplies the given predicate function (the second argument) to each element in\nthe array; the result is an array of those elements for which the predicate\nfunction returned `true`. See\n[`Array.filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)\non MDN.\n\n```res example\nlet nonEmpty = s => s != \"\"\nJs.Array2.filter([\"abc\", \"\", \"\", \"def\", \"ghi\"], nonEmpty) == [\"abc\", \"def\", \"ghi\"]\n```\n"} + }, { + "label": "Js_array2.shift", + "kind": 12, + "tags": [], + "detail": "t<'a> => option<'a>", + "documentation": {"kind": "markdown", "value": "\nIf the array is not empty, removes the first element and returns it as\n`Some(value)`; returns `None` if the array is empty. *This function modifies\nthe original array.* See\n[`Array.shift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.shift(arr) == Some(100)\narr == [101, 102, 103, 104]\n\nlet empty: array = []\nJs.Array2.shift(empty) == None\n```\n"} + }, { + "label": "Js_array2.reduceRight", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('b, 'a) => 'b, 'b) => 'b", + "documentation": {"kind": "markdown", "value": "\nThe `reduceRight()` function takes three parameters: an array, a *reducer\nfunction*, and a beginning accumulator value. The reducer function has two\nparameters: an accumulated value and an element of the array.\n\n`reduceRight()` first calls the reducer function with the beginning value and\nthe last element in the array. The result becomes the new accumulator value,\nwhich is passed in to the reducer function along with the next-to-last element\nin the array. `reduceRight()` proceeds from right to left through the array,\npassing in the result of each stage as the accumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reduceRight()`. See\n[`Array.reduceRight`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight)\non MDN.\n\n**NOTE:** In many cases, `reduce()` and `reduceRight()` give the same result.\nHowever, see the last example here and compare it to the example from\n`reduce()`, where order makes a difference.\n\n```res example\nlet sumOfSquares = (accumulator, item) => accumulator + item * item\n\nJs.Array2.reduceRight([10, 2, 4], sumOfSquares, 0) == 120\nJs.Array2.reduceRight([2.0, 4.0], (acc, item) => item /. acc, 1.0) == 0.5 // 2.0 / (4.0 / 1.0)\n```\n"} + }, { + "label": "Js_array2.joinWith", + "kind": 12, + "tags": [], + "detail": "(t<'a>, string) => string", + "documentation": {"kind": "markdown", "value": "\nThis function converts each element of the array to a string (via JavaScript)\nand concatenates them, separated by the string given in the first argument,\ninto a single string. See\n[`Array.join`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)\non MDN.\n\n```res example\nJs.Array2.joinWith([\"ant\", \"bee\", \"cat\"], \"--\") == \"ant--bee--cat\"\nJs.Array2.joinWith([\"door\", \"bell\"], \"\") == \"doorbell\"\nJs.Array2.joinWith([2020, 9, 4], \"/\") == \"2020/9/4\"\nJs.Array2.joinWith([2.5, 3.6, 3e-2], \";\") == \"2.5;3.6;0.03\"\n```\n"} + }, { + "label": "Js_array2.concatMany", + "kind": 12, + "tags": [], + "detail": "(t<'a>, array>) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nThe second argument to `concatMany()` is an array of arrays; these are added at\nthe end of the first argument, returning a new array. See\n[`Array.concat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)\non MDN.\n\n```res example\nJs.Array2.concatMany([\"a\", \"b\", \"c\"], [[\"d\", \"e\"], [\"f\", \"g\", \"h\"]]) == [\n \"a\",\n \"b\",\n \"c\",\n \"d\",\n \"e\",\n \"f\",\n \"g\",\n \"h\",\n ]\n```\n"} + }, { + "label": "Js_array2.fillInPlace", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nSets all elements of the given array (the first arumgent) to the designated\nvalue (the secon argument), returning the resulting array. *This function\n modifies the original array.*\n\nSee\n[`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.fillInPlace(arr, 99) == [99, 99, 99, 99, 99]\narr == [99, 99, 99, 99, 99]\n```\n"} + }, { + "label": "Js_array2.isArray", + "kind": 12, + "tags": [], + "detail": "'a => bool", + "documentation": {"kind": "markdown", "value": "\nReturns `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.\n\n```res example\nJs.Array2.isArray([5, 2, 3, 1, 4]) == true\nJs.Array2.isArray(list{5, 2, 3, 1, 4}) == true\nJs.Array2.isArray(\"abcd\") == false\n```\n"} + }, { + "label": "Js_array2.reduce", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('b, 'a) => 'b, 'b) => 'b", + "documentation": {"kind": "markdown", "value": "\nThe `reduce()` function takes three parameters: an array, a *reducer function*,\nand a beginning accumulator value. The reducer function has two parameters: an\naccumulated value and an element of the array.\n\n`reduce()` first calls the reducer function with the beginning value and the\nfirst element in the array. The result becomes the new accumulator value, which\nis passed in to the reducer function along with the second element in the\narray. `reduce()` proceeds through the array, passing in the result of each\nstage as the accumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reduce()`. See\n[`Array.reduce`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce)\non MDN.\n\n```res example\nlet sumOfSquares = (accumulator, item) => accumulator + item * item\n\nJs.Array2.reduce([10, 2, 4], sumOfSquares, 0) == 120\nJs.Array2.reduce([10, 2, 4], \\\"*\", 1) == 80\nJs.Array2.reduce(\n [\"animal\", \"vegetable\", \"mineral\"],\n (acc, item) => acc + Js.String.length(item),\n 0,\n) == 22 // 6 + 9 + 7\nJs.Array2.reduce([2.0, 4.0], (acc, item) => item /. acc, 1.0) == 2.0 // 4.0 / (2.0 / 1.0)\n```\n"} + }, { + "label": "Js_array2.copy", + "kind": 12, + "tags": [], + "detail": "t<'a> => t<'a>", + "documentation": {"kind": "markdown", "value": "\nReturns a copy of the entire array. Same as `Js.Array2.Slice(arr, ~start=0,\n~end_=Js.Array2.length(arr))`. See\n[`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\non MDN.\n"} + }, { + "label": "Js_array2.reducei", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('b, 'a, int) => 'b, 'b) => 'b", + "documentation": {"kind": "markdown", "value": "\nThe `reducei()` function takes three parameters: an array, a *reducer\nfunction*, and a beginning accumulator value. The reducer function has three\nparameters: an accumulated value, an element of the array, and the index of\nthat element.\n\n`reducei()` first calls the reducer function with the beginning value, the\nfirst element in the array, and zero (its index). The result becomes the new\naccumulator value, which is passed to the reducer function along with the\nsecond element in the array and one (its index). `reducei()` proceeds from left\nto right through the array, passing in the result of each stage as the\naccumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reducei()`. See\n[`Array.reduce`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce)\non MDN.\n\n```res example\n// find sum of even-index elements in array\nlet sumOfEvens = (accumulator, item, index) =>\n if mod(index, 2) == 0 {\n accumulator + item\n } else {\n accumulator\n }\n\nJs.Array2.reducei([2, 5, 1, 4, 3], sumOfEvens, 0) == 6\n```\n"} + }, { + "label": "Js_array2.forEachi", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => unit) => unit", + "documentation": {"kind": "markdown", "value": "\nThe `forEachi()` function applies the function given as the second argument to\neach element in the array. The function you provide takes an item in the array\nand its index number, and returns `unit`. The `forEachi()` function also\nreturns `unit`. You use `forEachi()` when you need to process each element in\nthe array but not return any new array or value; for example, to print the\nitems in an array. See\n[`Array.forEach`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)\non MDN.\n\n```res example\n// display all elements in an array as a numbered list\nJs.Array2.forEachi([\"a\", \"b\", \"c\"], (item, index) => Js.log2(index + 1, item)) == ()\n```\n"} + }, { + "label": "Js_array2.fillFromInPlace", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a, ~from: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nSets all elements of the given array (the first arumgent) from position `~from`\nto the end to the designated value (the second argument), returning the\nresulting array. *This function modifies the original array.* See\n[`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.fillFromInPlace(arr, 99, ~from=2) == [100, 101, 99, 99, 99]\narr == [100, 101, 99, 99, 99]\n```\n"} + }, { + "label": "Js_array2.findi", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => bool) => option<'a>", + "documentation": {"kind": "markdown", "value": "\nReturns `Some(value)` for the first element in the array that satisifies the\ngiven predicate function, or `None` if no element satisifies the predicate. The\npredicate function takes an array element and an index as its parameters. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\n// find first positive item at an odd index\nlet positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0\n\nJs.Array2.findi([66, -33, 55, 88, 22], positiveOddElement) == Some(88)\nJs.Array2.findi([66, -33, 55, -88, 22], positiveOddElement) == None\n```\n"} + }, { + "label": "Js_array2.filteri", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => bool) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nEach element of the given array are passed to the predicate function. The\nreturn value is an array of all those elements for which the predicate function\nreturned `true`.\n\nSee\n[`Array.filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)\non MDN.\n\n```res example\n// keep only positive elements at odd indices\nlet positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0\n\nJs.Array2.filteri([6, 3, 5, 8, 7, -4, 1], positiveOddElement) == [3, 8]\n```\n"} + }, { + "label": "Js_array2.slice", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~start: int, ~end_: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nReturns a shallow copy of the given array from the `~start` index up to but not\nincluding the `~end_` position. Negative numbers indicate an offset from the\nend of the array. See\n[`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104, 105, 106]\nJs.Array2.slice(arr, ~start=2, ~end_=5) == [102, 103, 104]\nJs.Array2.slice(arr, ~start=-3, ~end_=-1) == [104, 105]\nJs.Array2.slice(arr, ~start=9, ~end_=10) == []\n```\n"} + }, { + "label": "Js_array2.fromMap", + "kind": 12, + "tags": [], + "detail": "(array_like<'a>, 'a => 'b) => array<'b>", + "documentation": {"kind": "markdown", "value": "\nCreates a new array by applying a function (the second argument) to each item\nin the `array_like` first argument. See\n[`Array.from`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)\non MDN.\n\n```res example\nlet strArr = Js.String.castToArrayLike(\"abcd\")\nlet code = s => Js.String.charCodeAt(0, s)\nJs.Array2.fromMap(strArr, code) == [97.0, 98.0, 99.0, 100.0]\n```\n"} + }, { + "label": "Js_array2.removeFromInPlace", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~pos: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nRemoves elements from the given array starting at position `~pos` to the end of\nthe array, returning the removed elements. *This function modifies the original\narray.* See\n[`Array.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)\non MDN.\n\n```res example\nlet arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.removeFromInPlace(arr, ~pos=4) == [\"e\", \"f\"]\narr == [\"a\", \"b\", \"c\", \"d\"]\n```\n"} + }, { + "label": "Js_array2.from", + "kind": 12, + "tags": [], + "detail": "array_like<'a> => array<'a>", + "documentation": {"kind": "markdown", "value": "\nCreates a shallow copy of an array from an array-like object. See\n[`Array.from`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)\non MDN.\n\n```res example\nlet strArr = Js.String.castToArrayLike(\"abcd\")\nJs.Array2.from(strArr) == [\"a\", \"b\", \"c\", \"d\"]\n```\n"} + }, { + "label": "Js_array2.includes", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => bool", + "documentation": {"kind": "markdown", "value": "\nReturns true if the given value is in the array, `false` otherwise. See\n[`Array.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)\non MDN.\n\n```res example\nJs.Array2.includes([\"a\", \"b\", \"c\"], \"b\") == true\nJs.Array2.includes([\"a\", \"b\", \"c\"], \"x\") == false\n```\n"} + }, { + "label": "Js_array2.find", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => option<'a>", + "documentation": {"kind": "markdown", "value": "\nReturns `Some(value)` for the first element in the array that satisifies the\ngiven predicate function, or `None` if no element satisifies the predicate. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\n// find first negative element\nJs.Array2.find([33, 22, -55, 77, -44], x => x < 0) == Some(-55)\nJs.Array2.find([33, 22, 55, 77, 44], x => x < 0) == None\n```\n"} + }, { + "label": "Js_array2.reduceRighti", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('b, 'a, int) => 'b, 'b) => 'b", + "documentation": {"kind": "markdown", "value": "\nThe `reduceRighti()` function takes three parameters: an array, a *reducer\nfunction*, and a beginning accumulator value. The reducer function has three\nparameters: an accumulated value, an element of the array, and the index of\nthat element. `reduceRighti()` first calls the reducer function with the\nbeginning value, the last element in the array, and its index (length of array\nminus one). The result becomes the new accumulator value, which is passed in to\nthe reducer function along with the second element in the array and one (its\nindex). `reduceRighti()` proceeds from right to left through the array, passing\nin the result of each stage as the accumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reduceRighti()`. See\n[`Array.reduceRight`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight)\non MDN.\n\n**NOTE:** In many cases, `reducei()` and `reduceRighti()` give the same result.\nHowever, there are cases where the order in which items are processed makes a\ndifference.\n\n```res example\n// find sum of even-index elements in array\nlet sumOfEvens = (accumulator, item, index) =>\n if mod(index, 2) == 0 {\n accumulator + item\n } else {\n accumulator\n }\n\nJs.Array2.reduceRighti([2, 5, 1, 4, 3], sumOfEvens, 0) == 6\n```\n"} + }, { + "label": "Js_array2.findIndexi", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => bool) => int", + "documentation": {"kind": "markdown", "value": "\nReturns `Some(value)` for the first element in the array that satisifies the\ngiven predicate function, or `None` if no element satisifies the predicate. The\npredicate function takes an array element and an index as its parameters. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\n// find index of first positive item at an odd index\nlet positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0\n\nJs.Array2.findIndexi([66, -33, 55, 88, 22], positiveOddElement) == 3\nJs.Array2.findIndexi([66, -33, 55, -88, 22], positiveOddElement) == -1\n```\n"} + }, { + "label": "Js_array2.toLocaleString", + "kind": 12, + "tags": [], + "detail": "t<'a> => string", + "documentation": {"kind": "markdown", "value": "\nConverts the array to a string using the conventions of the current locale.\nEach element is converted to a string using JavaScript. Unlike the JavaScript\n`Array.toLocaleString()`, all elements in a ReasonML array must have the same\ntype. See\n[`Array.toLocaleString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString)\non MDN.\n\n```res example\nJs.Array2.toLocaleString([Js.Date.make()])\n// returns \"3/19/2020, 10:52:11 AM\" for locale en_US.utf8\n// returns \"2020-3-19 10:52:11\" for locale de_DE.utf8\n```\n"} + }, { + "label": "Js_array2.lastIndexOfFrom", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a, ~from: int) => int", + "documentation": {"kind": "markdown", "value": "\nReturns the index of the last element in the array that has the given value,\nsearching from position `~from` down to the start of the array. If the value is\nnot in the array, returns -1. See\n[`Array.lastIndexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)\non MDN.\n\n```res example\nJs.Array2.lastIndexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\", \"d\"], \"a\", ~from=3) == 2\nJs.Array2.lastIndexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\", \"d\"], \"c\", ~from=2) == -1\n```\n"} + }, { + "label": "Js_array2.copyWithinFromRange", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~to_: int, ~start: int, ~end_: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nCopies starting at element `~start` in the given array up to but not including\n`~end_` to the designated `~to_` position, returning the resulting array. *This\nfunction modifies the original array.* See\n[`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104, 105]\nJs.Array2.copyWithinFromRange(arr, ~start=2, ~end_=5, ~to_=1) == [100, 102, 103, 104, 104, 105]\narr == [100, 102, 103, 104, 104, 105]\n```\n"} + }, { + "label": "Js_array2.findIndex", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => int", + "documentation": {"kind": "markdown", "value": "\nReturns the index of the first element in the array that satisifies the given\npredicate function, or -1 if no element satisifies the predicate. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\nJs.Array2.findIndex([33, 22, -55, 77, -44], x => x < 0) == 2\nJs.Array2.findIndex([33, 22, 55, 77, 44], x => x < 0) == -1\n```\n"} + }, { + "label": "Js_array2.removeCountInPlace", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~pos: int, ~count: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nRemoves `~count` elements from the given array starting at position `~pos`,\nreturning the removed elements. *This function modifies the original array.*\nSee\n[`Array.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)\non MDN.\n\n```res example\nlet arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.removeCountInPlace(arr, ~pos=2, ~count=3) == [\"c\", \"d\", \"e\"]\narr == [\"a\", \"b\", \"f\"]\n```\n"} + }, { + "label": "Js_array2.reverseInPlace", + "kind": 12, + "tags": [], + "detail": "t<'a> => t<'a>", + "documentation": {"kind": "markdown", "value": "\nReturns an array with the elements of the input array in reverse order. *This\nfunction modifies the original array.* See\n[`Array.reverse`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse)\non MDN.\n\n```res example\nlet arr = [\"ant\", \"bee\", \"cat\"]\nJs.Array2.reverseInPlace(arr) == [\"cat\", \"bee\", \"ant\"]\narr == [\"cat\", \"bee\", \"ant\"]\n```\n"} + }, { + "label": "Js_array2.every", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => bool", + "documentation": {"kind": "markdown", "value": "\nThe first argument to `every()` is an array. The second argument is a predicate\nfunction that returns a boolean. The `every()` function returns `true` if the\npredicate function is true for all items in the given array. If given an empty\narray, returns `true`. See\n[`Array.every`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)\non MDN.\n\n```res example\nlet isEven = x => mod(x, 2) == 0\nJs.Array2.every([6, 22, 8, 4], isEven) == true\nJs.Array2.every([6, 22, 7, 4], isEven) == false\n```\n"} + }, { + "label": "Js_array2.length", + "kind": 12, + "tags": [], + "detail": "array<'a> => int", + "documentation": {"kind": "markdown", "value": "\nReturns the number of elements in the array. See\n[`Array.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)\non MDN.\n"} + }, { + "label": "Js_array2.indexOf", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => int", + "documentation": {"kind": "markdown", "value": "\nReturns the index of the first element in the array that has the given value.\nIf the value is not in the array, returns -1. See\n[`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)\non MDN.\n\n```res example\nJs.Array2.indexOf([100, 101, 102, 103], 102) == 2\nJs.Array2.indexOf([100, 101, 102, 103], 999) == -1\n```\n"} + }, { + "label": "Js_array2.unshift", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => int", + "documentation": {"kind": "markdown", "value": "\nAdds the given element to the array, returning the new number of elements in\nthe array. *This function modifies the original array.* See\n[`Array.unshift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)\non MDN.\n\n```res example\nlet arr = [\"b\", \"c\", \"d\"]\nJs.Array2.unshift(arr, \"a\") == 4\narr == [\"a\", \"b\", \"c\", \"d\"]\n```\n"} + }, { + "label": "Js_array2.sortInPlace", + "kind": 12, + "tags": [], + "detail": "t<'a> => t<'a>", + "documentation": {"kind": "markdown", "value": "\nSorts the given array in place and returns the sorted array. JavaScript sorts\nthe array by converting the arguments to UTF-16 strings and sorting them. See\nthe second example with sorting numbers, which does not do a numeric sort.\n*This function modifies the original array.* See\n[`Array.sort`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)\non MDN.\n\n```res example\nlet words = [\"bee\", \"dog\", \"ant\", \"cat\"]\nJs.Array2.sortInPlace(words) == [\"ant\", \"bee\", \"cat\", \"dog\"]\nwords == [\"ant\", \"bee\", \"cat\", \"dog\"]\n\nlet numbers = [3, 30, 10, 1, 20, 2]\nJs.Array2.sortInPlace(numbers) == [1, 10, 2, 20, 3, 30]\nnumbers == [1, 10, 2, 20, 3, 30]\n```\n"} + }, { + "label": "Js_array2.unsafe_get", + "kind": 12, + "tags": [], + "detail": "(array<'a>, int) => 'a", + "documentation": {"kind": "markdown", "value": "\nReturns the value at the given position in the array if the position is in\nbounds; returns the JavaScript value `undefined` otherwise.\n\n```res example\nlet arr = [100, 101, 102, 103]\nJs.Array2.unsafe_get(arr, 3) == 103\nJs.Array2.unsafe_get(arr, 4) // returns undefined\n```\n"} + }, { + "label": "Js_array2.some", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => bool) => bool", + "documentation": {"kind": "markdown", "value": "\nReturns `true` if the predicate function given as the second argument to\n`some()` returns `true` for any element in the array; `false` otherwise.\n\n```res example\nlet isEven = x => mod(x, 2) == 0\n\nJs.Array2.some([3, 7, 5, 2, 9], isEven) == true\nJs.Array2.some([3, 7, 5, 1, 9], isEven) == false\n```\n"} + }, { + "label": "Js_array2.map", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => 'b) => t<'b>", + "documentation": {"kind": "markdown", "value": "\nApplies the function (the second argument) to each item in the array, returning\na new array. The result array does not have to have elements of the same type\nas the input array. See\n[`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)\non MDN.\n\n```res example\nJs.Array2.map([12, 4, 8], x => x * x) == [144, 16, 64]\nJs.Array2.map([\"animal\", \"vegetable\", \"mineral\"], Js.String.length) == [6, 9, 7]\n```\n"} + }, { + "label": "Js_array2.push", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a) => int", + "documentation": {"kind": "markdown", "value": "\nAppends the given value to the array, returning the number of elements in the\nupdated array. *This function modifies the original array.* See\n[`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)\non MDN.\n\n```res example\nlet arr = [\"ant\", \"bee\", \"cat\"]\nJs.Array2.push(arr, \"dog\") == 4\narr == [\"ant\", \"bee\", \"cat\", \"dog\"]\n```\n"} + }, { + "label": "Js_array2.fillRangeInPlace", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a, ~start: int, ~end_: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nSets the elements of the given array (the first arumgent) from position\n`~start` up to but not including position `~end_` to the designated value (the\nsecond argument), returning the resulting array. *This function modifies the\noriginal array.* See\n[`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.fillRangeInPlace(arr, 99, ~start=1, ~end_=4) == [100, 99, 99, 99, 104]\narr == [100, 99, 99, 99, 104]\n```\n"} + }, { + "label": "Js_array2.pop", + "kind": 12, + "tags": [], + "detail": "t<'a> => option<'a>", + "documentation": {"kind": "markdown", "value": "\nIf the array is not empty, removes the last element and returns it as\n`Some(value)`; returns `None` if the array is empty. *This function modifies\nthe original array.* See\n[`Array.pop`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.pop(arr) == Some(104)\narr == [100, 101, 102, 103]\n\nlet empty: array = []\nJs.Array2.pop(empty) == None\n```\n"} + }, { + "label": "Js_array2.somei", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => bool) => bool", + "documentation": {"kind": "markdown", "value": "\nReturns `true` if the predicate function given as the second argument to\n`somei()` returns `true` for any element in the array; `false` otherwise. The\npredicate function has two arguments: an item from the array and the index\nvalue\n\n```res example\n// Does any string in the array\n// have the same length as its index?\n\nlet sameLength = (str, index) => Js.String.length(str) == index\n\n// \"ef\" has length 2 and is it at index 2\nJs.Array2.somei([\"ab\", \"cd\", \"ef\", \"gh\"], sameLength) == true\n// no item has the same length as its index\nJs.Array2.somei([\"a\", \"bc\", \"def\", \"gh\"], sameLength) == false\n```\n"} + }, { + "label": "Js_array2.append", + "kind": 12, + "tags": [1], + "detail": "(t<'a>, 'a) => t<'a>", + "documentation": {"kind": "markdown", "value": "Deprecated: `append` is not type-safe. Use `concat` instead.\n\n"} + }, { + "label": "Js_array2.unsafe_set", + "kind": 12, + "tags": [], + "detail": "(array<'a>, int, 'a) => unit", + "documentation": {"kind": "markdown", "value": "\nSets the value at the given position in the array if the position is in bounds.\nIf the index is out of bounds, well, “here there be dragons.“\n\n*This function modifies the original array.*\n\n```res example\nlet arr = [100, 101, 102, 103]\nJs.Array2.unsafe_set(arr, 3, 99)\n// result is [100, 101, 102, 99];\n\nJs.Array2.unsafe_set(arr, 4, 88)\n// result is [100, 101, 102, 99, 88]\n\nJs.Array2.unsafe_set(arr, 6, 77)\n// result is [100, 101, 102, 99, 88, <1 empty item>, 77]\n\nJs.Array2.unsafe_set(arr, -1, 66)\n// you don't want to know.\n```\n"} + }, { + "label": "Js_array2.copyWithin", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~to_: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nCopies from the first element in the given array to the designated `~to_`\nposition, returning the resulting array. *This function modifies the original\narray.* See\n[`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.copyWithin(arr, ~to_=2) == [100, 101, 100, 101, 102]\narr == [100, 101, 100, 101, 102]\n```\n"} + }, { + "label": "Js_array2.everyi", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, int) => bool) => bool", + "documentation": {"kind": "markdown", "value": "\nThe first argument to `everyi()` is an array. The second argument is a\npredicate function with two arguments: an array element and that element’s\nindex; it returns a boolean. The `everyi()` function returns `true` if the\npredicate function is true for all items in the given array. If given an empty\narray, returns `true`. See\n[`Array.every`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)\non MDN.\n\n```res example\n// determine if all even-index items are positive\nlet evenIndexPositive = (item, index) => mod(index, 2) == 0 ? item > 0 : true\n\nJs.Array2.everyi([6, -3, 5, 8], evenIndexPositive) == true\nJs.Array2.everyi([6, 3, -5, 8], evenIndexPositive) == false\n```\n"} + }, { + "label": "Js_array2.toString", + "kind": 12, + "tags": [], + "detail": "t<'a> => string", + "documentation": {"kind": "markdown", "value": "\nConverts the array to a string. Each element is converted to a string using\nJavaScript. Unlike the JavaScript `Array.toString()`, all elements in a\nReasonML array must have the same type. See\n[`Array.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString)\non MDN.\n\n```res example\nJs.Array2.toString([3.5, 4.6, 7.8]) == \"3.5,4.6,7.8\"\nJs.Array2.toString([\"a\", \"b\", \"c\"]) == \"a,b,c\"\n```\n"} + }, { + "label": "Js_array2.spliceInPlace", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~pos: int, ~remove: int, ~add: array<'a>) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nStarting at position `~pos`, remove `~remove` elements and then add the\nelements from the `~add` array. Returns an array consisting of the removed\nitems. *This function modifies the original array.* See\n[`Array.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)\non MDN.\n\n```res example\nlet arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.spliceInPlace(arr, ~pos=2, ~remove=2, ~add=[\"x\", \"y\", \"z\"]) == [\"c\", \"d\"]\narr == [\"a\", \"b\", \"x\", \"y\", \"z\", \"e\", \"f\"]\n\nlet arr2 = [\"a\", \"b\", \"c\", \"d\"]\nJs.Array2.spliceInPlace(arr2, ~pos=3, ~remove=0, ~add=[\"x\", \"y\"]) == []\narr2 == [\"a\", \"b\", \"c\", \"x\", \"y\", \"d\"]\n\nlet arr3 = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.spliceInPlace(arr3, ~pos=9, ~remove=2, ~add=[\"x\", \"y\", \"z\"]) == []\narr3 == [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"x\", \"y\", \"z\"]\n```\n"} + }, { + "label": "Js_array2.pushMany", + "kind": 12, + "tags": [], + "detail": "(t<'a>, array<'a>) => int", + "documentation": {"kind": "markdown", "value": "\nAppends the values from one array (the second argument) to another (the first\nargument), returning the number of elements in the updated array. *This\nfunction modifies the original array.* See\n[`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)\non MDN.\n\n```res example\nlet arr = [\"ant\", \"bee\", \"cat\"]\nJs.Array2.pushMany(arr, [\"dog\", \"elk\"]) == 5\narr == [\"ant\", \"bee\", \"cat\", \"dog\", \"elk\"]\n```\n"} + }, { + "label": "Js_array2.copyWithinFrom", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ~to_: int, ~from: int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nCopies starting at element `~from` in the given array to the designated `~to_`\nposition, returning the resulting array. *This function modifies the original\narray.* See\n[`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.copyWithinFrom(arr, ~from=2, ~to_=0) == [102, 103, 104, 103, 104]\narr == [102, 103, 104, 103, 104]\n```\n"} + }, { + "label": "Js_array2.forEach", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a => unit) => unit", + "documentation": {"kind": "markdown", "value": "\nThe `forEach()` function applies the function given as the second argument to\neach element in the array. The function you provide returns `unit`, and the\n`forEach()` function also returns `unit`. You use `forEach()` when you need to\nprocess each element in the array but not return any new array or value; for\nexample, to print the items in an array. See\n[`Array.forEach`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)\non MDN.\n\n```res example\n// display all elements in an array\nJs.Array2.forEach([\"a\", \"b\", \"c\"], x => Js.log(x)) == ()\n```\n"} + }, { + "label": "Js_array2.sliceFrom", + "kind": 12, + "tags": [], + "detail": "(t<'a>, int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nReturns a shallow copy of the given array from the given index to the end. See\n[`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\non MDN.\n"} + }, { + "label": "Js_array2.sortInPlaceWith", + "kind": 12, + "tags": [], + "detail": "(t<'a>, ('a, 'a) => int) => t<'a>", + "documentation": {"kind": "markdown", "value": "\nSorts the given array in place and returns the sorted array. *This function\n modifies the original array.*\n\nThe first argument to `sortInPlaceWith()` is a function that compares two items\nfrom the array and returns:\n\n* an integer less than zero if the first item is less than the second item *\nzero if the items are equal * an integer greater than zero if the first item is\ngreater than the second item\n\nSee\n[`Array.sort`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)\non MDN.\n\n```res example\n// sort by word length\nlet words = [\"horse\", \"aardvark\", \"dog\", \"camel\"]\nlet byLength = (s1, s2) => Js.String.length(s1) - Js.String.length(s2)\n\nJs.Array2.sortInPlaceWith(words, byLength) == [\"dog\", \"horse\", \"camel\", \"aardvark\"]\n\n// sort in reverse numeric order\nlet numbers = [3, 30, 10, 1, 20, 2]\nlet reverseNumeric = (n1, n2) => n2 - n1\nJs.Array2.sortInPlaceWith(numbers, reverseNumeric) == [30, 20, 10, 3, 2, 1]\n```\n"} + }, { + "label": "Js_array2.indexOfFrom", + "kind": 12, + "tags": [], + "detail": "(t<'a>, 'a, ~from: int) => int", + "documentation": {"kind": "markdown", "value": "\nReturns the index of the first element in the array with the given value. The\nsearch starts at position `~from`. See\n[`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)\non MDN.\n\n```res example\nJs.Array2.indexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\"], \"a\", ~from=2) == 2\nJs.Array2.indexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\"], \"a\", ~from=3) == 4\nJs.Array2.indexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\"], \"b\", ~from=2) == -1\n```\n"} + }] + From 48e3caf94e11ccfb592dd8fa3821b0bd7338785c Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Wed, 21 Dec 2022 10:51:16 +0100 Subject: [PATCH 11/11] Handle test with unit --- analysis/src/CompletionBackEnd.ml | 16 +- .../src/expected/CompletionPipeChain.res.txt | 338 +----------------- 2 files changed, 10 insertions(+), 344 deletions(-) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index 4e0b46af6..10463e787 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -1354,13 +1354,15 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos Some (List.rev rest) | _ -> (* Get the path from the comletion environment *) - let pathFromEnv = - let path = envFromCompletionItem.path in - if env.file.moduleName = envFromCompletionItem.file.moduleName - then path - else envFromCompletionItem.file.moduleName :: path - in - Some pathFromEnv)) + let path = envFromCompletionItem.path in + if path = [] then None + else + let pathFromEnv = + if env.file.moduleName = envFromCompletionItem.file.moduleName + then path + else envFromCompletionItem.file.moduleName :: path + in + Some pathFromEnv)) | None -> None in match completionPath with diff --git a/analysis/tests/src/expected/CompletionPipeChain.res.txt b/analysis/tests/src/expected/CompletionPipeChain.res.txt index d951e3a19..fe947a437 100644 --- a/analysis/tests/src/expected/CompletionPipeChain.res.txt +++ b/analysis/tests/src/expected/CompletionPipeChain.res.txt @@ -237,341 +237,5 @@ Completable: Cpath Value[CompletionSupport, Test, addSelf](Nolabel, Nolabel)-> Complete src/CompletionPipeChain.res 58:5 posCursor:[58:5] posNoWhite:[58:4] Found expr:[57:8->0:-1] Completable: Cpath Value[Js, Array2, forEach](Nolabel, Nolabel)-> -[{ - "label": "Js_array2.mapi", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => 'b) => t<'b>", - "documentation": {"kind": "markdown", "value": "\nApplies the function (the second argument) to each item in the array, returning\na new array. The function acceps two arguments: an item from the array and its\nindex number. The result array does not have to have elements of the same type\nas the input array. See\n[`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)\non MDN.\n\n```res example\n// multiply each item in array by its position\nlet product = (item, index) => item * index\nJs.Array2.mapi([10, 11, 12], product) == [0, 11, 24]\n```\n"} - }, { - "label": "Js_array2.lastIndexOf", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a) => int", - "documentation": {"kind": "markdown", "value": "\nReturns the index of the last element in the array that has the given value. If\nthe value is not in the array, returns -1. See\n[`Array.lastIndexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)\non MDN.\n\n```res example\nJs.Array2.lastIndexOf([\"a\", \"b\", \"a\", \"c\"], \"a\") == 2\nJs.Array2.lastIndexOf([\"a\", \"b\", \"a\", \"c\"], \"x\") == -1\n```\n"} - }, { - "label": "Js_array2.concat", - "kind": 12, - "tags": [], - "detail": "(t<'a>, t<'a>) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nConcatenates the second array argument to the first array argument, returning a\nnew array. The original arrays are not modified. See\n[`Array.concat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)\non MDN.\n\n```res example\nJs.Array2.concat([\"a\", \"b\"], [\"c\", \"d\", \"e\"]) == [\"a\", \"b\", \"c\", \"d\", \"e\"]\n```\n"} - }, { - "label": "Js_array2.unshiftMany", - "kind": 12, - "tags": [], - "detail": "(t<'a>, array<'a>) => int", - "documentation": {"kind": "markdown", "value": "\nAdds the elements in the second array argument at the beginning of the first\narray argument, returning the new number of elements in the array. *This\nfunction modifies the original array.* See\n[`Array.unshift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)\non MDN.\n\n```res example\nlet arr = [\"d\", \"e\"]\nJs.Array2.unshiftMany(arr, [\"a\", \"b\", \"c\"]) == 5\narr == [\"a\", \"b\", \"c\", \"d\", \"e\"]\n```\n"} - }, { - "label": "Js_array2.filter", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nApplies the given predicate function (the second argument) to each element in\nthe array; the result is an array of those elements for which the predicate\nfunction returned `true`. See\n[`Array.filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)\non MDN.\n\n```res example\nlet nonEmpty = s => s != \"\"\nJs.Array2.filter([\"abc\", \"\", \"\", \"def\", \"ghi\"], nonEmpty) == [\"abc\", \"def\", \"ghi\"]\n```\n"} - }, { - "label": "Js_array2.shift", - "kind": 12, - "tags": [], - "detail": "t<'a> => option<'a>", - "documentation": {"kind": "markdown", "value": "\nIf the array is not empty, removes the first element and returns it as\n`Some(value)`; returns `None` if the array is empty. *This function modifies\nthe original array.* See\n[`Array.shift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.shift(arr) == Some(100)\narr == [101, 102, 103, 104]\n\nlet empty: array = []\nJs.Array2.shift(empty) == None\n```\n"} - }, { - "label": "Js_array2.reduceRight", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('b, 'a) => 'b, 'b) => 'b", - "documentation": {"kind": "markdown", "value": "\nThe `reduceRight()` function takes three parameters: an array, a *reducer\nfunction*, and a beginning accumulator value. The reducer function has two\nparameters: an accumulated value and an element of the array.\n\n`reduceRight()` first calls the reducer function with the beginning value and\nthe last element in the array. The result becomes the new accumulator value,\nwhich is passed in to the reducer function along with the next-to-last element\nin the array. `reduceRight()` proceeds from right to left through the array,\npassing in the result of each stage as the accumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reduceRight()`. See\n[`Array.reduceRight`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight)\non MDN.\n\n**NOTE:** In many cases, `reduce()` and `reduceRight()` give the same result.\nHowever, see the last example here and compare it to the example from\n`reduce()`, where order makes a difference.\n\n```res example\nlet sumOfSquares = (accumulator, item) => accumulator + item * item\n\nJs.Array2.reduceRight([10, 2, 4], sumOfSquares, 0) == 120\nJs.Array2.reduceRight([2.0, 4.0], (acc, item) => item /. acc, 1.0) == 0.5 // 2.0 / (4.0 / 1.0)\n```\n"} - }, { - "label": "Js_array2.joinWith", - "kind": 12, - "tags": [], - "detail": "(t<'a>, string) => string", - "documentation": {"kind": "markdown", "value": "\nThis function converts each element of the array to a string (via JavaScript)\nand concatenates them, separated by the string given in the first argument,\ninto a single string. See\n[`Array.join`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)\non MDN.\n\n```res example\nJs.Array2.joinWith([\"ant\", \"bee\", \"cat\"], \"--\") == \"ant--bee--cat\"\nJs.Array2.joinWith([\"door\", \"bell\"], \"\") == \"doorbell\"\nJs.Array2.joinWith([2020, 9, 4], \"/\") == \"2020/9/4\"\nJs.Array2.joinWith([2.5, 3.6, 3e-2], \";\") == \"2.5;3.6;0.03\"\n```\n"} - }, { - "label": "Js_array2.concatMany", - "kind": 12, - "tags": [], - "detail": "(t<'a>, array>) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nThe second argument to `concatMany()` is an array of arrays; these are added at\nthe end of the first argument, returning a new array. See\n[`Array.concat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)\non MDN.\n\n```res example\nJs.Array2.concatMany([\"a\", \"b\", \"c\"], [[\"d\", \"e\"], [\"f\", \"g\", \"h\"]]) == [\n \"a\",\n \"b\",\n \"c\",\n \"d\",\n \"e\",\n \"f\",\n \"g\",\n \"h\",\n ]\n```\n"} - }, { - "label": "Js_array2.fillInPlace", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nSets all elements of the given array (the first arumgent) to the designated\nvalue (the secon argument), returning the resulting array. *This function\n modifies the original array.*\n\nSee\n[`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.fillInPlace(arr, 99) == [99, 99, 99, 99, 99]\narr == [99, 99, 99, 99, 99]\n```\n"} - }, { - "label": "Js_array2.isArray", - "kind": 12, - "tags": [], - "detail": "'a => bool", - "documentation": {"kind": "markdown", "value": "\nReturns `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.\n\n```res example\nJs.Array2.isArray([5, 2, 3, 1, 4]) == true\nJs.Array2.isArray(list{5, 2, 3, 1, 4}) == true\nJs.Array2.isArray(\"abcd\") == false\n```\n"} - }, { - "label": "Js_array2.reduce", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('b, 'a) => 'b, 'b) => 'b", - "documentation": {"kind": "markdown", "value": "\nThe `reduce()` function takes three parameters: an array, a *reducer function*,\nand a beginning accumulator value. The reducer function has two parameters: an\naccumulated value and an element of the array.\n\n`reduce()` first calls the reducer function with the beginning value and the\nfirst element in the array. The result becomes the new accumulator value, which\nis passed in to the reducer function along with the second element in the\narray. `reduce()` proceeds through the array, passing in the result of each\nstage as the accumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reduce()`. See\n[`Array.reduce`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce)\non MDN.\n\n```res example\nlet sumOfSquares = (accumulator, item) => accumulator + item * item\n\nJs.Array2.reduce([10, 2, 4], sumOfSquares, 0) == 120\nJs.Array2.reduce([10, 2, 4], \\\"*\", 1) == 80\nJs.Array2.reduce(\n [\"animal\", \"vegetable\", \"mineral\"],\n (acc, item) => acc + Js.String.length(item),\n 0,\n) == 22 // 6 + 9 + 7\nJs.Array2.reduce([2.0, 4.0], (acc, item) => item /. acc, 1.0) == 2.0 // 4.0 / (2.0 / 1.0)\n```\n"} - }, { - "label": "Js_array2.copy", - "kind": 12, - "tags": [], - "detail": "t<'a> => t<'a>", - "documentation": {"kind": "markdown", "value": "\nReturns a copy of the entire array. Same as `Js.Array2.Slice(arr, ~start=0,\n~end_=Js.Array2.length(arr))`. See\n[`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\non MDN.\n"} - }, { - "label": "Js_array2.reducei", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('b, 'a, int) => 'b, 'b) => 'b", - "documentation": {"kind": "markdown", "value": "\nThe `reducei()` function takes three parameters: an array, a *reducer\nfunction*, and a beginning accumulator value. The reducer function has three\nparameters: an accumulated value, an element of the array, and the index of\nthat element.\n\n`reducei()` first calls the reducer function with the beginning value, the\nfirst element in the array, and zero (its index). The result becomes the new\naccumulator value, which is passed to the reducer function along with the\nsecond element in the array and one (its index). `reducei()` proceeds from left\nto right through the array, passing in the result of each stage as the\naccumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reducei()`. See\n[`Array.reduce`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce)\non MDN.\n\n```res example\n// find sum of even-index elements in array\nlet sumOfEvens = (accumulator, item, index) =>\n if mod(index, 2) == 0 {\n accumulator + item\n } else {\n accumulator\n }\n\nJs.Array2.reducei([2, 5, 1, 4, 3], sumOfEvens, 0) == 6\n```\n"} - }, { - "label": "Js_array2.forEachi", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => unit) => unit", - "documentation": {"kind": "markdown", "value": "\nThe `forEachi()` function applies the function given as the second argument to\neach element in the array. The function you provide takes an item in the array\nand its index number, and returns `unit`. The `forEachi()` function also\nreturns `unit`. You use `forEachi()` when you need to process each element in\nthe array but not return any new array or value; for example, to print the\nitems in an array. See\n[`Array.forEach`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)\non MDN.\n\n```res example\n// display all elements in an array as a numbered list\nJs.Array2.forEachi([\"a\", \"b\", \"c\"], (item, index) => Js.log2(index + 1, item)) == ()\n```\n"} - }, { - "label": "Js_array2.fillFromInPlace", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a, ~from: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nSets all elements of the given array (the first arumgent) from position `~from`\nto the end to the designated value (the second argument), returning the\nresulting array. *This function modifies the original array.* See\n[`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.fillFromInPlace(arr, 99, ~from=2) == [100, 101, 99, 99, 99]\narr == [100, 101, 99, 99, 99]\n```\n"} - }, { - "label": "Js_array2.findi", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => bool) => option<'a>", - "documentation": {"kind": "markdown", "value": "\nReturns `Some(value)` for the first element in the array that satisifies the\ngiven predicate function, or `None` if no element satisifies the predicate. The\npredicate function takes an array element and an index as its parameters. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\n// find first positive item at an odd index\nlet positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0\n\nJs.Array2.findi([66, -33, 55, 88, 22], positiveOddElement) == Some(88)\nJs.Array2.findi([66, -33, 55, -88, 22], positiveOddElement) == None\n```\n"} - }, { - "label": "Js_array2.filteri", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => bool) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nEach element of the given array are passed to the predicate function. The\nreturn value is an array of all those elements for which the predicate function\nreturned `true`.\n\nSee\n[`Array.filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)\non MDN.\n\n```res example\n// keep only positive elements at odd indices\nlet positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0\n\nJs.Array2.filteri([6, 3, 5, 8, 7, -4, 1], positiveOddElement) == [3, 8]\n```\n"} - }, { - "label": "Js_array2.slice", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~start: int, ~end_: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nReturns a shallow copy of the given array from the `~start` index up to but not\nincluding the `~end_` position. Negative numbers indicate an offset from the\nend of the array. See\n[`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104, 105, 106]\nJs.Array2.slice(arr, ~start=2, ~end_=5) == [102, 103, 104]\nJs.Array2.slice(arr, ~start=-3, ~end_=-1) == [104, 105]\nJs.Array2.slice(arr, ~start=9, ~end_=10) == []\n```\n"} - }, { - "label": "Js_array2.fromMap", - "kind": 12, - "tags": [], - "detail": "(array_like<'a>, 'a => 'b) => array<'b>", - "documentation": {"kind": "markdown", "value": "\nCreates a new array by applying a function (the second argument) to each item\nin the `array_like` first argument. See\n[`Array.from`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)\non MDN.\n\n```res example\nlet strArr = Js.String.castToArrayLike(\"abcd\")\nlet code = s => Js.String.charCodeAt(0, s)\nJs.Array2.fromMap(strArr, code) == [97.0, 98.0, 99.0, 100.0]\n```\n"} - }, { - "label": "Js_array2.removeFromInPlace", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~pos: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nRemoves elements from the given array starting at position `~pos` to the end of\nthe array, returning the removed elements. *This function modifies the original\narray.* See\n[`Array.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)\non MDN.\n\n```res example\nlet arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.removeFromInPlace(arr, ~pos=4) == [\"e\", \"f\"]\narr == [\"a\", \"b\", \"c\", \"d\"]\n```\n"} - }, { - "label": "Js_array2.from", - "kind": 12, - "tags": [], - "detail": "array_like<'a> => array<'a>", - "documentation": {"kind": "markdown", "value": "\nCreates a shallow copy of an array from an array-like object. See\n[`Array.from`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)\non MDN.\n\n```res example\nlet strArr = Js.String.castToArrayLike(\"abcd\")\nJs.Array2.from(strArr) == [\"a\", \"b\", \"c\", \"d\"]\n```\n"} - }, { - "label": "Js_array2.includes", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a) => bool", - "documentation": {"kind": "markdown", "value": "\nReturns true if the given value is in the array, `false` otherwise. See\n[`Array.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)\non MDN.\n\n```res example\nJs.Array2.includes([\"a\", \"b\", \"c\"], \"b\") == true\nJs.Array2.includes([\"a\", \"b\", \"c\"], \"x\") == false\n```\n"} - }, { - "label": "Js_array2.find", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => option<'a>", - "documentation": {"kind": "markdown", "value": "\nReturns `Some(value)` for the first element in the array that satisifies the\ngiven predicate function, or `None` if no element satisifies the predicate. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\n// find first negative element\nJs.Array2.find([33, 22, -55, 77, -44], x => x < 0) == Some(-55)\nJs.Array2.find([33, 22, 55, 77, 44], x => x < 0) == None\n```\n"} - }, { - "label": "Js_array2.reduceRighti", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('b, 'a, int) => 'b, 'b) => 'b", - "documentation": {"kind": "markdown", "value": "\nThe `reduceRighti()` function takes three parameters: an array, a *reducer\nfunction*, and a beginning accumulator value. The reducer function has three\nparameters: an accumulated value, an element of the array, and the index of\nthat element. `reduceRighti()` first calls the reducer function with the\nbeginning value, the last element in the array, and its index (length of array\nminus one). The result becomes the new accumulator value, which is passed in to\nthe reducer function along with the second element in the array and one (its\nindex). `reduceRighti()` proceeds from right to left through the array, passing\nin the result of each stage as the accumulator to the reducer function.\n\nWhen all array elements are processed, the final value of the accumulator\nbecomes the return value of `reduceRighti()`. See\n[`Array.reduceRight`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight)\non MDN.\n\n**NOTE:** In many cases, `reducei()` and `reduceRighti()` give the same result.\nHowever, there are cases where the order in which items are processed makes a\ndifference.\n\n```res example\n// find sum of even-index elements in array\nlet sumOfEvens = (accumulator, item, index) =>\n if mod(index, 2) == 0 {\n accumulator + item\n } else {\n accumulator\n }\n\nJs.Array2.reduceRighti([2, 5, 1, 4, 3], sumOfEvens, 0) == 6\n```\n"} - }, { - "label": "Js_array2.findIndexi", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => bool) => int", - "documentation": {"kind": "markdown", "value": "\nReturns `Some(value)` for the first element in the array that satisifies the\ngiven predicate function, or `None` if no element satisifies the predicate. The\npredicate function takes an array element and an index as its parameters. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\n// find index of first positive item at an odd index\nlet positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0\n\nJs.Array2.findIndexi([66, -33, 55, 88, 22], positiveOddElement) == 3\nJs.Array2.findIndexi([66, -33, 55, -88, 22], positiveOddElement) == -1\n```\n"} - }, { - "label": "Js_array2.toLocaleString", - "kind": 12, - "tags": [], - "detail": "t<'a> => string", - "documentation": {"kind": "markdown", "value": "\nConverts the array to a string using the conventions of the current locale.\nEach element is converted to a string using JavaScript. Unlike the JavaScript\n`Array.toLocaleString()`, all elements in a ReasonML array must have the same\ntype. See\n[`Array.toLocaleString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString)\non MDN.\n\n```res example\nJs.Array2.toLocaleString([Js.Date.make()])\n// returns \"3/19/2020, 10:52:11 AM\" for locale en_US.utf8\n// returns \"2020-3-19 10:52:11\" for locale de_DE.utf8\n```\n"} - }, { - "label": "Js_array2.lastIndexOfFrom", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a, ~from: int) => int", - "documentation": {"kind": "markdown", "value": "\nReturns the index of the last element in the array that has the given value,\nsearching from position `~from` down to the start of the array. If the value is\nnot in the array, returns -1. See\n[`Array.lastIndexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)\non MDN.\n\n```res example\nJs.Array2.lastIndexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\", \"d\"], \"a\", ~from=3) == 2\nJs.Array2.lastIndexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\", \"d\"], \"c\", ~from=2) == -1\n```\n"} - }, { - "label": "Js_array2.copyWithinFromRange", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~to_: int, ~start: int, ~end_: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nCopies starting at element `~start` in the given array up to but not including\n`~end_` to the designated `~to_` position, returning the resulting array. *This\nfunction modifies the original array.* See\n[`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104, 105]\nJs.Array2.copyWithinFromRange(arr, ~start=2, ~end_=5, ~to_=1) == [100, 102, 103, 104, 104, 105]\narr == [100, 102, 103, 104, 104, 105]\n```\n"} - }, { - "label": "Js_array2.findIndex", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => int", - "documentation": {"kind": "markdown", "value": "\nReturns the index of the first element in the array that satisifies the given\npredicate function, or -1 if no element satisifies the predicate. See\n[`Array.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)\non MDN.\n\n```res example\nJs.Array2.findIndex([33, 22, -55, 77, -44], x => x < 0) == 2\nJs.Array2.findIndex([33, 22, 55, 77, 44], x => x < 0) == -1\n```\n"} - }, { - "label": "Js_array2.removeCountInPlace", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~pos: int, ~count: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nRemoves `~count` elements from the given array starting at position `~pos`,\nreturning the removed elements. *This function modifies the original array.*\nSee\n[`Array.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)\non MDN.\n\n```res example\nlet arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.removeCountInPlace(arr, ~pos=2, ~count=3) == [\"c\", \"d\", \"e\"]\narr == [\"a\", \"b\", \"f\"]\n```\n"} - }, { - "label": "Js_array2.reverseInPlace", - "kind": 12, - "tags": [], - "detail": "t<'a> => t<'a>", - "documentation": {"kind": "markdown", "value": "\nReturns an array with the elements of the input array in reverse order. *This\nfunction modifies the original array.* See\n[`Array.reverse`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse)\non MDN.\n\n```res example\nlet arr = [\"ant\", \"bee\", \"cat\"]\nJs.Array2.reverseInPlace(arr) == [\"cat\", \"bee\", \"ant\"]\narr == [\"cat\", \"bee\", \"ant\"]\n```\n"} - }, { - "label": "Js_array2.every", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => bool", - "documentation": {"kind": "markdown", "value": "\nThe first argument to `every()` is an array. The second argument is a predicate\nfunction that returns a boolean. The `every()` function returns `true` if the\npredicate function is true for all items in the given array. If given an empty\narray, returns `true`. See\n[`Array.every`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)\non MDN.\n\n```res example\nlet isEven = x => mod(x, 2) == 0\nJs.Array2.every([6, 22, 8, 4], isEven) == true\nJs.Array2.every([6, 22, 7, 4], isEven) == false\n```\n"} - }, { - "label": "Js_array2.length", - "kind": 12, - "tags": [], - "detail": "array<'a> => int", - "documentation": {"kind": "markdown", "value": "\nReturns the number of elements in the array. See\n[`Array.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)\non MDN.\n"} - }, { - "label": "Js_array2.indexOf", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a) => int", - "documentation": {"kind": "markdown", "value": "\nReturns the index of the first element in the array that has the given value.\nIf the value is not in the array, returns -1. See\n[`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)\non MDN.\n\n```res example\nJs.Array2.indexOf([100, 101, 102, 103], 102) == 2\nJs.Array2.indexOf([100, 101, 102, 103], 999) == -1\n```\n"} - }, { - "label": "Js_array2.unshift", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a) => int", - "documentation": {"kind": "markdown", "value": "\nAdds the given element to the array, returning the new number of elements in\nthe array. *This function modifies the original array.* See\n[`Array.unshift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)\non MDN.\n\n```res example\nlet arr = [\"b\", \"c\", \"d\"]\nJs.Array2.unshift(arr, \"a\") == 4\narr == [\"a\", \"b\", \"c\", \"d\"]\n```\n"} - }, { - "label": "Js_array2.sortInPlace", - "kind": 12, - "tags": [], - "detail": "t<'a> => t<'a>", - "documentation": {"kind": "markdown", "value": "\nSorts the given array in place and returns the sorted array. JavaScript sorts\nthe array by converting the arguments to UTF-16 strings and sorting them. See\nthe second example with sorting numbers, which does not do a numeric sort.\n*This function modifies the original array.* See\n[`Array.sort`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)\non MDN.\n\n```res example\nlet words = [\"bee\", \"dog\", \"ant\", \"cat\"]\nJs.Array2.sortInPlace(words) == [\"ant\", \"bee\", \"cat\", \"dog\"]\nwords == [\"ant\", \"bee\", \"cat\", \"dog\"]\n\nlet numbers = [3, 30, 10, 1, 20, 2]\nJs.Array2.sortInPlace(numbers) == [1, 10, 2, 20, 3, 30]\nnumbers == [1, 10, 2, 20, 3, 30]\n```\n"} - }, { - "label": "Js_array2.unsafe_get", - "kind": 12, - "tags": [], - "detail": "(array<'a>, int) => 'a", - "documentation": {"kind": "markdown", "value": "\nReturns the value at the given position in the array if the position is in\nbounds; returns the JavaScript value `undefined` otherwise.\n\n```res example\nlet arr = [100, 101, 102, 103]\nJs.Array2.unsafe_get(arr, 3) == 103\nJs.Array2.unsafe_get(arr, 4) // returns undefined\n```\n"} - }, { - "label": "Js_array2.some", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => bool) => bool", - "documentation": {"kind": "markdown", "value": "\nReturns `true` if the predicate function given as the second argument to\n`some()` returns `true` for any element in the array; `false` otherwise.\n\n```res example\nlet isEven = x => mod(x, 2) == 0\n\nJs.Array2.some([3, 7, 5, 2, 9], isEven) == true\nJs.Array2.some([3, 7, 5, 1, 9], isEven) == false\n```\n"} - }, { - "label": "Js_array2.map", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => 'b) => t<'b>", - "documentation": {"kind": "markdown", "value": "\nApplies the function (the second argument) to each item in the array, returning\na new array. The result array does not have to have elements of the same type\nas the input array. See\n[`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)\non MDN.\n\n```res example\nJs.Array2.map([12, 4, 8], x => x * x) == [144, 16, 64]\nJs.Array2.map([\"animal\", \"vegetable\", \"mineral\"], Js.String.length) == [6, 9, 7]\n```\n"} - }, { - "label": "Js_array2.push", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a) => int", - "documentation": {"kind": "markdown", "value": "\nAppends the given value to the array, returning the number of elements in the\nupdated array. *This function modifies the original array.* See\n[`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)\non MDN.\n\n```res example\nlet arr = [\"ant\", \"bee\", \"cat\"]\nJs.Array2.push(arr, \"dog\") == 4\narr == [\"ant\", \"bee\", \"cat\", \"dog\"]\n```\n"} - }, { - "label": "Js_array2.fillRangeInPlace", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a, ~start: int, ~end_: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nSets the elements of the given array (the first arumgent) from position\n`~start` up to but not including position `~end_` to the designated value (the\nsecond argument), returning the resulting array. *This function modifies the\noriginal array.* See\n[`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.fillRangeInPlace(arr, 99, ~start=1, ~end_=4) == [100, 99, 99, 99, 104]\narr == [100, 99, 99, 99, 104]\n```\n"} - }, { - "label": "Js_array2.pop", - "kind": 12, - "tags": [], - "detail": "t<'a> => option<'a>", - "documentation": {"kind": "markdown", "value": "\nIf the array is not empty, removes the last element and returns it as\n`Some(value)`; returns `None` if the array is empty. *This function modifies\nthe original array.* See\n[`Array.pop`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.pop(arr) == Some(104)\narr == [100, 101, 102, 103]\n\nlet empty: array = []\nJs.Array2.pop(empty) == None\n```\n"} - }, { - "label": "Js_array2.somei", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => bool) => bool", - "documentation": {"kind": "markdown", "value": "\nReturns `true` if the predicate function given as the second argument to\n`somei()` returns `true` for any element in the array; `false` otherwise. The\npredicate function has two arguments: an item from the array and the index\nvalue\n\n```res example\n// Does any string in the array\n// have the same length as its index?\n\nlet sameLength = (str, index) => Js.String.length(str) == index\n\n// \"ef\" has length 2 and is it at index 2\nJs.Array2.somei([\"ab\", \"cd\", \"ef\", \"gh\"], sameLength) == true\n// no item has the same length as its index\nJs.Array2.somei([\"a\", \"bc\", \"def\", \"gh\"], sameLength) == false\n```\n"} - }, { - "label": "Js_array2.append", - "kind": 12, - "tags": [1], - "detail": "(t<'a>, 'a) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: `append` is not type-safe. Use `concat` instead.\n\n"} - }, { - "label": "Js_array2.unsafe_set", - "kind": 12, - "tags": [], - "detail": "(array<'a>, int, 'a) => unit", - "documentation": {"kind": "markdown", "value": "\nSets the value at the given position in the array if the position is in bounds.\nIf the index is out of bounds, well, “here there be dragons.“\n\n*This function modifies the original array.*\n\n```res example\nlet arr = [100, 101, 102, 103]\nJs.Array2.unsafe_set(arr, 3, 99)\n// result is [100, 101, 102, 99];\n\nJs.Array2.unsafe_set(arr, 4, 88)\n// result is [100, 101, 102, 99, 88]\n\nJs.Array2.unsafe_set(arr, 6, 77)\n// result is [100, 101, 102, 99, 88, <1 empty item>, 77]\n\nJs.Array2.unsafe_set(arr, -1, 66)\n// you don't want to know.\n```\n"} - }, { - "label": "Js_array2.copyWithin", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~to_: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nCopies from the first element in the given array to the designated `~to_`\nposition, returning the resulting array. *This function modifies the original\narray.* See\n[`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.copyWithin(arr, ~to_=2) == [100, 101, 100, 101, 102]\narr == [100, 101, 100, 101, 102]\n```\n"} - }, { - "label": "Js_array2.everyi", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, int) => bool) => bool", - "documentation": {"kind": "markdown", "value": "\nThe first argument to `everyi()` is an array. The second argument is a\npredicate function with two arguments: an array element and that element’s\nindex; it returns a boolean. The `everyi()` function returns `true` if the\npredicate function is true for all items in the given array. If given an empty\narray, returns `true`. See\n[`Array.every`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)\non MDN.\n\n```res example\n// determine if all even-index items are positive\nlet evenIndexPositive = (item, index) => mod(index, 2) == 0 ? item > 0 : true\n\nJs.Array2.everyi([6, -3, 5, 8], evenIndexPositive) == true\nJs.Array2.everyi([6, 3, -5, 8], evenIndexPositive) == false\n```\n"} - }, { - "label": "Js_array2.toString", - "kind": 12, - "tags": [], - "detail": "t<'a> => string", - "documentation": {"kind": "markdown", "value": "\nConverts the array to a string. Each element is converted to a string using\nJavaScript. Unlike the JavaScript `Array.toString()`, all elements in a\nReasonML array must have the same type. See\n[`Array.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString)\non MDN.\n\n```res example\nJs.Array2.toString([3.5, 4.6, 7.8]) == \"3.5,4.6,7.8\"\nJs.Array2.toString([\"a\", \"b\", \"c\"]) == \"a,b,c\"\n```\n"} - }, { - "label": "Js_array2.spliceInPlace", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~pos: int, ~remove: int, ~add: array<'a>) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nStarting at position `~pos`, remove `~remove` elements and then add the\nelements from the `~add` array. Returns an array consisting of the removed\nitems. *This function modifies the original array.* See\n[`Array.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)\non MDN.\n\n```res example\nlet arr = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.spliceInPlace(arr, ~pos=2, ~remove=2, ~add=[\"x\", \"y\", \"z\"]) == [\"c\", \"d\"]\narr == [\"a\", \"b\", \"x\", \"y\", \"z\", \"e\", \"f\"]\n\nlet arr2 = [\"a\", \"b\", \"c\", \"d\"]\nJs.Array2.spliceInPlace(arr2, ~pos=3, ~remove=0, ~add=[\"x\", \"y\"]) == []\narr2 == [\"a\", \"b\", \"c\", \"x\", \"y\", \"d\"]\n\nlet arr3 = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\nJs.Array2.spliceInPlace(arr3, ~pos=9, ~remove=2, ~add=[\"x\", \"y\", \"z\"]) == []\narr3 == [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"x\", \"y\", \"z\"]\n```\n"} - }, { - "label": "Js_array2.pushMany", - "kind": 12, - "tags": [], - "detail": "(t<'a>, array<'a>) => int", - "documentation": {"kind": "markdown", "value": "\nAppends the values from one array (the second argument) to another (the first\nargument), returning the number of elements in the updated array. *This\nfunction modifies the original array.* See\n[`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)\non MDN.\n\n```res example\nlet arr = [\"ant\", \"bee\", \"cat\"]\nJs.Array2.pushMany(arr, [\"dog\", \"elk\"]) == 5\narr == [\"ant\", \"bee\", \"cat\", \"dog\", \"elk\"]\n```\n"} - }, { - "label": "Js_array2.copyWithinFrom", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ~to_: int, ~from: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nCopies starting at element `~from` in the given array to the designated `~to_`\nposition, returning the resulting array. *This function modifies the original\narray.* See\n[`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)\non MDN.\n\n```res example\nlet arr = [100, 101, 102, 103, 104]\nJs.Array2.copyWithinFrom(arr, ~from=2, ~to_=0) == [102, 103, 104, 103, 104]\narr == [102, 103, 104, 103, 104]\n```\n"} - }, { - "label": "Js_array2.forEach", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a => unit) => unit", - "documentation": {"kind": "markdown", "value": "\nThe `forEach()` function applies the function given as the second argument to\neach element in the array. The function you provide returns `unit`, and the\n`forEach()` function also returns `unit`. You use `forEach()` when you need to\nprocess each element in the array but not return any new array or value; for\nexample, to print the items in an array. See\n[`Array.forEach`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)\non MDN.\n\n```res example\n// display all elements in an array\nJs.Array2.forEach([\"a\", \"b\", \"c\"], x => Js.log(x)) == ()\n```\n"} - }, { - "label": "Js_array2.sliceFrom", - "kind": 12, - "tags": [], - "detail": "(t<'a>, int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nReturns a shallow copy of the given array from the given index to the end. See\n[`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\non MDN.\n"} - }, { - "label": "Js_array2.sortInPlaceWith", - "kind": 12, - "tags": [], - "detail": "(t<'a>, ('a, 'a) => int) => t<'a>", - "documentation": {"kind": "markdown", "value": "\nSorts the given array in place and returns the sorted array. *This function\n modifies the original array.*\n\nThe first argument to `sortInPlaceWith()` is a function that compares two items\nfrom the array and returns:\n\n* an integer less than zero if the first item is less than the second item *\nzero if the items are equal * an integer greater than zero if the first item is\ngreater than the second item\n\nSee\n[`Array.sort`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)\non MDN.\n\n```res example\n// sort by word length\nlet words = [\"horse\", \"aardvark\", \"dog\", \"camel\"]\nlet byLength = (s1, s2) => Js.String.length(s1) - Js.String.length(s2)\n\nJs.Array2.sortInPlaceWith(words, byLength) == [\"dog\", \"horse\", \"camel\", \"aardvark\"]\n\n// sort in reverse numeric order\nlet numbers = [3, 30, 10, 1, 20, 2]\nlet reverseNumeric = (n1, n2) => n2 - n1\nJs.Array2.sortInPlaceWith(numbers, reverseNumeric) == [30, 20, 10, 3, 2, 1]\n```\n"} - }, { - "label": "Js_array2.indexOfFrom", - "kind": 12, - "tags": [], - "detail": "(t<'a>, 'a, ~from: int) => int", - "documentation": {"kind": "markdown", "value": "\nReturns the index of the first element in the array with the given value. The\nsearch starts at position `~from`. See\n[`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)\non MDN.\n\n```res example\nJs.Array2.indexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\"], \"a\", ~from=2) == 2\nJs.Array2.indexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\"], \"a\", ~from=3) == 4\nJs.Array2.indexOfFrom([\"a\", \"b\", \"a\", \"c\", \"a\"], \"b\", ~from=2) == -1\n```\n"} - }] +[]