I’m currently looking into another one of your bowling games, this time written in F#. Again a language I’ve never heard of, but it seems to be pretty nice. Very similar to SML (yes, I also know some languages nobody else knows!), which I learned at university. I really like functional languages, especially when it comes to list operations, with all the folding, mapping and filtering. And I really miss them in Java!

Instead of a plain

  1. result = List.map function inputList

you need that clumsy and not at all explicit

  1. List<OtherType> result = new ArrayList<OtherType>;
  2. for (Type each : inputList) {
  3.     result.add(function(each));
  4. }


As long as you don’t look at what is happening inside the loop, you can’t know whether the list is modified, filtered, copied or whatever.
So we recently introduced our own CollectionUtils to avoid this reoccuring pattern and make it obvious at a glance that a transformation (resp. filtering, folding) is happening. But it’s still kind of ugly:

  1. List<Type> result = CollectionUtils.map(new Transform<Type, OtherType>() {
  2.    @Override
  3.    public OtherType transform(Type each) {
  4.         // do the mapping
  5.    }
  6. }, inputList);

It’s really frustrating that this should be the nicest way to deal with lists in Java.

2 Comments »

  • Scala may be the answer

    Comment by Shikhar — October 14, 2009 @ 11:19 am
  • Thanks for the hint! I’ll have a look at it.

    Comment by astro — October 14, 2009 @ 10:01 pm

Email this Share this on Facebook Share this on LinkedIn Tweet This! RSS feed for comments on this post. TrackBack URL

Leave a comment