documentcloud/underscore — pull request #594 by cederberg (2012-05-05 17:54:36+00:00)
Title: Added and(), or() and not() for composing predicate functions.

The basic set of predicates in Underscore are good, but mechanisms for combining them is somewhat lacking. Creating ad-hoc functions isn't difficult, but perhaps still a bit to tedious? Compare the following two lines:

```javascript
var okValue = function (o) { return _.isString(o) && !_.isEmpty(o); };
var okValue = _.and(_.isString, _.not(_.isEmpty));
```

Not sure that the example above motivates adding `and`, `or` & `not`, but perhaps it is useful to direct people to the higher-order-function way of thinking? Opinions?

### Documentation

**_.and(*functions)**

Returns a new predicate function for the logical AND of a set of functions. The function will return false as soon as one of the functions returns a falsy value.

```javascript
var hasStringValue = _.and(_.isString, _.not(_.isEmpty));
_.filter(["", "one", {}], hasStringValue);
=> ["one"]
```

**_.or(*functions)**

Returns a new predicate function for the logical OR of a set of functions. The function will return true as soon as one of the functions returns a truthy value.

```javascript
var isNullOrUndefined = _.or(_.isNull, _.isUndefined);
_.reject([1, null, undefined, 0], isNullOrUndefined);
=> [1, 0]
```

**_.not(*functions)**

Returns a new predicate function for the logical NOT for each of the functions. The function will return false as soon as one of the functions returns a truthy value.

```javascript
var isNotNull = _.not(_.isNull, _.isUndefined);
_.filter([1, null, undefined, 0], isNotNull);
=> [1, 0]
```