I am currently taking the Scala course on Coursera on my free time after work, in an attempt to finally give a try to functional programming. I am currently working on an as
I'm doing the same course, and the above implementation of union did turn out to be extremely inefficient.
I came up with the following not-so-functional solution to creating a union of binary-tree sets, which is WAY more efficient:
def union(that: BTSet): BTSet = {
var result:BTSet = this
that.foreach(element => result = result.incl(element))
result
}