Skip to content

Instantly share code, notes, and snippets.

View adam-arold's full-sized avatar
💭
Exploring the n'th dimension.

Adam Arold adam-arold

💭
Exploring the n'th dimension.
View GitHub Profile
val list = listOf("foo.bar", "baz.qux")
list.forEach {
it.split(".").forEach {
println(it)
}
}
list.forEach { item ->
item.split(".").forEach { part ->
println(part)
}
}
data class Foo(val bars: MutableList<String>)
val bars = mutableListOf("foobar", "wombar")
val foo0 = Foo(bars)
val foo1 = foo0.copy()
bars.add("oops")
println(foo1.bars.joinToString())
val bars = listOf("foobar", "wombar")
data class Foo(val bars: List<String>)
class MyApi {
fun operation0() {
}
internal fun hiddenOperation() {
}
}
interface MyApi {
fun operation0()
}
class MyApiImpl: MyApi {
override fun operation0() {
}
internal fun hiddenOperation() {
}
}
fun String.extractCustomerName() : String {
// ...
}
/**
* 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))
}
fun consumeText(text: String, fn: (String) -> Unit) {
}
// usage
consumeText("foo") {
println(it)
}