The editor-in-chief asked

Report a typo

We have a function that takes a list of strings and returns the last string that contains the substring "Scala".

We have implemented an additional error structure (already in the scope):

sealed trait Error
case object NoLines extends Error
case object NoScala extends Error

Modify the function so that, if there is no such string, the function would return NoScala, and if the list is empty, the function would return NoLines.

Sample Input 1:

User: What's the difference between Scala and Java?
ChatGPT: Scala is a functional language that runs on the JVM, with concise syntax and a strong type system. Java is object-oriented and commonly used for enterprise apps.
User: Which one is better for high-performance apps?
ChatGPT: Both are viable options, but Scala's functional nature and support for parallelism make it popular for data-intensive applications, while Java's widespread adoption and vast ecosystem make it a strong contender for high-performance apps.

Sample Output 1:

Right(ChatGPT: Both are viable options, but Scala's functional nature and support for parallelism make it popular for data-intensive applications, while Java's widespread adoption and vast ecosystem make it a strong contender for high-performance apps.)
Write a program in Scala 3
def findScalaString(lines: List[String]): Option[String] =
lines.findLast(_.contains("Scala"))
___

Create a free account to access the full topic