mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
added _.transform definition
This commit is contained in:
@@ -699,6 +699,18 @@ result = <any>_.pick({ 'name': 'moe', '_userid': 'moe1' }, function(value, key)
|
||||
return key.charAt(0) != '_';
|
||||
});
|
||||
|
||||
result = <any>_.transform([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], function(result, num) {
|
||||
num *= num;
|
||||
if (num % 2) {
|
||||
return result.push(num) < 3;
|
||||
}
|
||||
});
|
||||
// → [1, 9, 25]
|
||||
|
||||
result = <any>_.transform({ 'a': 1, 'b': 2, 'c': 3 }, function(result, num, key) {
|
||||
result[key] = num * 3;
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
//WHAT'S LEFT
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Vendored
+17
-1
@@ -2678,7 +2678,23 @@ declare module _ {
|
||||
callback: ObjectIterator<any, boolean>,
|
||||
thisArg?: any): any;
|
||||
|
||||
|
||||
/**
|
||||
* An alternative to _.reduce this method transforms object to a new accumulator object which is
|
||||
* the result of running each of its elements through a callback, with each callback execution
|
||||
* potentially mutating the accumulator object. The callback is bound to thisArg and invoked with
|
||||
* four arguments; (accumulator, value, key, object). Callbacks may exit iteration early by
|
||||
* explicitly returning false.
|
||||
* @param collection The collection to iterate over.
|
||||
* @param callback The function called per iteration.
|
||||
* @param accumulator The custom accumulator value.
|
||||
* @param thisArg The this binding of callback.
|
||||
* @return The accumulated value.
|
||||
**/
|
||||
export function transform<T>(
|
||||
collection: Collection<T>,
|
||||
callback?: MemoIterator<T, any>,
|
||||
accumulator?: any,
|
||||
thisArg?: any): any
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user