Kotlin 1.4-M2 brings standard library improvements – InfoWorld

JetBrains is working toward the general release of Kotlin 1.4, an upgrade to the open source, general purpose language for JVM, Android, web, and native development that promises improvements to the standard library including the API.

In a bulletin posted on May 12, JetBrains detailed standard library improvements in the forthcoming Kotlin 1.4-M2 milestone release. An early version has been deployed to the Kotlin playground for developers to try out. Changes to the existing API are featured, including updating signatures and introducing new constants. Some functions have been relaxed to accept nulls.

For example:

val s: String? = null
println(s.toBoolean())  // false

(Note that Kotlin 1.3 will not compile this code.)

Other API-related code changes also are featured, such as SIZE_BITS and SIZE_BYTES, which are new constants in Double and Float. These contain the number of bits and bytes used to represent an instance of the type in binary form.

Also new in the Kotlin 1.4-M2 standard library:

  • The common library is gradually being extended to add missing functionality. The standard library can be used in “common” code, i.e. the code shared between different platforms — Android, iOS, JVM, or JavaScript.
  • New array functions in the standard library include shuffle(), which puts array elements in a random order, and onEach(), which performs the given action on each array element and returns the array itself. Also, functions have been added for sorting array subranges.
  • The collections API has been expanded to cover more real-life cases. A new set creation function, set()NotNull(), makes a set