Ted Naleid
11/20/2020, 9:20 PMtypealias
or function signatureTed Naleid
11/20/2020, 9:21 PMtypealias
for a function signature fairly heavily. Here is small made-up example:
data class Widget(val name: String)
typealias PersistWidget = (Widget) -> Boolean
class RealBackend {
// other functions, not something that can be just a SAM
fun persist(widget: Widget): Boolean = TODO()
}
class FakeBackend {
fun persistSuccess(widget: Widget): Boolean = true
fun persistFailure(widget: Widget): Boolean = false
}
class Facade(val persist: PersistWidget) {
fun createWidget(): Widget {
val widget = Widget("default")
return if (persist(widget)) {
widget
} else {
throw Exception("failed to persist")
}
}
}
fun main() {
val backend = FakeBackend()
val facade = Facade(backend::persistSuccess)
facade.createWidget()
}
Ted Naleid
11/20/2020, 9:22 PMPersistWidget
were an interface, it'd be easy to find all of the classes that implement that interfaceTed Naleid
11/20/2020, 9:23 PMtypealias
I'm not aware of an equivalent ability to find all things that have the same type signature as my typealias
Ted Naleid
11/20/2020, 9:23 PMPersistWidget
typealias?Ted Naleid
11/20/2020, 9:24 PMPersistWidget
and it'll show me that there is a single use of it in this line:
class Facade(val persist: PersistWidget) {
which is correct for explicit usages of thatTed Naleid
11/20/2020, 9:26 PMtypealias
as well, so that it'd show me these too:Ted Naleid
11/20/2020, 9:27 PMAlexey Belkov [JB]
12/18/2020, 9:52 AMTed Naleid
12/18/2020, 3:34 PMTed Naleid
12/19/2020, 8:30 PM