scala - Generically adding implicits to both TreeSet and TreeMaps -
i want add helpful implicits both mutable , immutable treemaps , treesets in scala. here attempt: first try define least upper bound of treemap , treeset has headoption / lastoption (from gentraversablelike ) , from / to / until (from sorted ): type sortedcollection[a, repr <: sortedcollection[a, repr]] = collection.generic.sorted[a, repr] collection.gentraversablelike[a, repr] write util: implicit class richsortedcollection[a, repr <: sortedcollection[a, repr]](s: sortedcollection[a, repr]) { def greaterthanorequalto(a: a): option[a] = s.from(a).headoption def lessthan(a: a): option[a] = s.until(a).lastoption def lessthanorequalto(a: a): option[a] = s.to(a).lastoption } this works partially: sortedset#greaterthan compiles treemap#greaterthan not. how fix it? treemap[a, b] (transitively) extends gentraversablelike[(a, b), treemap[a, b]] , sorted[a, treemap[a, b]] , it's a: sorted[a, treemap[a, b]] gentraversablelike[(a, b), treemap[a,