scala - Generically adding implicits to both TreeSet and TreeMaps -


i want add helpful implicits both mutable , immutable treemaps , treesets in scala.

here attempt:

  1. 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] 
  2. 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, b]] 

this close type alias, first type parameter of sorted , gentraverablelike in type alias sortedcollection must same, not above. aren't compatible. is, repr = treemap[a, b] fine, a = (a, b) doesn't make sense.

you're going have same issue map types, , real choice re-implement richsortedcollection maps well.


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -