Thinking of a Scala Option as a List

Just wanted to show a tiny tidbit of cool and tidy code—and this is one of those things that become intuitive as you start working with lists and flatMap (i.e. Monads, even if you don’t know the term yet) and working toward the wizardry of true FP.

So I’ve got a list (or Seq or similar collection) and I want to append an object to it. Something like:

val name: Option[String] = Some(Dude)
val greetingWords: Seq[String] = List(Hi, there, Dude)

But we’ve got the hitch that the object we want to append is an Option[String]. Maybe it comes from a “getName” function that may not be able to get a name. We could always write the code like this…

val name: Option[String] = Some("Dude")
val greetingWords: Seq[String] = Seq("Hi", "there") ++ { 
  name match {
    case Some(name) => Seq(name)
    case None => Seq.empty[String]
  }
}

…but that’s ugly and inelegant.

So here’s the elegant way of approaching this: Option[A] can be thought of as a special kind of list that has either one or zero values, depending on whether it’s a Some or a None! So in fact, you can save a lot of the code and add the option as though it were another Seq…

scala> Seq("hi","there") ++ Some("dude")
val res3: Seq[String] = List(hi, there, dude)

scala> Seq("hi","there") ++ None
val res4: Seq[String] = List(hi, there)

Clever, huh?

My “Instant Pot” Experience

Months ago, my husband and I were watching TV—I think it might have been CBS Sunday Morning—and there was a short segment about this new “must have” kitchen item that was a 6-in-1 gadget replacing your rice cooker, slow cooker, pressure cooker and all those sorts of things. I told Bill that this gadget would be a great candidate for my Christmas list. Long story short: this device was one of the presents under the Christmas tree, and I figured I would share my experiences and learnings so far. Continue reading “My “Instant Pot” Experience”

Losing Faith in Banks

Two of my banks go under, two of my credit cards comprimised. I’m quickly losing faith.

I have two banks. One is a credit union that was based in Fort Collins with whom I had been a member since 1988. It’s name was Norlarco but is no more because it died and was merged with another Denver-based credit union. From what I hear, Norlarco’s board allowed someone to make risky investments in Miami property and that essentially killed it. (Ironically, when I was wanting to buy a home in Los Angeles they told me they couldn’t help me unless it was in Colorado. I guess I didn’t grease enough palms!) The biggest pain has been changing my checks and all of the settings for all my various auto-payments, from utilities to Netflix. Ugh.

Last year I opened an account at Washington Mutual because I neede the convenience of a local bank here in New York. As everyone knows, that died and got sold to JPMorganChase.

Now my drama continues with credit cards. I was notified last month by my credit union that due to an internal security breach all their debit cards were comprimised and would have to be replaced. New card just showed up in the mail. New PIN for me to memorize.

Last night I just got an e-mail from USAA (a credit card issuer) stating that there’s been a security breach, and they are going to have to replace my credit card.

This is crazy! I’m just about ready to start stuffing money into my mattress!

Things Are Looking Up in ’08

My life right now is so dramatically different than it had been both one and two years ago. Two years ago I was screwing up the courage to pack it all in with regard to my life in Los Angeles and to make back to New York City. My career path [as a computer freelance consultant] was completely stalled, my love-life was nonexistent, and I was generally not a happy person.

Guess who has a new job!

And in many ways I could say “Guess who has a new life!!” My life right now is so dramatically different than it had been both one and two years ago. Two years ago I was screwing up the courage to pack it all in with regard to my life in Los Angeles and to make back to New York City. My career path [as a computer freelance consultant] was completely stalled, my love-life was nonexistent, and I was generally not a happy person.

One thing I did enjoy: I was blogging a lot, including articles about my political views on the world. Being a freelancer, I was able to create and live by whatever image I wanted. My decision to move back to New York and to try to find a “corporate job” meant, for practical issues, that I would have to prune (one might even say “neuter”) my blog. Why? Because let’s face it: the first thing a (responsible) HR department does is to Google a job applicant. And with my livelihood at stake, I wasn’t about to take the risk of being considered a job candidate who lacked discretion.

For many personal reasons, I didn’t write about the last two years here in New York, nor am I likely to go into it publicly. But I will tell you this: I have seen some of the brightest and some of the darkest hours of my life. The job search was an endless, soul sucking, ego-degrading toil that I wouldn’t wish on anyone. I spent about a year and a half searching for a job. Then when I finally settled on a pay-so-low-it-didn’t-cover-the-mortgage job this last February, it turned into the worst employment experience of my life. Long story short, after they missed paying my second paycheck (and after getting in a shouting match with my evil superior) I walked out, and mystically my Dream Job appeared out of nowhere!

The abbreviated summary: I now work for Accenture, and specifically I work for the Accenture Marketing Sciences division, for the Digital Optimization group which consists mostly of a newly acquired company called “Memetrics”. My job is as an “integration engineer” which is really stimulating and exciting, and I even get to wear my “Statistician’s” hat every now and then!

The other great thing in my life is my boyfriend/partner Bill. This is the first long, solid relationship of my life, and it is incredibly enriching. (That also mean all the spare time I used to spend doing things like… er… blogging has dwindled away to something approaching zero.) I’m going to let that personal part of my life remain private, but I will encourage anyone to visit his website (which he maintains daily, and which I helped build and design) at http://www.scroggiestudio.com/.

Well, that’s about it for the recap. I don’t know how much blogging I’m going to do in the near future. I might write about the website design work I’m going to do for Bill’s website. It uses iWeb and Apple’s MobileMe right now, but I want to maybe integrate WordPress and direct hosting, strategic marketing, etc. Developing his site has really been a wonderful case-study for me in all these things. (And an important one—his livelihood depends on it!)