Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following Scala case class and function definitions: trait Result[tX,+Y] case class Errori+Y] (s:Y) extends Result [Nothing, Y case class Ok [+X (n:X) extends

image text in transcribed

Consider the following Scala case class and function definitions: trait Result[tX,+Y] case class Errori+Y] (s:Y) extends Result [Nothing, Y case class Ok [+X (n:X) extends Result [X, Nothing] def combine [ U, X,Y] (us: List[U], f:i->Result(X,Y]) : Result [List [X), List [Y]] { = us match case Nil >Ok (Nil) case v: :vs => E (v), combine (va, 1)) match case (Error (s), Error (33)) => Error (3:33) case (Ok , Error (ss)) Error (ss) case (Error (s), Ok (ns )) => Error (List (s)) case (Ok (n) , Ok (n3 ) )=>ok (n::ns) What is the output of running: combine (List (1,2,3), (n:Int ) => if (n% 2-0) Ok (n) else Error (n)) o Error(1):Result[List[Int).List Int]l o Error(List(13)ResultList[Int], Listlint]l This expression does not typecheck, so is rejected by the compiler. o Error(List(1,2,3) ResultList[Int.Listlint] o Ok(List(1,3):Result[List[Int],List[Int]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions