Multik 0.3.0 Help

last

Returns the last element of the array, or the last element matching a predicate. Throws NoSuchElementException if the array is empty or no match is found; use lastOrNull for a safe variant that returns null instead.

Signatures

fun <T, D : Dimension> MultiArray<T, D>.last(): T inline fun <T, D : Dimension> MultiArray<T, D>.last( predicate: (T) -> Boolean ): T fun <T, D : Dimension> MultiArray<T, D>.lastOrNull(): T? inline fun <T, D : Dimension> MultiArray<T, D>.lastOrNull( predicate: (T) -> Boolean ): T?

Parameters

Parameter

Type

Description

predicate

(T) -> Boolean

Condition to match the last element against.

Returns:

  • last(): the last element. Throws NoSuchElementException if the array is empty.

  • last(predicate): the last matching element. Throws NoSuchElementException if none match.

  • lastOrNull()/lastOrNull(predicate): same as above but returns null instead of throwing.

Example

val a = mk.ndarray(mk[10, 20, 30]) a.last() // 30 a.last { it < 25 } // 20 a.lastOrNull { it > 50 } // null
28 February 2026