// Created on savesnippets.com · https://savesnippets.com/NwBeFeuDe8oYhD fun main() { // buildString — like StringBuilder, but cleaner val sql: String = buildString { append("SELECT id, name FROM users\n") appendLine("WHERE status = 'active'") append("ORDER BY id DESC LIMIT 100") } println(sql) // buildList — start mutable, return List val nums: List = buildList { add(1) addAll(2..5) if (someCondition()) add(99) } println(nums) // buildMap — same idea, returns Map val config: Map = buildMap { put("host", "localhost") put("port", 8080) if (devMode()) put("debug", true) } println(config) // buildSet — for the rare case you need an immutable Set with conditional content val tags: Set = buildSet { add("public") add("featured") if (isPaid()) add("pro") } println(tags) } fun someCondition() = true fun devMode() = false fun isPaid() = true