associate
Builds a Map from key-value Pairs produced by applying transform to each row.
The transform is a RowExpression — a lambda that receives each DataRow both as this and it and is expected to return a pair, allowing you to generate Pairs of keys and values from row contents. You can also use extension properties for concise and type-safe access.
If several rows produce the same key, the map keeps the last value for that key, consistent with Kotlin's kotlin.collections.associate behavior.
The keys are in the same order as the rows. A key that occurs in several rows appears at the position of its first row, with the value of its last one.
For more information: See associate on the documentation website.
See also:
associateBy— builds a map with the rows themselves as values, so only a key is computed for each row.toMap— converts aDataFrameinto aMapby using column names as keys and their values as the corresponding map values.
Example
// Associate rows into a map where key = id, value = name
val map = df.associate { id to name }Return
A Map of keys to values.
Parameters
A RowExpression that returns a Pair of key and value for each row.