From b0dbd65883dfb27731642f1a767a75f5399c545f Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Thu, 17 Sep 2015 02:00:31 +0500 Subject: [PATCH] lodash: changed _.pull() method --- lodash/lodash-tests.ts | 30 ++++++++++++++++++++++++++++-- lodash/lodash.d.ts | 40 +++++++++++++++++++++++++++++----------- 2 files changed, 57 insertions(+), 13 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index e0fdc819e..f44ce8ccb 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -339,6 +339,34 @@ result = _([1, 2, 3]).last(); result = _.lastIndexOf([1, 2, 3, 1, 2, 3], 2); result = _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); +// _.pull +{ + let testPullArray: TResult[]; + let testPullValue: TResult; + let result: TResult[]; + result = _.pull(testPullArray); + result = _.pull(testPullArray, testPullValue); + result = _.pull(testPullArray, testPullValue, testPullValue); + result = _.pull(testPullArray, testPullValue, testPullValue, testPullValue); + result = _(testPullArray).pull().value(); + result = _(testPullArray).pull(testPullValue).value(); + result = _(testPullArray).pull(testPullValue, testPullValue).value(); + result = _(testPullArray).pull(testPullValue, testPullValue, testPullValue).value(); +} +{ + let testPullList: _.List; + let testPullValue: TResult; + let result: _.List; + result = _.pull(testPullList); + result = _.pull(testPullList, testPullValue); + result = _.pull(testPullList, testPullValue, testPullValue); + result = _.pull(testPullList, testPullValue, testPullValue, testPullValue); + result = _(testPullList).pull().value(); + result = _(testPullList).pull(testPullValue).value(); + result = _(testPullList).pull(testPullValue, testPullValue).value(); + result = _(testPullList).pull(testPullValue, testPullValue, testPullValue).value(); +} + // _.pullAt { let testPullAtArray: TResult[]; @@ -371,8 +399,6 @@ result = <_.LoDashObjectWrapper<_.Dictionary>>_([['moe', 30], ['larry', 40] result = <_.Dictionary>_.object([['moe', 30], ['larry', 40]]); result = <_.LoDashObjectWrapper<_.Dictionary>>_([['moe', 30], ['larry', 40]]).object(); -result = _.pull([1, 2, 3, 1, 2, 3], 2, 3); - result = _.remove([1, 2, 3, 4, 5, 6], function (num: number) { return num % 2 == 0; }); result = _.remove(foodsOrganic, 'organic'); result = _.remove(foodsType, { 'type': 'vegetable' }); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 875513570..044fb418c 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -1052,22 +1052,40 @@ declare module _ { //_.pull interface LoDashStatic { /** - * Removes all provided values from the given array using strict equality for comparisons, - * i.e. ===. - * @param array The array to modify. - * @param values The values to remove. - * @return array. - **/ + * Removes all provided values from array using SameValueZero for equality comparisons. + * + * Note: Unlike _.without, this method mutates array. + * + * @param array The array to modify. + * @param values The values to remove. + * @return Returns array. + */ pull( - array: Array, - ...values: T[]): T[]; + array: T[], + ...values: T[] + ): T[]; /** - * @see _.pull - **/ + * @see _.pull + */ pull( array: List, - ...values: T[]): T[]; + ...values: T[] + ): List; + } + + interface LoDashArrayWrapper { + /** + * @see _.pull + */ + pull(...values: T[]): LoDashArrayWrapper; + } + + interface LoDashObjectWrapper { + /** + * @see _.pull + */ + pull(...values: TValue[]): LoDashObjectWrapper>; } //_.pullAt