dMusicb
05/04/2022, 7:19 PM{
"type": "Foo" | "Bar" | "Baz"
"payload": FooPayload | BarPayload | BazPayload
}
martmists
05/04/2022, 11:33 PMclass MonoNode : BaseNode() {
protected val input by input() // getValue should resolve here; it's a delegate to use the property name
protected val output by output() // getValue should not resolve as its value may change over time
override fun process() {
// We don't want to call getValue too often in real-time code that needs to be fast!
// output.getValue should only be called once per process() call
// input.getValue should only be called in constructor/init
// Is there a good way to do it without having to store to a variable?
val x = input[0] // calls input.getValue
val y = input[1] // calls input.getValue
output[0] = x + y // calls output.getValue
output[0] = x + y // calls output.getValue
}
}
ahmad
05/05/2022, 9:47 AMinput: [ "this is item number one",
"this is item number two",
"this is item number three",
"this is item number four",
"this is item number five",
"this is item number six"
]
output: [
["this is item number one", "this is item number two", "this is item number three", "this is item number four"],
["this is item number five", "this is item number six"]
]
I wrote this
private fun List<String>.batch(): List<List<String>> {
return fold(mutableListOf(mutableListOf<String>())) { accumulator, string ->
val currentBucket = accumulator.last()
val currentBucketCharsCount = currentBucket.sumOf { item -> item.length }
val willBucketExceedMaximumCharCount = currentBucketCharsCount + string.length > 100
val willBucketExceedMaximumSize = currentBucket.size + 1 > 10
if (willBucketExceedMaximumCharCount || willBucketExceedMaximumSize) {
accumulator.add(mutableListOf(string))
} else {
currentBucket.add(string)
}
accumulator
}
}
but I have a feeling that it can be done in a more cleaner/simple way. any ideas?Ink
05/05/2022, 4:21 PM[5-XR6Bwlq, 2-Hada32U1D, 7-aaGE7Ve84]
I want to get every single number before -
and create list of Int with that values.
How I can achive that?nkiesel
05/05/2022, 5:24 PMursus
05/06/2022, 10:27 AMOkan Yıldırım
05/06/2022, 8:36 PMInk
05/06/2022, 8:45 PMdata class Foo(val price: Int?)
val items = List<Foo>(Foo(133), Foo(324), Foo(3))
How I can get List<Int?>
with all prices?
Is it only solution?
https://medium.com/@hayi/kotlin-get-list-of-some-property-values-of-object-from-list-of-object-8da9419c2e77Hassaan
05/07/2022, 3:44 AMHassaan
05/07/2022, 3:57 AMAndrew
05/08/2022, 7:44 PMsmit01
05/09/2022, 2:06 PMVampire
05/09/2022, 6:10 PMfun Provider<out Task>.generateChecksums(destination: Directory? = null) {
get().generateChecksums(destination)
}
fun Task.generateChecksums(destination: Directory? = null) {
}
fun FileSystemLocation.generateChecksums(destination: Directory? = null) {
}
somehow so that the first one can work for both Task
or FileSystemLocation
?
Just adding another method does not work of course as both would have the same type-erased form unless I call it differently.Stefan Oltmann
05/10/2022, 10:32 AM/**
* Returns an unsigned 16-bit int calculated from the next two bytes of the sequence.
*
* @return the 16 bit int value, between 0x0000 and 0xFFFF
*/
public int getUInt16() {
return (getByte() << 8 & 0xFF00) |
(getByte() & 0xFF);
}
If I add .toInt()
I can use the shl
function, but the result is wrong.
Is there already a standard function for this calculation?David Smith
05/10/2022, 2:32 PMinternal
modifier?Vitali Plagov
05/10/2022, 7:12 PM"abc".split("")
splits into a list of Strings [, a, b, c, ]
(5 elements) with an empty string at the beginning and end. Why is it so? And how to split the string into individual letters to the List<String>?hooliooo
05/11/2022, 10:35 AMSlackbot
05/11/2022, 7:06 PMDavid Smith
05/13/2022, 10:22 AMconfigure<org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension> {
jvm {
val main by compilations.getting {
kotlinOptions {
freeCompilerArgs = listOf("-Xallow-result-return-type", "-Xinline-classes")
jvmTarget = JavaVersion.VERSION_11.toString()
javaParameters = true
}
}
}
sourceSets {
val main by getting {
dependencies {
...
configurations["kapt"].dependencies.add(platform("io.micronaut:micronaut-bom:${properties["micronautVersion"]}"))
configurations["kapt"].dependencies.add(project.dependencies.create("io.micronaut:micronaut-inject-java"))
}
}
}
}
however when I run the kaptKotlinJvm
task I’m getting:
java.lang.IllegalArgumentException: The argument does not represent an annotation type: io.micronaut.context.annotation.Replaces
Any idea what I’m missing? What does this error mean, that the dependencies aren’t working or something else?ursus
05/13/2022, 11:05 PMformat
then there is another damn copy when it proxies to java
TLDR; are vararg apis harmful?martmists
05/15/2022, 11:44 PMclass BaseType {
val someProp: Int = 10
}
fun handleProperty(prop: KProperty1<BaseType, Int>) {
// get BaseType instance here somehow
}
fun main() {
val x = BaseType()
handleProperty(x::someProp)
}
Minsoo Cheong
05/16/2022, 8:03 AMPhani Mahesh
05/17/2022, 7:43 AMfrogger
05/17/2022, 11:02 AMspreadsheets:read.all
We would use is e.g. as requireScope("spreadsheets:read.all")
I like plain text here over using constants like SPREADSHEETS_READ_ALL
because it stays in the domain language of the scope, rather than using the kotlin constant. But it would be great to have some sort of compile time check here so you cannot have a typo in the scope string. (They are all known ahead). Any ideas?Lawrence
05/17/2022, 7:06 PMModuleLayer.boot().findModule(moduleName)
. Now when I moved that code over to Kotlin, I noticed that particular module is not included in the ModuleLayer. I understand that Kotlin doesn't have an equivalent of module-info.java
(I think) so does that mean this way of loading packages not gonna work in Kotlin?nkiesel
05/18/2022, 4:32 AMsealed interface Status
sealed class Failure(val message: String) : Status
sealed class Upload(val name: String) : Status
sealed class UploadFailure(message: String, name: String) : Failure(message), Upload(name)
David Smith
05/18/2022, 10:13 AMToo many element types registered. Out of (short) range. Most of element types (14991) were registered for 'Language: kotlin'
I’m completely stuck on this, it works fine if I run the ktlint binary with the jar file directly, seems like its something to do with the gradle plugin?hfhbd
05/19/2022, 4:13 PMpublic object GlobalScope : CoroutineScope {
override val coroutineContext: CoroutineContext
get() = EmptyCoroutineContext
}
Why is coroutineContext not a field? override val coroutineContext = EmptyCoroutineContext
Endre Deak
05/19/2022, 11:00 PMPoet
where I have full control on the generated Kotlin source code including removing redundant qualifiers, etc. My google research did not lead me any further than just construct the source as a String and write it to a file.Tariyel Islami
05/20/2022, 9:27 AMTariyel Islami
05/20/2022, 9:27 AMtseisel
05/20/2022, 11:25 AMTariyel Islami
05/20/2022, 1:30 PMtseisel
05/20/2022, 2:46 PMAdvitiay Anand
05/22/2022, 1:47 PMTariyel Islami
05/23/2022, 12:09 PMAdvitiay Anand
05/23/2022, 12:37 PMTariyel Islami
05/23/2022, 4:47 PM