Multik 0.3.0 Help

onEach

Performs the given action on each element and returns the array itself, enabling method chaining. Use it for side effects like logging or debugging within a pipeline of transformations.

Signature

inline fun <T, D : Dimension, C : MultiArray<T, D>> C.onEach( action: (T) -> Unit ): C

Parameters

Parameter

Type

Description

action

(T) -> Unit

Action to perform on each element.

Returns: The original array C, enabling method chaining.

Example

val a = mk.ndarray(mk[1, 2, 3]) val result = a .onEach { print("$it ") } // prints: 1 2 3 .map { it * 2 } // result: [2, 4, 6]
28 February 2026