Saturday, January 4, 2014

Using ruby to explore scalaz

I've been poking around scalaz, and sometimes it's nice to just get a quick overview of the code using some simple ruby. I could write some code using asm to look at the bytecode, but it's usually faster for me to just use ruby on the source. I'm not looking for 100%-complete tested code here, it's more like a very fancy grep.

For example, I was curious about all the places that define functions starting with lift:

And then to read the output, I use a google spreadsheet:

Run with:

find * -name *.scala -type f -print0 | xargs -0 ruby lift.rb | pbcopy

pbcopy is the mac utility that copies stdout to the clipboard, so it's fast to run this from the command line, switch to the spreadsheet, and hit paste.