Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack overflow when displaying large instances of LsSeq #341

Closed
ddtthh opened this Issue Feb 5, 2016 · 0 comments

Comments

Projects
None yet
2 participants
@ddtthh
Copy link

ddtthh commented Feb 5, 2016

Displaying LsSeq (e.g. a result of ls.rec!) creates a stack overflow in ammonite.repl.Util.transpose.
This is to be expected as the transpose implementation there is recursive.

I would suggest to replace the implementation by this tail recursive variant:

@scala.annotation.tailrec
def transpose[A](xs: List[List[A]], result: List[List[A]]): List[List[A]] =
  xs.filter(_.nonEmpty) match {
    case Nil    =>  result
    case ys: List[List[A]] => transpose(ys.map{ _.tail }, ys.map{ _.head }::result)
  }
def transpose[A](xs: List[List[A]]): List[List[A]] = transpose(xs, Nil).reverse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.