This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val list = listOf("foo.bar", "baz.qux") | |
list.forEach { | |
it.split(".").forEach { | |
println(it) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list.forEach { item -> | |
item.split(".").forEach { part -> | |
println(part) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Foo(val bars: MutableList<String>) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val bars = mutableListOf("foobar", "wombar") | |
val foo0 = Foo(bars) | |
val foo1 = foo0.copy() | |
bars.add("oops") | |
println(foo1.bars.joinToString()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val bars = listOf("foobar", "wombar") | |
data class Foo(val bars: List<String>) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyApi { | |
fun operation0() { | |
} | |
internal fun hiddenOperation() { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface MyApi { | |
fun operation0() | |
} | |
class MyApiImpl: MyApi { | |
override fun operation0() { | |
} | |
internal fun hiddenOperation() { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun String.extractCustomerName() : String { | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns an element of this [List] wrapped in an Optional | |
* which is empty if `idx` is out of bounds. | |
*/ | |
fun <T> List<T>.getIfPresent(idx: Int) = | |
if (idx >= size) { | |
Optional.empty() | |
} else { | |
Optional.of(get(idx)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun consumeText(text: String, fn: (String) -> Unit) { | |
} | |
// usage | |
consumeText("foo") { | |
println(it) | |
} |