File utils/arrayutil.lua
Functions
arrayutil.contains (array, item, equals) | Gets if the given array contains the given item. |
arrayutil.index (array, item, equals) | Gets the index of the item in the given array. |
arrayutil.next_matching_column (array, start_index, matcher, reverse) | Finds the next matching column. |
arrayutil.next_matching_row (array, start_index, matcher, reverse) | Finds the next matching row. |
arrayutil.previous_matching_column (array, start_index, matcher) | Finds the previous matching column. |
arrayutil.previous_matching_row (array, start_index, matcher) | Finds the previous matching row. |
arrayutil.reduce2d (array, is_empty) | Removes empty rows and columns at the beginning and the end of the given array. |
arrayutil.swapped_reindex2d (data, new_x, new_y) | Reindexes the given 2D array, swapping the two dimensions. |
arrayutil.swapped_reindex3d (data, new_x, new_y, new_z) | Reindexes the given 3d array, swapping the two dimensions. |
Functions
- arrayutil.contains (array, item, equals)
-
Gets if the given array contains the given item.
Parameters
- array: The array to search in.
- item: The item to search for, can either be an item or another array.
- equals: Optional. The function to determine if items equal each other, defaults to tableutil.equals.
Return value:
true if the array contains the given item. - arrayutil.index (array, item, equals)
-
Gets the index of the item in the given array.
Parameters
- array: The array to search in.
- item: The item to search for, can either be an item or another array.
- equals: Optional. The function to determine if items equal each other, defaults to tableutil.equals.
Return value:
The index of the given item or array, -1 if it was not found. - arrayutil.next_matching_column (array, start_index, matcher, reverse)
-
Finds the next matching column.
Parameters
- array: The 2D array to search.
- start_index: Optional. The index at which to start. Defaults to 1, or if the direction is reversed, the number of columns in the array.
- matcher: Optional. The function that is used to determine if the column matches or not. Is expected to take one argument, the item, and return a boolean. The column matches if any of its items matches this condition. Defaults to not nil and not empty string.
- reverse: Optional. If the array should be serched backwards. Defaults to false.
Return value:
The index of the matching column. -1 if none was found. - arrayutil.next_matching_row (array, start_index, matcher, reverse)
-
Finds the next matching row.
Parameters
- array: The 2D array to search.
- start_index: Optional. The index at which to start. Defaults to 1, or if the direction is reversed, the number of rows in the array.
- matcher: Optional. The function that is used to determine if the row matches or not. Is expected to take one argument, the item, and return a boolean. The row matches if any of its items matches this condition. Defaults to not nil and not empty string.
- reverse: Optional. If the array should be serched backwards. Defaults to false.
Return value:
The index of the matching row. -1 if none was found. - arrayutil.previous_matching_column (array, start_index, matcher)
-
Finds the previous matching column.
Parameters
- array: The 2D array to search.
- start_index: Optional. The index at which to start. Defaults to the number columns in the array.
- matcher: Optional. The function that is used to determine if the column matches or not. Is expected to take one argument, the item, and return a boolean. The column matches if any of its items matches this condition. Defaults to not nil and not empty string.
Return value:
The index of the matching column. -1 if none was found. - arrayutil.previous_matching_row (array, start_index, matcher)
-
Finds the previous matching row.
Parameters
- array: The 2D array to search.
- start_index: Optional. The index at which to start. Defaults to the number rows in the array.
- matcher: Optional. The function that is used to determine if the row matches or not. Is expected to take one argument, the item, and return a boolean. The row matches if any of its items matches this condition. Defaults to not nil and not empty string.
Return value:
The index of the matching row. -1 if none was found. - arrayutil.reduce2d (array, is_empty)
-
Removes empty rows and columns at the beginning and the end of the given array.
Parameters
- array: The array.
- is_empty: Optional. The function used for determining if the item is empty. By default nil and an empty string is considered empty. Expected is a function that takes one item and returns a boolean.
- arrayutil.swapped_reindex2d (data, new_x, new_y)
-
Reindexes the given 2D array, swapping the two dimensions.
Parameters
- data: The array to reindex.
- new_x: The new startpoint for the first dimension.
- new_y: The new startpoint for the second dimension.
Return value:
The reindexed array. - arrayutil.swapped_reindex3d (data, new_x, new_y, new_z)
-
Reindexes the given 3d array, swapping the two dimensions.
Parameters
- data: The array to reindex.
- new_x: The new startpoint for the first dimension.
- new_y: The new startpoint for the second dimension.
- new_z: The new startpoint for the third dimension.
Return value:
The reindexed array.