Skip to content

Instantly share code, notes, and snippets.

@nairbv
Created July 17, 2012 03:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nairbv/3126747 to your computer and use it in GitHub Desktop.
Save nairbv/3126747 to your computer and use it in GitHub Desktop.
//quick hack to pretty-print some text:
"((hi)(bye(yeah))((x)))".foldLeft(0){
(a,b)=> {
var indent=a;
b match {
case '('=> println("("); indent=a+2; print(" "*indent);
case ')'=>println;indent=a-2;println(" "*indent + ")");print(" "*indent)
case x => print(x);
}
indent;
}
}
prints:
(
(
hi
)
(
bye(
yeah
)
)
(
(
x
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment