Examples · Kotlin
Run Kotlin code without a project
Trying an idea in Kotlin usually means a Gradle project, a main() function and a wait for the build. In ByteRunner you type the lines and press F5: they run as they are, top to bottom, and you see each result.
Here a list of orders is sorted and then totalled per customer. dump() shows any value; a list of objects comes out as a table with a column per property.
The query
kotlin-without-a-project.kts · paste it into a Kotlin tab and press F5, or run byterunner run kotlin-without-a-project.kts in a terminal
// No project, no build file, no main(): these lines just run.
data class Order(val customer: String, val item: String, val total: Double)
val orders = listOf(
Order("Ada", "Keyboard", 89.00),
Order("Grace", "Monitor", 249.99),
Order("Ada", "Mouse", 25.50),
Order("Linus", "Laptop stand", 39.00),
Order("Grace", "Webcam", 74.00),
)
// dump() shows any value: a list of objects becomes a table, a column per property.
orders.sortedByDescending { it.total }.dump("Orders, biggest first")
orders.groupBy { it.customer }
.mapValues { (_, theirs) -> theirs.sumOf { it.total } }
.dump("Spent per customer")
What it shows
The output of that run, from byterunner run. In the app each table is a sortable grid.
Orders, biggest first
customer item total
-------- ------------ ------
Grace Monitor 249.99
Ada Keyboard 89.0
Grace Webcam 74.0
Linus Laptop stand 39.0
Ada Mouse 25.5
(5 rows)
Spent per customer
Key Value
----- ------
Ada 114.5
Grace 323.99
Linus 39.0
(3 rows)
Change a number and press F5 again: the run takes a moment, not a build. Statements mode, the default, runs the lines as a script. Expression mode shows the value of a single expression, and Program mode takes a full program with its own main().
In the app the tables can be sorted by clicking a column, and nested objects open as trees.