Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
2 votes
0 answers
45 views

"Leaked in-place lambda" warning after an upgrade to Kotlin 2.0

Consider the following Kotlin code which overloads Reader.useLines(). The 1st extension merely invokes Reader.useLines() and has an exactly the same contract, the 2nd one filters the line sequence ...
Bass's user avatar
  • 5,242
-2 votes
1 answer
45 views

In Kotlin, is it possible to change the reference in a closure?

The idea is that you pass a lambda to a class and you want to change the implementation after it is passed to the class, but the class does not expose any way to update the lambda's implementation. As ...
John Glen's user avatar
  • 882
2 votes
1 answer
58 views

Compose Conditional Modifier Not Working Properly

I tried making an extension function on Modifier to apply changes to it only if a condition was true, since quite frequently I need to make small changes to a Modifier object in case certain things ...
Felipe Ribeiro R. Magalhaes's user avatar
0 votes
2 answers
97 views

Kotlin generic lambda Type mismatch. Required: nothing

I have a problem using Kotlin generic and lambda. Basically I want my interface to have a lambda function on a generic type. My goal is to make multiple implementation of my class A and then use the ...
Basile Lamarque's user avatar
1 vote
1 answer
52 views

How does the reference to "this" get resolved in nested scopes in Kotlin

In the above code snippet, how does Kotlin compiler know that collect in line #10 is to be invoked on the instance of the flow on which merge is invoked? Isn't this in line #10 referring to ...
niting112's user avatar
  • 2,580
0 votes
1 answer
56 views

Prevent modification of original list after placing it in a closure in Kotlin

I don't know closures in Kotlin so I want to understand this aspect. I have a class Foo that holds a list bar, technically immutable. But if I need to change it I create a new list and replace the ...
Giancarlo's user avatar
0 votes
1 answer
57 views

Why non local return from inline function returns from lambda but proceed inline function execution?

Can't understand kotlin logic. For sush code inline fun inlined( block: () -> Unit) { block() println("hi!") } fun foo() { inlined { println("5") ...
Oleksii Kolotylenko's user avatar
1 vote
1 answer
39 views

Kotlin labmda invoke alternatve

Assume we have the following code: fun interface A { fun a() } interface B { fun b(a: A) } fun x(callback: A.() -> Unit) = object : B { override fun b(a: A) { a.callback() ...
Shamil's user avatar
  • 61
0 votes
0 answers
41 views

viewmodelscope.launch not getting called inside lambda kotlin android

I want to insert the VideoUrls object into the database through callback while enqueuing a network request through the volley library in Android just after I obtain the title from the response. Here ...
Rahul Arora's user avatar
-1 votes
1 answer
63 views

How to pass 2 arguments lambda as function argument ? Destructuring declarations initializer of type String must have a 'component1()' function

I have a function: fun foo(arg1: Int, arg2: String, lambda: (String, Int) -> Int): Int { return arg1 + arg2.length + lambda("123", 1) } Nw I want to call it and do following: fun bar(...
gstackoverflow's user avatar
0 votes
1 answer
86 views

How to Implement main/fallback function pattern in Kotlin?

I want to create function which will try to call main function. If it is ok return the resutl of this function outside. But if it is failed - call another function(fallback function) and return its ...
gstackoverflow's user avatar
1 vote
1 answer
91 views

Lambda value assignment with and without braces into @Composable function

I'm following an Android Developers Codelab. I have this code fragment into a composable: OutlinedTextField( value = userGuess, singleLine = true, ...
mcventur's user avatar
0 votes
0 answers
41 views

Can we use kotlin contracts to specify at least one of the lambda block will be executed in kotlin?

I have a function as follows. fun handleResult( onSuccess:() -> Unit, onFailure:() -> Unit ){ } Is there a way to specify kotlin compiler that one of the blocks between 2 is sure to be ...
Diken Mhrz's user avatar
1 vote
1 answer
171 views

map function returns a list of Unit instead of Char

why this function returns a list of Unit type instead of returning [c,c,c,c] list fun convert(name:String) { val list = name.map { if (it == 'a') { return@map } else { it+1 } } ...
kamal MKA's user avatar
0 votes
0 answers
32 views

Need help understanding whether internal state of viewModel is automatically updated along with ProtoDataStore

Working on an android app (personal project) with Kotlin and Jetpack. Using Proto datastore to store application settings/configurations. Using Hilt for D.I. My code was just working fine with ...
TheSelfTaughtNoob's user avatar

15 30 50 per page
1
2 3 4 5
34