我定义了一个
case class User(var firstName: String, var lastName: String, var city: String, var price: Int)
并且想要排序
val users = List(
User("Peter", "Fox", "Berlin", 30),
User("Otto", "Schmidt", "Berlin", 20),
User("Carl", "Schmidt", "Berlin", 30),
User("Igor", "Schmidt", "Berlin", 10),
User("Hugo", "Schmidt", "Berlin", 50))
我可以做到这一点,例如
val sorted = users.sortBy(p => (p.lastName,p.firstName))
是否可以通过这样的序列给 sortBy 排序标准?
val sortCriteria = Seq(lastname,firstname)
val sorted = test.sortBy(p => sortCriteria)
我想按用户请求将序列中的标准与 1 到 n 个参数组合在一起,而不定义所有可能的组合。