For lack of a better channel, I was trying to come...
# language-evolution
d
For lack of a better channel, I was trying to come up with a clever way to define a custom interface which extends both a function from T -> T and a predicate over T, I tried this, but it doesn't compile:
Copy code
interface Processor<T> : (T) -> T, (T) -> Boolean
The error message is
Type parameter R of 'Function' has inconsistent values: T, Boolean
Does anybody know if this is even possible or does anyone have an alternative other than reverting to Java's
Predicate<T>
for the second part?
a
what is your use case here? if a function extends from
(T) -> T
and
(T) -> Boolean
, it means that
T
must be equal to
Boolean
if your use case is to have two functions, one of type
(T) -> T
, and another
(T) -> Boolean
, I think a regular class would work better
d
Yeah it's the latter, maybe it's because both lambdas internally only have a single method called
invoke
and you can't have 2 invokes with different output I guess
d
Close, but it's not exactly that. It's actually the fact that you can't inherit from the same generic interface twice with different types:
Copy code
interface  Foo<T>

class Bar : Foo<String>, Foo<Int>
This fails, no method signature at all to worry about. My guess is that this is a consequence of type erasure.
👍 1
y
How do you intend to call this
Processor
? What should
myProcessor(tValue)
return? I think what you want is more like
Copy code
interface Processor<T> {
  fun transform(t: T): T
  fun predicate(t: T): Boolean
}
And then use it as
myProcessor::transform
and
myProcessor::predicate
when need be