Completed Coursera: Kotlin for developers course

This commit is contained in:
Martin Berg Alstad
2025-07-30 14:34:03 +02:00
commit 80c14c76ba
41 changed files with 608 additions and 0 deletions

33
src/With.kt Normal file
View File

@ -0,0 +1,33 @@
fun main() {
val sb = StringBuilder()
// sb becomes this within the lambda scope
val string = with(sb) /* Is an extention function on type T */ {
appendLine("Something")
append('a')
toString()
}
val buildString = buildString {
append(1)
append(2)
toString()
}
val words = Words()
with(words) {
// The following two lines should compile:
"one".record()
+"two"
}
words.toString() == "[one, two]"
}
class Words {
private val list = mutableListOf<String>()
fun String.record() = list.add(this)
operator fun String.unaryPlus() = list.add(this)
override fun toString() = list.toString()
}