scala.collection.Searching provides binary search but you need an Indexed sequence (eg. Array
), not a Linear sequence (eg. List
). Search will still work on the List but you get linear O(n) behaviour rather than O(Log n).
case class Employee (id: Int, name: String, age: Int)
val emp1 = Employee(1, "Jane Doe", 45)
val emp2 = Employee(2, "Jon Doe", 54)
val emp3 = Employee(3, "Tera Patrick", 38)
val emp4 = Employee(4, "Jenna Jameson", 36)
val emp5 = Employee(5, "Aurora Snow", 34) // not added