How to convert list to map in Kotlin

Two ways to convert list to map in Kotlin, with code examples
31 October 2017   5911

For example, you have a list of strings like:

val list = listOf("a", "b", "c", "d")

and you need to convert it to a map, where the strings are the keys.

There are two ways to do this:

The first and most performant is to use associateBy function that takes two lambdas for generating the key and value, and inlines the creation of the map:

val map = friends.associateBy({it.facebookId}, {it.points})

The second, less performant, is to use the standard map function to create a list of Pair which can be used by toMap to generate the final map:

val map = { it.facebookId to it.points }.toMap()

Kaspersky Lab to Open Kaspresso Source Code

The solution is designed for mobile services testing
21 October 2019   217

Kaspersky Lab has uploaded a tool for self-testing applications on Android on GitHub. The creation involved developers from HeadHunter and Avito. Kaspresso - as the framework is called - has already been tested on Kaspersky Lab’s mobile services.

The framework is based on two autotest libraries: Espresso and Kakao. Kaspresso can be used in AndroidDebugBridge tests - this is when specified commands are executed on the device for debugging. In normal tests through Espresso, there is no ADB support. Kaspresso also logs all actions and can solve problems with flaky tests when the result is unpredictable. It is written in Kotlin.

Kaspersky Lab believes that Kaspresso differs from its competitors in the flexibility of settings and ease of use.