Merge pull request #6110 from chrootsu/lodash-remove

lodash: changed _.remove() method
This commit is contained in:
Masahiro Wakame
2015-10-05 22:32:02 +09:00
2 changed files with 120 additions and 64 deletions
+35 -4
View File
@@ -501,10 +501,41 @@ result = <_.LoDashObjectWrapper<_.Dictionary<any>>>_([['moe', 30], ['larry', 40]
result = <_.Dictionary<any>>_.object([['moe', 30], ['larry', 40]]);
result = <_.LoDashObjectWrapper<_.Dictionary<any>>>_([['moe', 30], ['larry', 40]]).object();
result = <number[]>_.remove([1, 2, 3, 4, 5, 6], function (num: number) { return num % 2 == 0; });
result = <IFoodOrganic[]>_.remove(foodsOrganic, 'organic');
result = <IFoodType[]>_.remove(foodsType, { 'type': 'vegetable' });
var typedResult: IFoodType[] = _.remove([ <IFoodType>{ name: 'apple' }, <IFoodType>{ name: 'orange' }], <IFoodType>{ name: 'orange' });
// _.remove
module TestRemove {
let array: TResult[];
let list: _.List<TResult>;
let predicateFn: (value: TResult, index?: number, collection?: _.List<TResult>) => boolean;
let result: TResult[];
result = _.remove<TResult>(array);
result = _.remove<TResult>(array, predicateFn);
result = _.remove<TResult>(array, predicateFn, any);
result = _.remove<TResult>(array, '');
result = _.remove<TResult>(array, '', any);
result = _.remove<{a: number}, TResult>(array, {a: 42});
result = _.remove<TResult>(list);
result = _.remove<TResult>(list, predicateFn);
result = _.remove<TResult>(list, predicateFn, any);
result = _.remove<TResult>(list, '');
result = _.remove<TResult>(list, '', any);
result = _.remove<{a: number}, TResult>(list, {a: 42});
result = _<TResult>(array).remove().value();
result = _<TResult>(array).remove(predicateFn).value();
result = _<TResult>(array).remove(predicateFn, any).value();
result = _<TResult>(array).remove('').value();
result = _<TResult>(array).remove('', any).value();
result = _<TResult>(array).remove<{a: number}>({a: 42}).value();
result = _(list).remove<TResult>().value();
result = _(list).remove<TResult>(predicateFn).value();
result = _(list).remove<TResult>(predicateFn, any).value();
result = _(list).remove<TResult>('').value();
result = _(list).remove<TResult>('', any).value();
result = _(list).remove<{a: number}, TResult>({a: 42}).value();
}
// _.slice
{
+85 -60
View File
@@ -1023,72 +1023,97 @@ declare module _ {
//_.remove
interface LoDashStatic {
/**
* Removes all elements from an array that the callback returns truey for and returns
* an array of removed elements. The callback is bound to thisArg and invoked with three
* arguments; (value, index, array).
*
* If a property name is provided for callback the created "_.pluck" style callback will
* return the property value of the given element.
*
* If an object is provided for callback the created "_.where" style callback will return
* true for elements that have the properties of the given object, else false.
* @param array The array to modify.
* @param callback The function called per iteration.
* @param thisArg The this binding of callback.
* @return A new array of removed elements.
**/
remove<T>(
array: Array<T>,
callback?: ListIterator<T, boolean>,
thisArg?: any): T[];
/**
* @see _.remove
**/
* Removes all elements from array that predicate returns truthy for and returns an array of the removed
* elements. The predicate is bound to thisArg and invoked with three arguments: (value, index, array).
*
* If a property name is provided for predicate the created _.property style callback returns the property
* value of the given element.
*
* If a value is also provided for thisArg the created _.matchesProperty style callback returns true for
* elements that have a matching property value, else false.
*
* If an object is provided for predicate the created _.matches style callback returns true for elements that
* have the properties of the given object, else false.
*
* Note: Unlike _.filter, this method mutates array.
*
* @param array The array to modify.
* @param predicate The function invoked per iteration.
* @param thisArg The this binding of predicate.
* @return Returns the new array of removed elements.
*/
remove<T>(
array: List<T>,
callback?: ListIterator<T, boolean>,
thisArg?: any): T[];
/**
* @see _.remove
* @param pluckValue _.pluck style callback
**/
remove<T>(
array: Array<T>,
pluckValue?: string): T[];
/**
* @see _.remove
* @param pluckValue _.pluck style callback
**/
remove<T>(
array: List<T>,
pluckValue?: string): T[];
/**
* @see _.remove
* @param whereValue _.where style callback
**/
remove<W, T>(
array: Array<T>,
wherealue?: Dictionary<W>): T[];
/**
* @see _.remove
* @param whereValue _.where style callback
**/
remove<W, T>(
array: List<T>,
wherealue?: Dictionary<W>): T[];
predicate?: ListIterator<T, boolean>,
thisArg?: any
): T[];
/**
* @see _.remove
* @param item The item to remove
**/
*/
remove<T>(
array:Array<T>,
item:T): T[];
array: List<T>,
predicate?: string,
thisArg?: any
): T[];
/**
* @see _.remove
*/
remove<W, T>(
array: List<T>,
predicate?: W
): T[];
}
interface LoDashArrayWrapper<T> {
/**
* @see _.remove
*/
remove(
predicate?: ListIterator<T, boolean>,
thisArg?: any
): LoDashArrayWrapper<T>;
/**
* @see _.remove
*/
remove(
predicate?: string,
thisArg?: any
): LoDashArrayWrapper<T>;
/**
* @see _.remove
*/
remove<W>(
predicate?: W
): LoDashArrayWrapper<T>;
}
interface LoDashObjectWrapper<T> {
/**
* @see _.remove
*/
remove<TResult>(
predicate?: ListIterator<TResult, boolean>,
thisArg?: any
): LoDashArrayWrapper<TResult>;
/**
* @see _.remove
*/
remove<TResult>(
predicate?: string,
thisArg?: any
): LoDashArrayWrapper<TResult>;
/**
* @see _.remove
*/
remove<W, TResult>(
predicate?: W
): LoDashArrayWrapper<TResult>;
}
//_.rest