Kotlin collection.map supported yet


#1

I am trying to compile this sample which maps users by lastname, but it fails with "Compiler terminated with exit code: -1". Am I missing anything?

import std.util.* import std.*

fun main(args : Array<String>) {
  val users = arrayList(
  User(“John”, “Doe1”, 31),
  User(“John”, “Doe2”, 32),
  User(“John”, “Doe3”, 33))

  val usersByLastName = users.map {it.lastName}
  for (item in usersByLastName) {
  println(item)
  }
}


Here is the User.kt:

public class User(val firstName: String, val lastName: String, val age: Int) {
  fun toString() ="$firstName $lastName, age $age"
}


#2

No, you are not. It's a bug in type inference. Will be fixed soon. Workaround: import std.util.* import std.*

fun main(args : Array<String>) {
  val users = arrayList(
  User(“John”, “Doe1”, 31),
  User(“John”, “Doe2”, 32),
  User(“John”, “Doe3”, 33))

  val usersByLastName = users.map {(it : User) -> it.lastName}
  for (item in usersByLastName) {
  println(item)
  }
}


#3

Thanks Andrey, that works! I assume extension methods min(), max() are still in the works.