Merge pull request #5986 from chrootsu/lodash-chunk

lodash: changed _.chunk() method
This commit is contained in:
Masahiro Wakame
2015-09-27 12:55:26 +09:00
2 changed files with 40 additions and 27 deletions
+18 -11
View File
@@ -155,17 +155,24 @@ result = <number[]>_([1, 2, 3]).run();
result = <_.Dictionary<string>>_(<{ [index: string]: string; }>{ 'key1': 'test1', 'key2': 'test2' }).toJSON();
result = <_.Dictionary<number>>_({ a: 1, b: 2}).mapValues(function(num: number) { return num * 2; }).valueOf();
// /*************
// * Arrays *
// *************/
result = <any[][]>_.chunk([1, '2', '3', false]);
result = <_.LoDashArrayWrapper<any[]>>_([1, '2', '3', false]).chunk();
result = <any[][]>_.chunk([1, '2', '3', false], 2);
result = <_.LoDashArrayWrapper<any[]>>_([1, '2', '3', false]).chunk(2);
result = <number[][]>_.chunk([1, 2, 3, 4]);
result = <_.LoDashArrayWrapper<number[]>>_([1, 2, 3, 4]).chunk();
result = <number[][]>_.chunk([1, 2, 3, 4], 2);
result = <_.LoDashArrayWrapper<number[]>>_([1, 2, 3, 4]).chunk(2);
/*********
* Array *
*********/
// _.chunk
module TestChunk {
let array: TResult[];
let list: _.List<TResult>;
let result: TResult[][];
result = _.chunk<TResult>(array);
result = _.chunk<TResult>(array, 42);
result = _.chunk<TResult>(list);
result = _.chunk<TResult>(list, 42);
result = _(array).chunk().value();
result = _(array).chunk(42).value();
result = _(list).chunk<TResult>().value();
result = _(list).chunk<TResult>(42).value();
}
result = <any[]>_.compact([0, 1, false, 2, '', 3]);
result = <_.LoDashArrayWrapper<any>>_([0, 1, false, 2, '', 3]).compact();
+22 -16
View File
@@ -313,33 +313,39 @@ declare module _ {
}
/*********
* Arrays *
**********/
* Array *
*********/
//_.chunk
interface LoDashStatic {
/**
* Creates an array of elements split into groups the length of size. If collection can't be
* split evenly, the final chunk will be the remaining elements.
* @param array The array to process.
* @param size The length of each chunk.
* @return Returns the new array containing chunks.
**/
chunk<T>(array: Array<T>, size?: number): T[][];
/**
* @see _.chunk
**/
chunk<T>(array: List<T>, size?: number): T[][];
* Creates an array of elements split into groups the length of size. If collection cant be split evenly, the
* final chunk will be the remaining elements.
*
* @param array The array to process.
* @param size The length of each chunk.
* @return Returns the new array containing chunks.
*/
chunk<T>(
array: List<T>,
size?: number
): T[][];
}
interface LoDashArrayWrapper<T> {
/**
* @see _.chunk
**/
* @see _.chunk
*/
chunk(size?: number): LoDashArrayWrapper<T[]>;
}
interface LoDashObjectWrapper<T> {
/**
* @see _.chunk
*/
chunk<TResult>(size?: number): LoDashArrayWrapper<TResult[]>;
}
//_.compact
interface LoDashStatic {
/**