diff --git a/streamjs/streamjs.d.ts b/streamjs/streamjs.d.ts index 8ac67d583..464a449ca 100644 --- a/streamjs/streamjs.d.ts +++ b/streamjs/streamjs.d.ts @@ -8,36 +8,36 @@ declare class Stream { static make (elems: T[]): Stream; static range (startInclusive: number, endExclusive: number): Stream; static rangeClosed (startInclusive: number, endInclusive: number): Stream; - static generate (supplier: () => T): Stream; + static generate (supplier: Stream.Supplier): Stream; // static empty(): Stream; - anyMatch(predicate: Stream.Predicate): boolean; + anyMatch(predicate: Stream.Predicate): boolean; anyMatch(regexp: RegExp): boolean; - allMatch(predicate: (elem: T) => boolean): boolean; + allMatch(predicate: Stream.Predicate): boolean; allMatch(regexp: RegExp): boolean; average(): number; avg(): number; collect(collector: Stream.Collector): T; count(): number; distinct(): Stream; - dropWhile(predicate: (elem: T) => boolean): Stream; + dropWhile(predicate: Stream.Predicate): Stream; dropWhile(regexp: RegExp): Stream; - filter(predicate: (T) => boolean): Stream; + filter(predicate: Stream.Predicate): Stream; findAny(): Stream.Optional; findFirst(): Stream.Optional; - forEach(consumer: (elem: T) => void): void; + forEach(consumer: Stream.Consumer): void; - groupBy(mapper: (elem: T) => string): Stream.GroupingResult; - groupingBy(mapper: (elem: T) => string): Stream.GroupingResult; - indexBy(keyMapper: (elem: T) => string, mergeFunction?: (elem1: T, elem2: T) => T): T[]; - map (mapper: (T) => U): Stream; + groupBy(mapper: Stream.Function): Stream.GroupingResult; + groupingBy(mapper: Stream.Function): Stream.GroupingResult; + indexBy(keyMapper: Stream.Function, mergeFunction?: Stream.Accumulator): T[]; + map (mapper: Stream.Function): Stream; max(): Stream.Optional; - max(comparator: (e1: T, e2: T) => number): Stream.Optional; + max(comparator: Stream.Comparator): Stream.Optional; min(): Stream.Optional; - min(comparator: (elem1: T, elem2: T) => number): Stream.Optional; + min(comparator: Stream.Comparator): Stream.Optional; noneMatch(predicate: (elem: T) => boolean): boolean; noneMatch(regexp: RegExp): boolean; - flatMap (mapper: (T) => U[]): Stream; + flatMap (mapper: Stream.Function): Stream; iterator(): Stream.Iterator; joining(): string; joining(delimiter: string): string; @@ -46,56 +46,76 @@ declare class Stream { join(delimiter: string): string; join(options: Stream.JoinOptions): string; limit(limit: number): Stream; - partitioningBy(predicate: (elem: T) => boolean): T[][]; - partitionBy(predicate: (elem: T) => boolean): T[][]; + partitioningBy(predicate: Stream.Predicate): T[][]; + partitionBy(predicate: Stream.Predicate): T[][]; partitioningBy(regexp: RegExp): T[][]; partitionBy(regexp: RegExp): T[][]; partitioningBy(size: number): T[][]; partitionBy(size: number): T[][]; - peek(consumer: (elem: T) => void ): Stream; - reduce(identity: T, accumulator: (e1: T, e2: T) => T): T; - reduce(accumulator: (e1: T, e2: T) => T): Stream.Optional; + peek(consumer: Stream.Consumer): Stream; + reduce(identity: T, accumulator: Stream.Accumulator): T; + reduce(accumulator: Stream.Accumulator): Stream.Optional; reverse(): Stream; size(): number; sorted(): Stream; - sorted(comparator: (e1: T, e2: T) => number): Stream; + sorted(comparator: Stream.Comparator): Stream; sort(): Stream; - sort(comparator: (e1: T, e2: T) => number): Stream; + sort(comparator: Stream.Comparator): Stream; shuffle(): Stream; skip(n: number): Stream; slice(begin, end): Stream; sum(): T; - takeWhile(predicate: (elem: T) => boolean): Stream; + takeWhile(predicate: Stream.Predicate): Stream; takeWhile(regexp: RegExp): Stream; toArray(): T[]; - toMap(keyMapper: (elem: T) => string, mergeFunction?: (elem1: T, elem2: T) => T): T[]; + toMap(keyMapper: Stream.Function, mergeFunction?: Stream.Accumulator): T[]; } declare module Stream { - export interface Predicate { - (elem: T): boolean; + export interface Accumulator { + (e1: T, e2: T): T; + } + + export interface Collector { + supplier: Supplier; + accumulator: Stream.Accumulator; + finisher: Function; } + export interface Comparator { + (e1: T, e2: T): number + } + + export interface Consumer { + (elem: T): void; + } + + export interface Function { + (elem: T): U; + } + + export interface GroupingResult { + [index: string]: T + } + export interface Iterator { next(): T; done: boolean; } - + export interface JoinOptions { prefix: string; delimiter: string; suffix: string; } - export interface GroupingResult { - [index: string]: T + export interface Predicate { + (elem: T): boolean; } - - export interface Collector { - supplier(): T; - accumulator(e1: T, e2: T): T; - finisher(result: T): T + + export interface Supplier { + (): T } export class Optional { @@ -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; orElseThrow(error: any): T; } }