prettier is an implementation of Wadler's "A Prettier Printer".
$ go get -u github.com/tanishiking/prettier
import (
"fmt"
p "github.com/tanishiking/prettier"
)
j
func main() {
sep := p.Concat([]p.Doc{p.Text(","), p.LineOrSpace()})
ds := []p.Doc{
p.Text("foo"),
p.Text("bar"),
p.Text("baz"),
p.Text("hello"),
p.Text("world"),
}
doc := p.TightBracketBy(
p.Text("["),
p.Text("]"),
p.Intercalate(sep, ds),
uint(2),
)
fmt.Println(p.Pretty(40, doc))
// [foo, bar, baz, hello, world]
fmt.Println(p.Pretty(20, doc))
// [
// foo, bar, baz,
// hello, world
// ]
fmt.Println(p.Pretty(10, doc))
// [
// foo,
// bar,
// baz,
// hello,
// world
// ]
}
MIT License