As you already found, Seqs cannot contain more Int.MaxValue elements. Until the function is fixed, do not use Seq. You can
1) use while-loop
2) use for loop without sequence
but using these methods you cannot use the Scala collection methods, for example foldLeft in your example.
So you need an Iterator . eg.
def bigIterator(start: BigInt, end: BigInt, step: BigInt = 1) = Iterator.iterate(start)(_ + step).takeWhile(_ <= end)
then
bigIterator(0, BigInt("3000000000")).foldLeft(BigInt(0))(_ + _)
etc. will work. Note: if you do not need the full range of BigInt , use Long , which is significantly faster.
source share