Extending Scala collections

后端 未结 4 2134
执念已碎
执念已碎 2021-01-20 02:13

I would like to derive a version of a Scala built-in collection that expands on the functionality for a particular generic type e.g.,

import scala.collection         


        
4条回答
  •  心在旅途
    2021-01-20 02:28

    The reason your example doesn't work is that the return type of the + operation is a HashSet and not a Tuple2Set.

    You'll have much more luck using the "pimp my library" pattern instead of inheritance.

提交回复
热议问题