Array.map_with_index
map_with_indexfunctionon_problems
Documentation
Applies a function to each element of the array, returning the Vector
of results.
The function is called with both the element index as well as the element itself.
Arguments
function: A function that takes an index and an item and calculates a new value for at that index.on_problems: Specifies how to handle any problems that arise infunction.
Examples
Sum numbers with their indices in an array.
[1, 2, 3].to_array.map_with_index (+)
Errors
The result of Errors thrown when executing the function depend on
on_problems:
- Report_Error: The first error is thrown, and is wrapped in
Map_Error. - No_Wrap: The first error is thrown, and is not wrapped in
Map_Error. - Report_Warning: The result for that element is
Nothing, the error is attached as a warning. Currently unimplemented. - Ignore: The result is
Nothing, and the error is ignored. Errors that are thrown when executing the supplied function are wrapped inMap_Error, which contains the index at which the error occurred. In theReport_Warningcase, onlyMAX_MAP_WARNINGSwarnings are attached to result values. After that, the warnings are dropped, but a count of the additional warnings is attached in anAdditional_Warningswarning.