From a3563aa345170d93028999ab85f353a68ce712e4 Mon Sep 17 00:00:00 2001 From: jmagaram Date: Tue, 28 Mar 2023 17:50:37 -0700 Subject: [PATCH 01/12] docs for lastIndexOf and lastIndexOfFrom --- src/Core__Array.resi | 48 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/src/Core__Array.resi b/src/Core__Array.resi index 253f0cf2..cd130e6e 100644 --- a/src/Core__Array.resi +++ b/src/Core__Array.resi @@ -383,9 +383,53 @@ Console.log(array->Array.joinWith(" -- ")) // 1 -- 2 -- 3 */ @send external joinWith: (array<'a>, string) => string = "join" -@send external lastIndexOf: (array<'a>, 'a) => int = "lastIndexOf" + +/** +`lastIndexOf(array, item)` returns the last index of `item` in `array`, or `-1` if it is not present. **Note:** [Strict equality](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality) is used when searching, which may produce unexpected results; use `Array.findLastIndexOf` to search by value. + +See [Array.lastIndexOf on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf). + +## Examples +```rescript +[3, 5, 7, 5, 8]->Array.lastIndexOf(5) // 3 +[3, 5, 7, 5, 8]->Array.lastIndexOf(99) // -1 +[{"color": "red"}]->Array.lastIndexOf({"color": "red"}) // -1, because of strict equality +``` +*/ +@send +external lastIndexOf: (array<'a>, 'a) => int = "lastIndexOf" + +/** +`lastIndexOfOpt(array, item)` returns the last index of `item` in `array`, or `None` if it is not present. **Note:** [Strict equality](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality) is used when searching, which may produce unexpected results; use `Array.findLastIndexOf` to search by value. + +See [Array.lastIndexOf on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf). + +## Examples +```rescript +[3, 5, 7, 5, 8]->Array.lastIndexOf(5) // Some(3) +[3, 5, 7, 5, 8]->Array.lastIndexOf(99) // None +[{"color": "red"}]->Array.lastIndexOf({"color": "red"}) // None, because of strict equality +``` +*/ let lastIndexOfOpt: (array<'a>, 'a) => option -@send external lastIndexOfFrom: (array<'a>, 'a, int) => int = "lastIndexOf" + +/** +`lastIndexOfFrom(array, item, fromIndex)` returns the last index of `item` in `array`, or `-1` if it is not present. The search begins at `fromIndex`. A negative index counts back from the end of the array. + +**Note:** [Strict equality](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality) is used when searching, which may produce unexpected results; use `Array.findLastIndexOf` to search by value. + +See [Array.lastIndexOf on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf). + +## Examples +```rescript +[3, 5, 7, 5, 8]->Array.lastIndexOfFrom(5, -3) // 1 +[3, 5, 7, 5, 8]->Array.lastIndexOfFrom(5, 4) // 3 +[3, 5, 7, 5, 8]->Array.lastIndexOfFrom(5, 0) // -1 +[{"color": "red"}]->Array.lastIndexOfFrom({"color": "red"}, 99) // -1, because of strict equality +``` +*/ +@send +external lastIndexOfFrom: (array<'a>, 'a, int) => int = "lastIndexOf" /** `slice(array, ~start, ~end)` creates a new array of items copied from `array` from `start` until (but not including) `end`. From d2e124e1ca3d179a8dc68e49159d17771cede616 Mon Sep 17 00:00:00 2001 From: jmagaram Date: Tue, 28 Mar 2023 17:54:28 -0700 Subject: [PATCH 02/12] Add findLast, findLastIndex, and findLastIndexOpt --- src/Core__Array.mjs | 9 +++++++++ src/Core__Array.res | 12 ++++++++++++ src/Core__Array.resi | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) diff --git a/src/Core__Array.mjs b/src/Core__Array.mjs index 1560df8f..97658aaf 100644 --- a/src/Core__Array.mjs +++ b/src/Core__Array.mjs @@ -138,6 +138,14 @@ function findMap(arr, f) { }; } +function findLastIndexOpt(xs, pred) { + var inx = xs.findLastIndex(pred); + if (inx !== -1) { + return inx; + } + +} + export { make , fromInitializer , @@ -155,5 +163,6 @@ export { shuffle , shuffleInPlace , findMap , + findLastIndexOpt , } /* No side effect */ diff --git a/src/Core__Array.res b/src/Core__Array.res index cd1bda48..5943067b 100644 --- a/src/Core__Array.res +++ b/src/Core__Array.res @@ -214,3 +214,15 @@ let findMap = (arr, f) => { } @send external at: (array<'a>, int) => option<'a> = "at" + +@send +external findLast: (array<'a>, 'a => bool) => option<'a> = "findLast" + +@send +external findLastIndex: (array<'a>, 'a => bool) => int = "findLastIndex" + +let findLastIndexOpt = (xs, pred) => + switch findLastIndex(xs, pred) { + | -1 => None + | _ as inx => Some(inx) + } diff --git a/src/Core__Array.resi b/src/Core__Array.resi index cd130e6e..814bb878 100644 --- a/src/Core__Array.resi +++ b/src/Core__Array.resi @@ -999,3 +999,47 @@ let findMap: (array<'a>, 'a => option<'b>) => option<'b> */ @send external at: (array<'a>, int) => option<'a> = "at" + +/** +`findLast(array, predicate)` iterates the array in **reverse** order and returns the value of the first element that satisfies the provided testing function. Returns `None` if no elements satisfy the predicate. + +See [Array.findLast on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast) + +## Examples +```rescript +[3, 5, 7, 5, 8]->Array.findLast(i => i < 7) // Some(5) +[3, 5, 7, 5, 8]->Array.findLast(i=> i > 100) // None +[]->Array.findLast(_ => true) // None +``` +*/ +@send +external findLast: (array<'a>, 'a => bool) => option<'a> = "findLast" + +/** +`findLastIndex(array, predicate)` iterates the array in **reverse** order and returns the index of the first element that satisfies the provided testing function. Returns `-1` if no elements satisfy the predicate. + +See [Array.findLastIndex on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex) + +## Examples +```rescript +[3, 5, 7, 5, 8]->Array.findLastIndex(i => i < 7) // 3 +[3, 5, 7, 5, 8]->Array.findLast(i => i > 100) // -1 +[]->Array.findLast(_ => true) // -1 +``` +*/ +@send +external findLastIndex: (array<'a>, 'a => bool) => int = "findLastIndex" + +/** +`findLastIndexOpt(array, predicate)` iterates the array in **reverse** order and returns the index of the first element that satisfies the provided testing function. Returns `None` if no elements satisfy the predicate. + +See [Array.findLastIndex on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex) + +## Examples +```rescript +[3, 5, 7, 5, 8]->Array.findLastIndex(i => i < 7) // Some(3) +[3, 5, 7, 5, 8]->Array.findLast(i => i > 100) // None +[]->Array.findLast(_ => true) // None +``` +*/ +let findLastIndexOpt: (array<'a>, 'a => bool) => option From c49f1b90978c9742860f1982bbd0ecfae499f790 Mon Sep 17 00:00:00 2001 From: jmagaram Date: Wed, 29 Mar 2023 07:47:34 -0700 Subject: [PATCH 03/12] more array.findlast --- src/Core__Array.res | 3 + src/Core__Array.resi | 14 ++ src/TestingStuff.mjs | 2 + src/TestingStuff.res | 1 + test/ArrayTests.mjs | 398 +++++++++++++++++++++++++++++++++++++++++++ test/ArrayTests.res | 49 ++++++ test/TestSuite.mjs | 3 + 7 files changed, 470 insertions(+) create mode 100644 src/TestingStuff.mjs create mode 100644 src/TestingStuff.res diff --git a/src/Core__Array.res b/src/Core__Array.res index 5943067b..71adcdf0 100644 --- a/src/Core__Array.res +++ b/src/Core__Array.res @@ -226,3 +226,6 @@ let findLastIndexOpt = (xs, pred) => | -1 => None | _ as inx => Some(inx) } + +@send +external findLastIndexWithIndex: (array<'a>, ('a, int) => bool) => int = "findLastIndex" diff --git a/src/Core__Array.resi b/src/Core__Array.resi index 814bb878..c9f2c24d 100644 --- a/src/Core__Array.resi +++ b/src/Core__Array.resi @@ -1043,3 +1043,17 @@ See [Array.findLastIndex on MDN](https://developer.mozilla.org/en-US/docs/Web/Ja ``` */ let findLastIndexOpt: (array<'a>, 'a => bool) => option + +/** +`findLastIndexWithIndex(array, predicate)` iterates the array in **reverse** order and returns the index of the first element that satisfies the callback `predicate`. The `predicate` receives the current element being processed followed by its index. Returns `-1` if no elements satisfy the predicate. + +See [Array.findLastIndex on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex) + +## Examples +```rescript +["a", "x", "j", "b", "x"]->Array.findLastIndex((i, j) => i == "x" && j > 2) // 4 +["a", "x", "j", "b", "x"]->Array.findLastIndex((i, j) => i == "x" && j < 3) // 2 +``` +*/ +@send +external findLastIndexWithIndex: (array<'a>, ('a, int) => bool) => int = "findLastIndex" diff --git a/src/TestingStuff.mjs b/src/TestingStuff.mjs new file mode 100644 index 00000000..d856702b --- /dev/null +++ b/src/TestingStuff.mjs @@ -0,0 +1,2 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/src/TestingStuff.res b/src/TestingStuff.res new file mode 100644 index 00000000..ba09e17c --- /dev/null +++ b/src/TestingStuff.res @@ -0,0 +1 @@ +open RescriptCore diff --git a/test/ArrayTests.mjs b/test/ArrayTests.mjs index 7cc4a4c6..290e194d 100644 --- a/test/ArrayTests.mjs +++ b/test/ArrayTests.mjs @@ -401,7 +401,405 @@ Test.run([ })), eq, undefined); +Test.run([ + [ + "ArrayTests.res", + 102, + 20, + 33 + ], + "lastIndexOf" + ], [ + 3, + 5, + 7, + 5, + 8 + ].lastIndexOf(5), eq, 3); + +Test.run([ + [ + "ArrayTests.res", + 103, + 20, + 33 + ], + "lastIndexOf" + ], [ + 3, + 5, + 7, + 5, + 8 + ].lastIndexOf(100), eq, -1); + +Test.run([ + [ + "ArrayTests.res", + 104, + 20, + 33 + ], + "lastIndexOf" + ], [].lastIndexOf(100), eq, -1); + +Test.run([ + [ + "ArrayTests.res", + 105, + 20, + 33 + ], + "lastIndexOf" + ], [{ + a: 1 + }].lastIndexOf({ + a: 1 + }), eq, -1); + +Test.run([ + [ + "ArrayTests.res", + 107, + 20, + 37 + ], + "lastIndexOfFrom" + ], [ + 3, + 5, + 7, + 5, + 8 + ].lastIndexOf(5, -3), eq, 1); + +Test.run([ + [ + "ArrayTests.res", + 108, + 20, + 37 + ], + "lastIndexOfFrom" + ], [ + 3, + 5, + 7, + 5, + 8 + ].lastIndexOf(5, 4), eq, 3); + +Test.run([ + [ + "ArrayTests.res", + 109, + 20, + 37 + ], + "lastIndexOfFrom" + ], [ + 3, + 5, + 7, + 5, + 8 + ].lastIndexOf(5, 0), eq, -1); + +Test.run([ + [ + "ArrayTests.res", + 111, + 20, + 36 + ], + "lastIndexOfOpt" + ], Core__Array.lastIndexOfOpt([ + 3, + 5, + 7, + 5, + 8 + ], 5), eq, 3); + +Test.run([ + [ + "ArrayTests.res", + 112, + 20, + 36 + ], + "lastIndexOfOpt" + ], Core__Array.lastIndexOfOpt([ + 3, + 5, + 7, + 5, + 8 + ], 100), eq, undefined); + +Test.run([ + [ + "ArrayTests.res", + 113, + 20, + 36 + ], + "lastIndexOfOpt" + ], Core__Array.lastIndexOfOpt([], 100), eq, undefined); + +Test.run([ + [ + "ArrayTests.res", + 114, + 20, + 36 + ], + "lastIndexOfOpt" + ], Core__Array.lastIndexOfOpt([{ + a: 1 + }], { + a: 1 + }), eq, undefined); + +Test.run([ + [ + "ArrayTests.res", + 116, + 20, + 30 + ], + "findLast" + ], [ + 3, + 5, + 7, + 5, + 8 + ].findLast(function (i) { + return i < 7; + }), eq, 5); + +Test.run([ + [ + "ArrayTests.res", + 117, + 20, + 30 + ], + "findLast" + ], [ + 3, + 5, + 7, + 5, + 8 + ].findLast(function (i) { + return i > 100; + }), eq, undefined); + +Test.run([ + [ + "ArrayTests.res", + 118, + 20, + 30 + ], + "findLast" + ], [].findLast(function (param) { + return true; + }), eq, undefined); + +function isDigit(s) { + return "0123456789".includes(s); +} + +Test.run([ + [ + "ArrayTests.res", + 122, + 20, + 35 + ], + "findLastIndex" + ], [ + 3, + 5, + 7, + 5, + 8 + ].findLastIndex(function (i) { + return i === 5; + }), eq, 3); + +Test.run([ + [ + "ArrayTests.res", + 123, + 20, + 35 + ], + "findLastIndex" + ], [ + 3, + 5, + 7, + 5, + 8 + ].findLastIndex(function (i) { + return i > 100; + }), eq, -1); + +Test.run([ + [ + "ArrayTests.res", + 124, + 20, + 35 + ], + "findLastIndex" + ], [].findLastIndex(function (param) { + return true; + }), eq, -1); + +Test.run([ + [ + "ArrayTests.res", + 125, + 20, + 35 + ], + "findLastIndex" + ], [ + "3", + "a", + "4", + "x" + ].findLastIndex(isDigit), eq, 3); + +Test.run([ + [ + "ArrayTests.res", + 126, + 20, + 35 + ], + "findLastIndex" + ], [ + 3, + 5, + 7, + 5, + 8 + ].findLastIndex(function (i) { + return i > 100; + }), eq, -1); + +Test.run([ + [ + "ArrayTests.res", + 127, + 20, + 35 + ], + "findLastIndex" + ], [].findLastIndex(function (param) { + return true; + }), eq, -1); + +Test.run([ + [ + "ArrayTests.res", + 130, + 13, + 37 + ], + "findLastIndexWithIndex" + ], [ + "a", + "2", + "e", + "4", + "x" + ].findLastIndex(function (i, j) { + if ("0123456789".includes(i)) { + return j > 2; + } else { + return false; + } + }), eq, 4); + +Test.run([ + [ + "ArrayTests.res", + 136, + 13, + 37 + ], + "findLastIndexWithIndex" + ], [ + "a", + "x", + "j", + "b", + "x" + ].findLastIndex(function (i, j) { + if (i === "x") { + return j < 3; + } else { + return false; + } + }), eq, 1); + +Test.run([ + [ + "ArrayTests.res", + 143, + 13, + 31 + ], + "findLastIndexOpt" + ], Core__Array.findLastIndexOpt([ + 3, + 5, + 7, + 5, + 8 + ], (function (i) { + return i === 5; + })), eq, 3); + +Test.run([ + [ + "ArrayTests.res", + 149, + 13, + 31 + ], + "findLastIndexOpt" + ], Core__Array.findLastIndexOpt([ + 3, + 5, + 7, + 5, + 8 + ], (function (i) { + return i > 100; + })), eq, undefined); + +Test.run([ + [ + "ArrayTests.res", + 154, + 20, + 38 + ], + "findLastIndexOpt" + ], Core__Array.findLastIndexOpt([], (function (param) { + return true; + })), eq, undefined); + export { eq , + isDigit , } /* Not a pure module */ diff --git a/test/ArrayTests.res b/test/ArrayTests.res index 40c352f7..19cda060 100644 --- a/test/ArrayTests.res +++ b/test/ArrayTests.res @@ -98,3 +98,52 @@ Test.run( eq, None, ) + +Test.run(__POS_OF__("lastIndexOf"), [3, 5, 7, 5, 8]->Array.lastIndexOf(5), eq, 3) +Test.run(__POS_OF__("lastIndexOf"), [3, 5, 7, 5, 8]->Array.lastIndexOf(100), eq, -1) +Test.run(__POS_OF__("lastIndexOf"), []->Array.lastIndexOf(100), eq, -1) +Test.run(__POS_OF__("lastIndexOf"), [{"a": 1}]->Array.lastIndexOf({"a": 1}), eq, -1) + +Test.run(__POS_OF__("lastIndexOfFrom"), [3, 5, 7, 5, 8]->Array.lastIndexOfFrom(5, -3), eq, 1) +Test.run(__POS_OF__("lastIndexOfFrom"), [3, 5, 7, 5, 8]->Array.lastIndexOfFrom(5, 4), eq, 3) +Test.run(__POS_OF__("lastIndexOfFrom"), [3, 5, 7, 5, 8]->Array.lastIndexOfFrom(5, 0), eq, -1) + +Test.run(__POS_OF__("lastIndexOfOpt"), [3, 5, 7, 5, 8]->Array.lastIndexOfOpt(5), eq, Some(3)) +Test.run(__POS_OF__("lastIndexOfOpt"), [3, 5, 7, 5, 8]->Array.lastIndexOfOpt(100), eq, None) +Test.run(__POS_OF__("lastIndexOfOpt"), []->Array.lastIndexOfOpt(100), eq, None) +Test.run(__POS_OF__("lastIndexOfOpt"), [{"a": 1}]->Array.lastIndexOfOpt({"a": 1}), eq, None) + +Test.run(__POS_OF__("findLast"), [3, 5, 7, 5, 8]->Array.findLast(i => i < 7), eq, Some(5)) +Test.run(__POS_OF__("findLast"), [3, 5, 7, 5, 8]->Array.findLast(i => i > 100), eq, None) +Test.run(__POS_OF__("findLast"), []->Array.findLast(_ => true), eq, None) + +Test.run(__POS_OF__("findLastIndex"), [3, 5, 7, 5, 8]->Array.findLastIndex(i => i == 5), eq, 3) +Test.run(__POS_OF__("findLastIndex"), [3, 5, 7, 5, 8]->Array.findLastIndex(i => i > 100), eq, -1) +Test.run(__POS_OF__("findLastIndex"), []->Array.findLastIndex(_ => true), eq, -1) + +Test.run( + __POS_OF__("findLastIndexWithIndex"), + ["a", "2", "e", "4", "x"]->Array.findLastIndexWithIndex((i, j) => isDigit(i) && j > 2), + eq, + 4, +) +Test.run( + __POS_OF__("findLastIndexWithIndex"), + ["a", "x", "j", "b", "x"]->Array.findLastIndexWithIndex((i, j) => i == "x" && j < 3), + eq, + 1, +) + +Test.run( + __POS_OF__("findLastIndexOpt"), + [3, 5, 7, 5, 8]->Array.findLastIndexOpt(i => i == 5), + eq, + Some(3), +) +Test.run( + __POS_OF__("findLastIndexOpt"), + [3, 5, 7, 5, 8]->Array.findLastIndexOpt(i => i > 100), + eq, + None, +) +Test.run(__POS_OF__("findLastIndexOpt"), []->Array.findLastIndexOpt(_ => true), eq, None) diff --git a/test/TestSuite.mjs b/test/TestSuite.mjs index 2085495e..9a999dd2 100644 --- a/test/TestSuite.mjs +++ b/test/TestSuite.mjs @@ -27,6 +27,8 @@ var Concurrently = PromiseTest.Concurrently; var panicTest = ErrorTests.panicTest; +var isDigit = ArrayTests.isDigit; + var $$catch = IntTests.$$catch; var eq = ResultTests.eq; @@ -46,6 +48,7 @@ export { Catching , Concurrently , panicTest , + isDigit , $$catch , eq , forEachIfOkCallFunction , From e9ec9b171aace8789181f44f65f053e0042e2ad8 Mon Sep 17 00:00:00 2001 From: jmagaram Date: Wed, 29 Mar 2023 12:25:26 -0700 Subject: [PATCH 04/12] better docs and examples --- src/Core__Array.resi | 23 ++++++---- test/ArrayTests.mjs | 100 ++++++++++++++++--------------------------- test/ArrayTests.res | 14 ++++-- test/TestSuite.mjs | 3 -- 4 files changed, 60 insertions(+), 80 deletions(-) diff --git a/src/Core__Array.resi b/src/Core__Array.resi index c9f2c24d..9f816965 100644 --- a/src/Core__Array.resi +++ b/src/Core__Array.resi @@ -1007,8 +1007,9 @@ See [Array.findLast on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScr ## Examples ```rescript -[3, 5, 7, 5, 8]->Array.findLast(i => i < 7) // Some(5) -[3, 5, 7, 5, 8]->Array.findLast(i=> i > 100) // None +let nums = [3, 5, 7, 5, 8] +nums->Array.findLast(i => i < 7) // Some(5) +nums->Array.findLast(i=> i > 100) // None []->Array.findLast(_ => true) // None ``` */ @@ -1022,8 +1023,9 @@ See [Array.findLastIndex on MDN](https://developer.mozilla.org/en-US/docs/Web/Ja ## Examples ```rescript -[3, 5, 7, 5, 8]->Array.findLastIndex(i => i < 7) // 3 -[3, 5, 7, 5, 8]->Array.findLast(i => i > 100) // -1 +let nums = [3, 5, 7, 5, 8] +nums->Array.findLastIndex(i => i < 7) // 3 +nums->Array.findLast(i => i > 100) // -1 []->Array.findLast(_ => true) // -1 ``` */ @@ -1037,22 +1039,25 @@ See [Array.findLastIndex on MDN](https://developer.mozilla.org/en-US/docs/Web/Ja ## Examples ```rescript -[3, 5, 7, 5, 8]->Array.findLastIndex(i => i < 7) // Some(3) -[3, 5, 7, 5, 8]->Array.findLast(i => i > 100) // None +let nums = [3, 5, 7, 5, 8] +nums->Array.findLastIndex(i => i < 7) // Some(3) +nums->Array.findLast(i => i > 100) // None []->Array.findLast(_ => true) // None ``` */ let findLastIndexOpt: (array<'a>, 'a => bool) => option /** -`findLastIndexWithIndex(array, predicate)` iterates the array in **reverse** order and returns the index of the first element that satisfies the callback `predicate`. The `predicate` receives the current element being processed followed by its index. Returns `-1` if no elements satisfy the predicate. +`findLastIndexWithIndex(array, predicate)` iterates the array in **reverse** order and returns the index of the first element that satisfies the callback `predicate`. The callback receives the current element being processed followed by its index. Returns `-1` if no elements satisfy the predicate. See [Array.findLastIndex on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex) ## Examples ```rescript -["a", "x", "j", "b", "x"]->Array.findLastIndex((i, j) => i == "x" && j > 2) // 4 -["a", "x", "j", "b", "x"]->Array.findLastIndex((i, j) => i == "x" && j < 3) // 2 +let nums = [3, 5, 7, 5, 8] +nums->Array.findLastIndexWithIndex((val, inx) => val == 5 && inx <= 2) // 1 +nums->Array.findLastIndexWithIndex((val, inx) => val == 5 && inx >= 1) // 3 +nums->Array.findLastIndexWithIndex((val, inx) => val >= 8 && inx < 2) // -1 ``` */ @send diff --git a/test/ArrayTests.mjs b/test/ArrayTests.mjs index 290e194d..1db4ef39 100644 --- a/test/ArrayTests.mjs +++ b/test/ArrayTests.mjs @@ -609,14 +609,10 @@ Test.run([ return true; }), eq, undefined); -function isDigit(s) { - return "0123456789".includes(s); -} - Test.run([ [ "ArrayTests.res", - 122, + 120, 20, 35 ], @@ -634,7 +630,7 @@ Test.run([ Test.run([ [ "ArrayTests.res", - 123, + 121, 20, 35 ], @@ -652,7 +648,7 @@ Test.run([ Test.run([ [ "ArrayTests.res", - 124, + 122, 20, 35 ], @@ -665,95 +661,72 @@ Test.run([ [ "ArrayTests.res", 125, - 20, - 35 - ], - "findLastIndex" - ], [ - "3", - "a", - "4", - "x" - ].findLastIndex(isDigit), eq, 3); - -Test.run([ - [ - "ArrayTests.res", - 126, - 20, - 35 + 13, + 37 ], - "findLastIndex" + "findLastIndexWithIndex" ], [ 3, 5, 7, 5, 8 - ].findLastIndex(function (i) { - return i > 100; - }), eq, -1); - -Test.run([ - [ - "ArrayTests.res", - 127, - 20, - 35 - ], - "findLastIndex" - ], [].findLastIndex(function (param) { - return true; - }), eq, -1); + ].findLastIndex(function (val, inx) { + if (val === 5) { + return inx <= 2; + } else { + return false; + } + }), eq, 1); Test.run([ [ "ArrayTests.res", - 130, + 131, 13, 37 ], "findLastIndexWithIndex" ], [ - "a", - "2", - "e", - "4", - "x" - ].findLastIndex(function (i, j) { - if ("0123456789".includes(i)) { - return j > 2; + 3, + 5, + 7, + 5, + 8 + ].findLastIndex(function (val, inx) { + if (val === 5) { + return inx >= 1; } else { return false; } - }), eq, 4); + }), eq, 3); Test.run([ [ "ArrayTests.res", - 136, + 137, 13, 37 ], "findLastIndexWithIndex" ], [ - "a", - "x", - "j", - "b", - "x" - ].findLastIndex(function (i, j) { - if (i === "x") { - return j < 3; + 3, + 5, + 7, + 5, + 8 + ].findLastIndex(function (val, inx) { + if (val >= 8) { + return inx < 2; } else { return false; } - }), eq, 1); + }), eq, -1); Test.run([ [ "ArrayTests.res", - 143, + 144, 13, 31 ], @@ -771,7 +744,7 @@ Test.run([ Test.run([ [ "ArrayTests.res", - 149, + 150, 13, 31 ], @@ -789,7 +762,7 @@ Test.run([ Test.run([ [ "ArrayTests.res", - 154, + 155, 20, 38 ], @@ -800,6 +773,5 @@ Test.run([ export { eq , - isDigit , } /* Not a pure module */ diff --git a/test/ArrayTests.res b/test/ArrayTests.res index 19cda060..c5609f70 100644 --- a/test/ArrayTests.res +++ b/test/ArrayTests.res @@ -123,15 +123,21 @@ Test.run(__POS_OF__("findLastIndex"), []->Array.findLastIndex(_ => true), eq, -1 Test.run( __POS_OF__("findLastIndexWithIndex"), - ["a", "2", "e", "4", "x"]->Array.findLastIndexWithIndex((i, j) => isDigit(i) && j > 2), + [3, 5, 7, 5, 8]->Array.findLastIndexWithIndex((val, inx) => val == 5 && inx <= 2), eq, - 4, + 1, ) Test.run( __POS_OF__("findLastIndexWithIndex"), - ["a", "x", "j", "b", "x"]->Array.findLastIndexWithIndex((i, j) => i == "x" && j < 3), + [3, 5, 7, 5, 8]->Array.findLastIndexWithIndex((val, inx) => val == 5 && inx >= 1), eq, - 1, + 3, +) +Test.run( + __POS_OF__("findLastIndexWithIndex"), + [3, 5, 7, 5, 8]->Array.findLastIndexWithIndex((val, inx) => val >= 8 && inx < 2), + eq, + -1, ) Test.run( diff --git a/test/TestSuite.mjs b/test/TestSuite.mjs index 9a999dd2..2085495e 100644 --- a/test/TestSuite.mjs +++ b/test/TestSuite.mjs @@ -27,8 +27,6 @@ var Concurrently = PromiseTest.Concurrently; var panicTest = ErrorTests.panicTest; -var isDigit = ArrayTests.isDigit; - var $$catch = IntTests.$$catch; var eq = ResultTests.eq; @@ -48,7 +46,6 @@ export { Catching , Concurrently , panicTest , - isDigit , $$catch , eq , forEachIfOkCallFunction , From e1a20f08c643abb8a71293d63ce9848cfe359d88 Mon Sep 17 00:00:00 2001 From: jmagaram Date: Wed, 29 Mar 2023 12:30:29 -0700 Subject: [PATCH 05/12] findLastIndexWithIndexOpt --- src/Core__Array.mjs | 9 +++++++++ src/Core__Array.res | 8 +++++++- src/Core__Array.resi | 15 +++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/Core__Array.mjs b/src/Core__Array.mjs index 97658aaf..0955b56f 100644 --- a/src/Core__Array.mjs +++ b/src/Core__Array.mjs @@ -146,6 +146,14 @@ function findLastIndexOpt(xs, pred) { } +function findLastIndexWithIndexOpt(xs, pred) { + var inx = xs.findLastIndex(pred); + if (inx !== -1) { + return inx; + } + +} + export { make , fromInitializer , @@ -164,5 +172,6 @@ export { shuffleInPlace , findMap , findLastIndexOpt , + findLastIndexWithIndexOpt , } /* No side effect */ diff --git a/src/Core__Array.res b/src/Core__Array.res index 71adcdf0..786f4995 100644 --- a/src/Core__Array.res +++ b/src/Core__Array.res @@ -224,8 +224,14 @@ external findLastIndex: (array<'a>, 'a => bool) => int = "findLastIndex" let findLastIndexOpt = (xs, pred) => switch findLastIndex(xs, pred) { | -1 => None - | _ as inx => Some(inx) + | inx => Some(inx) } @send external findLastIndexWithIndex: (array<'a>, ('a, int) => bool) => int = "findLastIndex" + +let findLastIndexWithIndexOpt = (xs, pred) => + switch findLastIndexWithIndex(xs, pred) { + | -1 => None + | inx => Some(inx) + } diff --git a/src/Core__Array.resi b/src/Core__Array.resi index 9f816965..6b78cf1d 100644 --- a/src/Core__Array.resi +++ b/src/Core__Array.resi @@ -1062,3 +1062,18 @@ nums->Array.findLastIndexWithIndex((val, inx) => val >= 8 && inx < 2) // -1 */ @send external findLastIndexWithIndex: (array<'a>, ('a, int) => bool) => int = "findLastIndex" + +/** +`findLastIndexWithIndexOpt(array, predicate)` iterates the array in **reverse** order and returns the index of the first element that satisfies the callback `predicate`. The callback receives the current element being processed followed by its index. Returns `None` if no elements satisfy the predicate. + +See [Array.findLastIndex on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex) + +## Examples +```rescript +let nums = [3, 5, 7, 5, 8] +nums->Array.findLastIndexWithIndex((val, inx) => val == 5 && inx <= 2) // 1 +nums->Array.findLastIndexWithIndex((val, inx) => val == 5 && inx >= 1) // 3 +nums->Array.findLastIndexWithIndex((val, inx) => val >= 8 && inx < 2) // None +``` +*/ +let findLastIndexWithIndexOpt: (array<'a>, ('a, int) => bool) => option From 74d6e013b913c0832e8014270cefc948a44a18f2 Mon Sep 17 00:00:00 2001 From: jmagaram Date: Wed, 29 Mar 2023 12:37:56 -0700 Subject: [PATCH 06/12] add indexOfFromOpt --- src/Core__Array.mjs | 9 +++++++++ src/Core__Array.res | 6 ++++++ src/Core__Array.resi | 3 +++ 3 files changed, 18 insertions(+) diff --git a/src/Core__Array.mjs b/src/Core__Array.mjs index 0955b56f..87fef9dd 100644 --- a/src/Core__Array.mjs +++ b/src/Core__Array.mjs @@ -154,11 +154,20 @@ function findLastIndexWithIndexOpt(xs, pred) { } +function indexOfFromOpt(xs, val, fromInx) { + var inx = xs.indexOf(val, fromInx); + if (inx !== -1) { + return inx; + } + +} + export { make , fromInitializer , sort , indexOfOpt , + indexOfFromOpt , lastIndexOfOpt , reduce , reduceWithIndex , diff --git a/src/Core__Array.res b/src/Core__Array.res index 786f4995..82d0cd0e 100644 --- a/src/Core__Array.res +++ b/src/Core__Array.res @@ -235,3 +235,9 @@ let findLastIndexWithIndexOpt = (xs, pred) => | -1 => None | inx => Some(inx) } + +let indexOfFromOpt = (xs, val, fromInx) => + switch indexOfFrom(xs, val, fromInx) { + | -1 => None + | inx => Some(inx) + } diff --git a/src/Core__Array.resi b/src/Core__Array.resi index 6b78cf1d..39364a51 100644 --- a/src/Core__Array.resi +++ b/src/Core__Array.resi @@ -369,8 +369,11 @@ Console.log([{"language": "ReScript"}]->Array.indexOfOpt({"language": "ReScript" ``` */ let indexOfOpt: (array<'a>, 'a) => option + @send external indexOfFrom: (array<'a>, 'a, int) => int = "indexOf" +let indexOfFromOpt: (array<'a>, 'a, int) => option + /** `joinWith(array, separator)` produces a string where all items of `array` are printed, separated by `separator`. Under the hood this will run JavaScript's `toString` on all the array items. From a1e7ef5a62813e094505f0cb3689005688f110ae Mon Sep 17 00:00:00 2001 From: jmagaram Date: Wed, 29 Mar 2023 12:47:36 -0700 Subject: [PATCH 07/12] clean up tests a bit --- test/ArrayTests.mjs | 100 ++++++++++++++++++++++---------------------- test/ArrayTests.res | 28 ++++++------- 2 files changed, 64 insertions(+), 64 deletions(-) diff --git a/test/ArrayTests.mjs b/test/ArrayTests.mjs index 1db4ef39..aa67319d 100644 --- a/test/ArrayTests.mjs +++ b/test/ArrayTests.mjs @@ -662,6 +662,54 @@ Test.run([ "ArrayTests.res", 125, 13, + 31 + ], + "findLastIndexOpt" + ], Core__Array.findLastIndexOpt([ + 3, + 5, + 7, + 5, + 8 + ], (function (i) { + return i === 5; + })), eq, 3); + +Test.run([ + [ + "ArrayTests.res", + 131, + 13, + 31 + ], + "findLastIndexOpt" + ], Core__Array.findLastIndexOpt([ + 3, + 5, + 7, + 5, + 8 + ], (function (i) { + return i > 100; + })), eq, undefined); + +Test.run([ + [ + "ArrayTests.res", + 136, + 20, + 38 + ], + "findLastIndexOpt" + ], Core__Array.findLastIndexOpt([], (function (param) { + return true; + })), eq, undefined); + +Test.run([ + [ + "ArrayTests.res", + 139, + 13, 37 ], "findLastIndexWithIndex" @@ -682,7 +730,7 @@ Test.run([ Test.run([ [ "ArrayTests.res", - 131, + 145, 13, 37 ], @@ -704,7 +752,7 @@ Test.run([ Test.run([ [ "ArrayTests.res", - 137, + 151, 13, 37 ], @@ -723,54 +771,6 @@ Test.run([ } }), eq, -1); -Test.run([ - [ - "ArrayTests.res", - 144, - 13, - 31 - ], - "findLastIndexOpt" - ], Core__Array.findLastIndexOpt([ - 3, - 5, - 7, - 5, - 8 - ], (function (i) { - return i === 5; - })), eq, 3); - -Test.run([ - [ - "ArrayTests.res", - 150, - 13, - 31 - ], - "findLastIndexOpt" - ], Core__Array.findLastIndexOpt([ - 3, - 5, - 7, - 5, - 8 - ], (function (i) { - return i > 100; - })), eq, undefined); - -Test.run([ - [ - "ArrayTests.res", - 155, - 20, - 38 - ], - "findLastIndexOpt" - ], Core__Array.findLastIndexOpt([], (function (param) { - return true; - })), eq, undefined); - export { eq , } diff --git a/test/ArrayTests.res b/test/ArrayTests.res index c5609f70..4353a939 100644 --- a/test/ArrayTests.res +++ b/test/ArrayTests.res @@ -121,6 +121,20 @@ Test.run(__POS_OF__("findLastIndex"), [3, 5, 7, 5, 8]->Array.findLastIndex(i => Test.run(__POS_OF__("findLastIndex"), [3, 5, 7, 5, 8]->Array.findLastIndex(i => i > 100), eq, -1) Test.run(__POS_OF__("findLastIndex"), []->Array.findLastIndex(_ => true), eq, -1) +Test.run( + __POS_OF__("findLastIndexOpt"), + [3, 5, 7, 5, 8]->Array.findLastIndexOpt(i => i == 5), + eq, + Some(3), +) +Test.run( + __POS_OF__("findLastIndexOpt"), + [3, 5, 7, 5, 8]->Array.findLastIndexOpt(i => i > 100), + eq, + None, +) +Test.run(__POS_OF__("findLastIndexOpt"), []->Array.findLastIndexOpt(_ => true), eq, None) + Test.run( __POS_OF__("findLastIndexWithIndex"), [3, 5, 7, 5, 8]->Array.findLastIndexWithIndex((val, inx) => val == 5 && inx <= 2), @@ -139,17 +153,3 @@ Test.run( eq, -1, ) - -Test.run( - __POS_OF__("findLastIndexOpt"), - [3, 5, 7, 5, 8]->Array.findLastIndexOpt(i => i == 5), - eq, - Some(3), -) -Test.run( - __POS_OF__("findLastIndexOpt"), - [3, 5, 7, 5, 8]->Array.findLastIndexOpt(i => i > 100), - eq, - None, -) -Test.run(__POS_OF__("findLastIndexOpt"), []->Array.findLastIndexOpt(_ => true), eq, None) From b6dafea1e4e1abb344869e558940b5035682bbe4 Mon Sep 17 00:00:00 2001 From: jmagaram Date: Wed, 29 Mar 2023 12:48:55 -0700 Subject: [PATCH 08/12] remove TestingStuff --- src/TestingStuff.mjs | 2 -- src/TestingStuff.res | 1 - 2 files changed, 3 deletions(-) delete mode 100644 src/TestingStuff.mjs delete mode 100644 src/TestingStuff.res diff --git a/src/TestingStuff.mjs b/src/TestingStuff.mjs deleted file mode 100644 index d856702b..00000000 --- a/src/TestingStuff.mjs +++ /dev/null @@ -1,2 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/src/TestingStuff.res b/src/TestingStuff.res deleted file mode 100644 index ba09e17c..00000000 --- a/src/TestingStuff.res +++ /dev/null @@ -1 +0,0 @@ -open RescriptCore From b5ed4b5db414dc68f4dac9fb06c1b66aeac99fc4 Mon Sep 17 00:00:00 2001 From: jmagaram Date: Wed, 29 Mar 2023 13:04:08 -0700 Subject: [PATCH 09/12] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96d70a5b..0dd055a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### API changes - Add `Result.forEach` https://github.com/rescript-association/rescript-core/pull/116 +- Add missing Array functions : `indexOfFromOpt`, `findLast`, `findLastIndex`, `findLastIndexOpt`, `findLastIndexWithIndex`, `findLastIndexWithIndexOpt` ## 0.2.0 From d2aafc61615f85a8e7a5c392c8d88ff60ff9c112 Mon Sep 17 00:00:00 2001 From: jmagaram Date: Wed, 29 Mar 2023 13:04:57 -0700 Subject: [PATCH 10/12] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0dd055a8..dd29569d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ ### API changes - Add `Result.forEach` https://github.com/rescript-association/rescript-core/pull/116 -- Add missing Array functions : `indexOfFromOpt`, `findLast`, `findLastIndex`, `findLastIndexOpt`, `findLastIndexWithIndex`, `findLastIndexWithIndexOpt` +- Add missing Array functions : `indexOfFromOpt`, `findLast`, `findLastIndex`, `findLastIndexOpt`, `findLastIndexWithIndex`, `findLastIndexWithIndexOpt` https://github.com/rescript-association/rescript-core/pull/126/files ## 0.2.0 From cbef6d3d882eca807edadc716fd5ccc019ca70d1 Mon Sep 17 00:00:00 2001 From: jmagaram Date: Wed, 29 Mar 2023 13:15:20 -0700 Subject: [PATCH 11/12] problem with tests? --- test/ArrayTests.mjs | 22 +++++++++++----------- test/ArrayTests.res | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/test/ArrayTests.mjs b/test/ArrayTests.mjs index aa67319d..42245d8b 100644 --- a/test/ArrayTests.mjs +++ b/test/ArrayTests.mjs @@ -576,7 +576,7 @@ Test.run([ 5, 8 ].findLast(function (i) { - return i < 7; + return i < 8; }), eq, 5); Test.run([ @@ -587,14 +587,8 @@ Test.run([ 30 ], "findLast" - ], [ - 3, - 5, - 7, - 5, - 8 - ].findLast(function (i) { - return i > 100; + ], [].findLast(function (param) { + return true; }), eq, undefined); Test.run([ @@ -605,8 +599,14 @@ Test.run([ 30 ], "findLast" - ], [].findLast(function (param) { - return true; + ], [ + 3, + 5, + 7, + 5, + 8 + ].findLast(function (i) { + return i > 100; }), eq, undefined); Test.run([ diff --git a/test/ArrayTests.res b/test/ArrayTests.res index 4353a939..948dce12 100644 --- a/test/ArrayTests.res +++ b/test/ArrayTests.res @@ -113,9 +113,9 @@ Test.run(__POS_OF__("lastIndexOfOpt"), [3, 5, 7, 5, 8]->Array.lastIndexOfOpt(100 Test.run(__POS_OF__("lastIndexOfOpt"), []->Array.lastIndexOfOpt(100), eq, None) Test.run(__POS_OF__("lastIndexOfOpt"), [{"a": 1}]->Array.lastIndexOfOpt({"a": 1}), eq, None) -Test.run(__POS_OF__("findLast"), [3, 5, 7, 5, 8]->Array.findLast(i => i < 7), eq, Some(5)) -Test.run(__POS_OF__("findLast"), [3, 5, 7, 5, 8]->Array.findLast(i => i > 100), eq, None) +Test.run(__POS_OF__("findLast"), [3, 5, 7, 5, 8]->Array.findLast(i => i < 8), eq, Some(5)) Test.run(__POS_OF__("findLast"), []->Array.findLast(_ => true), eq, None) +Test.run(__POS_OF__("findLast"), [3, 5, 7, 5, 8]->Array.findLast(i => i > 100), eq, None) Test.run(__POS_OF__("findLastIndex"), [3, 5, 7, 5, 8]->Array.findLastIndex(i => i == 5), eq, 3) Test.run(__POS_OF__("findLastIndex"), [3, 5, 7, 5, 8]->Array.findLastIndex(i => i > 100), eq, -1) From eb647c862bebad8f42800c9ffb398dd6685c7345 Mon Sep 17 00:00:00 2001 From: jmagaram Date: Wed, 29 Mar 2023 13:26:04 -0700 Subject: [PATCH 12/12] reorganize tests --- test/ArrayTests.mjs | 102 ++++++++++++++++++++++---------------------- test/ArrayTests.res | 8 ++-- 2 files changed, 55 insertions(+), 55 deletions(-) diff --git a/test/ArrayTests.mjs b/test/ArrayTests.mjs index 42245d8b..9cf2b75c 100644 --- a/test/ArrayTests.mjs +++ b/test/ArrayTests.mjs @@ -462,54 +462,6 @@ Test.run([ "ArrayTests.res", 107, 20, - 37 - ], - "lastIndexOfFrom" - ], [ - 3, - 5, - 7, - 5, - 8 - ].lastIndexOf(5, -3), eq, 1); - -Test.run([ - [ - "ArrayTests.res", - 108, - 20, - 37 - ], - "lastIndexOfFrom" - ], [ - 3, - 5, - 7, - 5, - 8 - ].lastIndexOf(5, 4), eq, 3); - -Test.run([ - [ - "ArrayTests.res", - 109, - 20, - 37 - ], - "lastIndexOfFrom" - ], [ - 3, - 5, - 7, - 5, - 8 - ].lastIndexOf(5, 0), eq, -1); - -Test.run([ - [ - "ArrayTests.res", - 111, - 20, 36 ], "lastIndexOfOpt" @@ -524,7 +476,7 @@ Test.run([ Test.run([ [ "ArrayTests.res", - 112, + 108, 20, 36 ], @@ -540,7 +492,7 @@ Test.run([ Test.run([ [ "ArrayTests.res", - 113, + 109, 20, 36 ], @@ -550,7 +502,7 @@ Test.run([ Test.run([ [ "ArrayTests.res", - 114, + 110, 20, 36 ], @@ -561,6 +513,54 @@ Test.run([ a: 1 }), eq, undefined); +Test.run([ + [ + "ArrayTests.res", + 112, + 20, + 37 + ], + "lastIndexOfFrom" + ], [ + 3, + 5, + 7, + 5, + 8 + ].lastIndexOf(5, -3), eq, 1); + +Test.run([ + [ + "ArrayTests.res", + 113, + 20, + 37 + ], + "lastIndexOfFrom" + ], [ + 3, + 5, + 7, + 5, + 8 + ].lastIndexOf(5, 4), eq, 3); + +Test.run([ + [ + "ArrayTests.res", + 114, + 20, + 37 + ], + "lastIndexOfFrom" + ], [ + 3, + 5, + 7, + 5, + 8 + ].lastIndexOf(5, 0), eq, -1); + Test.run([ [ "ArrayTests.res", diff --git a/test/ArrayTests.res b/test/ArrayTests.res index 948dce12..5884f1e9 100644 --- a/test/ArrayTests.res +++ b/test/ArrayTests.res @@ -104,15 +104,15 @@ Test.run(__POS_OF__("lastIndexOf"), [3, 5, 7, 5, 8]->Array.lastIndexOf(100), eq, Test.run(__POS_OF__("lastIndexOf"), []->Array.lastIndexOf(100), eq, -1) Test.run(__POS_OF__("lastIndexOf"), [{"a": 1}]->Array.lastIndexOf({"a": 1}), eq, -1) -Test.run(__POS_OF__("lastIndexOfFrom"), [3, 5, 7, 5, 8]->Array.lastIndexOfFrom(5, -3), eq, 1) -Test.run(__POS_OF__("lastIndexOfFrom"), [3, 5, 7, 5, 8]->Array.lastIndexOfFrom(5, 4), eq, 3) -Test.run(__POS_OF__("lastIndexOfFrom"), [3, 5, 7, 5, 8]->Array.lastIndexOfFrom(5, 0), eq, -1) - Test.run(__POS_OF__("lastIndexOfOpt"), [3, 5, 7, 5, 8]->Array.lastIndexOfOpt(5), eq, Some(3)) Test.run(__POS_OF__("lastIndexOfOpt"), [3, 5, 7, 5, 8]->Array.lastIndexOfOpt(100), eq, None) Test.run(__POS_OF__("lastIndexOfOpt"), []->Array.lastIndexOfOpt(100), eq, None) Test.run(__POS_OF__("lastIndexOfOpt"), [{"a": 1}]->Array.lastIndexOfOpt({"a": 1}), eq, None) +Test.run(__POS_OF__("lastIndexOfFrom"), [3, 5, 7, 5, 8]->Array.lastIndexOfFrom(5, -3), eq, 1) +Test.run(__POS_OF__("lastIndexOfFrom"), [3, 5, 7, 5, 8]->Array.lastIndexOfFrom(5, 4), eq, 3) +Test.run(__POS_OF__("lastIndexOfFrom"), [3, 5, 7, 5, 8]->Array.lastIndexOfFrom(5, 0), eq, -1) + Test.run(__POS_OF__("findLast"), [3, 5, 7, 5, 8]->Array.findLast(i => i < 8), eq, Some(5)) Test.run(__POS_OF__("findLast"), []->Array.findLast(_ => true), eq, None) Test.run(__POS_OF__("findLast"), [3, 5, 7, 5, 8]->Array.findLast(i => i > 100), eq, None)