Added chainable definitions for _(...).first and aliases

This commit is contained in:
Brian Zengel
2014-06-02 22:40:45 -04:00
parent f100b9e970
commit 5968a6823b
2 changed files with 122 additions and 0 deletions
+24
View File
@@ -183,6 +183,14 @@ result = <number[]>_.first([1, 2, 3], function (num) {
result = <IFoodOrganic[]>_.first(foodsOrganic, 'organic');
result = <IFoodType[]>_.first(foodsType, { 'type': 'fruit' });
result = <number>_([1, 2, 3]).first();
result = <number[]>_([1, 2, 3]).first(2).value();
result = <number[]>_([1, 2, 3]).first(function (num) {
return num < 3;
}).value();
result = <IFoodOrganic[]>_(foodsOrganic).first('organic').value();
result = <IFoodType[]>_(foodsType).first({ 'type': 'fruit' }).value();
result = <number>_.head([1, 2, 3]);
result = <number[]>_.head([1, 2, 3], 2);
result = <number[]>_.head([1, 2, 3], function (num) {
@@ -191,12 +199,28 @@ result = <number[]>_.head([1, 2, 3], function (num) {
result = <IFoodOrganic[]>_.head(foodsOrganic, 'organic');
result = <IFoodType[]>_.head(foodsType, { 'type': 'fruit' });
result = <number>_([1, 2, 3]).head();
result = <number[]>_([1, 2, 3]).head(2).value();
result = <number[]>_([1, 2, 3]).head(function (num) {
return num < 3;
}).value();
result = <IFoodOrganic[]>_(foodsOrganic).head('organic').value();
result = <IFoodType[]>_(foodsType).head({ 'type': 'fruit' }).value();
result = <number>_.take([1, 2, 3]);
result = <number[]>_.take([1, 2, 3], 2);
result = <number[]>_.take([1, 2, 3], (num) => num < 3);
result = <IFoodOrganic[]>_.take(foodsOrganic, 'organic');
result = <IFoodType[]>_.take(foodsType, { 'type': 'fruit' });
result = <number>_([1, 2, 3]).take();
result = <number[]>_([1, 2, 3]).take(2).value();
result = <number[]>_([1, 2, 3]).take(function (num) {
return num < 3;
}).value();
result = <IFoodOrganic[]>_(foodsOrganic).take('organic').value();
result = <IFoodType[]>_(foodsType).take({ 'type': 'fruit' }).value();
result = <number[]>_.flatten([1, [2], [3, [[4]]]]);
result = <any[]>_.flatten([1, [2], [3, [[4]]]], true);
var result: any
+98
View File
@@ -644,6 +644,104 @@ declare module _ {
whereValue: W): T[];
}
interface LoDashArrayWrapper<T> {
/**
* @see _.first
**/
first(): T;
/**
* @see _.first
* @param n The number of elements to return.
**/
first(n: number): LoDashArrayWrapper<T>;
/**
* @see _.first
* @param callback The function called per element.
* @param [thisArg] The this binding of callback.
**/
first(
callback: ListIterator<T, boolean>,
thisArg?: any): LoDashArrayWrapper<T>;
/**
* @see _.first
* @param pluckValue "_.pluck" style callback value
**/
first(pluckValue: string): LoDashArrayWrapper<T>;
/**
* @see _.first
* @param whereValue "_.where" style callback value
**/
first<W>(whereValue: W): LoDashArrayWrapper<T>;
/**
* @see _.first
**/
head(): T;
/**
* @see _.first
* @param n The number of elements to return.
**/
head(n: number): LoDashArrayWrapper<T>;
/**
* @see _.first
* @param callback The function called per element.
* @param [thisArg] The this binding of callback.
**/
head(
callback: ListIterator<T, boolean>,
thisArg?: any): LoDashArrayWrapper<T>;
/**
* @see _.first
* @param pluckValue "_.pluck" style callback value
**/
head(pluckValue: string): LoDashArrayWrapper<T>;
/**
* @see _.first
* @param whereValue "_.where" style callback value
**/
head<W>(whereValue: W): LoDashArrayWrapper<T>;
/**
* @see _.first
**/
take(): T;
/**
* @see _.first
* @param n The number of elements to return.
**/
take(n: number): LoDashArrayWrapper<T>;
/**
* @see _.first
* @param callback The function called per element.
* @param [thisArg] The this binding of callback.
**/
take(
callback: ListIterator<T, boolean>,
thisArg?: any): LoDashArrayWrapper<T>;
/**
* @see _.first
* @param pluckValue "_.pluck" style callback value
**/
take(pluckValue: string): LoDashArrayWrapper<T>;
/**
* @see _.first
* @param whereValue "_.where" style callback value
**/
take<W>(whereValue: W): LoDashArrayWrapper<T>;
}
//_.flatten
interface LoDashStatic {
/**