kotlinforandroid
06/30/2022, 11:54 AMannotation class Ref(val icon: ImageVector)
Is this somehow possible to accomplish? I guess I can use KClass<out ImageVector>
but I do not really understand how that would interact since all material icons from compose are defined as `val Icons.Filled.Add`for example.smit01
06/30/2022, 11:57 AMhfhbd
07/01/2022, 7:15 AMKlitos Kyriacou
07/01/2022, 4:45 PMMap<Int, String>
. Each map has only a small handful of entries. I need to keep many thousands of these maps in memory. 99% of the time the Int
key is small, between 1 an 10. If it was guaranteed to always be that small, the most efficient implementation of such a map would use an Array<String?>
. However, 1% of the time there would be a key that would be a very large integer, so a simple array is unusable. Yet if I use a HashMap
or TreeMap
I would be wasting memory for 99% of the time by using a sub-optimal implementation. Is there any specialized Map that uses a strategy of changing internal implementation depending on the value of the key?julian
07/01/2022, 10:13 PMHassaan
07/02/2022, 12:33 PModay
07/02/2022, 4:13 PMLoney Chou
07/04/2022, 5:28 AMPablo
07/04/2022, 7:23 AMfun getList() : List<Foo>
val myList = getList()
Now I want depending on my flag sort or not that list, I've tried it but did not work
val myList = getList().apply { if(bar) mySorter.sort(this) }
Is there any kotlinian way to sort the list instead of creating a new val?reactormonk
07/04/2022, 9:26 AMenum class
with an "other value"? Aka
enum class Status(val value: Int) {
Present(2),
Absent(1),
Error(value)
}
?reactormonk
07/04/2022, 1:47 PMx and 0xFF.toByte()
a noop? Aka x and 0xFF.toByte() == x
is always true?Andrew Cerne
07/04/2022, 3:14 PMreactormonk
07/04/2022, 4:50 PMByte
to send them to the wire and back, and preferably a reasonable API along the way.Chris Fillmore
07/04/2022, 8:23 PMT & Any
to T
?reactormonk
07/04/2022, 8:54 PMfun <A: Enum<A>, Positional> EnumSet<A>.toByte(): Byte {
Apparently it's not ,
nor :
Alan B
07/05/2022, 1:56 PMmap
while supplying the map-like operation with a list of functions (or vararg) to apply to each element, rather than a single transformation? basically collection.mapAll(transformers: List<(T) -> R>)
sequence.mapAll(transformers: List<(T) -> T>)
I want to supply a list of transformers so I don’t have to do something like:
sequence.map(::first)
.map(::second)
.map(::third)
would be:
sequence.map(tranformers)
Marcus Brito
07/05/2022, 2:29 PMLong
exposed as a boxed java.lang.Long
, as opposed to a long
primitive? Other than making it nullable, that is.reactormonk
07/05/2022, 2:43 PMPascal Gerrist
07/05/2022, 3:19 PMnkiesel
07/05/2022, 7:25 PMMonroe Walker
07/05/2022, 10:16 PMErik
07/06/2022, 3:06 PMfun f(x: Int, y: Int) = TODO()
then it is possible to autocomplete them with arguments like so:
Type: f
, then it should suggest to autocomplete f
and then you press some key so that the IDE (Android Studio or IntelliJ) now completes it to f(x = , y = )
, with the cursor just before the comma so you can continue typing, e.g. 1
and then you press tab to move the cursor to the next argument (y =
) so you can continue typing.
I'm sitting right next to a colleague who can do this in one project. But not in another, so we think it's a project setting that's somehow enabled in one project, but not in the other. This would be super helpful to enable this in all our projects, but how do we do that? What's this feature called? Is there a keystroke to use? Is this something that can be enabled?Sangeet
07/06/2022, 3:30 PMfun <T : CharSequence> doSomething(): T {
return String() as T
}
class Something(intValue: Int)
Something(doSomething()) // Doesn't show any compile error
It seems that it is automatically casting CharSequence to Number and throwing error in runtime.Monroe Walker
07/06/2022, 6:01 PMallan.conda
07/07/2022, 4:27 AMflow(1, 1, 2, 2, 3).map { expensiveMapping(it) }.collect()
Colton Idle
07/07/2022, 4:07 PMWill_505
07/07/2022, 7:26 PMfun sayHello(itemToGreet:String) = println("Hello $itemToGreet")
fun main() {
sayHello(itemToGreet: "Kotlin")
sayHello(itemToGreet: "World")
}
The error:Alex Stelmachonak
07/08/2022, 1:18 AMAn exception occurred applying plugin request [id: 'org.jetbrains.kotlin.jvm', version: '1.7.10']
> Failed to apply plugin 'org.jetbrains.kotlin.jvm'.
> The task 'compileKotlin' (org.jetbrains.kotlin.gradle.tasks.KotlinCompile) is not a subclass of the given type (org.gradle.api.tasks.compile.AbstractCompile).
* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Exception is:
org.gradle.api.plugins.InvalidPluginException: An exception occurred applying plugin request [id: 'org.jetbrains.kotlin.jvm', version: '1.7.10']
at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.exceptionOccurred(DefaultPluginRequestApplicator.java:223)
Looks like something simple, but as often with gradle, simple things are not simple to find 😞
Any ideas anyone?reactormonk
07/08/2022, 9:56 AMCardStatus.Companion.Present
instead of CardStatus.Present
here?
sealed class CardStatus(val value: Int) {
companion object {
fun fromInt(int: Int): CardStatus {
return when(int) {
255 -> PowerSavingMode
3 -> Powered
2 -> Present
1 -> Absent
else -> Error(int)
}
}
object PowerSavingMode: CardStatus(255)
object Powered: CardStatus(3)
object Present: CardStatus(2)
object Absent: CardStatus(1)
data class Error(val errorValue: Int): CardStatus(errorValue)
}
}
Slackbot
07/08/2022, 10:35 AMSlackbot
07/08/2022, 10:35 AM