Trying to study collection transformations in Kotlin and I'm a bit confused by the documentation for the associateWith transformation extension function.
It says:
The basic association function associateWith() creates a Map in which the elements of the original collection are keys, and values are produced from them by the given transformation function. If two elements are equal, only the last one remains in the map.
Yet when I test this function with a list that contains duplicate elements i.e. they're equal, the last one gets excluded from the map, and only the first is the one that remains, contrary to what it says in the doc.
fun main() {
val numbers = listOf("one", "two", "three", "four", "five", "four")
val mapOfNumbers = numbers.associateWith { it.length }
println(mapOfNumbers) //the first "four" element is the one that remains in the map
}
Running this in the Kotlin Playground prints the following
{one=3, two=3, three=5, four=4, five=4}
Is the wording off in the documentation or am I missing something here with my train-of-thought?