Regarding the new 1.4 version: When would one use ...
# announcements
o
Regarding the new 1.4 version: When would one use
fun interface CreateTodoUseCase { fun run() }
over
interface CreateTodoUseCase { operator fun invoke() }
? I see the latter being used alot for writing UseCases (myself included. Should I switch to functional interfaces instead?
m
Can you provide an example? In our codebase we haven't used either. I'd like to know a usecase for them in general
o
Are you familiar with the UseCase pattern?
Common in Clean Architecture
m
Doesn't ring a bell/we don't use it
j
Why, are you using lambdas with your usecases?
a
I don't see
fun interface
as a replacement for
operator fun invoke()
🤔 I'm wondering what would be an example of that I see
fun interface
being useful in case some function accepts the interface as argument and you want to make possible to use lambda syntax when calling it:
Copy code
fun foo(bar: Bar) {
    bar.baz()
}

fun interface Bar {
    fun baz()
}

fun main() {
    foo {
        println("Spam")
    }
}
m
I think the main reason for their introduction is improved interoperability with Java’s SAM.
j
I think they are different use cases as @arekolek said