Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala return type when extending collection

If I write

class Things extends scala.collection.immutable.HashSet[Int]

new Things + 5

Then the result is

res0: scala.collection.immutable.HashSet[Int] = Set(5)

What do I need to do for the result to be of type Things? I suspect the answer might be here, but am struggling to understand what's going on.

like image 623
Pengin Avatar asked Oct 14 '22 20:10

Pengin


1 Answers

I can't really tell without a sample of your code but you can take a look at Jesse Eichar's post which provides a walk through the implementation of a custom collection and addresses your question nicely.

http://daily-scala.blogspot.com/2010/04/creating-custom-traversable.html

like image 119
fedesilva Avatar answered Nov 18 '22 08:11

fedesilva