Adds functional collections operations to simplify distance, error, etc.

The distance, error, test metrics, and other scores that we compute on corresponding data sets are really just a monoid on doubles. In order to work with monoids, I wrote a couple of simple functional collections operations.

I still have to transform the test metric code to adopt the monoid on doubles. However, at least one of them maintains state, so it will be tricky.

Optionally, we can start porting some of this to a functional programming language (Clojure?).

@pushkar