Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Given and Using

Exercise 1

val cities = List("London", "Paris", "Lisbon", "Berlin")

Create a list of cities:

  1. sort the list of cities in ascending order
  2. sort in list of cities in descending order
  3. Put the two ordering function in their own scope
  4. Choice which order you use with the import

Create a case class CapitalCity with a city and a country Create a list of capital cities

  1. sort the capital cities in ascending order on the country name
  2. sort the capital cities in descending order in the city name
  3. Add the first ordering in the companion object and the second a separate object
  4. Choice which order you use with the import

Exercise 2

val names = List("John", "Alice", "Jane", "Edward")

Create a list of names:

  1. sort the names in ascending order
  2. sort in names in descending order
  3. Put the two ordering function in their own scope
  4. Choice which order you use with the import

Create a case class Person with a name and age Create a list of persons

  1. sort the persons in ascending order on the age
  2. sort the persons in descending order on the age
  3. Add the ascending ordering in the companion object and the descending a separate scope
  4. Choice which order you use with the import