ExCellerate.Functions.General.Index (excellerate v0.4.0)

Copy Markdown View Source

Returns a value from a list or 2D array by position.

Inspired by Excel's INDEX function. Uses 0-based indexing, consistent with the rest of ExCellerate. Negative indices count from the end of the list, the same way they work in Elixir.

  • index(list, row) — returns the element at position row in a 1D list.
  • index(array, row, col) — returns the element at row and col in a 2D array (list of lists).

Returns null for out-of-bounds positions (consistent with ExCellerate's nil-propagation philosophy).

Examples

index(items, 2)             third element of items
index(items, -1)            last element of items
index(grid, 1, 2)           row 1, column 2 of a 2D grid
index(grid, -1, -1)         last row, last column
index(items, 99)            null (out of bounds)