added some functional interfaces to reduce the number of inline anonymous types

This commit is contained in:
Bence Eros
2015-06-14 00:57:48 +02:00
parent aad6b603af
commit c5432f4533
+53 -33
View File
@@ -8,36 +8,36 @@ declare class Stream<T> {
static make <T> (elems: T[]): Stream<T>;
static range (startInclusive: number, endExclusive: number): Stream<number>;
static rangeClosed (startInclusive: number, endInclusive: number): Stream<number>;
static generate <T> (supplier: () => T): Stream<T>;
static generate <T> (supplier: Stream.Supplier<T>): Stream<T>;
// static empty<T>(): Stream<T>;
anyMatch(predicate: Stream.Predicate): boolean;
anyMatch(predicate: Stream.Predicate<T>): boolean;
anyMatch(regexp: RegExp): boolean;
allMatch(predicate: (elem: T) => boolean): boolean;
allMatch(predicate: Stream.Predicate<T>): boolean;
allMatch(regexp: RegExp): boolean;
average(): number;
avg(): number;
collect(collector: Stream.Collector<T>): T;
count(): number;
distinct(): Stream<T>;
dropWhile(predicate: (elem: T) => boolean): Stream<T>;
dropWhile(predicate: Stream.Predicate<T>): Stream<T>;
dropWhile(regexp: RegExp): Stream<string>;
filter(predicate: (T) => boolean): Stream<T>;
filter(predicate: Stream.Predicate<T>): Stream<T>;
findAny(): Stream.Optional<T>;
findFirst(): Stream.Optional<T>;
forEach(consumer: (elem: T) => void): void;
forEach(consumer: Stream.Consumer<T>): void;
groupBy(mapper: (elem: T) => string): Stream.GroupingResult<T>;
groupingBy(mapper: (elem: T) => string): Stream.GroupingResult<T>;
indexBy(keyMapper: (elem: T) => string, mergeFunction?: (elem1: T, elem2: T) => T): T[];
map <U> (mapper: (T) => U): Stream<U>;
groupBy(mapper: Stream.Function<T, string>): Stream.GroupingResult<T>;
groupingBy(mapper: Stream.Function<T, string>): Stream.GroupingResult<T>;
indexBy(keyMapper: Stream.Function<T, string>, mergeFunction?: Stream.Accumulator<T>): T[];
map <U> (mapper: Stream.Function<T, U>): Stream<U>;
max(): Stream.Optional<T>;
max(comparator: (e1: T, e2: T) => number): Stream.Optional<T>;
max(comparator: Stream.Comparator<T>): Stream.Optional<T>;
min(): Stream.Optional<T>;
min(comparator: (elem1: T, elem2: T) => number): Stream.Optional<T>;
min(comparator: Stream.Comparator<T>): Stream.Optional<T>;
noneMatch(predicate: (elem: T) => boolean): boolean;
noneMatch(regexp: RegExp): boolean;
flatMap <U> (mapper: (T) => U[]): Stream<U>;
flatMap <U> (mapper: Stream.Function<T, U[]>): Stream<U>;
iterator(): Stream.Iterator<T>;
joining(): string;
joining(delimiter: string): string;
@@ -46,56 +46,76 @@ declare class Stream<T> {
join(delimiter: string): string;
join(options: Stream.JoinOptions): string;
limit(limit: number): Stream<T>;
partitioningBy(predicate: (elem: T) => boolean): T[][];
partitionBy(predicate: (elem: T) => boolean): T[][];
partitioningBy(predicate: Stream.Predicate<T>): T[][];
partitionBy(predicate: Stream.Predicate<T>): T[][];
partitioningBy(regexp: RegExp): T[][];
partitionBy(regexp: RegExp): T[][];
partitioningBy(size: number): T[][];
partitionBy(size: number): T[][];
peek(consumer: (elem: T) => void ): Stream<T>;
reduce(identity: T, accumulator: (e1: T, e2: T) => T): T;
reduce(accumulator: (e1: T, e2: T) => T): Stream.Optional<T>;
peek(consumer: Stream.Consumer<T>): Stream<T>;
reduce(identity: T, accumulator: Stream.Accumulator<T>): T;
reduce(accumulator: Stream.Accumulator<T>): Stream.Optional<T>;
reverse(): Stream<T>;
size(): number;
sorted(): Stream<T>;
sorted(comparator: (e1: T, e2: T) => number): Stream<T>;
sorted(comparator: Stream.Comparator<T>): Stream<T>;
sort(): Stream<T>;
sort(comparator: (e1: T, e2: T) => number): Stream<T>;
sort(comparator: Stream.Comparator<T>): Stream<T>;
shuffle(): Stream<T>;
skip(n: number): Stream<T>;
slice(begin, end): Stream<T>;
sum(): T;
takeWhile(predicate: (elem: T) => boolean): Stream<T>;
takeWhile(predicate: Stream.Predicate<T>): Stream<T>;
takeWhile(regexp: RegExp): Stream<string>;
toArray(): T[];
toMap(keyMapper: (elem: T) => string, mergeFunction?: (elem1: T, elem2: T) => T): T[];
toMap(keyMapper: Stream.Function<T, string>, mergeFunction?: Stream.Accumulator<T>): T[];
}
declare module Stream {
export interface Predicate<T> {
(elem: T): boolean;
export interface Accumulator<T> {
(e1: T, e2: T): T;
}
export interface Collector<T> {
supplier: Supplier<T>;
accumulator: Stream.Accumulator<T>;
finisher: Function<T, T>;
}
export interface Comparator<T> {
(e1: T, e2: T): number
}
export interface Consumer<T> {
(elem: T): void;
}
export interface Function<T, U> {
(elem: T): U;
}
export interface GroupingResult<T> {
[index: string]: T
}
export interface Iterator<T> {
next(): T;
done: boolean;
}
export interface JoinOptions {
prefix: string;
delimiter: string;
suffix: string;
}
export interface GroupingResult<T> {
[index: string]: T
export interface Predicate<T> {
(elem: T): boolean;
}
export interface Collector<T> {
supplier(): T;
accumulator(e1: T, e2: T): T;
finisher(result: T): T
export interface Supplier<T> {
(): T
}
export class Optional<T> {
@@ -110,7 +130,7 @@ declare module Stream {
get(): T;
ifPresent(consumer: (elem: T) => void): void;
orElse(other: T): T;
orElseGet(supplier: () => T): T;
orElseGet(supplier: Stream.Supplier<T>): T;
orElseThrow(error: any): T;
}
}