Florian
07/14/2019, 8:39 PMcompareTo
methods? They don't need Kotlin's Comparable
interface?Katie Levy
07/15/2019, 4:40 PMIve Vasiljevic
07/16/2019, 1:59 PMfangzhzh
07/17/2019, 12:59 AM// NOT RECOMMENDED
fun process(str: String?) {
str?.let { /*Do something*/ }
}
// -> decompile will get
public final void process(@Nullable String str) {
if (str != null) {
boolean var4 = false;
/*Do something*/
}
}
// RECOMMENDED
fun process(str: String?) {
if (str != null) {
// Do Something
}
}
tjohnn
07/17/2019, 5:04 AMProduct
and ProductToOrder
which are quite similar in terms of id
and name
, I overrode the`equals()` already but productsToOrder?.indexOf<Any>(product)
always returns -1
Ive Vasiljevic
07/17/2019, 9:48 AMBig Chungus
07/17/2019, 12:42 PMinline fun <T> Array<Array<T>>.forEach2D(action: (T) -> Unit): Unit {
for (array in this) for (element in array) action(element)
}
Dennis Schröder
07/17/2019, 3:29 PMTimerTask
) at runtime and excute the run()
method on them?Karolis
07/18/2019, 3:25 PMno
? val x = BigDecimal.ONE
val y = x.setScale(999)
x == y // => false
x.compareTo(y) == 0 // => true
ursus
07/18/2019, 5:38 PMmap
with identity function?Florian
07/19/2019, 4:01 PMMike R
07/20/2019, 10:10 PMinterface IterableResponse {
val data: List<T>
val paginationInfo: More?
}
and I am getting an error "Unresolved reference T".
I would like for any class that implements the interface to have a data
property that is a list of anything - but I don't want to use List<Any>
because I need the implementing classes to have typed Lists.
Am I using generics incorrectly? What am I doing wrong?Akhil Suseelan
07/22/2019, 10:16 AMMarko Mitic
07/22/2019, 11:42 AMprivate fun <E> Set<E>.immutable(): Set<E> = if (this is MutableSet) this.toSet() else this
Florian
07/22/2019, 1:10 PMin
resolves to a call to the iterator
?Florian
07/22/2019, 1:12 PMMarko Mitic
07/22/2019, 3:40 PMStefan
07/24/2019, 7:59 AMSoren Valle
07/25/2019, 6:33 PMMike R
07/27/2019, 5:06 PMfun Response<*>.createError(): Error {
val errorBody = this.errorBody() ?: run {
logger.error { "createError failed: null errorBody found" }
throw ClassCastException("Null errorBody found on response")
}
val error = Gson().fromJson(errorBody.string(), models.Error::class.java)
return error
}
What is happening is I am losing the contents of errorBody
when I try to use the receiver (Response)... I've read over the docs on class extension and I don't see anything about this?Jérémy Touati
07/27/2019, 6:18 PMclass Position(val x: Int, val y: Int) {
constructor(positionCode: String) {
// construct a position from code here
}
}
this yields an error as the secondary constructor must call the primary one with : this(...)
i don't see an easy way to achieve this, i could call a function in the parent call such as this(getCoordsFromCode(positionFromCode))
but it obviously won't work as the primary one expects two ints, and I don't think you can unpack an array into a function that isn't expecting vararg
i could obviously swap the constructors and have the parent constructor call be something like this(getCodeFromCoords(x, y))
, but I was wondering if I was missing something (and I'm pretty sure I am)Magnus W
07/28/2019, 2:22 PMPablichjenkov
07/28/2019, 9:50 PMsuspend send
coroutine in the executor. Maybe not, maybe it spins lock on the Queue capacity.
The same for the counterpart suspend consumer
Does anyone can explain what happens internally?Mike R
07/28/2019, 11:35 PMwith(...) { }
? It was error-free until I changed it to
with(...) { sf -> ... }
and now IntelliJ says Expected no parameters
diego-gomez-olvera
07/29/2019, 9:59 AMSandeep Gurram
07/30/2019, 7:20 AMdiego-gomez-olvera
07/30/2019, 9:23 AMw_bianrytree
07/31/2019, 3:59 AMclass Derived(b: Base) : Base by b {
override fun printMessage() { print("abc") }
}
I want
class Derived : Base by b {
late init var b:Base
fun initB(outerB:Base){
b = outerB
}
override fun printMessage() { print("abc") }
}
Is it doable?Bill Burcham
07/31/2019, 2:48 PMtypealias
didn’t support a recursive definition so I couldn’t do:
typealias State = (pushes: ReceiveChannel<Unit>, coins: ReceiveChannel<Unit>) -> State
So I had to resort to defining State
as a @FunctionalInterface
meh.
With some liberal casts, this compiles but it fails at runtime (see comment above line 59):
https://gist.github.com/Bill/b9cbfdb1d6fbba42258ee0a6fcee7240
Eschewing fun
and defining the states as `object`s works but that seems like a lot of extra ceremony:
https://gist.github.com/Bill/d5fa8c0290e49fccb90936745b29e86f
Any ideas here?Greg Stepniewski
07/31/2019, 8:06 PMfun Example.sequence(vararg operations: Example.() -> Example): List<Example> {
val sequence = mutableListOf(this)
operations.forEach { sequence.add(it(sequence.last())) }
return sequence.toList()
}
Greg Stepniewski
07/31/2019, 8:06 PMfun Example.sequence(vararg operations: Example.() -> Example): List<Example> {
val sequence = mutableListOf(this)
operations.forEach { sequence.add(it(sequence.last())) }
return sequence.toList()
}
Shawn
07/31/2019, 8:08 PMfoldWithNext
Greg Stepniewski
07/31/2019, 8:14 PM5.sequence({plus(1)}, {minus(2)}, {times(2)}) // [5, 6, 4, 8]
Shawn
07/31/2019, 8:18 PMkarelpeeters
07/31/2019, 8:23 PMfun <T> T.chainOperations(ops: List<(T) -> T>): List<T> {
var curr = this
return listOf(curr) + ops.map { it(curr).also { curr = it } }
}
Dominaezzz
07/31/2019, 8:25 PMsequence {
var curr = this
for (op in operation) {
yield(curr)
curr = op(curr)
}
yield(curr)
}.toList()
Matias Reparaz
07/31/2019, 8:27 PMfun Example.sequence(vararg operations: Example.() -> Example): List<Example> {
return operations.fold(listOf(this)) {acc, cur -> acc + (cur(acc.last()))}
}
karelpeeters
07/31/2019, 8:28 PMfold
is called scan
in other languages.Greg Stepniewski
07/31/2019, 8:30 PMMatias Reparaz
07/31/2019, 8:37 PMDominaezzz
07/31/2019, 8:39 PMoperations.fold(mutableListOf(this)) { acc, cur -> acc += cur(acc.last()) }
might perform a bit better.karelpeeters
07/31/2019, 8:40 PMDominaezzz
07/31/2019, 8:40 PMmarstran
08/01/2019, 8:05 AMfun Example.sequence(vararg operations: Example.() -> Example): List<Example> {
if (operations.isEmpty()) {
return listOf(this)
}
val mappedExample = operations.first()(this)
val nextOperations = operations.drop(1)
val seq = mappedExample.sequence(*nextOperations.toTypedArray())
return listOf(this) + seq
}
It could probably be optimized to not create so many intermediate arrays and lists though. It should also probably be made tail recursive.karelpeeters
08/01/2019, 9:21 AMsubList(1)
instead of drop(1)
. Still terrible performance of course 🙃Dico
08/01/2019, 6:25 PMtailrec fun <E> E.sequence(ops: List<(E) -> E>, target: MutableList<E> = arrayListOf(), ind: Int = 0): List<E> {
target += this
if (ind >= ops.size) return target
return ops[ind](this).sequence(ops, target, ind+1)
karelpeeters
08/01/2019, 6:28 PMDico
08/01/2019, 6:29 PMkarelpeeters
08/01/2019, 6:29 PM