Although I hoped to wait another day or two to talk about this on my blog, circumstances have force my hand. Therefore, I would like to take a few of your spare moments to talk about a new project that I’m working on called underscore-contrib — an extensions library / proving ground for Underscore.js.1

Why underscore-contrib?

Underscore is a great library supporting a functional style of programming in JavaScript. While Underscore provides a bevy of useful tools to this end, there are many more functions that can be derived from it that are of less-broad applicability. The reasons that any given function is not available directly in Underscore are too numerous to list here, but two in particular help to define the “why” of underscore-contrib:

Some functions are limited in scope.

Some functions are lesser known, but are highly useful.

In the case of #1, underscore-contrib can serve as a home for functions that solve certain pointed problems; stopping somewhere below domain-specific. In the case of #2 underscore-contrib will work as a proving ground for features that should be in Underscore proper, but need some advocacy and/or evolution (or devolution) to get them there.

What’s in underscore-contrib?

At the moment, the following contrib libraries are in place:

underscore.array.builders.js – building arrays

underscore.array.selectors.js – getting stuff from arrays

underscore.function.arity.js – partial application/currying

underscore.function.combinators.js – function combinators

underscore.function.predicates.js – isX functions return true|false

underscore.object.builders.js – building objects

underscore.object.selectors.js – getting stuff from objects

underscore.util.existential.js – truthiness

underscore.util.trampolines.js – function trampolining

These libraries are not complete and do not represent the entire universe of future libraries. Instead, most of the functions used to build the initial set were taken from my upcoming book “Functional JavaScript” and my Lemonad JavaScript library.2

How to use underscore.contrib

First, you’ll need Underscore. Next you can grab the relevant underscore-contrib libraries and simply add something like the following to your pages:

At the moment there are no cross-contrib dependencies (i.e. each library can stand by itself), but that may change in the future.

How you can help

There is still a lot of work to do around perf, documentation, examples, testing and distribution so any help in those areas is welcomed. Pull requests are accepted, but please search the underscore-contrib issues before proposing a new sub-contrib or addition. Additionally, all patches and proposals should have strong documentation, motivating cases and tests. It would be nice if we could not only provide useful tools built on Underscore, but also provide an educational experience for why and how one might use them