I have this Scala code segment that defines the order and applies it to the TreeSet. This part is compiling.
val acctOrdering = new Ordering[Account] { def compare(acc1: Account, acc2: Account) { // code to compare based on various criteria } } private var accountSet = new TreeSet[Account]()(acctOrdering)
Elsewhere in the code, I want to get the first element in the set (and later get the next if the first does not produce what I want, although this is usually not required), based on which I pointed out earlier. I thought the following would work, but it did not compile:
val firstAccount = accountSet.min
Error "could not find implicit value for parameter cmp: Ordering[Account]"
However, if I specify the order object again when requesting a minimum, it will compile:
val firstAccount = accountSet.min(acctOrdering)
I thought that he would automatically use the ordering that I gave at build time and stepwise sorting as I add to the set, so I would not need to specify the order when calling min .
What am I doing wrong? Do I need to explicitly specify an implicit function somewhere?
source share