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

Exercises Bookstore GroupBy

Use Case 1: Grouping Books by Category

  library.groupBy(_.category)

Use Case 2: Grouping Books by Author

  library.groupBy(_.author.name)

Use Case 3: Grouping Books by Decade

  library.groupBy(book => (book.year / 10) * 10)

Use Case 4: Grouping Books by Price Range

  library.groupBy { book =>
    if (book.price < 10) "<$10"
    else if (book.price <= 20) "$10-$20"
    else ">$20"
  }

Use Case 5: Grouping Books by Availability of Description

  library.groupBy { book =>
    if (book.description.isDefined) "With Description"
    else "Without Description"
  }