java - Scala - error: value max is not a member of my custom class -
i've got own class
class foo { mycustomclass value; ... }
which consists of mycustomclass java enum following signature:
enum mycustomclass{ one(1), two(2), three(3) private int nominal; mycustomclass(int nominal) { this.nominal = nominal; } public int nominal() { return nominal; } }
for define ordering as:
implicit val mycustomclassordering = new ordering[foo] { override def compare(c1: foo, c2:foo): int = { c1.value.nominal.compareto(c2.value.nominal) } } import mycustomclassordering ._
and i'm able use function max sequence of objects ofmycustomclass type. got error trying use max fucntion in reduceoption function
val l = list[foo](...) l.reduceoption(_ max _)
got error message: value max not member of ...
what should able use in reduceoption
max
function?
max method delegated mycustomclass. either add ordering foo or add method returns foo object according result of max method call on mycustomclass values.
def op(x: foo,y: foo):foo = { if( (x.value max y.value) == x.value) x else y } val b = l.reduceoption( op(_,_) )
Comments
Post a Comment