https://kotlinlang.org logo
#announcements
Title
# announcements
m

Marc

08/03/2017, 9:44 AM
any idea on how can I do this from scala to Kotlin?:
Copy code
List(1,2) match {
  case x :: xs => println(x + " " + xs)
  case _ => println("")
}
d

diesieben07

08/03/2017, 9:48 AM
Copy code
val list = listOf(1, 2)
if (list.size >= 2) {
    println(list[0] + " " + list.drop(1))
} else {
    println("")
}
👍🏻 1
d

delater

08/03/2017, 7:27 PM
when { list.size == 2 -> println("${list[0]} ${list[1]}") else -> println("") }
d

diesieben07

08/03/2017, 7:29 PM
That's not the same it only prints elements at 0 and 1, the original code prints element 0 and "the rest".
2 Views