Demo
Simple Playground
class Contact(val id: Int, var email: String) fun main(args: Array<String>) { val contact = Contact(1, "mary@gmail.com") println(contact.id) }
Readonly Playground
fun main(args: Array<String>) { println("Hello World!") }
JS compiler
fun main(args: Array<String>) { println("Hello World!") }
JS IR compiler
fun mul(a: Int, b: Int): Int { return a * b } fun main(args: Array<String>) { print(mul(-2, 4)) }
WASM compiler
fun mul(a: Int, b: Int): Int { return a * b } fun main(args: Array<String>) { print(mul(-2, 4)) }
Test Playground
import org.junit.Test import org.junit.Assert class TestExtensionFunctions() { @Test fun testIntExtension() { Assert.assertEquals("Rational number creation error: ", RationalNumber(4, 1), 4.r()) } @Test fun testPairExtension() { Assert.assertEquals("Rational number creation error: ", RationalNumber(2, 3), Pair(2, 3).r()) } } //sampleStart /* Then implement extension functions Int.r() and Pair.r() and make them convert Int and Pair to RationalNumber. */ fun Int.r(): RationalNumber = RationalNumber(this, 2) fun Pair<Int, Int>.r(): RationalNumber = RationalNumber(first, second) data class RationalNumber(val numerator: Int, val denominator: Int) //sampleEnd
External JS Libraries
external fun moment(): dynamic fun main() { val startOfDay = moment().startOf("day").fromNow() println("The start of the day was $startOfDay") }
Multiple files
import cat.Cat fun main(args: Array<String>) { //sampleStart val cat = Cat("Kitty") println(cat.name) //sampleEnd }