From eb06688d41f1b6335f75dbc27be51a4e79293cc1 Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Sat, 10 Oct 2015 07:14:59 +0500 Subject: [PATCH] lodash: changed signatures of the method _.zipObject (and alias _.object) --- lodash/lodash-tests.ts | 135 +++++++++++++++++++++++++++++--- lodash/lodash.d.ts | 170 +++++++++++++++++++++++++++++++++-------- 2 files changed, 266 insertions(+), 39 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index db15ebc4a..2455d86ab 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -488,6 +488,69 @@ module TestLastIndexOf { result = _(list).lastIndexOf(value, 42); } +// _.object +module TestObject { + let arrayOfKeys: string[]; + let arrayOfValues: number[]; + + let listOfKeys: _.List; + let listOfValues: _.List; + + { + let result: _.Dictionary; + + result = _.object<_.Dictionary>(arrayOfKeys); + result = _.object<_.Dictionary>(listOfKeys); + + result = _(arrayOfKeys).object<_.Dictionary>().value(); + result = _(listOfKeys).object<_.Dictionary>().value(); + } + + { + let result: _.Dictionary; + + result = _.object<_.Dictionary>(arrayOfKeys, arrayOfValues); + result = _.object<_.Dictionary>(arrayOfKeys, listOfValues); + result = _.object<_.Dictionary>(listOfKeys, listOfValues); + result = _.object<_.Dictionary>(listOfKeys, arrayOfValues); + + result = _.object>(arrayOfKeys, arrayOfValues); + result = _.object>(arrayOfKeys, listOfValues); + result = _.object>(listOfKeys, listOfValues); + result = _.object>(listOfKeys, arrayOfValues); + + result = _(arrayOfKeys).object<_.Dictionary>(arrayOfValues).value(); + result = _(arrayOfKeys).object<_.Dictionary>(listOfValues).value(); + result = _(listOfKeys).object<_.Dictionary>(listOfValues).value(); + result = _(listOfKeys).object<_.Dictionary>(arrayOfValues).value(); + + result = _(arrayOfKeys).object>(arrayOfValues).value(); + result = _(arrayOfKeys).object>(listOfValues).value(); + result = _(listOfKeys).object>(listOfValues).value(); + result = _(listOfKeys).object>(arrayOfValues).value(); + } + + { + let result: _.Dictionary; + + result = _.object(arrayOfKeys); + result = _.object(arrayOfKeys, arrayOfValues); + result = _.object(arrayOfKeys, listOfValues); + + result = _.object(listOfKeys); + result = _.object(listOfKeys, listOfValues); + result = _.object(listOfKeys, arrayOfValues); + + result = _(arrayOfKeys).object().value(); + result = _(arrayOfKeys).object(arrayOfValues).value(); + result = _(arrayOfKeys).object(listOfValues).value(); + + result = _(listOfKeys).object().value(); + result = _(listOfKeys).object(listOfValues).value(); + result = _(listOfKeys).object(arrayOfValues).value(); + } +} + // _.pull { let testPullArray: TResult[]; @@ -539,15 +602,6 @@ module TestLastIndexOf { result = _(testPullAtList).pullAt(4, [2, 3], 1).value(); } -result = <_.Dictionary>_.zipObject(['moe', 'larry'], [30, 40]); -result = <_.LoDashObjectWrapper<_.Dictionary>>_(['moe', 'larry']).zipObject([30, 40]); -result = <_.Dictionary>_.object(['moe', 'larry'], [30, 40]); -result = <_.LoDashObjectWrapper<_.Dictionary>>_(['moe', 'larry']).object([30, 40]); -result = <_.Dictionary>_.zipObject([['moe', 30], ['larry', 40]]); -result = <_.LoDashObjectWrapper<_.Dictionary>>_([['moe', 30], ['larry', 40]]).zipObject(); -result = <_.Dictionary>_.object([['moe', 30], ['larry', 40]]); -result = <_.LoDashObjectWrapper<_.Dictionary>>_([['moe', 30], ['larry', 40]]).object(); - // _.remove module TestRemove { let array: TResult[]; @@ -817,6 +871,69 @@ result = _.unzip(['moe', 'larry'], [30, 40], [true, false]); result = _(['moe', 'larry']).zip([30, 40], [true, false]).value(); result = _(['moe', 'larry']).unzip([30, 40], [true, false]).value(); +// _.zipObject +module TestZipObject { + let arrayOfKeys: string[]; + let arrayOfValues: number[]; + + let listOfKeys: _.List; + let listOfValues: _.List; + + { + let result: _.Dictionary; + + result = _.zipObject<_.Dictionary>(arrayOfKeys); + result = _.zipObject<_.Dictionary>(listOfKeys); + + result = _(arrayOfKeys).zipObject<_.Dictionary>().value(); + result = _(listOfKeys).zipObject<_.Dictionary>().value(); + } + + { + let result: _.Dictionary; + + result = _.zipObject<_.Dictionary>(arrayOfKeys, arrayOfValues); + result = _.zipObject<_.Dictionary>(arrayOfKeys, listOfValues); + result = _.zipObject<_.Dictionary>(listOfKeys, listOfValues); + result = _.zipObject<_.Dictionary>(listOfKeys, arrayOfValues); + + result = _.zipObject>(arrayOfKeys, arrayOfValues); + result = _.zipObject>(arrayOfKeys, listOfValues); + result = _.zipObject>(listOfKeys, listOfValues); + result = _.zipObject>(listOfKeys, arrayOfValues); + + result = _(arrayOfKeys).zipObject<_.Dictionary>(arrayOfValues).value(); + result = _(arrayOfKeys).zipObject<_.Dictionary>(listOfValues).value(); + result = _(listOfKeys).zipObject<_.Dictionary>(listOfValues).value(); + result = _(listOfKeys).zipObject<_.Dictionary>(arrayOfValues).value(); + + result = _(arrayOfKeys).zipObject>(arrayOfValues).value(); + result = _(arrayOfKeys).zipObject>(listOfValues).value(); + result = _(listOfKeys).zipObject>(listOfValues).value(); + result = _(listOfKeys).zipObject>(arrayOfValues).value(); + } + + { + let result: _.Dictionary; + + result = _.zipObject(arrayOfKeys); + result = _.zipObject(arrayOfKeys, arrayOfValues); + result = _.zipObject(arrayOfKeys, listOfValues); + + result = _.zipObject(listOfKeys); + result = _.zipObject(listOfKeys, listOfValues); + result = _.zipObject(listOfKeys, arrayOfValues); + + result = _(arrayOfKeys).zipObject().value(); + result = _(arrayOfKeys).zipObject(arrayOfValues).value(); + result = _(arrayOfKeys).zipObject(listOfValues).value(); + + result = _(listOfKeys).zipObject().value(); + result = _(listOfKeys).zipObject(listOfValues).value(); + result = _(listOfKeys).zipObject(arrayOfValues).value(); + } +} + // _.zipWith interface TestZipWithFn { (a1: number, a2: number): number; diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 5a3e0df9e..35593b5ca 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -995,6 +995,79 @@ declare module _ { ): number; } + //_.object + interface LoDashStatic { + /** + * @see _.zipObject + */ + object( + props: List, + values?: List + ): TResult; + + /** + * @see _.zipObject + */ + object( + props: List, + values?: List + ): TResult; + + /** + * @see _.zipObject + */ + object( + props: List, + values?: List + ): _.Dictionary; + } + + interface LoDashArrayWrapper { + /** + * @see _.zipObject + */ + object( + values?: List + ): _.LoDashObjectWrapper; + + /** + * @see _.zipObject + */ + object( + values?: List + ): _.LoDashObjectWrapper; + + /** + * @see _.zipObject + */ + object( + values?: List + ): _.LoDashObjectWrapper<_.Dictionary>; + } + + interface LoDashObjectWrapper { + /** + * @see _.zipObject + */ + object( + values?: List + ): _.LoDashObjectWrapper; + + /** + * @see _.zipObject + */ + object( + values?: List + ): _.LoDashObjectWrapper; + + /** + * @see _.zipObject + */ + object( + values?: List + ): _.LoDashObjectWrapper<_.Dictionary>; + } + //_.pull interface LoDashStatic { /** @@ -2159,45 +2232,82 @@ declare module _ { //_.zipObject interface LoDashStatic { /** - * The inverse of _.pairs; this method returns an object composed from arrays of property - * names and values. Provide either a single two dimensional array, e.g. [[key1, value1], - * [key2, value2]] or two arrays, one of property names and one of corresponding values. - * @param props The property names. - * @param values The property values. - * @return Returns the new object. - **/ + * The inverse of _.pairs; this method returns an object composed from arrays of property names and values. + * Provide either a single two dimensional array, e.g. [[key1, value1], [key2, value2]] or two arrays, one of + * property names and one of corresponding values. + * + * @alias _.object + * + * @param props The property names. + * @param values The property values. + * @return Returns the new object. + */ + zipObject( + props: List, + values?: List + ): TResult; + + /** + * @see _.zipObject + */ zipObject( - props: List, - values?: List): TResult; + props: List, + values?: List + ): TResult; /** - * @see _.zipObject - **/ - zipObject(props: List>): Dictionary; - - /** - * @see _.zipObject - **/ - object( - props: List, - values?: List): TResult; - - /** - * @see _.zipObject - **/ - object(props: List>): Dictionary; + * @see _.zipObject + */ + zipObject( + props: List, + values?: List + ): _.Dictionary; } interface LoDashArrayWrapper { /** - * @see _.zipObject - **/ - zipObject(values?: List): _.LoDashObjectWrapper>; + * @see _.zipObject + */ + zipObject( + values?: List + ): _.LoDashObjectWrapper; /** - * @see _.zipObject - **/ - object(values?: List): _.LoDashObjectWrapper>; + * @see _.zipObject + */ + zipObject( + values?: List + ): _.LoDashObjectWrapper; + + /** + * @see _.zipObject + */ + zipObject( + values?: List + ): _.LoDashObjectWrapper<_.Dictionary>; + } + + interface LoDashObjectWrapper { + /** + * @see _.zipObject + */ + zipObject( + values?: List + ): _.LoDashObjectWrapper; + + /** + * @see _.zipObject + */ + zipObject( + values?: List + ): _.LoDashObjectWrapper; + + /** + * @see _.zipObject + */ + zipObject( + values?: List + ): _.LoDashObjectWrapper<_.Dictionary>; } //_.zipWith