Created
July 17, 2012 03:05
-
-
Save nairbv/3126747 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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