jeudi 18 juin 2020

how to print a collection as valid code in scala

Assume I have

val x = List("a","b","c")

I'd like to have a function f which when called, returns

List("a","b","c")

Currently, println(x) just prints List(a,b,c) which will not compile when compiled/pasted into an Scala-Notebook or Unit-Test.

I'm stuck to find a general solution which also works for Seq[Double] etc , I managed to get something for Seq[String] by re-adding the quotes, but I'm unable to get a proper solution for all collection types





Aucun commentaire:

Enregistrer un commentaire