@@ -904,17 +904,18 @@ let wrapNegativeIndex = (arrLen, idx) => {
904904 * If either index is a negative number, it will be treated as a reverse index from
905905 * the end of the array. e.g. `slice(1, -1, [> 'a', 'b', 'c']) == [> 'b']`.
906906 *
907- * @param startIndex : The index of the array where the slice will begin (inclusive)
908- * @param endIndex : The index of the array where the slice will end (exclusive)
907+ * @param start : The index of the array where the slice will begin (inclusive)
908+ * @param end : The index of the array where the slice will end (exclusive)
909909 * @param array: The array to be sliced
910910 * @returns The subset of the array that was sliced
911911 *
912912 * @since v0.4.0
913+ * @history v0.6.0: Default `end` to the Array length
913914 */
914- provide let slice = (startIndex, endIndex , array) => {
915+ provide let slice = (start, end=length(array) , array) => {
915916 let arrayLength = length(array)
916- let startIndex = wrapNegativeIndex(arrayLength, startIndex )
917- let endIndex = wrapNegativeIndex(arrayLength, endIndex )
917+ let startIndex = wrapNegativeIndex(arrayLength, start )
918+ let endIndex = wrapNegativeIndex(arrayLength, end )
918919 // Ensure we aren't working with an `end` value that is too big
919920 let endIndex = if (endIndex > arrayLength) {
920921 arrayLength
@@ -1016,7 +1017,7 @@ provide let rotate = (n, arr) => {
10161017
10171018/**
10181019 * An immutable array implementation.
1019- *
1020+ *
10201021 * @since v0.6.0
10211022 * @history v0.5.4: Originally in `"immutablearray"` module
10221023 */
@@ -1103,7 +1104,7 @@ provide module Immutable {
11031104
11041105 /**
11051106 * An empty array.
1106- *
1107+ *
11071108 * @since v0.6.0
11081109 * @history v0.5.4: Originally in `"immutablearray"` module
11091110 */
@@ -1115,7 +1116,7 @@ provide module Immutable {
11151116
11161117 /**
11171118 * Determines if the array contains no elements.
1118- *
1119+ *
11191120 * @param array: The array to check
11201121 * @returns `true` if the array is empty and `false` otherwise
11211122 *
@@ -1161,7 +1162,7 @@ provide module Immutable {
11611162
11621163 let numToAppend = Number.min(len2, branchingFactor - len1)
11631164 let toAppend = if (numToAppend < len2) {
1164- mutSlice(0, numToAppend, array2)
1165+ mutSlice(0, end= numToAppend, array2)
11651166 } else {
11661167 array2
11671168 }
@@ -1188,7 +1189,7 @@ provide module Immutable {
11881189 * @param array: The array to access
11891190 * @returns The element from the array
11901191 * @throws IndexOutOfBounds: When the index being accessed is outside the array's bounds
1191- *
1192+ *
11921193 * @example get(1, fromList([1, 2, 3, 4])) == 2
11931194 * @example get(-1, fromList([1, 2, 3, 4])) == 4
11941195 *
@@ -1226,7 +1227,7 @@ provide module Immutable {
12261227 * @param array: The array to update
12271228 * @returns A new array containing the new element at the given index
12281229 * @throws IndexOutOfBounds: When the index being updated is outside the array's bounds
1229- *
1230+ *
12301231 * @example set(1, 9, fromList([1, 2, 3, 4, 5])) == fromList([1, 9, 3, 4, 5])
12311232 *
12321233 * @since v0.6.0
@@ -1304,7 +1305,11 @@ provide module Immutable {
13041305 let newArray = replaceTail(appended, array)
13051306 if (numNotAppended > 0) {
13061307 let appendLen = mutLength(toAppend)
1307- let newTail = mutSlice(appendLen - numNotAppended, appendLen, toAppend)
1308+ let newTail = mutSlice(
1309+ appendLen - numNotAppended,
1310+ end=appendLen,
1311+ toAppend
1312+ )
13081313 replaceTail(newTail, newArray)
13091314 } else {
13101315 newArray
@@ -1378,7 +1383,7 @@ provide module Immutable {
13781383 if (numNotAppended >= 0) {
13791384 let appendLen = mutLength(toAppend)
13801385 {
1381- btail: mutSlice(appendLen - numNotAppended, appendLen, toAppend),
1386+ btail: mutSlice(appendLen - numNotAppended, end= appendLen, toAppend),
13821387 nodes: [Leaf(appended), ...nodes],
13831388 numNodes: numNodes + 1,
13841389 }
@@ -1432,7 +1437,7 @@ provide module Immutable {
14321437 *
14331438 * @param arrays: A list containing all arrays to combine
14341439 * @returns The new array
1435- *
1440+ *
14361441 * @example concat([fromList([1, 2]), fromList([3, 4]), fromList([5, 6])]) == fromList([1, 2, 3, 4, 5, 6])
14371442 *
14381443 * @since v0.6.0
@@ -1628,7 +1633,7 @@ provide module Immutable {
16281633 * @param fn: The function to be called on each element, where the value returned will be an array that gets appended to the new array
16291634 * @param array: The array to iterate
16301635 * @returns The new array
1631- *
1636+ *
16321637 * @example flatMap(n => fromList([n, n + 1]), fromList([1, 3, 5])) == fromList([1, 2, 3, 4, 5, 6])
16331638 *
16341639 * @since v0.6.0
@@ -1850,7 +1855,7 @@ provide module Immutable {
18501855 *
18511856 * Calling this function with arrays of different sizes will cause the returned
18521857 * array to have the length of the smaller array.
1853- *
1858+ *
18541859 * @param array1: The array to provide values for the first tuple element
18551860 * @param array2: The array to provide values for the second tuple element
18561861 * @returns The new array containing indexed pairs of `(a, b)`
@@ -1869,7 +1874,7 @@ provide module Immutable {
18691874 * applying the function to the first elements of each array, the second element
18701875 * will contain the result of applying the function to the second elements of
18711876 * each array, and so on.
1872- *
1877+ *
18731878 * Calling this function with arrays of different sizes will cause the returned
18741879 * array to have the length of the smaller array.
18751880 *
@@ -1880,7 +1885,7 @@ provide module Immutable {
18801885 *
18811886 * @example zipWith((a, b) => a + b, fromList([1, 2, 3]), fromList([4, 5, 6])) == fromList([5, 7, 9])
18821887 * @example zipWith((a, b) => a * b, fromList([1, 2, 3]), fromList([4, 5])) == fromList([4, 10])
1883- *
1888+ *
18841889 * @since v0.6.0
18851890 * @history v0.5.4: Originally in `"immutablearray"` module
18861891 */
@@ -1944,15 +1949,16 @@ provide module Immutable {
19441949 * @param end: The index of the array where the slice will end (exclusive)
19451950 * @param array: The array to be sliced
19461951 * @returns The subset of the array that was sliced
1947- *
1952+ *
19481953 * @example slice(0, 2, fromList(['a', 'b', 'c'])) == fromList(['a', 'b'])
19491954 * @example slice(1, -1, fromList(['a', 'b', 'c'])) == fromList(['b'])
19501955 *
19511956 * @since v0.6.0
19521957 * @history v0.5.4: Originally in `"immutablearray"` module
1958+ * @history v0.6.0: Default `end` to the Array length
19531959 */
19541960
1955- provide let slice = (start, end, array) => {
1961+ provide let slice = (start, end=length(array) , array) => {
19561962 let begin = clampIndex(array.length, start)
19571963 let end = clampIndex(array.length, end)
19581964 let mut i = array.length
@@ -1999,8 +2005,8 @@ provide module Immutable {
19992005
20002006 provide let rotate = (n, array) => {
20012007 let sliceI = if (array.length == 0) 0 else n % array.length
2002- let before = slice(0, sliceI, array)
2003- let after = slice(sliceI, array.length, array)
2008+ let before = slice(0, end= sliceI, array)
2009+ let after = slice(sliceI, end= array.length, array)
20042010 append(after, before)
20052011 }
20062012}
0 commit comments