maxBy method is used for
finding the first element which yields the largest value measured by function f.
f you gave is
_ < x, which yields
Boolean. Seems like Scala considers
True is larger than
TreeSet(1, 3, 5).maxBy(_ < 5) returns 1, due to 1 and 3 both yield
maxBy is not the one I want in this case.
TreeSet(1, 3, 5).maxBy(x => if (x < 5) x else Int.MinValue) this will return the desired result 3. However, I think the complexity of it is