diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index c842304494..8567b62f4e 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -612,6 +612,42 @@ module TestTake { result = _(testTakeRightList).takeRight(42).value(); } +// _.takeRightWhile +module TestTakeRightWhile { + let array: TResult[]; + let list: _.List; + let predicateFn: (value: TResult, index: number, collection: _.List) => boolean; + let result: TResult[]; + + result = _.takeRightWhile(array); + result = _.takeRightWhile(array, predicateFn); + result = _.takeRightWhile(array, predicateFn, any); + result = _.takeRightWhile(array, '') + result = _.takeRightWhile(array, '', any); + result = _.takeRightWhile<{a: number;}, TResult>(array, {a: 42}); + + result = _.takeRightWhile(list); + result = _.takeRightWhile(list, predicateFn); + result = _.takeRightWhile(list, predicateFn, any); + result = _.takeRightWhile(list, '') + result = _.takeRightWhile(list, '', any); + result = _.takeRightWhile<{a: number;}, TResult>(list, {a: 42}); + + result = _(array).takeRightWhile().value(); + result = _(array).takeRightWhile(predicateFn).value(); + result = _(array).takeRightWhile(predicateFn, any).value(); + result = _(array).takeRightWhile('').value(); + result = _(array).takeRightWhile('', any).value(); + result = _(array).takeRightWhile<{a: number;}>({a: 42}).value(); + + result = _(list).takeRightWhile().value(); + result = _(list).takeRightWhile(predicateFn).value(); + result = _(list).takeRightWhile(predicateFn, any).value(); + result = _(list).takeRightWhile('').value(); + result = _(list).takeRightWhile('', any).value(); + result = _(list).takeRightWhile<{a: number;}, TResult>({a: 42}).value(); +} + result = _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); result = _([1, 2, 3]).union([101, 2, 1, 10], [2, 1]).value(); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 3bde8d8166..d8cf0d0563 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -1437,6 +1437,100 @@ declare module _ { takeRight(n?: number): LoDashArrayWrapper; } + //_.takeRightWhile + interface LoDashStatic { + /** + * Creates a slice of array with elements taken from the end. Elements are taken until predicate returns + * falsey. 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. + * + * @param array The array to query. + * @param predicate The function invoked per iteration. + * @param thisArg The this binding of predicate. + * @return Returns the slice of array. + */ + takeRightWhile( + array: List, + predicate?: ListIterator, + thisArg?: any + ): TValue[]; + + /** + * @see _.takeRightWhile + */ + takeRightWhile( + array: List, + predicate?: string, + thisArg?: any + ): TValue[]; + + /** + * @see _.takeRightWhile + */ + takeRightWhile( + array: List, + predicate?: TWhere + ): TValue[]; + } + + interface LoDashArrayWrapper { + /** + * @see _.takeRightWhile + */ + takeRightWhile( + predicate?: ListIterator, + thisArg?: any + ): LoDashArrayWrapper; + + /** + * @see _.takeRightWhile + */ + takeRightWhile( + predicate?: string, + thisArg?: any + ): LoDashArrayWrapper; + + /** + * @see _.takeRightWhile + */ + takeRightWhile( + predicate?: TWhere + ): LoDashArrayWrapper; + } + + interface LoDashObjectWrapper { + /** + * @see _.takeRightWhile + */ + takeRightWhile( + predicate?: ListIterator, + thisArg?: any + ): LoDashArrayWrapper; + + /** + * @see _.takeRightWhile + */ + takeRightWhile( + predicate?: string, + thisArg?: any + ): LoDashArrayWrapper; + + /** + * @see _.takeRightWhile + */ + takeRightWhile( + predicate?: TWhere + ): LoDashArrayWrapper; + } + //_.union interface LoDashStatic { /**