flatMapRightWithEither

fun <L, R, T> <Error class: unknown class><Either<L, R>>.flatMapRightWithEither(block: suspend (R) -> <Error class: unknown class><Either<L, T>>): <Error class: unknown class><Either<L, T>>

flatMapLatest the Flow> into Flow>.

Parameters

block

function to run on Either.Right value and that returns Flow>

Usecase for it: we have 2 functions both of it returns Flow but one of it is depends on the Right value from the other and we need to combine Right values from both of it, or emit 1 error (Either.Left) if it occurs on any step. Use that fun to have better code style.

Example:

fun getUserId(): Either fun getFriendsFroUser(userId: ID): Either>

data class MeWithFriends(val myId: ID, val friends: List)

val observeMeWithFriends: Flow> = getUserId().flatMapRightWithEither { id -> getFriendsFroUser(id).mapRight { MeWithFriends(id, it) }}