Changed iterators to use _.List and _.Dictionary, added test.

This commit is contained in:
Daniel Beckwith
2015-05-02 12:50:41 -04:00
parent 35036ae8dd
commit 92acb8f42f
2 changed files with 17 additions and 16 deletions

View File

@@ -11,6 +11,7 @@ _.map({ one: 1, two: 2, three: 3 }, (value, key) => value * 3);
//var sum = _.reduce([1, 2, 3], (memo, num) => memo + num, 0); // https://typescript.codeplex.com/workitem/1960
var sum = _.reduce<number, number>([1, 2, 3], (memo, num) => memo + num, 0);
sum = _.reduce<number, number>([1, 2, 3], (memo, num) => memo + num); // memo is optional #issue 5 github
sum = _.reduce<string, number>({'a':'1', 'b':'2', 'c':'3'}, (memo, numstr) => memo + (+numstr));
var list = [[0, 1], [2, 3], [4, 5]];
//var flat = _.reduceRight(list, (a, b) => a.concat(b), []); // https://typescript.codeplex.com/workitem/1960

View File

@@ -41,22 +41,6 @@ declare module _ {
escape?: RegExp;
}
interface ListIterator<T, TResult> {
(value: T, index: number, list: T[]): TResult;
}
interface ObjectIterator<T, TResult> {
(element: T, key: string, list: any): TResult;
}
interface MemoIterator<T, TResult> {
(prev: TResult, curr: T, index: number, list: T[]): TResult;
}
interface MemoObjectIterator<T, TResult> {
(prev: TResult, curr: T, key: string, list: any): TResult;
}
interface Collection<T> { }
// Common interface between Arrays and jQuery objects
@@ -68,6 +52,22 @@ declare module _ {
interface Dictionary<T> extends Collection<T> {
[index: string]: T;
}
interface ListIterator<T, TResult> {
(value: T, index: number, list: List<T>): TResult;
}
interface ObjectIterator<T, TResult> {
(element: T, key: string, list: Dictionary<T>): TResult;
}
interface MemoIterator<T, TResult> {
(prev: TResult, curr: T, index: number, list: List<T>): TResult;
}
interface MemoObjectIterator<T, TResult> {
(prev: TResult, curr: T, key: string, list: Dictionary<T>): TResult;
}
}
interface UnderscoreStatic {