Mostafa Hadian
03/12/2022, 11:35 PMNo_One
03/13/2022, 9:16 PMGeorge
03/14/2022, 10:14 AMinternal fun AtomicRef<MutableList<Pair<KClass<*>, KSerializer<*>>>>.getOrWait(): MutableList<Pair<KClass<*>, KSerializer<*>>> {
while (this.value == emptyList<MutableList<Pair<KClass<*>, KSerializer<*>>>>())
suspend {
delay(10)
}
return this.value
}
Can anyone point any docs or articles on this subject? thanks in advance!Lucas Schiavini
03/14/2022, 12:40 PMSamuel Ajibade
03/14/2022, 10:12 PMS.
03/14/2022, 10:16 PModay
03/15/2022, 1:05 PMprivate val routes = mapOf<Regex, (vararg args: String) -> LaunchAction?>(
I would like to accept a variable number of arguments in that anonymous function defined as the map’s value, how can I do that? I’m not allowed to set a modifier like vararg
thereIdo Flax
03/16/2022, 6:46 AMCoroutineScope.launch{ }
takes 40 ms. Isn’t this a bit much? Part of the point of launching is that you don’t need to wait for it, but apparently you do need to wait 40 ms as least
val scope = CoroutineScope(Dispatchers.Default)
println(
measureTimeMillis {
scope.launch { }
}
)
// 40
This is done on a macbook pro 2021 m1 proVitali Plagov
03/16/2022, 1:02 PMval version = service.getAllTemplates()
.find { ... }
?.versions // returns a list
?.single()
?: error("no template found matching the given predicate")
I’m using the find{}
on purpose so I could handle its failure with a proper error message,
I want to do the same with single()
. I want to throw an exception with my own error message if the list contains more than one element.
I tried singleOrNull()
but still can’t provide a separate error message for it. Looks like the last error(…)
handles both nulls.Nat Strangerweather
03/16/2022, 4:30 PMfun removeUsedLetters() {
val boardLetters = readBoardLetters.value!!.toMutableList()
val newList = boardLetters.remove(letter.value)
println("remaining = $newList")
}
Why does remove()
act as a Boolean, and how can I get each letter that I click on to be removed from my list?Ayfri
03/16/2022, 5:59 PMtypealias AABB = Rectangle
with an external "constructor" fun Rectangle(x: Int = 0, y: Int = 0, width: Int = 0, height = 0) = ...
but it's not present on the type AABB, I also tested with fun Rectangle.invoke(x: Int ...
but it still doesn't work, is it possible ?Hozaifa Bhutta
03/16/2022, 11:08 PMAnthony Flores
03/17/2022, 1:34 AMval someProperty: SomeClass = 50%
?kierans777
03/17/2022, 2:44 AMopen class Animal(val name: String)
class LandAnimal(name: String, val legs: Int) : Animal(name)
class SeaAnimal(name: String, val flippers: Int) : Animal(name)
fun printAppendages(animal: SeaAnimal) {
print(" has ${animal.flippers} flippers")
}
fun printAppendages(animal: LandAnimal) {
print(" has ${animal.legs} legs")
}
fun printAppendages(animal: Animal) {
print(" has no appendages")
}
fun <T : Animal> printAnimal(animal: T) {
print(animal.name)
printAppendages(animal)
print("\n")
}
fun main() {
val lassie = LandAnimal("Lassie", 4)
val nemo = SeaAnimal("Nemo", 2)
printAnimal(lassie)
printAnimal(nemo)
}
Lassie has no appendages
Nemo has no appendages
Or is polymorphic dispatch only for methods?Nat Strangerweather
03/17/2022, 7:39 PMletterList.value
all the "A"s in boardLetterList
are removed. Is there a way of getting only one "A" filtered out if I only have one in my letterList?
val difference = boardLetterList.filterNot{ letterList.value!!.contains(it) }
David W
03/17/2022, 10:37 PMJasin Colegrove
03/18/2022, 3:03 PMJorge Bo
03/18/2022, 7:50 PMAvi Perl
03/18/2022, 8:54 PMtherealbluepandabear
03/19/2022, 3:24 AMtailrec
do here?
tailrec fun Context.activity(): Activity? = when {
this is Activity -> this
else -> (this as? ContextWrapper)?.baseContext?.activity()
}
Gavin Ray
03/19/2022, 7:21 PMand((MutableCollection<out Condition!>..Collection<Condition!>?))
I think this means "A type with a lower-bounds of MutableCollection<out Condition!>
and an upper-bounds of `Collection<Condition!>?`"
But if that is true, then explicitly casting to either of those should have made it work, which it doesn't (as you see in the image) 🤔 😕oday
03/20/2022, 10:08 PMimport kotlin.reflect.full.*
class Plant{
fun trim(){}
fun fertilize(){}
}
fun testAnnotations(){
val classObj = Plant::class
for (m in classObj.declaredMemberFunctions){
println(m.name)
}
}
declaredMemberFunctions
is still unrecognizedRE
03/21/2022, 11:55 AMjcechace
03/21/2022, 4:12 PMHozaifa Bhutta
03/21/2022, 10:09 PMJason5lee
03/22/2022, 10:20 AMclass SomeThing {
fun throwAnException(): Nothing { ... }
}
// ...
val s: SomeThing = ...
if (...)
s.throwAnException()
2.
class SomeThing {
fun anException(): Exception { ... }
}
// ...
val s: SomeThing = ...
if (...)
throw s.anException()
Stylianos Gakis
03/24/2022, 9:25 AMandodeki
03/24/2022, 10:45 PMfun main() {
var newList1 = listOf(listOf(1, "a", "b"), listOf(1, "a", "b"), listOf(1, "a", "b"))
var newList = listOf(1, "b", "C" to newList1)
var defaultList = listOf(1, "a", 'B' to newList)
var a = defaultList[2]
print(a::class.java.typeName) //kotlin.Pair
}
I need to access "newList1" but i cant since "defaultList" is a Pair
how can i access via index or how can i construct to get this behaviour
Jason5lee
03/25/2022, 8:21 AMkotlinx.collections.immutable
.
4. Others. State in the comment.Jason5lee
03/25/2022, 2:50 PMsealed interface
or sealed class
?Jason5lee
03/25/2022, 2:50 PMsealed interface
or sealed class
?Luke
03/25/2022, 2:52 PMsealed interface
unless I need a constructor in the sealed class
Alejandro Rios
03/25/2022, 2:53 PMsealed class
is to handle the states of a response Failure/Success/Loading
ephemient
03/25/2022, 3:26 PM@Serializable
at present, so I still default to sealed class
unless there is a particular structure that can only be expressed as sealed interface
andylamax
03/25/2022, 11:48 PMephemient
03/25/2022, 11:51 PMStephan Schroeder
03/28/2022, 7:10 AMsealed interface
is that its implementing classes can be data classes, which is why sealed interfaces is my default. (good to know about the serializable restriction!)ephemient
03/28/2022, 4:27 PMŁukasz Gendek
03/29/2022, 9:12 AMephemient
03/29/2022, 3:49 PM