Gopal S Akshintala
03/12/2020, 12:14 PMAsync<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?raulraja
03/12/2020, 1:15 PMraulraja
03/12/2020, 1:15 PMGopal S Akshintala
03/12/2020, 1:16 PMraulraja
03/12/2020, 1:17 PMGopal S Akshintala
03/12/2020, 1:18 PMGopal S Akshintala
03/12/2020, 1:18 PMraulraja
03/12/2020, 1:18 PMTC.run { }
raulraja
03/12/2020, 1:18 PMGopal S Akshintala
03/12/2020, 1:19 PMGopal S Akshintala
03/12/2020, 2:53 PM