Hi, I have a requirement to make use of two typeclasses
Async<F>, ApplicativeError<S, Nel<E>>
. I achieved it as below:
interface RepoTC<F> : Async<F> {
fun User.isUserCityValid(): Kind<F, Boolean>
fun <S> ApplicativeError<S, Nel<ValidationError>>.userCityShouldBeValid(user: User) = fx.async {
val cityValid = user.isUserCityValid().bind()
if (cityValid) this@userCityShouldBeValid.just(cityValid)
else raiseError(UserCityInvalid(user.city).nel())
}
}
But it just doesn’t feel right, as:
- It can’t be extended if I need other typeclasses.
- I see
ApplicativeError
in
Async
hierarchy. So do I need both the TCs?
I tried this, but am getting compiler errors due to clashes.
interface RepoTC2<F, S> : Async<F>, ApplicativeError<S, Nel<ValidationError>> {
fun User.isUserCityValid(): Kind<F, Boolean>
fun userCityShouldBeValid(user: User) = fx.async {
val cityValid = user.isUserCityValid().bind()
if (cityValid) just(cityValid)
else raiseError(UserCityInvalid(user.city).nel())
}
}
Can I achieve it just by using Async itself?