amnaredo / test

0 stars 0 forks source link

why not a toString method? #192

Open amnaredo opened 2 years ago

amnaredo commented 2 years ago

apart from pprint.pprintln(t: T, width: Integer = null, ...), why not a pprint.toString(t: T, width: Integer = null, ...)?

I understand that pprintln is streamed and it can print very large instances, but a toString method is also useful.

I can make a pull request with such a code (to be tested) if you like:

def toString[T: PPrint](t: T,
                          width: Integer = null,
                          height: Integer = null,
                          indent: Integer = null,
                          colors: Colors = null)
                         (implicit cfg: Config = Config.Defaults.PPrintConfig): String = {
    tokenize(t, width, height, indent, colors)(implicitly[PPrint[T]], cfg).mkString
}

ID: 176 Original Author: dportabella

amnaredo commented 2 years ago

Sure I can see the use. Let's call it stringify rather than toString, since toString is already pretty standard and has a meaning/signature that isn't what this is

Original Author: lihaoyi