kioba
11/27/2019, 11:30 AMError<E> | Loading | Success<T>
. I tried to implement applicative
for the type. What I would like to achieve is the that the error
would have a higher precedence than Loading
, but the ap()
implementation with
flatmap{ .map{ ff() } }
I can not obtain the state of the second state unless the first is success.
an example that I would like to achive:
Result.applicative().tupled(Loading, Error)
// current result: Loading
Instead of the loading I am looking for the Error
to be returned. is there a good way to execute it? 🤔 is that a good idea t all? 😄raulraja
11/27/2019, 2:09 PMkioba
11/27/2019, 3:25 PMkioba
11/27/2019, 3:28 PMfun <B> ap(ff: ResultOf<(T) -> B>): Result<B> {
val next = ff.fix().flatMap {this.map(it)}
return when (val current = this.fix()) {
is Loading -> when(next) {
Loading -> current
is Error -> next
is Success -> current
}
is Error -> current
is Success -> next
}
}
Jannis
11/27/2019, 3:28 PMkioba
11/27/2019, 3:45 PMJannis
11/27/2019, 3:49 PMJannis
11/27/2019, 3:51 PMJannis
11/27/2019, 3:52 PM