Multik 0.3.0 Help

associate

Signatures

inline fun <T, D : Dimension, K, V> MultiArray<T, D>.associate( transform: (T) -> Pair<K, V> ): Map<K, V> inline fun <T, D : Dimension, K> MultiArray<T, D>.associateBy( keySelector: (T) -> K ): Map<K, T> inline fun <T, D : Dimension, K, V> MultiArray<T, D>.associateBy( keySelector: (T) -> K, valueTransform: (T) -> V ): Map<K, V> inline fun <K, D : Dimension, V> MultiArray<K, D>.associateWith( valueSelector: (K) -> V ): Map<K, V>

Parameters

Parameter

Type

Description

transform

(T) -> Pair<K, V>

Produces a key-value pair from each element.

keySelector

(T) -> K

Extracts the key from each element.

valueTransform

(T) -> V

Transforms the element into the map value.

valueSelector

(K) -> V

Produces the value for each element used as key.

Returns: Map<K, V> preserving iteration order. Duplicate keys keep the last value.

Example

val a = mk.ndarray(mk[1, 2, 3]) a.associate { it to it * it } // {1=1, 2=4, 3=9} a.associateBy { it * 10 } // {10=1, 20=2, 30=3} a.associateWith { it.toString() } // {1="1", 2="2", 3="3"}
28 February 2026