diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 8be3a0ef09..6c4dce44ae 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -344,16 +344,6 @@ module TestFirst { result = _(list).first(); } -result = _.takeWhile([1, 2, 3], (num) => num < 3); -result = _.takeWhile(foodsOrganic, 'organic'); -result = _.takeWhile(foodsType, { 'type': 'fruit' }); - -result = _([1, 2, 3]).takeWhile(function (num) { - return num < 3; -}).value(); -result = _(foodsType).takeWhile('organic').value(); -result = _(foodsType).takeWhile({ 'type': 'fruit' }).value(); - result = >_.flatten([[1, 2], [3, 4]]); result = >_.flatten([[1, 2], [3, 4], 5, 6]); result = >>>_.flatten([1, [2], [3, [[4]]]]); @@ -648,6 +638,42 @@ module TestTakeRightWhile { result = _(list).takeRightWhile<{a: number;}, TResult>({a: 42}).value(); } +// _.takeWhile +module TestTakeWhile { + let array: TResult[]; + let list: _.List; + let predicateFn: (value: TResult, index: number, collection: _.List) => boolean; + let result: TResult[]; + + result = _.takeWhile(array); + result = _.takeWhile(array, predicateFn); + result = _.takeWhile(array, predicateFn, any); + result = _.takeWhile(array, '') + result = _.takeWhile(array, '', any); + result = _.takeWhile<{a: number;}, TResult>(array, {a: 42}); + + result = _.takeWhile(list); + result = _.takeWhile(list, predicateFn); + result = _.takeWhile(list, predicateFn, any); + result = _.takeWhile(list, '') + result = _.takeWhile(list, '', any); + result = _.takeWhile<{a: number;}, TResult>(list, {a: 42}); + + result = _(array).takeWhile().value(); + result = _(array).takeWhile(predicateFn).value(); + result = _(array).takeWhile(predicateFn, any).value(); + result = _(array).takeWhile('').value(); + result = _(array).takeWhile('', any).value(); + result = _(array).takeWhile<{a: number;}>({a: 42}).value(); + + result = _(list).takeWhile().value(); + result = _(list).takeWhile(predicateFn).value(); + result = _(list).takeWhile(predicateFn, any).value(); + result = _(list).takeWhile('').value(); + result = _(list).takeWhile('', any).value(); + result = _(list).takeWhile<{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 e18e5f6b37..9aa573de7d 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -671,66 +671,6 @@ declare module _ { first(): TResult; } - interface LoDashStatic { - /** - * Takes the first items from an array or list based on a predicate - * @param array The array or list of items on which the result set will be based - * @param predicate A predicate function to determine whether a value will be taken. Optional; defaults to identity. - * @param [thisArg] The this binding of predicate. - */ - takeWhile( - array: (Array|List), - predicate?: ListIterator, - thisArg?: any - ): T[]; - - /** - * Takes the first items from an array or list based on a predicate - * @param array The array or list of items on which the result set will be based - * @param pluckValue Uses a _.property style callback to return the property value of the given element - */ - takeWhile( - array: (Array|List), - pluckValue: string - ): any[]; - - /** - * Takes the first items from an array or list based on a predicate - * @param array The array or list of items on which the result set will be based - * @param whereValue Uses a _.matches style callback to return the first elements that match the given value - */ - takeWhile( - array: (Array|List), - whereValue: W - ): T[]; - } - - interface LoDashArrayWrapper { - /** - * Takes the first items based on a predicate - * @param predicate The function called per element. - * @param [thisArg] The this binding of callback. - **/ - takeWhile( - predicate: ListIterator, - thisArg?: any): LoDashArrayWrapper; - - /** - * Takes the first items based on a predicate - * @param pluckValue Uses a _.property style callback to return the property value of the given element - **/ - takeWhile( - pluckValue: string): LoDashArrayWrapper; - - /** - * Takes the first items based on a predicate - * @param whereValue Uses a _.matches style callback to return the first elements that match the given value - **/ - takeWhile( - whereValue: W): LoDashArrayWrapper; - - } - interface MaybeNestedList extends List> { } interface RecursiveList extends List> { } @@ -1531,6 +1471,100 @@ declare module _ { ): LoDashArrayWrapper; } + //_.takeWhile + interface LoDashStatic { + /** + * Creates a slice of array with elements taken from the beginning. 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. + */ + takeWhile( + array: List, + predicate?: ListIterator, + thisArg?: any + ): TValue[]; + + /** + * @see _.takeWhile + */ + takeWhile( + array: List, + predicate?: string, + thisArg?: any + ): TValue[]; + + /** + * @see _.takeWhile + */ + takeWhile( + array: List, + predicate?: TWhere + ): TValue[]; + } + + interface LoDashArrayWrapper { + /** + * @see _.takeWhile + */ + takeWhile( + predicate?: ListIterator, + thisArg?: any + ): LoDashArrayWrapper; + + /** + * @see _.takeWhile + */ + takeWhile( + predicate?: string, + thisArg?: any + ): LoDashArrayWrapper; + + /** + * @see _.takeWhile + */ + takeWhile( + predicate?: TWhere + ): LoDashArrayWrapper; + } + + interface LoDashObjectWrapper { + /** + * @see _.takeWhile + */ + takeWhile( + predicate?: ListIterator, + thisArg?: any + ): LoDashArrayWrapper; + + /** + * @see _.takeWhile + */ + takeWhile( + predicate?: string, + thisArg?: any + ): LoDashArrayWrapper; + + /** + * @see _.takeWhile + */ + takeWhile( + predicate?: TWhere + ): LoDashArrayWrapper; + } + //_.union interface LoDashStatic { /**