How can I use Kotlin Function type as a Data type ...
# announcements
g
How can I use Kotlin Function type as a Data type within Java? For example: I have a typealias 
typealias _Validator_<_ValidatableT_, _FailureT_> = _suspend_ (_ValidatableT_) -> _Either_<_FailureT_, Any?>
Within Kotlin, I use it like this as a data type to assign to a lamda 
val validateParent3X: _Validator_<_Egg_, _ValidationFailure_> = {...}
But I cannot use typealias from Java. What is the idiomatic way to use this Function type as data type on Java? I see two unknows I have for java interoperability. 1. How can I idimotically refer a Function type 2. Function type being 
suspend
v
This is untested and just out of my head while not being that Kotlin-skilled yet, but I think what you want is
kotlin.jvm.functions.Function1<_ValidatableT_, Deferred<_FailureT>_>
or something like that.
a
typealiases aren’t visible from Java, but you could do it Java style by creating an interface:
interface Validator<V, F> { suspend fun validate(input: V): Either<F, Any?> }
This won’t address calling a suspend function from Java, though, which is a bigger can of worms. TBH I’d suggest writing an adapter layer (in Kotlin) that is to be used by Java and exposes simpler interfaces, and adapts a SAM interface where the function returns
CompletableFuture<…>
or similar