Gopal S Akshintala
03/05/2021, 10:25 AMtypealias _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
Vampire
03/05/2021, 11:14 AMkotlin.jvm.functions.Function1<_ValidatableT_, Deferred<_FailureT>_>
or something like that.araqnid
03/05/2021, 3:44 PMinterface 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