Ayfri
11/25/2022, 9:06 PMVishal Rao
11/26/2022, 9:23 AMlist[2:5] = mlist
This python code assigns mlist into list at indices 2 to 5. I am not able to do the same in kotlin using inbuilt methods. Can anyone help me.Tech
11/26/2022, 4:10 PMval test: String by rootProject
but that just produces null.
Thank you in advance.Antonio Acuña Prieto
11/27/2022, 1:07 PMAleksandr
11/27/2022, 1:41 PMRohan Maity
11/27/2022, 4:44 PMDaniel Souza Bertoldi
11/27/2022, 4:56 PMRodrigo Silva
11/27/2022, 8:58 PMhfhbd
11/28/2022, 11:37 AM1.7.22
?Ulises Serrano
11/28/2022, 3:29 PMxun su
11/29/2022, 12:36 AMname:"foo"
? though I didn't initialize the field in the constructor, but they got a default value.Tracey Yoshima
11/29/2022, 12:39 AMFirSessionFactory.INSTANCE
using createLibrarySession
and am getting an error (will be linked in thread).
Could someone point me to an example of how to instantiate the Kotlin compiler?Android Mahi
11/29/2022, 1:20 AMKroppeb
11/29/2022, 4:49 PMJakub Gwóźdź
11/30/2022, 2:01 PMfun <R> String.parseRecords(regex: Regex, op: (MatchResult) -> R): Sequence<R> =
lineSequence().filterNot(String::isBlank)
.map { regex.matchEntire(it) ?: error("WTF `$it`") }
.map(op)
That works just fine.
How would it look like if I want to make parameters optional (with some default mapping)? I can use regex: Regex = "(.*)"
but the op: (MatchResult) -> R = { it.destructured.component1().toInt()}
is a big no-no, because of Type mismatch: inferred type is Int but R was expected.
Is it even possible to add default parameter values for generic functions?iGrid
11/30/2022, 2:16 PMCraig
11/30/2022, 4:31 PM@Test
fun start() {
val sourceFlow = (0..20).asFlow()
val stateFlow = MutableStateFlow(mutableMapOf<String, Int>())
runBlocking {
stateFlow.asStateFlow().combine(sourceFlow) { state, number ->
println("got number $number")
state[(number % 2).toString()] = number
state
}
.take(20)
.collect { result -> println("got result $result") }
}
}
xun su
11/30/2022, 5:47 PMinfo
as nullable
, why still got error?Daniel Felipe Henao Toro
11/30/2022, 7:22 PMprivate fun getClickTagName(textOptions: List<String>, tag: StringBuilder): String {
var textToSearch = ""
run clickTags@{
textOptions.forEach { clickTag ->
if (tag.contains(clickTag, true)) {
textToSearch = clickTag
return@clickTags
}
}
}
return textToSearch
}
Is it kind of notation? does someone know it?Gavin Ray
11/30/2022, 8:08 PM?.let { } ?: emptyList()
that lets you place the default value at the beginning of the .let
statement?
One of my few complaints with Kotlin is that it becomes hard to read in cases like this:
val foo = maybe?.null?.let {
// really long series of statements
} ?: someDefault()
I'd love something like:
val foo = maybe?.null?.letWith(someDefault) {}
Gavin Ray
11/30/2022, 8:08 PMGavin Ray
11/30/2022, 8:09 PM.ifEmpty { }
but for nullable valuesEdward Muller
11/30/2022, 10:54 PMy
12/01/2022, 9:42 AMUnable to evaluate the expression Cannot find source class for java.util.Map
(or java.util.List
, etc.) for everything that is a `Map`/`List`/etc.
only reindexing the project solves it, which is time consuming
what is the cause of this issue? can I prevent it?KotlinLeaner
12/01/2022, 1:22 PMDK
12/01/2022, 3:15 PMDK
12/01/2022, 3:15 PMKlitos Kyriacou
12/01/2022, 4:06 PMString.contains
(or a in b
), but if I can do a byte-array search instead it would be preferable as it would save the overhead of converting to String. I don't want to write a Boyer-Moore (or similar fast algorithm) implementation for this myself, as (1) I might get it wrong and (2) there may already be one and I don't want to reinvent the wheel. I'm hoping there's something already there in the stdlib.Slackbot
12/02/2022, 7:50 AMJakub Gwóźdź
12/02/2022, 7:51 AMJakub Gwóźdź
12/02/2022, 7:51 AMJohann Pardanaud
12/02/2022, 8:01 AM123L
https://kotlinlang.org/docs/numbers.html#literal-constants-for-numbersephemient
12/02/2022, 8:06 AMInt
or a Long
sumOf
for as long as it has existed, https://youtrack.jetbrains.com/issue/KT-46360Jakub Gwóźdź
12/02/2022, 8:09 AMephemient
12/02/2022, 8:11 AM0.toInt()
instead of as Int
to force the type, but the KTIJ plugin will (falsely) show that as unnecessary too 😞Jakub Gwóźdź
12/02/2022, 8:13 AMephemient
12/02/2022, 8:14 AMJakub Gwóźdź
12/02/2022, 8:19 AM❯ ./gradlew clean build
> Task :compileKotlin
w: /Users/jakub.gwozdz/personal/advent-of-code-2022/src/main/kotlin/day2/Day2.kt: (33, 11): No cast needed
w: /Users/jakub.gwozdz/personal/advent-of-code-2022/src/main/kotlin/day2/Day2.kt: (49, 11): No cast needed
🙂ephemient
12/02/2022, 8:20 AM@Suppress("USELESS_CAST")
will stop that from showing upJakub Gwóźdź
12/02/2022, 8:26 AMKlitos Kyriacou
12/02/2022, 2:55 PMlineSequence().count { it == "one" }
?Jakub Gwóźdź
12/02/2022, 2:56 PMfoo()
example 🙂