From 4b1040d341a9a9a19c2fde0790412b5f40be3731 Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Tue, 4 Aug 2015 13:32:16 +0500 Subject: [PATCH] lodash: added _.before() method --- lodash/lodash-tests.ts | 18 ++++++++++++++++++ lodash/lodash.d.ts | 20 ++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 14f68e1c4..f60472eef 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -765,6 +765,24 @@ var testBackflowAddFn = (n: number, m: number) => n + m; result = _.backflow<(n: number, m: number) => number>(testBackflowSquareFn, testBackflowAddFn)(1, 2); result = _(testBackflowSquareFn).backflow<(n: number, m: number) => number>(testBackflowAddFn).value()(1, 2); +// _.before +var testBeforeFn = ((n: number) => () => ++n)(0); +var testBeforeResultFn = <() => number>_.before<() => number>(3, testBeforeFn); +result = testBeforeResultFn(); +// → 1 +result = testBeforeResultFn(); +// → 2 +result = testBeforeResultFn(); +// → 2 +var testBeforeFn = ((n: number) => () => ++n)(0); +var testBeforeResultFn = <() => number>_(3).before<() => number>(testBeforeFn); +result = testBeforeResultFn(); +// → 1 +result = testBeforeResultFn(); +// → 2 +result = testBeforeResultFn(); +// → 2 + var funcBind = function(greeting: string, punctuation: string) { return greeting + ' ' + this.user + punctuation; }; var funcBound1: (punctuation: string) => any = _.bind(funcBind, { 'name': 'moe' }, 'hi'); funcBound1('!'); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index ee2134766..1e92962fc 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -5164,6 +5164,26 @@ declare module _ { backflow(...funcs: Function[]): LoDashObjectWrapper; } + //_.before + interface LoDashStatic { + /** + * Creates a function that invokes func, with the this binding and arguments of the created function, while + * it is called less than n times. Subsequent calls to the created function return the result of the last func + * invocation. + * @param n The number of calls at which func is no longer invoked. + * @param func The function to restrict. + * @return Returns the new restricted function. + */ + before(n: number, func: TFunc): TFunc; + } + + interface LoDashWrapper { + /** + * @sed _.before + */ + before(func: TFunc): TFunc; + } + //_.bind interface LoDashStatic { /**