{"route":"/en-US-v0.13.1/reference/foundations/array/","title":"Array","description":"Documentation for the Array type.","part":null,"outline":[{"id":"summary","name":"Summary","children":[]},{"id":"example","name":"Example","children":[]},{"id":"constructor","name":"Constructor","children":[{"id":"constructor-value","name":"value","children":[]}]},{"id":"definitions","name":"Definitions","children":[{"id":"definitions-len","name":"Length","children":[]},{"id":"definitions-first","name":"First","children":[]},{"id":"definitions-last","name":"Last","children":[]},{"id":"definitions-at","name":"At","children":[{"id":"definitions-at-index","name":"index","children":[]},{"id":"definitions-at-default","name":"default","children":[]}]},{"id":"definitions-push","name":"Push","children":[{"id":"definitions-push-value","name":"value","children":[]}]},{"id":"definitions-pop","name":"Pop","children":[]},{"id":"definitions-insert","name":"Insert","children":[{"id":"definitions-insert-index","name":"index","children":[]},{"id":"definitions-insert-value","name":"value","children":[]}]},{"id":"definitions-remove","name":"Remove","children":[{"id":"definitions-remove-index","name":"index","children":[]},{"id":"definitions-remove-default","name":"default","children":[]}]},{"id":"definitions-slice","name":"Slice","children":[{"id":"definitions-slice-start","name":"start","children":[]},{"id":"definitions-slice-end","name":"end","children":[]},{"id":"definitions-slice-count","name":"count","children":[]}]},{"id":"definitions-contains","name":"Contains","children":[{"id":"definitions-contains-value","name":"value","children":[]}]},{"id":"definitions-find","name":"Find","children":[{"id":"definitions-find-searcher","name":"searcher","children":[]}]},{"id":"definitions-position","name":"Position","children":[{"id":"definitions-position-searcher","name":"searcher","children":[]}]},{"id":"definitions-range","name":"Range","children":[{"id":"definitions-range-start","name":"start","children":[]},{"id":"definitions-range-end","name":"end","children":[]},{"id":"definitions-range-step","name":"step","children":[]}]},{"id":"definitions-filter","name":"Filter","children":[{"id":"definitions-filter-test","name":"test","children":[]}]},{"id":"definitions-map","name":"Map","children":[{"id":"definitions-map-mapper","name":"mapper","children":[]}]},{"id":"definitions-enumerate","name":"Enumerate","children":[{"id":"definitions-enumerate-start","name":"start","children":[]}]},{"id":"definitions-zip","name":"Zip","children":[{"id":"definitions-zip-exact","name":"exact","children":[]},{"id":"definitions-zip-others","name":"others","children":[]}]},{"id":"definitions-fold","name":"Fold","children":[{"id":"definitions-fold-init","name":"init","children":[]},{"id":"definitions-fold-folder","name":"folder","children":[]}]},{"id":"definitions-sum","name":"Sum","children":[{"id":"definitions-sum-default","name":"default","children":[]}]},{"id":"definitions-product","name":"Product","children":[{"id":"definitions-product-default","name":"default","children":[]}]},{"id":"definitions-any","name":"Any","children":[{"id":"definitions-any-test","name":"test","children":[]}]},{"id":"definitions-all","name":"All","children":[{"id":"definitions-all-test","name":"test","children":[]}]},{"id":"definitions-flatten","name":"Flatten","children":[]},{"id":"definitions-rev","name":"Reverse","children":[]},{"id":"definitions-split","name":"Split","children":[{"id":"definitions-split-at","name":"at","children":[]}]},{"id":"definitions-join","name":"Join","children":[{"id":"definitions-join-separator","name":"separator","children":[]},{"id":"definitions-join-last","name":"last","children":[]}]},{"id":"definitions-intersperse","name":"Intersperse","children":[{"id":"definitions-intersperse-separator","name":"separator","children":[]}]},{"id":"definitions-chunks","name":"Chunks","children":[{"id":"definitions-chunks-chunk-size","name":"chunk-size","children":[]},{"id":"definitions-chunks-exact","name":"exact","children":[]}]},{"id":"definitions-windows","name":"Windows","children":[{"id":"definitions-windows-window-size","name":"window-size","children":[]}]},{"id":"definitions-sorted","name":"Sorted","children":[{"id":"definitions-sorted-key","name":"key","children":[]}]},{"id":"definitions-dedup","name":"Deduplicate","children":[{"id":"definitions-dedup-key","name":"key","children":[]}]},{"id":"definitions-to-dict","name":"To Dict","children":[]},{"id":"definitions-reduce","name":"Reduce","children":[{"id":"definitions-reduce-reducer","name":"reducer","children":[]}]}]}],"body":{"kind":"type","content":{"name":"array","title":"Array","keywords":[],"oneliner":"A sequence of values.","details":"<p>A sequence of values.</p>\n<p>You can construct an array by enclosing a comma-separated sequence of values\nin parentheses. The values do not have to be of the same type.</p>\n<p>You can access and update array items with the <code>.at()</code> method. Indices are\nzero-based and negative indices wrap around to the end of the array. You can\niterate over an array using a <a href=\"/en-US-v0.13.1/reference/scripting/#loops\">for loop</a>. Arrays can be\nadded together with the <code>+</code> operator, <a href=\"/en-US-v0.13.1/reference/scripting/#blocks\">joined together</a>\nand multiplied with integers.</p>\n<p><strong>Note:</strong> An array of length one needs a trailing comma, as in <code><span class=\"typ-punct\">(</span><span class=\"typ-num\">1</span><span class=\"typ-punct\">,</span><span class=\"typ-punct\">)</span></code>.\nThis is to disambiguate from a simple parenthesized expressions like <code><span class=\"typ-punct\">(</span><span class=\"typ-num\">1</span> <span class=\"typ-op\">+</span> <span class=\"typ-num\">2</span><span class=\"typ-punct\">)</span> <span class=\"typ-op\">*</span> <span class=\"typ-num\">3</span></code>. An empty array is written as <code><span class=\"typ-punct\">(</span><span class=\"typ-punct\">)</span></code>.</p>\n<h2 id=\"example\">Example</h2>\n<div class=\"previewed-code\"><pre><code><span class=\"typ-key\">#</span><span class=\"typ-key\">let</span> values <span class=\"typ-op\">=</span> <span class=\"typ-punct\">(</span><span class=\"typ-num\">1</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">7</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">4</span><span class=\"typ-punct\">,</span> <span class=\"typ-op\">-</span><span class=\"typ-num\">3</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">2</span><span class=\"typ-punct\">)</span>\n\n<span class=\"typ-pol\">#</span><span class=\"typ-pol\">values</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">at</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">0</span><span class=\"typ-punct\">)</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-punct\">#</span><span class=\"typ-punct\">(</span>values<span class=\"typ-punct\">.</span><span class=\"typ-func\">at</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">0</span><span class=\"typ-punct\">)</span> <span class=\"typ-op\">=</span> <span class=\"typ-num\">3</span><span class=\"typ-punct\">)</span>\n<span class=\"typ-pol\">#</span><span class=\"typ-pol\">values</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">at</span><span class=\"typ-punct\">(</span><span class=\"typ-op\">-</span><span class=\"typ-num\">1</span><span class=\"typ-punct\">)</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-pol\">#</span><span class=\"typ-pol\">values</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">find</span><span class=\"typ-punct\">(</span>calc<span class=\"typ-punct\">.</span>even<span class=\"typ-punct\">)</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-pol\">#</span><span class=\"typ-pol\">values</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">filter</span><span class=\"typ-punct\">(</span>calc<span class=\"typ-punct\">.</span>odd<span class=\"typ-punct\">)</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-pol\">#</span><span class=\"typ-pol\">values</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">map</span><span class=\"typ-punct\">(</span>calc<span class=\"typ-punct\">.</span>abs<span class=\"typ-punct\">)</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-pol\">#</span><span class=\"typ-pol\">values</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">rev</span><span class=\"typ-punct\">(</span><span class=\"typ-punct\">)</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-punct\">#</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">1</span><span class=\"typ-punct\">,</span> <span class=\"typ-punct\">(</span><span class=\"typ-num\">2</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">3</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">flatten</span><span class=\"typ-punct\">(</span><span class=\"typ-punct\">)</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-punct\">#</span><span class=\"typ-punct\">(</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;A&quot;</span><span class=\"typ-punct\">,</span> <span class=\"typ-str\">&quot;B&quot;</span><span class=\"typ-punct\">,</span> <span class=\"typ-str\">&quot;C&quot;</span><span class=\"typ-punct\">)</span>\n    <span class=\"typ-punct\">.</span><span class=\"typ-func\">join</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;, &quot;</span><span class=\"typ-punct\">,</span> last<span class=\"typ-punct\">:</span> <span class=\"typ-str\">&quot; and &quot;</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">)</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.13.1/assets/b82dcffb69c678f6966654cb6a9894a3.png\" alt=\"Preview\"></div></div>","constructor":{"path":[],"name":"array","title":"Construct","keywords":[],"oneliner":"Converts a value to an array.","element":false,"contextual":false,"deprecation":null,"details":"<p>Converts a value to an array.</p>\n<p>Note that this function is only intended for conversion of a collection-like\nvalue to an array, not for creation of an array from individual items. Use\nthe array syntax <code>(1, 2, 3)</code> (or <code>(1,)</code> for a single-element array) instead.</p>","example":"<div class=\"previewed-code\"><pre><code><span class=\"typ-key\">#</span><span class=\"typ-key\">let</span> hi <span class=\"typ-op\">=</span> <span class=\"typ-str\">&quot;Hello 😃&quot;</span>\n<span class=\"typ-func\">#</span><span class=\"typ-func\">array</span><span class=\"typ-punct\">(</span><span class=\"typ-func\">bytes</span><span class=\"typ-punct\">(</span>hi<span class=\"typ-punct\">)</span><span class=\"typ-punct\">)</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.13.1/assets/5f88747ad7a056745bb4d94b9e4440e4.png\" alt=\"Preview\"></div></div>","self":false,"params":[{"name":"value","details":"<p>The value that should be converted to an array.</p>","example":null,"types":["bytes","array","version"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["array"],"scope":[]},"scope":[{"path":["array"],"name":"len","title":"Length","keywords":[],"oneliner":"The number of values in the array.","element":false,"contextual":false,"deprecation":null,"details":"<p>The number of values in the array.</p>","example":null,"self":true,"params":[],"returns":["int"],"scope":[]},{"path":["array"],"name":"first","title":"First","keywords":[],"oneliner":"Returns the first item in the array. May be used on the left-hand side","element":false,"contextual":false,"deprecation":null,"details":"<p>Returns the first item in the array. May be used on the left-hand side\nof an assignment. Fails with an error if the array is empty.</p>","example":null,"self":true,"params":[],"returns":["any"],"scope":[]},{"path":["array"],"name":"last","title":"Last","keywords":[],"oneliner":"Returns the last item in the array. May be used on the left-hand side of","element":false,"contextual":false,"deprecation":null,"details":"<p>Returns the last item in the array. May be used on the left-hand side of\nan assignment. Fails with an error if the array is empty.</p>","example":null,"self":true,"params":[],"returns":["any"],"scope":[]},{"path":["array"],"name":"at","title":"At","keywords":[],"oneliner":"Returns the item at the specified index in the array. May be used on the","element":false,"contextual":false,"deprecation":null,"details":"<p>Returns the item at the specified index in the array. May be used on the\nleft-hand side of an assignment. Returns the default value if the index\nis out of bounds or fails with an error if no default value was\nspecified.</p>","example":null,"self":true,"params":[{"name":"index","details":"<p>The index at which to retrieve the item. If negative, indexes from\nthe back.</p>","example":null,"types":["int"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false},{"name":"default","details":"<p>A default value to return if the index is out of bounds.</p>","example":null,"types":["any"],"strings":[],"default":null,"positional":false,"named":true,"required":false,"variadic":false,"settable":false}],"returns":["any"],"scope":[]},{"path":["array"],"name":"push","title":"Push","keywords":[],"oneliner":"Adds a value to the end of the array.","element":false,"contextual":false,"deprecation":null,"details":"<p>Adds a value to the end of the array.</p>","example":null,"self":true,"params":[{"name":"value","details":"<p>The value to insert at the end of the array.</p>","example":null,"types":["any"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":[],"scope":[]},{"path":["array"],"name":"pop","title":"Pop","keywords":[],"oneliner":"Removes the last item from the array and returns it. Fails with an error","element":false,"contextual":false,"deprecation":null,"details":"<p>Removes the last item from the array and returns it. Fails with an error\nif the array is empty.</p>","example":null,"self":true,"params":[],"returns":["any"],"scope":[]},{"path":["array"],"name":"insert","title":"Insert","keywords":[],"oneliner":"Inserts a value into the array at the specified index, shifting all","element":false,"contextual":false,"deprecation":null,"details":"<p>Inserts a value into the array at the specified index, shifting all\nsubsequent elements to the right. Fails with an error if the index is\nout of bounds.</p>\n<p>To replace an element of an array, use <a href=\"/en-US-v0.13.1/reference/foundations/array/#definitions-at\"><code>at</code></a>.</p>","example":null,"self":true,"params":[{"name":"index","details":"<p>The index at which to insert the item. If negative, indexes from\nthe back.</p>","example":null,"types":["int"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false},{"name":"value","details":"<p>The value to insert into the array.</p>","example":null,"types":["any"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":[],"scope":[]},{"path":["array"],"name":"remove","title":"Remove","keywords":[],"oneliner":"Removes the value at the specified index from the array and return it.","element":false,"contextual":false,"deprecation":null,"details":"<p>Removes the value at the specified index from the array and return it.</p>","example":null,"self":true,"params":[{"name":"index","details":"<p>The index at which to remove the item. If negative, indexes from\nthe back.</p>","example":null,"types":["int"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false},{"name":"default","details":"<p>A default value to return if the index is out of bounds.</p>","example":null,"types":["any"],"strings":[],"default":null,"positional":false,"named":true,"required":false,"variadic":false,"settable":false}],"returns":["any"],"scope":[]},{"path":["array"],"name":"slice","title":"Slice","keywords":[],"oneliner":"Extracts a subslice of the array. Fails with an error if the start or end","element":false,"contextual":false,"deprecation":null,"details":"<p>Extracts a subslice of the array. Fails with an error if the start or end\nindex is out of bounds.</p>","example":null,"self":true,"params":[{"name":"start","details":"<p>The start index (inclusive). If negative, indexes from the back.</p>","example":null,"types":["int"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false},{"name":"end","details":"<p>The end index (exclusive). If omitted, the whole slice until the end\nof the array is extracted. If negative, indexes from the back.</p>","example":null,"types":["none","int"],"strings":[],"default":"<code><span class=\"typ-key\">none</span></code>","positional":true,"named":false,"required":false,"variadic":false,"settable":false},{"name":"count","details":"<p>The number of items to extract. This is equivalent to passing\n<code>start + count</code> as the <code>end</code> position. Mutually exclusive with <code>end</code>.</p>","example":null,"types":["int"],"strings":[],"default":null,"positional":false,"named":true,"required":false,"variadic":false,"settable":false}],"returns":["array"],"scope":[]},{"path":["array"],"name":"contains","title":"Contains","keywords":[],"oneliner":"Whether the array contains the specified value.","element":false,"contextual":false,"deprecation":null,"details":"<p>Whether the array contains the specified value.</p>\n<p>This method also has dedicated syntax: You can write <code><span class=\"typ-num\">2</span> <span class=\"typ-key\">in</span> <span class=\"typ-punct\">(</span><span class=\"typ-num\">1</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">2</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">3</span><span class=\"typ-punct\">)</span></code>\ninstead of <code><span class=\"typ-punct\">(</span><span class=\"typ-num\">1</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">2</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">3</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">contains</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">2</span><span class=\"typ-punct\">)</span></code>.</p>","example":null,"self":true,"params":[{"name":"value","details":"<p>The value to search for.</p>","example":null,"types":["any"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["bool"],"scope":[]},{"path":["array"],"name":"find","title":"Find","keywords":[],"oneliner":"Searches for an item for which the given function returns `{true}` and","element":false,"contextual":false,"deprecation":null,"details":"<p>Searches for an item for which the given function returns <code><span class=\"typ-key\">true</span></code> and\nreturns the first match or <code><span class=\"typ-key\">none</span></code> if there is no match.</p>","example":null,"self":true,"params":[{"name":"searcher","details":"<p>The function to apply to each item. Must return a boolean.</p>","example":null,"types":["function"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["any","none"],"scope":[]},{"path":["array"],"name":"position","title":"Position","keywords":[],"oneliner":"Searches for an item for which the given function returns `{true}` and","element":false,"contextual":false,"deprecation":null,"details":"<p>Searches for an item for which the given function returns <code><span class=\"typ-key\">true</span></code> and\nreturns the index of the first match or <code><span class=\"typ-key\">none</span></code> if there is no match.</p>","example":null,"self":true,"params":[{"name":"searcher","details":"<p>The function to apply to each item. Must return a boolean.</p>","example":null,"types":["function"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["none","int"],"scope":[]},{"path":["array"],"name":"range","title":"Range","keywords":[],"oneliner":"Create an array consisting of a sequence of numbers.","element":false,"contextual":false,"deprecation":null,"details":"<p>Create an array consisting of a sequence of numbers.</p>\n<p>If you pass just one positional parameter, it is interpreted as the\n<code>end</code> of the range. If you pass two, they describe the <code>start</code> and <code>end</code>\nof the range.</p>\n<p>This function is available both in the array function's scope and\nglobally.</p>","example":"<div class=\"previewed-code\"><pre><code><span class=\"typ-func\">#</span><span class=\"typ-func\">range</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">5</span><span class=\"typ-punct\">)</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-func\">#</span><span class=\"typ-func\">range</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">2</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">5</span><span class=\"typ-punct\">)</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-func\">#</span><span class=\"typ-func\">range</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">20</span><span class=\"typ-punct\">,</span> step<span class=\"typ-punct\">:</span> <span class=\"typ-num\">4</span><span class=\"typ-punct\">)</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-func\">#</span><span class=\"typ-func\">range</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">21</span><span class=\"typ-punct\">,</span> step<span class=\"typ-punct\">:</span> <span class=\"typ-num\">4</span><span class=\"typ-punct\">)</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-func\">#</span><span class=\"typ-func\">range</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">5</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">2</span><span class=\"typ-punct\">,</span> step<span class=\"typ-punct\">:</span> <span class=\"typ-op\">-</span><span class=\"typ-num\">1</span><span class=\"typ-punct\">)</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.13.1/assets/ceb87963d025cafe69d4f502bb2cf46c.png\" alt=\"Preview\"></div></div>","self":false,"params":[{"name":"start","details":"<p>The start of the range (inclusive).</p>","example":null,"types":["int"],"strings":[],"default":"<code><span class=\"typ-num\">0</span></code>","positional":true,"named":false,"required":false,"variadic":false,"settable":false},{"name":"end","details":"<p>The end of the range (exclusive).</p>","example":null,"types":["int"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false},{"name":"step","details":"<p>The distance between the generated numbers.</p>","example":null,"types":["int"],"strings":[],"default":"<code><span class=\"typ-num\">1</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":false}],"returns":["array"],"scope":[]},{"path":["array"],"name":"filter","title":"Filter","keywords":[],"oneliner":"Produces a new array with only the items from the original one for which","element":false,"contextual":false,"deprecation":null,"details":"<p>Produces a new array with only the items from the original one for which\nthe given function returns true.</p>","example":null,"self":true,"params":[{"name":"test","details":"<p>The function to apply to each item. Must return a boolean.</p>","example":null,"types":["function"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["array"],"scope":[]},{"path":["array"],"name":"map","title":"Map","keywords":[],"oneliner":"Produces a new array in which all items from the original one were","element":false,"contextual":false,"deprecation":null,"details":"<p>Produces a new array in which all items from the original one were\ntransformed with the given function.</p>","example":null,"self":true,"params":[{"name":"mapper","details":"<p>The function to apply to each item.</p>","example":null,"types":["function"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["array"],"scope":[]},{"path":["array"],"name":"enumerate","title":"Enumerate","keywords":[],"oneliner":"Returns a new array with the values alongside their indices.","element":false,"contextual":false,"deprecation":null,"details":"<p>Returns a new array with the values alongside their indices.</p>\n<p>The returned array consists of <code>(index, value)</code> pairs in the form of\nlength-2 arrays. These can be <a href=\"/en-US-v0.13.1/reference/scripting/#bindings\">destructured</a> with\na let binding or for loop.</p>","example":null,"self":true,"params":[{"name":"start","details":"<p>The index returned for the first pair of the returned list.</p>","example":null,"types":["int"],"strings":[],"default":"<code><span class=\"typ-num\">0</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":false}],"returns":["array"],"scope":[]},{"path":["array"],"name":"zip","title":"Zip","keywords":[],"oneliner":"Zips the array with other arrays.","element":false,"contextual":false,"deprecation":null,"details":"<p>Zips the array with other arrays.</p>\n<p>Returns an array of arrays, where the <code>i</code>th inner array contains all the\n<code>i</code>th elements from each original array.</p>\n<p>If the arrays to be zipped have different lengths, they are zipped up to\nthe last element of the shortest array and all remaining elements are\nignored.</p>\n<p>This function is variadic, meaning that you can zip multiple arrays\ntogether at once: <code><span class=\"typ-punct\">(</span><span class=\"typ-num\">1</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">2</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">zip</span><span class=\"typ-punct\">(</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;A&quot;</span><span class=\"typ-punct\">,</span> <span class=\"typ-str\">&quot;B&quot;</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">,</span> <span class=\"typ-punct\">(</span><span class=\"typ-num\">10</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">20</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">)</span></code> yields\n<code><span class=\"typ-punct\">(</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">1</span><span class=\"typ-punct\">,</span> <span class=\"typ-str\">&quot;A&quot;</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">10</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">,</span> <span class=\"typ-punct\">(</span><span class=\"typ-num\">2</span><span class=\"typ-punct\">,</span> <span class=\"typ-str\">&quot;B&quot;</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">20</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">)</span></code>.</p>","example":null,"self":true,"params":[{"name":"exact","details":"<p>Whether all arrays have to have the same length.\nFor example, <code><span class=\"typ-punct\">(</span><span class=\"typ-num\">1</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">2</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">zip</span><span class=\"typ-punct\">(</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">1</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">2</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">3</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">,</span> exact<span class=\"typ-punct\">:</span> <span class=\"typ-key\">true</span><span class=\"typ-punct\">)</span></code> produces an\nerror.</p>","example":null,"types":["bool"],"strings":[],"default":"<code><span class=\"typ-key\">false</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":false},{"name":"others","details":"<p>The arrays to zip with.</p>","example":null,"types":["array"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":true,"settable":false}],"returns":["array"],"scope":[]},{"path":["array"],"name":"fold","title":"Fold","keywords":[],"oneliner":"Folds all items into a single value using an accumulator function.","element":false,"contextual":false,"deprecation":null,"details":"<p>Folds all items into a single value using an accumulator function.</p>","example":null,"self":true,"params":[{"name":"init","details":"<p>The initial value to start with.</p>","example":null,"types":["any"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false},{"name":"folder","details":"<p>The folding function. Must have two parameters: One for the\naccumulated value and one for an item.</p>","example":null,"types":["function"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["any"],"scope":[]},{"path":["array"],"name":"sum","title":"Sum","keywords":[],"oneliner":"Sums all items (works for all types that can be added).","element":false,"contextual":false,"deprecation":null,"details":"<p>Sums all items (works for all types that can be added).</p>","example":null,"self":true,"params":[{"name":"default","details":"<p>What to return if the array is empty. Must be set if the array can\nbe empty.</p>","example":null,"types":["any"],"strings":[],"default":null,"positional":false,"named":true,"required":false,"variadic":false,"settable":false}],"returns":["any"],"scope":[]},{"path":["array"],"name":"product","title":"Product","keywords":[],"oneliner":"Calculates the product all items (works for all types that can be","element":false,"contextual":false,"deprecation":null,"details":"<p>Calculates the product all items (works for all types that can be\nmultiplied).</p>","example":null,"self":true,"params":[{"name":"default","details":"<p>What to return if the array is empty. Must be set if the array can\nbe empty.</p>","example":null,"types":["any"],"strings":[],"default":null,"positional":false,"named":true,"required":false,"variadic":false,"settable":false}],"returns":["any"],"scope":[]},{"path":["array"],"name":"any","title":"Any","keywords":[],"oneliner":"Whether the given function returns `{true}` for any item in the array.","element":false,"contextual":false,"deprecation":null,"details":"<p>Whether the given function returns <code><span class=\"typ-key\">true</span></code> for any item in the array.</p>","example":null,"self":true,"params":[{"name":"test","details":"<p>The function to apply to each item. Must return a boolean.</p>","example":null,"types":["function"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["bool"],"scope":[]},{"path":["array"],"name":"all","title":"All","keywords":[],"oneliner":"Whether the given function returns `{true}` for all items in the array.","element":false,"contextual":false,"deprecation":null,"details":"<p>Whether the given function returns <code><span class=\"typ-key\">true</span></code> for all items in the array.</p>","example":null,"self":true,"params":[{"name":"test","details":"<p>The function to apply to each item. Must return a boolean.</p>","example":null,"types":["function"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["bool"],"scope":[]},{"path":["array"],"name":"flatten","title":"Flatten","keywords":[],"oneliner":"Combine all nested arrays into a single flat one.","element":false,"contextual":false,"deprecation":null,"details":"<p>Combine all nested arrays into a single flat one.</p>","example":null,"self":true,"params":[],"returns":["array"],"scope":[]},{"path":["array"],"name":"rev","title":"Reverse","keywords":[],"oneliner":"Return a new array with the same items, but in reverse order.","element":false,"contextual":false,"deprecation":null,"details":"<p>Return a new array with the same items, but in reverse order.</p>","example":null,"self":true,"params":[],"returns":["array"],"scope":[]},{"path":["array"],"name":"split","title":"Split","keywords":[],"oneliner":"Split the array at occurrences of the specified value.","element":false,"contextual":false,"deprecation":null,"details":"<p>Split the array at occurrences of the specified value.</p>","example":null,"self":true,"params":[{"name":"at","details":"<p>The value to split at.</p>","example":null,"types":["any"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["array"],"scope":[]},{"path":["array"],"name":"join","title":"Join","keywords":[],"oneliner":"Combine all items in the array into one.","element":false,"contextual":false,"deprecation":null,"details":"<p>Combine all items in the array into one.</p>","example":null,"self":true,"params":[{"name":"separator","details":"<p>A value to insert between each item of the array.</p>","example":null,"types":["any","none"],"strings":[],"default":"<code><span class=\"typ-key\">none</span></code>","positional":true,"named":false,"required":false,"variadic":false,"settable":false},{"name":"last","details":"<p>An alternative separator between the last two items.</p>","example":null,"types":["any"],"strings":[],"default":null,"positional":false,"named":true,"required":false,"variadic":false,"settable":false}],"returns":["any"],"scope":[]},{"path":["array"],"name":"intersperse","title":"Intersperse","keywords":[],"oneliner":"Returns an array with a copy of the separator value placed between","element":false,"contextual":false,"deprecation":null,"details":"<p>Returns an array with a copy of the separator value placed between\nadjacent elements.</p>","example":null,"self":true,"params":[{"name":"separator","details":"<p>The value that will be placed between each adjacent element.</p>","example":null,"types":["any"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["array"],"scope":[]},{"path":["array"],"name":"chunks","title":"Chunks","keywords":[],"oneliner":"Splits an array into non-overlapping chunks, starting at the beginning,","element":false,"contextual":false,"deprecation":null,"details":"<p>Splits an array into non-overlapping chunks, starting at the beginning,\nending with a single remainder chunk.</p>\n<p>All chunks but the last have <code>chunk-size</code> elements.\nIf <code>exact</code> is set to <code><span class=\"typ-key\">true</span></code>, the remainder is dropped if it\ncontains less than <code>chunk-size</code> elements.</p>","example":"<div class=\"previewed-code\"><pre><code><span class=\"typ-key\">#</span><span class=\"typ-key\">let</span> array <span class=\"typ-op\">=</span> <span class=\"typ-punct\">(</span><span class=\"typ-num\">1</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">2</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">3</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">4</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">5</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">6</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">7</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">8</span><span class=\"typ-punct\">)</span>\n<span class=\"typ-pol\">#</span><span class=\"typ-pol\">array</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">chunks</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">3</span><span class=\"typ-punct\">)</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-pol\">#</span><span class=\"typ-pol\">array</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">chunks</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">3</span><span class=\"typ-punct\">,</span> exact<span class=\"typ-punct\">:</span> <span class=\"typ-key\">true</span><span class=\"typ-punct\">)</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.13.1/assets/35c1baf0f7902b3b48cc164333d55b.png\" alt=\"Preview\"></div></div>","self":true,"params":[{"name":"chunk-size","details":"<p>How many elements each chunk may at most contain.</p>","example":null,"types":["int"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false},{"name":"exact","details":"<p>Whether to keep the remainder if its size is less than <code>chunk-size</code>.</p>","example":null,"types":["bool"],"strings":[],"default":"<code><span class=\"typ-key\">false</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":false}],"returns":["array"],"scope":[]},{"path":["array"],"name":"windows","title":"Windows","keywords":[],"oneliner":"Returns sliding windows of `window-size` elements over an array.","element":false,"contextual":false,"deprecation":null,"details":"<p>Returns sliding windows of <code>window-size</code> elements over an array.</p>\n<p>If the array length is less than <code>window-size</code>, this will return an empty array.</p>","example":"<div class=\"previewed-code\"><pre><code><span class=\"typ-key\">#</span><span class=\"typ-key\">let</span> array <span class=\"typ-op\">=</span> <span class=\"typ-punct\">(</span><span class=\"typ-num\">1</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">2</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">3</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">4</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">5</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">6</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">7</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">8</span><span class=\"typ-punct\">)</span>\n<span class=\"typ-pol\">#</span><span class=\"typ-pol\">array</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">windows</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">5</span><span class=\"typ-punct\">)</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.13.1/assets/19a732fa351d05f71c5f8ddfc73c2a3e.png\" alt=\"Preview\"></div></div>","self":true,"params":[{"name":"window-size","details":"<p>How many elements each window will contain.</p>","example":null,"types":["int"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["array"],"scope":[]},{"path":["array"],"name":"sorted","title":"Sorted","keywords":[],"oneliner":"Return a sorted version of this array, optionally by a given key","element":false,"contextual":false,"deprecation":null,"details":"<p>Return a sorted version of this array, optionally by a given key\nfunction. The sorting algorithm used is stable.</p>\n<p>Returns an error if two values could not be compared or if the key\nfunction (if given) yields an error.</p>\n<p>To sort according to multiple criteria at once, e.g. in case of equality\nbetween some criteria, the key function can return an array. The results\nare in lexicographic order.</p>","example":"<div class=\"previewed-code\"><pre><code><span class=\"typ-key\">#</span><span class=\"typ-key\">let</span> array <span class=\"typ-op\">=</span> <span class=\"typ-punct\">(</span>\n  <span class=\"typ-punct\">(</span>a<span class=\"typ-punct\">:</span> <span class=\"typ-num\">2</span><span class=\"typ-punct\">,</span> b<span class=\"typ-punct\">:</span> <span class=\"typ-num\">4</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">,</span>\n  <span class=\"typ-punct\">(</span>a<span class=\"typ-punct\">:</span> <span class=\"typ-num\">1</span><span class=\"typ-punct\">,</span> b<span class=\"typ-punct\">:</span> <span class=\"typ-num\">5</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">,</span>\n  <span class=\"typ-punct\">(</span>a<span class=\"typ-punct\">:</span> <span class=\"typ-num\">2</span><span class=\"typ-punct\">,</span> b<span class=\"typ-punct\">:</span> <span class=\"typ-num\">3</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">,</span>\n<span class=\"typ-punct\">)</span>\n<span class=\"typ-pol\">#</span><span class=\"typ-pol\">array</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">sorted</span><span class=\"typ-punct\">(</span>key<span class=\"typ-punct\">:</span> it <span class=\"typ-op\">=&gt;</span> <span class=\"typ-punct\">(</span>it<span class=\"typ-punct\">.</span>a<span class=\"typ-punct\">,</span> it<span class=\"typ-punct\">.</span>b<span class=\"typ-punct\">)</span><span class=\"typ-punct\">)</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.13.1/assets/fe903cbcc2093647a0fabae43aaaaf52.png\" alt=\"Preview\"></div></div>","self":true,"params":[{"name":"key","details":"<p>If given, applies this function to the elements in the array to\ndetermine the keys to sort by.</p>","example":null,"types":["function"],"strings":[],"default":null,"positional":false,"named":true,"required":false,"variadic":false,"settable":false}],"returns":["array"],"scope":[]},{"path":["array"],"name":"dedup","title":"Deduplicate","keywords":[],"oneliner":"Deduplicates all items in the array.","element":false,"contextual":false,"deprecation":null,"details":"<p>Deduplicates all items in the array.</p>\n<p>Returns a new array with all duplicate items removed. Only the first\nelement of each duplicate is kept.</p>","example":"<div class=\"previewed-code\"><pre><code><span class=\"typ-punct\">#</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">1</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">1</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">2</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">3</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">1</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">dedup</span><span class=\"typ-punct\">(</span><span class=\"typ-punct\">)</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.13.1/assets/37c0a9dbb361b1e7aef5584fddbfa0d2.png\" alt=\"Preview\"></div></div>","self":true,"params":[{"name":"key","details":"<p>If given, applies this function to the elements in the array to\ndetermine the keys to deduplicate by.</p>","example":null,"types":["function"],"strings":[],"default":null,"positional":false,"named":true,"required":false,"variadic":false,"settable":false}],"returns":["array"],"scope":[]},{"path":["array"],"name":"to-dict","title":"To Dict","keywords":[],"oneliner":"Converts an array of pairs into a dictionary.","element":false,"contextual":false,"deprecation":null,"details":"<p>Converts an array of pairs into a dictionary.\nThe first value of each pair is the key, the second the value.</p>\n<p>If the same key occurs multiple times, the last value is selected.</p>","example":"<div class=\"previewed-code\"><pre><code><span class=\"typ-punct\">#</span><span class=\"typ-punct\">(</span>\n  <span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;apples&quot;</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">2</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">,</span>\n  <span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;peaches&quot;</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">3</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">,</span>\n  <span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;apples&quot;</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">5</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">,</span>\n<span class=\"typ-punct\">)</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">to-dict</span><span class=\"typ-punct\">(</span><span class=\"typ-punct\">)</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.13.1/assets/2e6b8e445cf77edd022ddf968946479e.png\" alt=\"Preview\"></div></div>","self":true,"params":[],"returns":["dictionary"],"scope":[]},{"path":["array"],"name":"reduce","title":"Reduce","keywords":[],"oneliner":"Reduces the elements to a single one, by repeatedly applying a reducing","element":false,"contextual":false,"deprecation":null,"details":"<p>Reduces the elements to a single one, by repeatedly applying a reducing\noperation.</p>\n<p>If the array is empty, returns <code><span class=\"typ-key\">none</span></code>, otherwise, returns the result\nof the reduction.</p>\n<p>The reducing function is a closure with two arguments: an &quot;accumulator&quot;,\nand an element.</p>\n<p>For arrays with at least one element, this is the same as <a href=\"/en-US-v0.13.1/reference/foundations/array/#definitions-fold\" title=\"`array.fold`\"><code>array.fold</code></a>\nwith the first element of the array as the initial accumulator value,\nfolding every subsequent element into it.</p>","example":null,"self":true,"params":[{"name":"reducer","details":"<p>The reducing function. Must have two parameters: One for the\naccumulated value and one for an item.</p>","example":null,"types":["function"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["any"],"scope":[]}]}}}