Interesting ``` class Foo: (key: String) -> Str...
# announcements
k
Interesting
Copy code
class Foo: (key: String) -> String
gives an error "Unsupported: named parameter in function type in supertype position", but
Copy code
typealias KeyFunction = (key: String) -> String
class Foo: KeyFunction
actually works. The benefit is that when you let IDEA generate the missing members, the parameter name is set to
key
instead
p1
🤔 1
e
I don't get, you can make a class extending a lambda? Purpouse?
k
you can make a class extend a function type. usecases are debateable, but it's definitely possible
e
can you name one?
k
When you have a function that should accept a provider of some value. in some cases, the implementation is so simple that you'd want to implement it using a lambda so you use
typealias Provider = (Foo) -> Bar
. But in other cases, the implementation is more complex and has dependencies, so you implement it using a standalone type
class MyProvider: Provider
👍 1