From 78ca9de07e5634c25a9e5f7817053e79a8406c96 Mon Sep 17 00:00:00 2001 From: peferron Date: Mon, 13 Apr 2015 20:04:34 -0700 Subject: [PATCH] lodash: add _.chunk --- lodash/lodash-tests.ts | 9 +++++++++ lodash/lodash.d.ts | 26 +++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 46c11ebf6..10900315f 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -139,6 +139,15 @@ result = <_.Dictionary>_(<{ [index: string]: string; }>{ 'key1': 'test1' // /************* // * Arrays * // *************/ +result = _.chunk([1, '2', '3', false]); +result = <_.LoDashArrayWrapper>_([1, '2', '3', false]).chunk(); +result = _.chunk([1, '2', '3', false], 2); +result = <_.LoDashArrayWrapper>_([1, '2', '3', false]).chunk(2); +result = _.chunk([1, 2, 3, 4]); +result = <_.LoDashArrayWrapper>_([1, 2, 3, 4]).chunk(); +result = _.chunk([1, 2, 3, 4], 2); +result = <_.LoDashArrayWrapper>_([1, 2, 3, 4]).chunk(2); + result = _.compact([0, 1, false, 2, '', 3]); result = <_.LoDashArrayWrapper>_([0, 1, false, 2, '', 3]).compact(); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 55d35707f..01238b769 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -17,7 +17,7 @@ declare module _ { * explicitly included in the build. * * The chainable wrapper functions are: - * after, assign, bind, bindAll, bindKey, chain, compact, compose, concat, countBy, + * after, assign, bind, bindAll, bindKey, chain, chunk, compact, compose, concat, countBy, * createCallback, curry, debounce, defaults, defer, delay, difference, filter, flatten, * forEach, forEachRight, forIn, forInRight, forOwn, forOwnRight, functions, groupBy, * indexBy, initial, intersection, invert, invoke, keys, map, max, memoize, merge, min, @@ -254,6 +254,30 @@ declare module _ { /********* * Arrays * **********/ + + //_.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(array: Array, size?: number): T[][]; + + /** + * @see _.chunk + **/ + chunk(array: List, size?: number): T[][]; + } + + interface LoDashArrayWrapper { + /** + * @see _.chunk + **/ + chunk(size?: number): LoDashArrayWrapper; + } //_.compact interface LoDashStatic {