//Question 1 implicit def toInt(value: String): Int = value.toInt implicit def toString(student: Student): String = student.name case class Student(id:Int, name:String) val studentName:String = Student("10","John Dole") //Question 2 implicit def toList(marks: Marks): List[Int] = marks.marks case class Marks(course:String, marks:List[Int]) def totalMarks(marks: List[Int]):Int = marks.sum val marks = List(80,50,100,30) totalMarks(Marks("FunctionalProgramming",marks)) //Question 3 case class Course(subjects:List[String]) def getNumberofSubjects(course:Course):Int = course.subject.size getNumberofSubjects //Question 4 implicit class greetTheWorld(helloWorld: HelloWorld){ def greetTheWorld = helloworld.greeting } class HelloWorld{ def greeting ="Greeting from hello World" val getGreeting = new HelloWord().greetTheWorld }
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more