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 |
|---|---|---|
|
| Produces a key-value pair from each element. |
|
| Extracts the key from each element. |
|
| Transforms the element into the map value. |
|
| 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