The Try type represents a computation that may either result in an exception, or return a successfully computed value. It’s similar to, but semantically different from the scala.util.Either type.
@ import scalaz._
The result of a
Try is either a
Success or a
Failure. This can very easily be translated to a Scalaz disjunction. A
Success produces a right disjunction whereas a
Failure produces a left disjunction.
@ val validation = t1 toValidation
Similarly, if this
Try were a part of validating your data like checking values in a JSON object, you can convert this to a Scalaz
@ val nel = t1 toValidationNel
ValidationNel is useful for accumulating errors. We’ll cover all of this in coming posts.
This brings us to the end of the post on
TryOps. In coming posts we’ll look at
Validation type which lets us represent, as you might have guessed, the result of validating an input. Similarly, if we want to accumulate all the results of validating inputs, we use
ValidationNel. Both of these are subjects of coming posts.