Guards of for-comprehension

Report a typo

There is a database of counties, where a country is implemented as follows:

case class Country(name: String, visa: Boolean, price: BigDecimal, travelHours: Double)

We aim to help UK clients find the best countries for their vacations. We need a function that will return a list of country names where clients do not need a visa, the trip cost doesn't exceed 10000 euros, and journey time doesn't exceed 5 hours.

You can implement three filtering functions or combine them all into one.

Sample Input 1:

Country("Germany", false, 3000, 1.0)
Country("Brazil", false, 10000, 11.3)
Country("Cameroon", true, 5000, 10.4)
Country("China", true, 8000, 11.5)
Country("Denmark", false, 2000, 2.0)

Sample Output 1:

Germany
Denmark
Write a program in Scala 3
def listToTravel(countries: List[Country]): List[String] =
for
country <- countries
if !country.visa
if ???
if ???
yield ???
___

Create a free account to access the full topic