Tolriq
06/03/2022, 2:53 PMjavaClass.superclass.
works for the 1st level parent but
javaClass.superclass.javaClass.superclass.
Does not for the second one 😞Jonathan Ellis
06/03/2022, 3:14 PMoperator fun Body.iterator(): Iterator<Body> {
val body = this
return object : Iterator<Body> {
var current: Body? = body
override fun hasNext(): Boolean {
return current != null
}
override fun next(): Body {
val result = current!!
current = result.getNext()
return result
}
}
}
Jonathan Ellis
06/03/2022, 3:15 PMvar current: Body? = this@Body
but the compiler doesn't like thatNat Strangerweather
06/03/2022, 5:24 PMprivate fun shakeLetterBag(slice: IntRange): Array<Letter> {
repository.arr.shuffle()
return repository.arr.sliceArray(slice)
}
var boardLetters = MutableLiveData(repository.arr)
fun loadTiles(): Array<Letter>? {
boardLetters.value = shakeLetterBag(0..27)
return boardLetters.value}
I am wondering if there is something wrong with my logic because I seem to be getting the occasional identical set, which statistically should not be the case. Any ideas? 🤔Jonathan Ellis
06/03/2022, 5:28 PMJan
06/05/2022, 12:34 PMval tags = "".split(" ")
println(tags.size) //prints 1
Lawrence
06/06/2022, 7:43 PM\
to do so. Wondering if Kotlin has something similar
String a = "This is a long string";
String b = """
This is a \
long string""";
a.equals(b) // true
elect
06/07/2022, 11:14 AMIwan Aucamp
06/07/2022, 11:46 AMWojciech Rozwadowski
06/07/2022, 1:43 PMinvoke
operator? I tried to do this with below function:
operator fun <Param, T : Any> ((Param) -> T).invoke(
param: Param,
onResult: (Result<T>) -> Unit
) {
val state = runCatching { this@invoke(param) }
onResult(state)
}
Above works fine for this function reference:
fun test(param: Int): String = "testFunction"
and lambda itself but not for this class:
class ClassTest {
operator fun invoke(param: Int): String = "testClass"
}
Any suggestions?
fun main() {
val testLambda = { param: Int -> "testLambda" }
val testFunctionReference = ::test
val testClass = ClassTest()
testLambda(1) // returns String
testLambda(1) { onResult: Result<String> ->
// do sth
}
testFunctionReference(1) // returns String
testFunctionReference(1) { onResult: Result<String> ->
// do sth
}
testClass(1) // returns String
testClass(1) { onResult: Result<String> ->
// Too many arguments for public final operator fun invoke(param: Int): String defined in ClassTest
}
}
Jonathan Ellis
06/07/2022, 2:48 PMScott Peterson
06/07/2022, 3:47 PMUInt8
encoded byte array that I need to convert to a UTF-8 string, using Kotlin.
various things I’ve tried have converted it into the ASCII value “d”, which is the correct value. But I want the UTF-8 string value “100"Jonathan Ellis
06/07/2022, 7:49 PMJonathon Cain
06/07/2022, 8:32 PMDragos Rachieru
06/08/2022, 9:08 AMX
or min
or max
, like:
X=50
,min=0
,max=40
, then the result is 40
I need this to calculate some positions, don't know if there's a method using IntRange
allan.conda
06/08/2022, 10:13 AMlet
hides the uninitialized variable being null. Is there an explanation regarding this? Seems Kotlin (1.6.21) is not null-safe in this situation.
class SomeClass { // extremely minified code
val foo = let { bar } // compile error (almost broke production but my unit test captured it)
// val foo = bar // compile error (safe!)
val bar = true
}
kevin_abrioux
06/08/2022, 11:25 AMJonathan Ellis
06/08/2022, 7:54 PMjames
06/09/2022, 1:09 AMthanksforallthefish
06/09/2022, 5:44 AMfun cast(value: Any?) = (value as? Map<String, String?>)
?
maybe followup question, am I misusing as?
? context, in this scenario I know that value
might not be a map, so using as?
on purpose since it returns null
, but this “null-trick” makes the cast safe in my eyes, since `null`s need to be handled explicitlyJonathan Ellis
06/09/2022, 8:31 PMMark
06/10/2022, 5:10 AMSpannableStringBuilder.inSpans()
fun <A : Appendable> A.inSpans(vararg spans: Any, builderAction: A.() -> Unit): A =
if (this is SpannableStringBuilder) {
// PROBLEM: doesn't call SpannableStringBuilder.inSpans()
inSpans(spans = spans, builderAction = builderAction)
} else {
builderAction()
this
}
zain
06/10/2022, 12:21 PMgabin
06/10/2022, 3:34 PMLawrence
06/10/2022, 6:35 PM// The api I am working with is blocking and throws an error if not connected
suspend fun determineType(): Type? {
var type: Type? = null
withTimeoutOrNull(15.seconds) {
while (type == null) {
select<Unit> {
async {
runInterruptible(<http://Dispatchers.IO|Dispatchers.IO>) {
kotlin.runCatching { apiA.typeA }.getOrNull()
}
}.onAwait {
if (it != null) {
make = it
}
}
async {
runInterruptible(<http://Dispatchers.IO|Dispatchers.IO>) {
kotlin.runCatching { apiB.typeB }.getOrNull()
}
}.onAwait {
if (it != null) {
type = it
}
}
}
}
}
return type
}
wck
06/11/2022, 1:54 AMsmit01
06/11/2022, 8:58 AMNat Strangerweather
06/11/2022, 7:13 PMElizeu Silva dos Santos
06/12/2022, 6:34 PMelect
06/13/2022, 7:49 AMelect
06/13/2022, 7:49 AMephemient
06/13/2022, 7:52 AMval child = object : AbstractCollection() {
override val size get() = root.count { isChild }
override fun iterator() = root.filter { isChild }.iterator()
}
elect
06/13/2022, 7:59 AMMichael de Kaste
06/13/2022, 10:16 AMelect
06/13/2022, 10:18 AMMichael de Kaste
06/13/2022, 10:27 AMelect
06/13/2022, 12:04 PMmap<name, ArrayList>
on the root containing the corresponding children lists and then forwarding the methods I needephemient
06/13/2022, 12:08 PMnkiesel
06/13/2022, 7:01 PM