How to determine the maximum function for each type using the ">" method?
This standard library already does this. But without assigning a type to an object having a method >...
List(1,2,3).max(Ordering.fromLessThan( (a:Int, b:Int) => b > a) )
, , > - >. , max.
:
case class S(s:String) {
def >(that:S) = java.text.Collator.getInstance.compare(s, that.s) > 0
}
List(S("abc"), S("ABa"), S("abd")).max(Ordering.fromLessThan( (a:S,b:S) => b>a) )
// res9: S = S(abd)
The order value may be relevant.
It covers standard numeric types (and then some — see “Known Subclasses”). Implicits can be used to “open” by external types.
Happy coding.