aaron.harnly.net

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

August 6th, 2008 by twitterbot
  • wants to ride in an A380 just for the Tailcam. #

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

August 4th, 2008 by twitterbot
  • wondering whether cherries would be as delicious if they were the size of plums. Would they be too strong? Or the best thing ever? #

What I’ve been up to on 2008-08-01

August 1st, 2008 by twitterbot
  • so happy there’s going to be an official “garfield minus garfield” book. Jim Davis must be cooler than I’ve given him credit for. #

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! #