Question: Consider the following Scala case class and function definitions trait Result [+X, +Y] case class Error+Y] (:Y) extends Result [Nothing, Y] case class Ok [+X]

 Consider the following Scala case class and function definitions trait Result

Consider the following Scala case class and function definitions trait Result [+X, +Y] case class Error+Y] (:Y) extends Result [Nothing, Y] case class Ok [+X] (n :X) extends Result [X, Nothing] def combine [U,X,Y] (us: List [U], f:U=>Result(X,Y]) Result [List[X],List [Y]] { : = us match t case Nil => Ok (Nil) case v: :vs => (f (v), combine (vs, f)) match case case case case (Error (s), Error (33)) => Error (Ok (Error (3), Ok (ns)) => Error (Ok (s::33) (33) (List (s)) (n), Error (33)) => Error (n), Ok What is the output of running combine (List (0,2,4), (n:Int ) => if (n% 2-0) Ok (n) else Error (n)) Ok(List(O)): Result[List[Int],List[Int] Ok(List(2)): Result[List[Int],List[Int] This expression does not typecheck, so is rejected by the compiler. Ok(List(O, 2, 4)): Result[List[Int],List[Int] Error(List(0, 2, 4) Result[List[Int],List[Int]]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!