documentcloud/underscore — pull request #1071 by bmac (2013-04-14 19:22:29+00:00)
Title: Add a _.maybe function

I've found myself writing several functions where the first thing I do is check to see if the variable passed into the function is not null or undefined.

```javascript
function(someValue) {
if (someValue == null) {
return;
}
// Modify some state...
}
```

I have come across two common use cases for this technique.
When pulling a value out of local storage that may or may not have previously be set.

When working with `` in a data binding library like knockout. Often I will want to write a function that consumes the current value of a select list. However my select list may have an option with no value that is just used as a caption to prompt the user to select a real option. In this case a maybe function would be useful because I often do not want to perform any action of the caption option is selected.

Using a maybe wrapper would prevent a function from being called if any of the arguments are null or undefined.

```javascript
var foo = _.maybe(function(someValue) {
// someValue is not null or undefined
// Modify some state...
});

foo(JSON.parse(localStorage.getItem('key')));
```