aaron.harnly.net

What I’ve been up to on 2008-07-22

July 22nd, 2008 by twitterbot
  • is wrestling with cyclic reference errors, and feels like a cyclic reference error himself. #

What I’ve been up to on 2008-07-19

July 19th, 2008 by twitterbot
  • has been watching 90 minutes of 30 Rock every night. I think this TV thing might catch on. #

Lazy vals with implicit parameters

July 17th, 2008 by aaronharnly

Lazy vals were an excellent addition to Scala 2.6.0. They allow you to defer calculation of a value until it is actually needed, after which the calculated value is cached.

Unfortunately, this doesn’t play so well with another wonderful Scala feature — implicit parameters. It’s often the case that you’ll want to defer resolution of an implicit until a method call, rather than in the scope of object creation. But lazy values cannot take any parameters, implicit or otherwise — so it seems you’re stuck.

Memoized to the rescue! This is a simple helper class that takes care of the caching of a result. Where you might have had the following method with an implicit parameter:

def foo(implicit bar: Bar): ResultType = { ... }

you instead write the following:

private var _foo = Memoized[ResultType]
def foo(implicit bar: Bar) = _foo or { ... }

(complete source below the fold) Read the rest of this entry »

What I’ve been up to on 2008-07-14

July 14th, 2008 by twitterbot
  • is in the office, looking forward to a fried green tomato/pita sandwich. #

What I’ve been up to on 2008-06-26

June 26th, 2008 by twitterbot
  • going on a yoga retreat in Mexico. Yes, really. Yes, Aaron Harnly. And I’m very excited about it! #

What I’ve been up to on 2008-06-25

June 25th, 2008 by twitterbot
  • I’ve got to stop putting off conditional random fields. #

What I’ve been up to on 2008-06-11

June 11th, 2008 by
  • gonna build a grubstake by minstrelsy. #

What I’ve been up to on 2008-06-04

June 4th, 2008 by
  • I would really, really like my senator back now. Time to come home. #