mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
adding support for most of the methods receiving sample or path as parameter
This commit is contained in:
parent
f4fd84bb10
commit
bd123fb882
@ -4,19 +4,6 @@ Unsupported StreamJS function / method signatures:
|
||||
* Stream(collection)
|
||||
* Stream(string)
|
||||
* Stream.empty()
|
||||
* filter(sample)
|
||||
* map(path)
|
||||
* flatMap(path)
|
||||
* sorted(path)
|
||||
* takeWhile(sample)
|
||||
* dropWhile(sample)
|
||||
* min(path)
|
||||
* max(path)
|
||||
* sum(path)
|
||||
* average(path)
|
||||
* allMatch(sample)
|
||||
* anyMatch(sample)
|
||||
* groupingBy(path)
|
||||
* toMap(path, mergeFunction)
|
||||
* partitioningBy(sample);
|
||||
* Optional.empty()
|
||||
|
||||
@ -22,8 +22,10 @@ var strStream = numStream
|
||||
.limit(100)
|
||||
.sorted()
|
||||
.sort()
|
||||
.sort("propName")
|
||||
.sorted(comparator)
|
||||
.sort(comparator)
|
||||
.sorted("propName")
|
||||
.shuffle()
|
||||
.reverse()
|
||||
.distinct()
|
||||
@ -47,8 +49,11 @@ opt = strStream.min();
|
||||
opt = strStream.min((s1, s2) => 0);
|
||||
|
||||
var sum = numStream.sum();
|
||||
sum = numStream.sum("foo");
|
||||
var avg = numStream.average();
|
||||
avg = numStream.average("foo");
|
||||
avg = numStream.avg();
|
||||
avg = numStream.avg("foo");
|
||||
|
||||
var count = numStream.count();
|
||||
count = numStream.size();
|
||||
@ -78,6 +83,13 @@ elems = myStream
|
||||
.toArray();
|
||||
//.forEach(s => console.log(s));
|
||||
|
||||
myStream = myStream.takeWhile({name: "foo"});
|
||||
myStream = myStream.dropWhile({name: "foo"});
|
||||
myStream = myStream.filter({name: "foo"});
|
||||
var myResult = myStream.min("name");
|
||||
myResult = myStream.max("name");
|
||||
var match: boolean = myStream.allMatch({name: "foo"});
|
||||
match = myStream.anyMatch({name: "foo"});
|
||||
|
||||
numStream.collect({
|
||||
supplier: () => 0,
|
||||
@ -88,9 +100,13 @@ numStream.collect({
|
||||
var groupingResult = myStream.groupBy(lst => lst.name);
|
||||
var elems = groupingResult["hello"].elems;
|
||||
groupingResult = myStream.groupingBy(lst => lst.name);
|
||||
groupingResult = myStream.groupBy("name");
|
||||
groupingResult = myStream.groupingBy("name");
|
||||
|
||||
var mappingResult = myStream.toMap(lst => lst.name, (e1, e2) => e2);
|
||||
console.log(mappingResult["a"]);
|
||||
var aMappingResult: MyList = mappingResult["a"];
|
||||
|
||||
mappingResult = myStream.toMap("a");
|
||||
|
||||
myStream.toMap(lst => lst.name);
|
||||
|
||||
@ -104,6 +120,9 @@ partitionedStrings = strStream.partitioningBy(/^a$/);
|
||||
partitionedStrings = strStream.partitioningBy(5);
|
||||
partitionedStrings = strStream.partitionBy(5);
|
||||
|
||||
var partitionedList: MyList[][] = myStream.partitionBy({name : "foo"});
|
||||
partitionedList = myStream.partitioningBy({name : "foo"});
|
||||
|
||||
var s: string = numStream.joining();
|
||||
s = numStream.join();
|
||||
s = numStream.joining(", ");
|
||||
@ -131,3 +150,5 @@ optNum.ifPresent(n => console.log(n));
|
||||
var def: number = optNum.orElse(2);
|
||||
def = optNum.orElseGet(() => 3);
|
||||
def = optNum.orElseThrow("something went wrong");
|
||||
|
||||
|
||||
|
||||
25
streamjs/streamjs.d.ts
vendored
25
streamjs/streamjs.d.ts
vendored
@ -1,5 +1,5 @@
|
||||
// Type definitions for streamjs 1.4.0
|
||||
// Project: http://streamjs.org/
|
||||
// Project: https://github.com/winterbe/streamjs
|
||||
// Definitions by: Bence Eros <https://github.com/erosb>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
@ -15,30 +15,40 @@ declare class Stream<T> {
|
||||
|
||||
anyMatch(predicate: Stream.Predicate<T>): boolean;
|
||||
anyMatch(regexp: RegExp): boolean;
|
||||
anyMatch(sample: Stream.Sample): boolean;
|
||||
allMatch(predicate: Stream.Predicate<T>): boolean;
|
||||
allMatch(regexp: RegExp): boolean;
|
||||
allMatch(sample: Stream.Sample): boolean;
|
||||
average(): number;
|
||||
average(path: string): number;
|
||||
avg(): number;
|
||||
avg(path: string): number;
|
||||
collect(collector: Stream.Collector<T>): T;
|
||||
count(): number;
|
||||
distinct(): Stream<T>;
|
||||
dropWhile(predicate: Stream.Predicate<T>): Stream<T>;
|
||||
dropWhile(regexp: RegExp): Stream<string>;
|
||||
dropWhile(sample: Stream.Sample): Stream<T>;
|
||||
each(consumer: Stream.Consumer<T>): void;
|
||||
filter(predicate: Stream.Predicate<T>): Stream<T>;
|
||||
filter(regexp: RegExp): Stream<string>;
|
||||
filter(sample: Stream.Sample): Stream<T>;
|
||||
findAny(): Stream.Optional<T>;
|
||||
findFirst(): Stream.Optional<T>;
|
||||
forEach(consumer: Stream.Consumer<T>): void;
|
||||
|
||||
groupBy(mapper: Stream.Function<T, string>): Stream.GroupingResult<T>;
|
||||
groupBy(path: string): Stream.GroupingResult<T>;
|
||||
groupingBy(mapper: Stream.Function<T, string>): Stream.GroupingResult<T>;
|
||||
groupingBy(path: 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: Stream.Comparator<T>): Stream.Optional<T>;
|
||||
max(path: string): Stream.Optional<T>;
|
||||
min(): Stream.Optional<T>;
|
||||
min(comparator: Stream.Comparator<T>): Stream.Optional<T>;
|
||||
min(path: string): Stream.Optional<T>;
|
||||
noneMatch(predicate: (elem: T) => boolean): boolean;
|
||||
noneMatch(regexp: RegExp): boolean;
|
||||
flatMap <U> (mapper: Stream.Function<T, U[]>): Stream<U>;
|
||||
@ -52,10 +62,12 @@ declare class Stream<T> {
|
||||
limit(limit: number): Stream<T>;
|
||||
partitioningBy(predicate: Stream.Predicate<T>): T[][];
|
||||
partitionBy(predicate: Stream.Predicate<T>): T[][];
|
||||
partitionBy(sample: Stream.Sample): T[][];
|
||||
partitioningBy(regexp: RegExp): T[][];
|
||||
partitionBy(regexp: RegExp): T[][];
|
||||
partitioningBy(size: number): T[][];
|
||||
partitionBy(size: number): T[][];
|
||||
partitioningBy(sample: Stream.Sample): T[][];
|
||||
peek(consumer: Stream.Consumer<T>): Stream<T>;
|
||||
reduce(identity: T, accumulator: Stream.Accumulator<T>): T;
|
||||
reduce(accumulator: Stream.Accumulator<T>): Stream.Optional<T>;
|
||||
@ -63,21 +75,30 @@ declare class Stream<T> {
|
||||
size(): number;
|
||||
sorted(): Stream<T>;
|
||||
sorted(comparator: Stream.Comparator<T>): Stream<T>;
|
||||
sorted(path: string): Stream<T>;
|
||||
sort(): Stream<T>;
|
||||
sort(comparator: Stream.Comparator<T>): Stream<T>;
|
||||
sort(path: string): Stream<T>;
|
||||
shuffle(): Stream<T>;
|
||||
skip(n: number): Stream<T>;
|
||||
slice(begin, end): Stream<T>;
|
||||
sum(): T;
|
||||
sum(): number;
|
||||
sum(path: string): number;
|
||||
takeWhile(predicate: Stream.Predicate<T>): Stream<T>;
|
||||
takeWhile(regexp: RegExp): Stream<string>;
|
||||
takeWhile(sample: Stream.Sample): Stream<T>;
|
||||
toArray(): T[];
|
||||
toList(): T[];
|
||||
toMap(keyMapper: Stream.Function<T, string>, mergeFunction?: Stream.Accumulator<T>): T[];
|
||||
toMap(path: string, mergeFunction?: Stream.Accumulator<T>): T[];
|
||||
}
|
||||
|
||||
declare module Stream {
|
||||
|
||||
export interface Sample {
|
||||
[index: string]: any
|
||||
}
|
||||
|
||||
export interface Accumulator<T> {
|
||||
(e1: T, e2: T): T;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user