Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 [+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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started