Aliases for _.first: head and take

This commit is contained in:
Brian Zengel
2013-10-13 01:33:52 -04:00
parent 377e2b13de
commit da61ddf7e7
2 changed files with 60 additions and 0 deletions
+16
View File
@@ -72,6 +72,22 @@ result = <number[]>_.first([1, 2, 3], function(num) {
result = <IFoodOrganic[]>_.first(foodsOrganic, 'organic');
result = <IFoodType[]>_.first(foodsType, { 'type': 'fruit' });
result = <number>_.head([1, 2, 3]);
result = <number[]>_.head([1, 2, 3], 2);
result = <number[]>_.head([1, 2, 3], function(num) {
return num < 3;
});
result = <IFoodOrganic[]>_.head(foodsOrganic, 'organic');
result = <IFoodType[]>_.head(foodsType, { 'type': 'fruit' });
result = <number>_.take([1, 2, 3]);
result = <number[]>_.take([1, 2, 3], 2);
result = <number[]>_.take([1, 2, 3], function(num) {
return num < 3;
});
result = <IFoodOrganic[]>_.take(foodsOrganic, 'organic');
result = <IFoodType[]>_.take(foodsType, { 'type': 'fruit' });
////////////////////////////////////////////////////////////////////////////////////////
//WHAT'S LEFT
+44
View File
@@ -653,6 +653,28 @@ declare module _ {
array: List<T>,
n: number): T[];
/**
* @see _.first
**/
export function head<T>(
array: List<T>,
callback: ListIterator<T, boolean>,
thisArg?: any): T[];
/**
* @see _.first
**/
export function head<T>(
array: List<T>,
pluckValue: string): T[];
/**
* @see _.first
**/
export function head<T>(
array: List<T>,
whereValue: Dictionary<string>): T[];
/**
* @see _.first
**/
@@ -665,6 +687,28 @@ declare module _ {
array: List<T>,
n: number): T[];
/**
* @see _.first
**/
export function take<T>(
array: List<T>,
callback: ListIterator<T, boolean>,
thisArg?: any): T[];
/**
* @see _.first
**/
export function take<T>(
array: List<T>,
pluckValue: string): T[];
/**
* @see _.first
**/
export function take<T>(
array: List<T>,
whereValue: Dictionary<string>): T[];
/**
* Returns everything but the last entry of the array. Especially useful on the arguments object.
* Pass n to exclude the last n elements from the result.