Question: Recall that unlike Options where multiple errors are simply subsumed by a None, when we deal with multiple errors in Eithers, all but one are
Recall that unlike Options where multiple errors are simply subsumed by a None, when we deal with multiple errors in Eithers, all but one are lost. Implement a datatype to return back multiple errors. Pay close attention to situations which do and do not require recording of multiple errors. You may use the following definition for the purpose of defining your data type.
trait Partial[+A,+B]
case class Errors[+A](get: Seq[A]) extends Partial[A,Nothing]
case class Success[+B](get: B) extends Partial[Nothing,B]
Now, implement the following functions for this datatype, accumulating errors when meaningful to do so:
a) map
b) flatMap
c) getOrElse
d) orElse
e) map2
f) traverse
Finally:
g) Implement the Try function to convert a possible exception into a Partial
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
