Damian
12/07/2019, 2:38 PMrollButton.setOnClickListener { rollDice(diceImage1)}
but want to call rollDice twice, with two different arguments e.g.
rollButton.setOnClickListener { rollDice(diceImage1) rollDice(diceImage2)}
bjonnh
12/09/2019, 3:31 AMDouglas KN
12/10/2019, 4:05 PMjvmArgs "-Dfoo=true"
) from kotlin?Florian
12/11/2019, 9:42 AMval healthBonus
inside the init block doesn't make much sense, does it?Simon Kågedal Reimer
12/11/2019, 12:39 PMVertxHttpHeaders
. That’s a type that implements Iterable<Map.Entry<String, String>>
but it does not implement Map
. I want to filter out some headers and get back a Map. This is what I’ve come up with:
headers
.map { it.toPair() }
.toMap()
.filterKeys { noCopyHeaders.contains(it).not() }
Can I do better somehow? 🙂 I wish I didn’t have to do the two-step conversion to the map and I wish I had a `filterNotKeys`… I guess I could just add those as extensionsJames Richardson
12/11/2019, 2:19 PMHong Minhee
12/12/2019, 7:50 PMIve Vasiljevic
12/13/2019, 9:46 AMHoanghun5
12/14/2019, 11:12 AM@BenchmarkMode(Mode.AverageTime)
@Fork(2)
@Measurement(iterations = 10)
class MyBenchmark {
@Benchmark
fun testMethod(): Any {
val list: List<Int> = ArrayList()
for (i in 0 until NR_TO_INSERT) {
list.add(list.size / 2, i)
}
return list
}
companion object {
private const val NR_TO_INSERT = 500000
}
}
Mr.NiceGuy
12/15/2019, 12:40 PMJarek Rozanski
12/15/2019, 2:31 PM.let
and nullability.
Code snippet:
val foo : String? = "sample"
foo.let { it.toUpperCase() }
Results in:
Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type String?
bjonnh
12/16/2019, 3:50 AMIve Vasiljevic
12/16/2019, 9:46 AMpoohbar
12/16/2019, 6:59 PMclass MyClass<T> {
var prop: T = null // error
}
why does this not work? I thought that the upper bound of a type parameter is by default Any?
Will Nixon
12/17/2019, 12:31 PMimport android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
class EntryAdapter(private val context: SpeechPageActivity, private val entryList: Array<String>) : RecyclerView.Adapter<EntryAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EntryAdapter.ViewHolder {
return ViewHolder(LayoutInflater.from(context).inflate(R.layout.entry_cell, parent, false))
}
override fun getItemCount(): Int {
return entryList.size
}
override fun onBindViewHolder(holder: EntryAdapter.ViewHolder, position: Int) {
holder.entryText?.text = entryList[position]
holder.itemView.setOnClickListener {
println(entryList[position])
}
}
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val entryText = view.entryText
val entryImage = view.entryImage
}
}
oday
12/17/2019, 3:32 PModay
12/18/2019, 5:55 PMam
12/20/2019, 12:27 AMLauritz Hilsøe
12/20/2019, 9:56 AMDmitri Sh
12/21/2019, 3:30 AMHullaballoonatic
12/21/2019, 5:24 PMval height = points.maxBy(Point::y)!!.y - points.minBy(Point::y)!!.y
I often find myself using this schema
val height = points.map(Point::y).run { max()!! - min()!! }
uses less characters but iterates an additional time through points
of course if i really wanted to do it best by performance, i could accomplish this in only one iteration...Tuang
12/23/2019, 4:16 AMjoinToString()
I means
val list = listOf(1,2,3)
// i want the result like this
// 1,2,3 <= each is int value
Ive Vasiljevic
12/23/2019, 1:07 PMStefan Kanev
12/24/2019, 12:32 PMdata class User(val name: String, val location: Location)
data class Location(val city: City, val somethingElse: String) // for example
data class City(val name: String, val country: String)
I have a user and I want to change the city name, getting a copy of user with everything else on the chain unchanged. I can do it with copy:
val newUser = user.copy(location = user.location.copy(city = user.location.city.copy(name = "New name")))
but that's far too long esentially I'd like to be able to do something shorter like:
val newUser = user.copy { it.location.city.name = "New name" }
I don't think the above could get gotten to work, but is there something in those lines I can do?
(also, not my actual data structure, but sufficient for this example)
Thanks 🙂Egor Okhterov
12/24/2019, 3:13 PMbuild.gradle
:
jvmJar {
dependsOn(jsBrowserWebpack)
from(new File(jsBrowserWebpack.entry.name, jsBrowserWebpack.outputPath))
}
How do you express that in build.gradle.kts
?
Probably, I've got a part of this right, but I'm not sure about the last expression
tasks.named("jvmJar") {
dependsOn("jsBrowserWebpack")
}
Bipul
12/26/2019, 5:18 AMTuang
12/26/2019, 10:03 AMval topStudents = arrayOf("Jake", "Jesse", "Matt", "Alec")
names.forEach { println(it) }
but how to do in this condition.
val allStudents = setOf {
"Michael",
"Kim",
topStudents <= i don't know how to retrieve topStudent each names likes "Michael" and "Kim"
}
// the result what i want is
val allStudents = setOf {
"Michael",
"Kim",
"Jake",
"Jesse",
"Matt",
"Alec"
}
Michał Kalinowski
12/26/2019, 10:23 AMNumber
operators and now I want make generics Point
that will also overload operators based on Number
, f.e result of Point<Float> + Point<Float>
should be Point<Float>
but recently is Point<in Float>
:<
data class Point<Unit : Number>(val x: Unit, val y: Unit, val z: Unit) {
operator fun plus(increment: Point<Unit>): Point<in Unit> {
return Point(x + increment.x, y + increment.y, z + increment.z)
}
operator fun minus(increment: Point<Unit>): Point<in Unit> {
return Point(x - increment.x, y - increment.y, z - increment.z)
}
operator fun times(increment: Point<Unit>): Point<in Unit> {
return Point(x * increment.x, y * increment.y, z * increment.z)
}
operator fun div(increment: Point<Unit>): Point<in Unit> {
return Point(x / increment.x, y / increment.y, z / increment.z)
}
}
Ive Vasiljevic
12/26/2019, 4:40 PMAlpesh Vas
12/26/2019, 5:02 PMreturn
statement in the end even if we are throwing exception onFailure
fun<T> withRetryOnRateLimit(numOfRetries: Int = 10, func: () -> T): T {
repeat(numOfRetries) {
runCatching(func)
.onSuccess { return it }
.onFailure { throw it }
}
}
Alpesh Vas
12/26/2019, 5:02 PMreturn
statement in the end even if we are throwing exception onFailure
fun<T> withRetryOnRateLimit(numOfRetries: Int = 10, func: () -> T): T {
repeat(numOfRetries) {
runCatching(func)
.onSuccess { return it }
.onFailure { throw it }
}
}
Simon Kågedal Reimer
12/26/2019, 5:21 PMStavFX
12/26/2019, 7:05 PMreturn func()