Merge pull request #6226 from chrootsu/lodash-zipObject

lodash: changed signatures of the method _.zipObject (alias _.object)
This commit is contained in:
Masahiro Wakame
2015-10-13 01:30:56 +09:00
2 changed files with 266 additions and 39 deletions
+126 -9
View File
@@ -538,6 +538,69 @@ module TestLastIndexOf {
result = _(list).lastIndexOf<TResult>(value, 42);
}
// _.object
module TestObject {
let arrayOfKeys: string[];
let arrayOfValues: number[];
let listOfKeys: _.List<string>;
let listOfValues: _.List<number>;
{
let result: _.Dictionary<void>;
result = _.object<_.Dictionary<void>>(arrayOfKeys);
result = _.object<_.Dictionary<void>>(listOfKeys);
result = _(arrayOfKeys).object<_.Dictionary<void>>().value();
result = _(listOfKeys).object<_.Dictionary<void>>().value();
}
{
let result: _.Dictionary<number>;
result = _.object<_.Dictionary<number>>(arrayOfKeys, arrayOfValues);
result = _.object<_.Dictionary<number>>(arrayOfKeys, listOfValues);
result = _.object<_.Dictionary<number>>(listOfKeys, listOfValues);
result = _.object<_.Dictionary<number>>(listOfKeys, arrayOfValues);
result = _.object<number, _.Dictionary<number>>(arrayOfKeys, arrayOfValues);
result = _.object<number, _.Dictionary<number>>(arrayOfKeys, listOfValues);
result = _.object<number, _.Dictionary<number>>(listOfKeys, listOfValues);
result = _.object<number, _.Dictionary<number>>(listOfKeys, arrayOfValues);
result = _(arrayOfKeys).object<_.Dictionary<number>>(arrayOfValues).value();
result = _(arrayOfKeys).object<_.Dictionary<number>>(listOfValues).value();
result = _(listOfKeys).object<_.Dictionary<number>>(listOfValues).value();
result = _(listOfKeys).object<_.Dictionary<number>>(arrayOfValues).value();
result = _(arrayOfKeys).object<number, _.Dictionary<number>>(arrayOfValues).value();
result = _(arrayOfKeys).object<number, _.Dictionary<number>>(listOfValues).value();
result = _(listOfKeys).object<number, _.Dictionary<number>>(listOfValues).value();
result = _(listOfKeys).object<number, _.Dictionary<number>>(arrayOfValues).value();
}
{
let result: _.Dictionary<any>;
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[];
@@ -589,15 +652,6 @@ module TestLastIndexOf {
result = _(testPullAtList).pullAt<TResult>(4, [2, 3], 1).value();
}
result = <_.Dictionary<any>>_.zipObject(['moe', 'larry'], [30, 40]);
result = <_.LoDashObjectWrapper<_.Dictionary<any>>>_(['moe', 'larry']).zipObject([30, 40]);
result = <_.Dictionary<any>>_.object(['moe', 'larry'], [30, 40]);
result = <_.LoDashObjectWrapper<_.Dictionary<any>>>_(['moe', 'larry']).object([30, 40]);
result = <_.Dictionary<any>>_.zipObject([['moe', 30], ['larry', 40]]);
result = <_.LoDashObjectWrapper<_.Dictionary<any>>>_([['moe', 30], ['larry', 40]]).zipObject();
result = <_.Dictionary<any>>_.object([['moe', 30], ['larry', 40]]);
result = <_.LoDashObjectWrapper<_.Dictionary<any>>>_([['moe', 30], ['larry', 40]]).object();
// _.remove
module TestRemove {
let array: TResult[];
@@ -916,6 +970,69 @@ result = <any[][]>_.unzip(['moe', 'larry'], [30, 40], [true, false]);
result = <any[][]>_(['moe', 'larry']).zip([30, 40], [true, false]).value();
result = <any[][]>_(['moe', 'larry']).unzip([30, 40], [true, false]).value();
// _.zipObject
module TestZipObject {
let arrayOfKeys: string[];
let arrayOfValues: number[];
let listOfKeys: _.List<string>;
let listOfValues: _.List<number>;
{
let result: _.Dictionary<void>;
result = _.zipObject<_.Dictionary<void>>(arrayOfKeys);
result = _.zipObject<_.Dictionary<void>>(listOfKeys);
result = _(arrayOfKeys).zipObject<_.Dictionary<void>>().value();
result = _(listOfKeys).zipObject<_.Dictionary<void>>().value();
}
{
let result: _.Dictionary<number>;
result = _.zipObject<_.Dictionary<number>>(arrayOfKeys, arrayOfValues);
result = _.zipObject<_.Dictionary<number>>(arrayOfKeys, listOfValues);
result = _.zipObject<_.Dictionary<number>>(listOfKeys, listOfValues);
result = _.zipObject<_.Dictionary<number>>(listOfKeys, arrayOfValues);
result = _.zipObject<number, _.Dictionary<number>>(arrayOfKeys, arrayOfValues);
result = _.zipObject<number, _.Dictionary<number>>(arrayOfKeys, listOfValues);
result = _.zipObject<number, _.Dictionary<number>>(listOfKeys, listOfValues);
result = _.zipObject<number, _.Dictionary<number>>(listOfKeys, arrayOfValues);
result = _(arrayOfKeys).zipObject<_.Dictionary<number>>(arrayOfValues).value();
result = _(arrayOfKeys).zipObject<_.Dictionary<number>>(listOfValues).value();
result = _(listOfKeys).zipObject<_.Dictionary<number>>(listOfValues).value();
result = _(listOfKeys).zipObject<_.Dictionary<number>>(arrayOfValues).value();
result = _(arrayOfKeys).zipObject<number, _.Dictionary<number>>(arrayOfValues).value();
result = _(arrayOfKeys).zipObject<number, _.Dictionary<number>>(listOfValues).value();
result = _(listOfKeys).zipObject<number, _.Dictionary<number>>(listOfValues).value();
result = _(listOfKeys).zipObject<number, _.Dictionary<number>>(arrayOfValues).value();
}
{
let result: _.Dictionary<any>;
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;
+140 -30
View File
@@ -1111,6 +1111,79 @@ declare module _ {
): number;
}
//_.object
interface LoDashStatic {
/**
* @see _.zipObject
*/
object<TValues, TResult extends {}>(
props: List<StringRepresentable>,
values?: List<TValues>
): TResult;
/**
* @see _.zipObject
*/
object<TResult extends {}>(
props: List<StringRepresentable>,
values?: List<any>
): TResult;
/**
* @see _.zipObject
*/
object(
props: List<StringRepresentable>,
values?: List<any>
): _.Dictionary<any>;
}
interface LoDashArrayWrapper<T> {
/**
* @see _.zipObject
*/
object<TValues, TResult extends {}>(
values?: List<TValues>
): _.LoDashObjectWrapper<TResult>;
/**
* @see _.zipObject
*/
object<TResult extends {}>(
values?: List<any>
): _.LoDashObjectWrapper<TResult>;
/**
* @see _.zipObject
*/
object(
values?: List<any>
): _.LoDashObjectWrapper<_.Dictionary<any>>;
}
interface LoDashObjectWrapper<T> {
/**
* @see _.zipObject
*/
object<TValues, TResult extends {}>(
values?: List<TValues>
): _.LoDashObjectWrapper<TResult>;
/**
* @see _.zipObject
*/
object<TResult extends {}>(
values?: List<any>
): _.LoDashObjectWrapper<TResult>;
/**
* @see _.zipObject
*/
object(
values?: List<any>
): _.LoDashObjectWrapper<_.Dictionary<any>>;
}
//_.pull
interface LoDashStatic {
/**
@@ -2178,45 +2251,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<TValues, TResult extends {}>(
props: List<StringRepresentable>,
values?: List<TValues>
): TResult;
/**
* @see _.zipObject
*/
zipObject<TResult extends {}>(
props: List<string>,
values?: List<any>): TResult;
props: List<StringRepresentable>,
values?: List<any>
): TResult;
/**
* @see _.zipObject
**/
zipObject<TResult extends {}>(props: List<List<any>>): Dictionary<any>;
/**
* @see _.zipObject
**/
object<TResult extends {}>(
props: List<string>,
values?: List<any>): TResult;
/**
* @see _.zipObject
**/
object<TResult extends {}>(props: List<List<any>>): Dictionary<any>;
* @see _.zipObject
*/
zipObject(
props: List<StringRepresentable>,
values?: List<any>
): _.Dictionary<any>;
}
interface LoDashArrayWrapper<T> {
/**
* @see _.zipObject
**/
zipObject(values?: List<any>): _.LoDashObjectWrapper<Dictionary<any>>;
* @see _.zipObject
*/
zipObject<TValues, TResult extends {}>(
values?: List<TValues>
): _.LoDashObjectWrapper<TResult>;
/**
* @see _.zipObject
**/
object(values?: List<any>): _.LoDashObjectWrapper<Dictionary<any>>;
* @see _.zipObject
*/
zipObject<TResult extends {}>(
values?: List<any>
): _.LoDashObjectWrapper<TResult>;
/**
* @see _.zipObject
*/
zipObject(
values?: List<any>
): _.LoDashObjectWrapper<_.Dictionary<any>>;
}
interface LoDashObjectWrapper<T> {
/**
* @see _.zipObject
*/
zipObject<TValues, TResult extends {}>(
values?: List<TValues>
): _.LoDashObjectWrapper<TResult>;
/**
* @see _.zipObject
*/
zipObject<TResult extends {}>(
values?: List<any>
): _.LoDashObjectWrapper<TResult>;
/**
* @see _.zipObject
*/
zipObject(
values?: List<any>
): _.LoDashObjectWrapper<_.Dictionary<any>>;
}
//_.zipWith