Jason Inbody
02/18/2021, 6:29 PMDaronee
02/19/2021, 12:48 AMrun()
function of a thread
Its like the app is receiving the data from the inputstream consistently. It always varies
Seems to be a problem when the number of bytes > ~6 for some reason?Colton Idle
02/19/2021, 5:35 PM,
between strings in a string builder.
I know joinToString
exists and it works great for arrays, but I basically want the same functionality for a string builder.
Here's what I'm currently doing (no commas yet):
topic.data.forEach {
myBuilder.append("${it.city} ${it.status}")
}
}
Maybe I'm missing something basic. Thankspoohbar
02/20/2021, 8:03 PMT -> T
and T? -> T?
poohbar
02/20/2021, 8:22 PMto
from Kotlin? it keeps trying to use the Pair
extension 🤔Melvin Biamont
02/21/2021, 6:06 PMtypealias AFunction<R, A> = suspend (args: A) -> Result<R>
val functionMap = mutableMapOf<String, AFunction<Any?, Any?>>()
fun <R, A> addFunctionToMap(name: String, function: AFunction<R, A>) {
functionMap[name] = function
}
For some reasons, it doesn’t compile (on the line functionMap[name] = function
) as it is saying it was expecting a type AFunction<Any?, Any?>
and not AFunction<R, A>
.
I tried modifying a bit the addFunctionToMap
function like this:
fun <R: Any?, A: Any?> addFunctionToMap(name: String, function: AFunction<R, A>) {
functionMap[name] = function
}
But, it doesn’t change the compiler error.
Do you have an idea how I could solve that?
🙏Mark
02/22/2021, 3:43 AMgabrielfv
02/23/2021, 5:33 PMPedro Alberto
02/25/2021, 7:21 PMSudhir Singh Khanger
02/27/2021, 3:30 AM// generated by JsonToKotlinClass
data class JsonToKotlinClass(
val `data`: List<Data?>?
) {
data class Data(
val id: Int?
)
}
// generated by RoboPOJOGenerator
data class RoboPOJOGenerator(
val data: List<DataItem?>? = null
)
data class DataItem(
val id: Int? = null
)
fun main() {
val jsonToKotlinClassData: JsonToKotlinClass.Data = JsonToKotlinClass.Data(1)
val roboPOJOGeneratorData: DataItem = DataItem(1)
}
The former is generated by JsonToKotlinClass plugin and latter is generated by RoboPOJOGenerator. Which one would you prefer? Besides differences in syntax and how they are used are there other pros and cons of these two approaches.dephinera
03/01/2021, 9:21 AMfun foo(block: String.(String) -> Unit) {
}
fun foo(block: () -> Unit) {
}
fun main() {
foo { it: String ->
// calls foo(block: String.(String) -> Unit)
}
foo { // ERROR
// how to call foo(block: () -> Unit)
}
}
Basically is there a way to specify in the second case that I want to call foo(block: () -> Unit)
. When I specified the type of the lambda argument, it seemed that the compiler was able to figure it out, however it: Unit
doesn't work for the second case.Cicero
03/01/2021, 2:17 PMtherealbluepandabear
03/01/2021, 11:34 PMtherealbluepandabear
03/02/2021, 5:26 AMColton Idle
03/03/2021, 4:01 AMBut kdoc documentation currently links out to <https://daringfireball.net/projects/markdown/syntax#precode> which seems to say that you should just indent?
Which one is correct?
I just want to have something like this
```/**
* Sample usage
* ```kotlin
* blah.boop()
*
*/```
Is that correct? I thought I would maybe get some syntax highlight in the IDE, but nothing. Is having the kotlin keyword following the backticks not needed?therealbluepandabear
03/03/2021, 5:05 AMfun main() {
println(alternatingCase("hello kotlin"))
}
fun alternatingCase(param: String) : String {
val array: CharArray = param.toCharArray()
var newString = ""
for ((index, char) in array.withIndex()) {
newString += if (index % 2 != 0) char.toUpperCase() else char.toLowerCase()
}
return newString
}
Brian Carr
03/03/2021, 8:03 PM@Throws(IOException::class)
to my method, it gets highlighted as an inappropriate blocking call in IDEA, and I can just add docs to the method and hope people read them when they get the unrelated warning. However, I’m hoping for something a little more direct.
Anyone have any ideas or pointers?therealbluepandabear
03/04/2021, 1:03 AMcrummy
03/04/2021, 7:58 AMval l = listOf<Any>("foo")
l.first { it is String}.length // unresolved reference: length
And is there a way to get this to work with a smartcast?Sudhir Singh Khanger
03/08/2021, 4:12 AMpackage leetcode
import kotlin.collections.set
fun main() {
val nums1 = intArrayOf(1, 2, 2, 1)
val nums2 = intArrayOf(2, 2)
println(intersect(nums1, nums2).joinToString())
}
fun intersect(nums1: IntArray, nums2: IntArray): MutableList<Int> {
val outputMap = hashMapOf<Int, Int>()
val outputList = mutableListOf<Int>()
for (i in nums1.indices) {
if (nums1[i] in outputMap) {
outputMap[nums1[i]]++
} else {
outputMap[nums1[i]] = 1
}
}
for (i in nums2.indices) {
if (nums2[i] in outputMap && outputMap[nums2[i]] > 1) {
outputList.add(nums2[i])
outputMap[nums1[i]]--
}
}
return outputList
}
outputMap[nums1[i]]++
is complaining that No set method providing array access
. I am not sure why.Eivind
03/08/2021, 8:47 AMtherealbluepandabear
03/09/2021, 1:49 AMJungIn Choi
03/09/2021, 11:00 AMfor ((index, element) in swarm.withIndex()){
println("Fish at $index is $element")
}
Fish at 0 is 12Fish at 1 is 5
therealbluepandabear
03/10/2021, 2:06 AMConor Fennell
03/11/2021, 5:30 PMdata class Calculation(
val money: Double,
val multiplier: Double,
)
fun Calculation.total(): Double = money * multiplier
OR
data class Calculation(
val money: Double,
val multiplier: Double,
) {
fun total(): Double = money * multiplier
}
Tom Niesytto
03/12/2021, 7:58 AMDaniele B
03/12/2021, 6:12 PMdata class AppState (
val masterState : MasterState = MasterState(),
)
data class MasterState (
val isLoading : Boolean = false,
)
is there a more concise way than this?
val myState = AppState()
val newState = myState.copy(masterState = myState.masterState.copy(isLoading = true))
Daniele B
03/12/2021, 8:25 PMfun MyModel.anExtensionFunction() {
objectLambda {
it.getText()
}
}
where it is the obj property of the MyModel class
How should I write the objectLambda function in order to do so?
class MyModel {
var obj = MyObject()
fun objectLambda() {
// HOW SHOULD I WRITE THIS FUNCTION?
}
}
class MyObject {
fun getText() = "myText"
}
ursus
03/14/2021, 8:02 PMhuehnerlady
03/16/2021, 10:26 AMtypealias my.test.Foo = String
I would now like to get the quaifiedName, so my.test.Foo
. but using Foo::class.qualifiedName
I get kotlin.String
.
I found this in a proposal, but the issue to it is closed and unfortunately Foo::typealias.qualifiedName
does not work.
Is there another way?
I am currently on version 1.4.21
huehnerlady
03/16/2021, 10:26 AMtypealias my.test.Foo = String
I would now like to get the quaifiedName, so my.test.Foo
. but using Foo::class.qualifiedName
I get kotlin.String
.
I found this in a proposal, but the issue to it is closed and unfortunately Foo::typealias.qualifiedName
does not work.
Is there another way?
I am currently on version 1.4.21
Ruckus
03/16/2021, 2:07 PM