marcinmoskala
04/29/2021, 5:42 AMdave08
04/29/2021, 9:26 AMmarcinmoskala
04/29/2021, 10:35 AM// fun type
val a: ()->Unit = { print("A") }
// fun interface
fun interface A {
fun call()
}
val a: A = A { print("A") }
dave08
04/29/2021, 10:55 AMfun interface
when it needs to be passed in for a specific purpose (like a specific type of event. Even though when implementing them the lambda looks the same more or less, but there's some restrictions as to where they can be passed.
But recently I wanted to use it to implement a base UseCase interface, in the production code, I would implement it as a full class with deps on repos and such, whereas in my test code, I can provide a one-liner to Stub them. (The problem is that they don't work with suspend fun
yet, so I had to try something else for that...)Orhan Tozan
04/29/2021, 5:18 PMinterface MyUseCase {
suspend operator fun invoke(foo: Foo): Bar
}
...
val myUseCase: MyUseCase = ...
val bar = myUseCase(foo)
dave08
04/29/2021, 8:12 PM