jashkenas/underscore — pull request #1901 by thejameskyle (2014-10-22 19:22:33+00:00)
Title: Add _.transform method

`_.transform` is a useful alternative to `_.reduce` that calls the iterator with `accumulator` object each time and then returns it.

This is useful for creating new objects applying transformations of another object.

```js
_.transform([1, 2, 3, 4], function(accumulator, value, index, original) {
arr[index] = value * 2;
});
// >> [2, 4, 6, 8];
```

```js
_.chain({ foo: 'foo', bar: 2, baz: 3 })
.values()
.filter(_.isNumber)
.transform((arr, val, i) => arr[i] = val * 2)
.value();
// >> [4, 6];
```

There was a [previous issue](https://github.com/jashkenas/underscore/pull/1112) on a similar function with the same name, however I think lodash has [fully fleshed](https://lodash.com/docs#transform) it out and is much more useful in this form.

I've taken the lodash implementation and tried to make it consistent with some of underscore's behavior.

- No Object.create for obj.constructor
- Can't return false to exit

Ref: @megawac https://github.com/marionettejs/backbone.marionette/pull/2009#issuecomment-60128932