Mike
12/05/2018, 10:41 PMEither
Starting to use filterOrElse
for doing a validation, and returning an Error as the default side.
Ideally, I’d like the Error to have context about the item being filtered, but the default function doesn’t get the right passed to it.
I suspect this is because I’m abusing filterOrElse
, but if not, would it be acceptable to create a feature request to have default passed the right
?
If not, then without getting too complicated (I’ve been looking at the ApplicativeError but neither I nor the team are ready for that), is there another approach?
For now, I’m doing something like
.flatMap {
if(it.something) {
it.right()
} else {
Error("Some message with context: ${it.property}").left()
}
}
But of course that’s very ugly