Dear All,
I have a large collection of objects which I am trying to make into a set. When doing this using the .toSet method (in scala 2.13.1) I get a stack overflow error. What is the recommended way around this?
One way I can think of is to group, make each group a set and tail recursively form a union. Can someone recommend a better way (or does this look like a reasonable way)?

It was fixed in my case. Perhaps a factor is that the objects I used were themselves deeply nested tree-like structures, and it was in computing their hashes that it crashed.

I replaced toSet by grouping, using toSet on groups and tail recursively taking the union, and also changed my internal representation so that Sum(a, Sum(b, Sum(c, ..))). became Sum(Vector(a, b, c, ...) (here a, b etc are themselves complicated objects). I do not know which change fixed it, and the crash happens after over an hour of computations, so cannot be replicated easily.

The structure I was using is List I believe (I used groupMapReduce to get a Map and then a function of the form m.map{case (k, v) => fn(k, v).