Multik 0.3.0 Help

indexOf

Returns the flat (row-major) index of the first occurrence of the specified element, or -1 if not found. Predicate-based variants (indexOfFirst, indexOfLast) and lastIndexOf are also available.

Signatures

fun <T, D : Dimension> MultiArray<T, D>.indexOf(element: T): Int inline fun <T, D : Dimension> MultiArray<T, D>.indexOfFirst( predicate: (T) -> Boolean ): Int inline fun <T, D : Dimension> MultiArray<T, D>.indexOfLast( predicate: (T) -> Boolean ): Int fun <T, D : Dimension> MultiArray<T, D>.lastIndexOf(element: T): Int

Parameters

Parameter

Type

Description

element

T

The element to search for.

predicate

(T) -> Boolean

Condition to match elements against.

Returns: Flat index (0-based), or -1 if not found.

Example

val a = mk.ndarray(mk[10, 20, 30, 20, 10]) a.indexOf(20) // 1 a.lastIndexOf(20) // 3 a.indexOfFirst { it > 15 } // 1 a.indexOfLast { it > 15 } // 3 a.indexOf(99) // -1
28 February 2026