From 6d4df3d1661db3175306bd88aab05a74dd4c8369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20So=CC=88hnlein?= Date: Fri, 21 Oct 2016 14:52:02 +0200 Subject: [PATCH] [Lodash] Add fromIndex param to findIndex, findLastIndex and findLast. Param available since loodash 4.13.0, see https://github.com/lodash/lodash/wiki/Changelog#v4130 --- lodash/lodash-tests.ts | 18 ++++++ lodash/lodash.d.ts | 141 +++++++++++++++++++++++++++++------------ 2 files changed, 117 insertions(+), 42 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index f0f958b0c8..b23d94f48d 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -681,6 +681,7 @@ namespace TestFindIndex { let array: TResult[]; let list: _.List; let predicateFn: (value: TResult, index?: number, collection?: _.List) => boolean; + let fromIndex: number; { let result: number; @@ -689,21 +690,25 @@ namespace TestFindIndex { result = _.findIndex(array, predicateFn); result = _.findIndex(array, ''); result = _.findIndex<{a: number}, TResult>(array, {a: 42}); + result = _.findIndex(array, predicateFn, fromIndex); result = _.findIndex(list); result = _.findIndex(list, predicateFn); result = _.findIndex(list, ''); result = _.findIndex<{a: number}, TResult>(list, {a: 42}); + result = _.findIndex(list, predicateFn, fromIndex); result = _(array).findIndex(); result = _(array).findIndex(predicateFn); result = _(array).findIndex(''); result = _(array).findIndex<{a: number}>({a: 42}); + result = _(array).findIndex(predicateFn, fromIndex); result = _(list).findIndex(); result = _(list).findIndex(predicateFn); result = _(list).findIndex(''); result = _(list).findIndex<{a: number}>({a: 42}); + result = _(list).findIndex(predicateFn, fromIndex); } { @@ -713,11 +718,13 @@ namespace TestFindIndex { result = _(array).chain().findIndex(predicateFn); result = _(array).chain().findIndex(''); result = _(array).chain().findIndex<{a: number}>({a: 42}); + result = _(array).chain().findIndex(predicateFn, fromIndex); result = _(list).chain().findIndex(); result = _(list).chain().findIndex(predicateFn); result = _(list).chain().findIndex(''); result = _(list).chain().findIndex<{a: number}>({a: 42}); + result = _(list).chain().findIndex(predicateFn, fromIndex); } } @@ -727,6 +734,7 @@ namespace TestFindLastIndex { let list: _.List; let predicateFn: (value: TResult, index?: number, collection?: _.List) => boolean; + let fromIndex: number; { let result: number; @@ -735,21 +743,25 @@ namespace TestFindLastIndex { result = _.findLastIndex(array, predicateFn); result = _.findLastIndex(array, ''); result = _.findLastIndex<{a: number}, TResult>(array, {a: 42}); + result = _.findLastIndex(array, predicateFn, fromIndex); result = _.findLastIndex(list); result = _.findLastIndex(list, predicateFn); result = _.findLastIndex(list, ''); result = _.findLastIndex<{a: number}, TResult>(list, {a: 42}); + result = _.findLastIndex(list, predicateFn, fromIndex); result = _(array).findLastIndex(); result = _(array).findLastIndex(predicateFn); result = _(array).findLastIndex(''); result = _(array).findLastIndex<{a: number}>({a: 42}); + result = _(array).findLastIndex(predicateFn, fromIndex); result = _(list).findLastIndex(); result = _(list).findLastIndex(predicateFn); result = _(list).findLastIndex(''); result = _(list).findLastIndex<{a: number}>({a: 42}); + result = _(list).findLastIndex(predicateFn, fromIndex); } { @@ -759,11 +771,13 @@ namespace TestFindLastIndex { result = _(array).chain().findLastIndex(predicateFn); result = _(array).chain().findLastIndex(''); result = _(array).chain().findLastIndex<{a: number}>({a: 42}); + result = _(array).chain().findLastIndex(predicateFn, fromIndex); result = _(list).chain().findLastIndex(); result = _(list).chain().findLastIndex(predicateFn); result = _(list).chain().findLastIndex(''); result = _(list).chain().findLastIndex<{a: number}>({a: 42}); + result = _(list).chain().findLastIndex(predicateFn, fromIndex); } } @@ -3735,12 +3749,16 @@ result = _.findLast([1, 2, 3, 4], function (num) { result = _.findLast(foodsCombined, { 'type': 'vegetable' }); result = _.findLast(foodsCombined, 'organic'); +result = _.findLast(foodsCombined, 'organic', 1); + result = _([1, 2, 3, 4]).findLast(function (num) { return num % 2 == 0; }); result = _(foodsCombined).findLast({ 'type': 'vegetable' }); result = _(foodsCombined).findLast('organic'); +result = _(foodsCombined).findLast('organic', 1); + // _.flatMap namespace TestFlatMap { let numArray: (number|number[])[] = [1, [2, 3]]; diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 09dd1e74c2..d1c8c43633 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -1590,11 +1590,13 @@ declare module _ { * * @param array The array to search. * @param predicate The function invoked per iteration. + * @param fromIndex The index to search from. * @return Returns the index of the found element, else -1. */ findIndex( array: List, - predicate?: ListIterator + predicate?: ListIterator, + fromIndex?: number ): number; /** @@ -1602,7 +1604,8 @@ declare module _ { */ findIndex( array: List, - predicate?: string + predicate?: string, + fromIndex?: number ): number; /** @@ -1610,7 +1613,8 @@ declare module _ { */ findIndex( array: List, - predicate?: W + predicate?: W, + fromIndex?: number ): number; } @@ -1619,21 +1623,24 @@ declare module _ { * @see _.findIndex */ findIndex( - predicate?: ListIterator + predicate?: ListIterator, + fromIndex?: number ): number; /** * @see _.findIndex */ findIndex( - predicate?: string + predicate?: string, + fromIndex?: number ): number; /** * @see _.findIndex */ findIndex( - predicate?: W + predicate?: W, + fromIndex?: number ): number; } @@ -1642,21 +1649,24 @@ declare module _ { * @see _.findIndex */ findIndex( - predicate?: ListIterator + predicate?: ListIterator, + fromIndex?: number ): number; /** * @see _.findIndex */ findIndex( - predicate?: string + predicate?: string, + fromIndex?: number ): number; /** * @see _.findIndex */ findIndex( - predicate?: W + predicate?: W, + fromIndex?: number ): number; } @@ -1665,21 +1675,24 @@ declare module _ { * @see _.findIndex */ findIndex( - predicate?: ListIterator + predicate?: ListIterator, + fromIndex?: number ): LoDashExplicitWrapper; /** * @see _.findIndex */ findIndex( - predicate?: string + predicate?: string, + fromIndex?: number ): LoDashExplicitWrapper; /** * @see _.findIndex */ findIndex( - predicate?: W + predicate?: W, + fromIndex?: number ): LoDashExplicitWrapper; } @@ -1688,21 +1701,24 @@ declare module _ { * @see _.findIndex */ findIndex( - predicate?: ListIterator + predicate?: ListIterator, + fromIndex?: number ): LoDashExplicitWrapper; /** * @see _.findIndex */ findIndex( - predicate?: string + predicate?: string, + fromIndex?: number ): LoDashExplicitWrapper; /** * @see _.findIndex */ findIndex( - predicate?: W + predicate?: W, + fromIndex?: number ): LoDashExplicitWrapper; } @@ -1722,11 +1738,13 @@ declare module _ { * * @param array The array to search. * @param predicate The function invoked per iteration. + * @param fromIndex The index to search from. * @return Returns the index of the found element, else -1. */ findLastIndex( array: List, - predicate?: ListIterator + predicate?: ListIterator, + fromIndex?: number ): number; /** @@ -1734,7 +1752,8 @@ declare module _ { */ findLastIndex( array: List, - predicate?: string + predicate?: string, + fromIndex?: number ): number; /** @@ -1742,7 +1761,8 @@ declare module _ { */ findLastIndex( array: List, - predicate?: W + predicate?: W, + fromIndex?: number ): number; } @@ -1751,21 +1771,24 @@ declare module _ { * @see _.findLastIndex */ findLastIndex( - predicate?: ListIterator + predicate?: ListIterator, + fromIndex?: number ): number; /** * @see _.findLastIndex */ findLastIndex( - predicate?: string + predicate?: string, + fromIndex?: number ): number; /** * @see _.findLastIndex */ findLastIndex( - predicate?: W + predicate?: W, + fromIndex?: number ): number; } @@ -1774,21 +1797,24 @@ declare module _ { * @see _.findLastIndex */ findLastIndex( - predicate?: ListIterator + predicate?: ListIterator, + fromIndex?: number ): number; /** * @see _.findLastIndex */ findLastIndex( - predicate?: string + predicate?: string, + fromIndex?: number ): number; /** * @see _.findLastIndex */ findLastIndex( - predicate?: W + predicate?: W, + fromIndex?: number ): number; } @@ -1797,21 +1823,24 @@ declare module _ { * @see _.findLastIndex */ findLastIndex( - predicate?: ListIterator + predicate?: ListIterator, + fromIndex?: number ): LoDashExplicitWrapper; /** * @see _.findLastIndex */ findLastIndex( - predicate?: string + predicate?: string, + fromIndex?: number ): LoDashExplicitWrapper; /** * @see _.findLastIndex */ findLastIndex( - predicate?: W + predicate?: W, + fromIndex?: number ): LoDashExplicitWrapper; } @@ -1820,21 +1849,24 @@ declare module _ { * @see _.findLastIndex */ findLastIndex( - predicate?: ListIterator + predicate?: ListIterator, + fromIndex?: number ): LoDashExplicitWrapper; /** * @see _.findLastIndex */ findLastIndex( - predicate?: string + predicate?: string, + fromIndex?: number ): LoDashExplicitWrapper; /** * @see _.findLastIndex */ findLastIndex( - predicate?: W + predicate?: W, + fromIndex?: number ): LoDashExplicitWrapper; } @@ -6892,25 +6924,32 @@ declare module _ { * right to left. * @param collection Searches for a value in this list. * @param callback The function called per iteration. + * @param fromIndex The index to search from. * @return The found element, else undefined. **/ findLast( collection: Array, - callback: ListIterator): T; + callback: ListIterator, + fromIndex?: number + ): T; /** * @see _.find **/ findLast( collection: List, - callback: ListIterator): T; + callback: ListIterator, + fromIndex?: number + ): T; /** * @see _.find **/ findLast( collection: Dictionary, - callback: DictionaryIterator): T; + callback: DictionaryIterator, + fromIndex?: number + ): T; /** * @see _.find @@ -6918,7 +6957,9 @@ declare module _ { **/ findLast( collection: Array, - whereValue: W): T; + whereValue: W, + fromIndex?: number + ): T; /** * @see _.find @@ -6926,7 +6967,9 @@ declare module _ { **/ findLast( collection: List, - whereValue: W): T; + whereValue: W, + fromIndex?: number + ): T; /** * @see _.find @@ -6934,7 +6977,9 @@ declare module _ { **/ findLast( collection: Dictionary, - whereValue: W): T; + whereValue: W, + fromIndex?: number + ): T; /** * @see _.find @@ -6942,7 +6987,9 @@ declare module _ { **/ findLast( collection: Array, - pluckValue: string): T; + pluckValue: string, + fromIndex?: number + ): T; /** * @see _.find @@ -6950,7 +6997,9 @@ declare module _ { **/ findLast( collection: List, - pluckValue: string): T; + pluckValue: string, + fromIndex?: number + ): T; /** * @see _.find @@ -6958,7 +7007,9 @@ declare module _ { **/ findLast( collection: Dictionary, - pluckValue: string): T; + pluckValue: string, + fromIndex?: number + ): T; } interface LoDashImplicitArrayWrapper { @@ -6966,20 +7017,26 @@ declare module _ { * @see _.findLast */ findLast( - callback: ListIterator): T; + callback: ListIterator, + fromIndex?: number + ): T; /** * @see _.findLast * @param _.where style callback */ findLast( - whereValue: W): T; + whereValue: W, + fromIndex?: number + ): T; /** * @see _.findLast * @param _.where style callback */ findLast( - pluckValue: string): T; + pluckValue: string, + fromIndex?: number + ): T; } //_.flatMap