Right now I feel about this a lot like I felt about getting Twitter. Nobody I know personally is there, but all the “famous” “technological” people are, and something like 90% of the open-source projects I bump into are too.
Just like Twitter, I barely know how to use Git either, but that’s okay. For version control I’m going all command-line now! Last time I tried to link stuff up with Eclipse everything exploded, but after I ran git init
from the terminal this time, it’s highlighting things red and green everywhere like it’s suddenly begging me not to forsake it for the command line. Nice try, Eclipse. You can’t even get your “presentation compiler” to stop crashing.
Anyway, I’m recoding my grid-puzzle-drawing project from scratch (Step 3 of writing a complex program, according to Knuth) and having a lot of fun (ab)using Scala monads.
def tryToInt(str: String): Either[String, Int] = {
try {
Right(str.toInt)
} catch {
case e: NumberFormatException => Left("Error: cannot parse int: " + str)
}
}
def tryToInts(strs: Seq[String]): Either[String, Seq[Int]] = {
((strs map tryToInt).foldLeft
(Right(List.empty): Either[String, Seq[Int]])
((collected, next) =>
for (c <- collected.right; n <- next.right)
yield (c :+ n)))
}