Perhaps I don’t understand how it should be used, ...
# arrow
m
Perhaps I don’t understand how it should be used, or should be using a different approach, but I’ll ask anyway. Introducing aspects of Functional (mostly around controlling return values rather than using Exceptions for errors/validations) to my team, and learning it myself. Keeping it fairly simple right now and mostly using
Either
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
Copy code
.flatMap {
  if(it.something) {
       it.right()
  } else {
     Error("Some message with context: ${it.property}").left()
  }
}
But of course that’s very ugly