Let an object constructed using the builder template be assumed.
This builder template will contain a build method focused on checking fields and then converting to the target type.
This check can be implemented using:
Either[FailureObject, TargetObject] typeTry[TargetObject] (new feature from Scala 2.10)Validation[FailureObject, TargetObject] or ValidationNEL[FailureObject, TargetObject] from the scalaz library
I read that one of the main benefits of the Validation over Either is that Validation can accumulate out of the box crashes.
But what about the "new" Try way? I noticed that Try also has "monadic" methods like map , flatMap , etc ... which was really absent in any type without the help of Projection .
Thus, I would suggest that each field validation method returns Try[FieldType] or rather, in the event of any failure, Try[SpecificFieldExceptionType] ; it is nested, containing the String message field and the rootCause field, which can be accumulated throughout the build method.
Using Scala 2.10, can or should Try replace the scalaz authentication library for simple verification, for example, does the linker template include?
** EDIT ****
Reading the source code for Try , it sounds like Try cannot accumulate a few exceptions and, therefore, canβt navigate quickly. Even Try.flatMap returns a potential previous failure and therefore has no notion of accumulation:
def flatMap[U](f: T => Try[U]): Try[U] = this.asInstanceOf[Try[U]]
On the contrary, ValidationNEL , which handles the accumulation function.
Any confirmation?