Saturday, 26 January 2008

a bit of fun with collections

A while ago a friend introduced me to hamcrest matchers and soon after that I started looking in to how I could start to use these to make working with collections. I've spent a little while working with dynamic languages such as groovy, ruby and python and they have got under my skin. In the java world you just don't have the flexiblity of fancy closures and chained method calls.

In order to satisfiy my craving for collection tools, what I really want to do is what this guy claims to be able to do. I first looked at Sam Newman's hamcrest-collections project, it's good, but it didn't do what I really wanted completely.

So in true if it wasn't invented here style I've written my own collections library.

http://code.google.com/p/logicalpractice-collections/

It's not 100% complete, but it does allow you to do some quite clever stuff:

smiths = select(from(people).getLastName(), equalToIgnoringCase("smith"));

Give it a go and let me know what you think.

1 comment:

Nat Pryce said...

Very nice! I've added a link from the Uses of Hamcrest page.