Luke
01/21/2022, 8:33 PMEither
only if it is a Left
? I have a state that I want to modify its Either
variable, something like:
data class State(val either: Either<Error, Something>)
And I want something like this:
State.either./*focusIfLeft()*/.modify(state) { left: Left<Error> -> Something().right() }
Is there a way to do that already or a need to define my own extension?Luke
01/21/2022, 9:23 PMfun <T, R, L> Lens<T, Either<L, R>>.onLeft(): POptional<T, T, L, Either<L, R>> = plus(
POptional(
getOrModify = { (it as? Either.Left<L>)?.value?.right() ?: it.left() },
set = { _, newValue -> newValue }
)
)
Ties
01/22/2022, 4:36 PM