I am trying to extend a set of integers in Scala. Based on an earlier answer I have decided to use a SetProxy object. I am now trying to implement the newBuilder
Give this a shot:
case class CustomSet(override val self: Set[Int]) extends SetProxy[Int] {
override def newBuilder = new mutable.SetBuilder[Int, Set[Int]](CustomSet())
}
object CustomSet {
def apply(values: Int*): CustomSet = CustomSet(HashSet(values.toSeq: _*))
}
When creating the SetBuilder
, specifying CustomSet
as the second type param did not satisfy the type bound for that param. Switching it to Set[Int]
meets that criteria and allows you to still pass in your CustomSet
as the constructor arg. Hope this helps.