.toEither()
# arrow
p
.toEither()
s
Ok that's great. I am doing this:
Copy code
Validated.applicative(NonEmptyList.semigroup<Any?>()).map(x, y) { (x, y) ->
              x.read(y)
            }.fix().toEither()
But I end up with a really weird sig
I've got an Either, with errors on the left (good), on the right I have another validatednel
Basically I want the result of
x.read(y)
to completely replace the outside value (if it's executed)
This seems to do it, but it seems quite redundant to be returning itself in the fold:
Copy code
Validated.applicative(NonEmptyList.semigroup<ConfigFailure>()).map(x, y) { (x, y) ->
              x.read(y)
            }.fix().fold(
                { it.invalid() },
                { it }
            )
p
weird
I’d need to touch the code, dunno top of my head
s
ok
p
ooooh I see
x.read(y)
is another Validated
s
yep
so what I want is kind of
Validated.applicative(NonEmptyList.semigroup<ConfigFailure>()).ifNotErrorThenUseLambdaResult(x, y)  { }
p
yeah what you’re doing is the right thing to do
flatten it
then change to either
s
the fold kind of seems redundant
since it's just wrapping
This is what I was incorrectly imagining as flatMap the other day
p
the fold isn’t redundant, you’re flattening something that’s not sequential
s
right
redundant in the sense that one of the lambdas is just returning itself
Something like this would be good
Copy code
Validated.applicative(NonEmptyList.semigroup<ConfigFailure>()).apply(x, y) { (x, y) ->
              x.read(y)
            }.fix()
.apply (or whatever) could just keep the Invalid, or if it's a Valid, execute the lambda and take that result (which itself would be a Valid or Invalid)
p
that¡s two steps