From 5760ad3aa8b50b38a95e5c009236d795b7b3962b Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Wed, 19 Aug 2015 05:09:15 +0500 Subject: [PATCH] lodash: added _.thru() method --- lodash/lodash-tests.ts | 42 ++++++++++++++++++++++++++-- lodash/lodash.d.ts | 62 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 98 insertions(+), 6 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 00ca144fd2..a363b8ea53 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -403,9 +403,45 @@ result = _([1, 2]).zipWith(testZipWithFn, any).value(); result = _([1, 2]).zipWith([1, 2], testZipWithFn, any).value(); result = _([1, 2]).zipWith([1, 2], [1, 2], [1, 2], [1, 2], [1, 2], testZipWithFn, any).value(); -// /* ************* -// * Collections * -// ************* */ +/********* + * Chain * + *********/ + +// _.thru +{ + let result: number; + result = _.thru(1, (value: number) => value); + result = _.thru(1, (value: number) => value, any); +} +{ + let result: _.LoDashWrapper; + result = _(1).thru((value: number) => value); + result = _(1).thru((value: number) => value, any); +} +{ + let result: _.LoDashWrapper; + result = _('').thru((value: string) => value); + result = _('').thru((value: string) => value, any); +} +{ + let result: _.LoDashWrapper; + result = _(true).thru((value: boolean) => value); + result = _(true).thru((value: boolean) => value, any); +} +{ + let result: _.LoDashObjectWrapper; + result = _({}).thru((value: Object) => value); + result = _({}).thru((value: Object) => value, any); +} +{ + let result: _.LoDashArrayWrapper; + result = _([1, 2, 3]).thru((value: number[]) => value); + result = _([1, 2, 3]).thru((value: number[]) => value, any); +} + +/************** + * Collection * + **************/ result = _.at(['a', 'b', 'c', 'd', 'e'], [0, 2, 4]); result = _.at(['moe', 'larry', 'curly'], 0, 2); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 77daeca2a1..3436c48c4f 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -2000,9 +2000,65 @@ declare module _ { zipWith(...args: any[]): LoDashArrayWrapper; } - /* ************* - * Collections * - ************* */ + /********* + * Chain * + *********/ + + //_.thru + interface LoDashStatic { + /** + * This method is like _.tap except that it returns the result of interceptor. + * @param value The value to provide to interceptor. + * @param interceptor The function to invoke. + * @param thisArg The this binding of interceptor. + * @return Returns the result of interceptor. + */ + thru( + value: T, + interceptor: (value: T) => TResult, + thisArg?: any): TResult; + } + + interface LoDashWrapperBase { + /** + * @see _.thru + */ + thru( + interceptor: (value: T) => TResult, + thisArg?: any): LoDashWrapper; + + /** + * @see _.thru + */ + thru( + interceptor: (value: T) => TResult, + thisArg?: any): LoDashWrapper; + + /** + * @see _.thru + */ + thru( + interceptor: (value: T) => TResult, + thisArg?: any): LoDashWrapper; + + /** + * @see _.thru + */ + thru( + interceptor: (value: T) => TResult, + thisArg?: any): LoDashObjectWrapper; + + /** + * @see _.thru + */ + thru( + interceptor: (value: T) => TResult[], + thisArg?: any): LoDashArrayWrapper; + } + + /************** + * Collection * + **************/ //_.at interface LoDashStatic {