Early access program for Kotlin 1.2 has been started

The start of the early access program for Kotlin 1.2 has been announced and its first milestone release 1.2-M1 is now out
30 June 2017   487
Kotlin

Kotlin is a statically-typed programming language that runs on the Java Virtual Machine and also can be compiled to JavaScript source code

Statically typed programming language for modern multiplatform applications opens access for Kotlin 1.2. The list of changes is not so big though contains several features:

  • Language

The single notable language feature proposed in this milestone is array literals, whose usages are constrained to annotation arguments.

  • Standard library

The release features two KEEPs (Kotlin Evolution and Enhancement Proposals) regarding the standard library API. The first is KEEP-49 introducing additional operations and conversion extensions for BigIntegerand and BigDecimal types. The second one is KEEP-11 which covers a number of functions related to partitioning collections and sequences.

  • JavaScript
JavaScript

JavaScript is a lightweight interpreted or JIT-compiled programming language with first-class functions

Earlier in 1.1.2 release the opt-in JS typed arrays support has been introduced. When enabled it translates Kotlin primitive arrays, such as IntArray, DoubleArray etc, into JavaScript typed arrays. Now the opt-in is no longer required as this support is enabled by default.

Check out Kotlin’s changelog to see the full list of changes.

How to convert list to map in Kotlin

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

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 = friends.map { it.facebookId to it.points }.toMap()