alllex
12/16/2020, 3:34 PMget
operator in kotlin is strictly typed)
fun main() {
val intList: List<Int> = listOf(1, 2)
val stringMap: Map<String, String> = mapOf("abc" to "xyz")
val x = intList.associateWith { map[it] } // should be an error, because key is String, and not Int
println(x)
}
Kotlin: 1.4.21Rob Elliot
12/16/2020, 4:00 PMkotlinc
programatically? I’d like to compile a kotlin class from a kotlin source file in a JVM app at runtime.Rob Elliot
12/16/2020, 4:05 PMEdoardo Luppi
12/16/2020, 6:53 PMmain
function.
When on multiplatform, is there a way to do the same thing for JS?Grant Park
12/16/2020, 10:14 PMwhen
statement can evaluate its cases in constant time, because the compiler will change the switch structure to a map. Does anyone know if this is true?rocketraman
12/17/2020, 1:03 AMzain
12/17/2020, 4:34 AMdata class Setting(val typeId: Int, val type: String, val isSubscribed: Boolean, val matchId: Int)
val settings = mutableListOf(Setting(1, "Goal Notification", true, matchId = 123), Setting(2, "Half Time Notification", true, matchId = 567))
//upsert?/
val newSettings = settings.add(Setting(1, "Goal Notification", false, matchId = 123))
val latestSettings = settings.filter { setting -> setting.typeId == 1 }.map {
// add or update over here
}
zokipirlo
12/17/2020, 8:21 AMval myNotRequiredStuff : SomeClass by lazy { SomeClass(...) }
...
fun onDestroy() {
myNotRequiredStuff.useIfCreated {
myNotRequiredStuff.destroy()
}
}
Benjamin Vallet
12/17/2020, 9:11 AMikej
12/17/2020, 9:45 AMPeter Ertl
12/17/2020, 1:58 PMPeter Ertl
12/17/2020, 3:03 PMCLOVIS
12/17/2020, 4:04 PMinterface A<T>
I want to write a function that takes an A
and a value of the same type.
Intuitively, this would look like:
fun <T> foo(a: A<T>, v: T)
The problem is that if I call it this way:
val a: A<String> = ...
val v: Int = ...
foo(a, v)
It calls foo<Any>(a, v)
, but I want it to call foo<String>(a, v)
(and fail, because `v`'s type doesn't match what was expected by a
).
This function is fairly simple, so solutions using reified
or other inline
mechanism are not a problem, but I don't see how to do it.Lauren Yew
12/17/2020, 4:10 PMclass Builder (
private val function: (suspend () -> String) //Don't want to force Builder to have to provide a no argument function
)
Context: I used to be able to do this in RxJava with a Single. Moving to Coroutines / Flow.user
12/17/2020, 4:33 PMJoost Klitsie
12/17/2020, 5:09 PMJames Ward
12/17/2020, 6:45 PMNir
12/17/2020, 10:33 PMColton Idle
12/18/2020, 12:37 AMParameter 'w' is never used, could be renamed to _
Is there a way to auto fix all of these kotlin warnings? I know in android-lint you can select a group of issues and hit the fix button all in one shot.Slackbot
12/18/2020, 7:57 AMKamilH
12/18/2020, 9:58 AMtpgillam
12/18/2020, 1:48 PMval x = foo() ?: return moo
, where foo(): T?
is a method returning a nullable generic T?
. Now previously, x
was of type T
, however now the IDE is telling me that it is of type T!!
. I can seemingly force it to be of type T
, however can somebody explain what is going on here? I also can't find the relevant part of documentation that explains what !!
means when postfixing a (possibly only generic?) type. Thanks!Animesh Sahu
12/18/2020, 3:43 PMreturn when {
cond1 -> try { something() } catch (e: Exception) { TODO() /* Goto cond2 */ }
cond2 -> TODO()
else -> throw RuntimeException("Whatever reason")
}
janvladimirmostert
12/18/2020, 4:44 PMoutputStream.use { out -> baos.writeTo(out) }
Nir
12/18/2020, 7:30 PMasad.awadia
12/19/2020, 4:10 AMcode .
In shell which opens VSCode in the current directory but for intellij? Like intellij .
That launches intellij for the current dir - create or open if not exists the projectchristophsturm
12/19/2020, 3:44 PM[1,2,3,4,5,4,6].takeUntilLast { it == 4}
results in [1,2,3,4,5,4]
Nir
12/19/2020, 5:05 PMval finalSet = whateverlist.fold(mutableSetOf()) { acc, element ->
val individualSet = someCode(element)
acc.apply { addAll(individualSet) }
}
I'd expect this to be a little faster than some of the other approaches (e.g. reduce with regular Set and union
)Lulu
12/19/2020, 6:50 PMNikky
12/21/2020, 11:14 AMNikky
12/21/2020, 11:14 AMgildor
12/21/2020, 1:29 PMLeoColman
12/21/2020, 4:25 PMfoo( { x -> x + 1 } )
fun foo(any: Any) {}
Nikky
12/21/2020, 9:25 PMObject...
as last arguments