From a5e6460613f138de522206dc1eb9ec5a2211e95a Mon Sep 17 00:00:00 2001 From: Bart van der Schoor Date: Sun, 16 Mar 2014 18:48:56 +0100 Subject: [PATCH] small API updates for highland 1.19.0 --- highland/highland-tests.ts | 31 +++++++++++------ highland/highland.d.ts | 69 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 87 insertions(+), 13 deletions(-) diff --git a/highland/highland-tests.ts b/highland/highland-tests.ts index 7acc6c50b..3625b3f81 100644 --- a/highland/highland-tests.ts +++ b/highland/highland-tests.ts @@ -73,15 +73,15 @@ var barArr: Bar[]; var fooStream: Highland.Stream; var barStream: Highland.Stream; +var fooStreamStream: Highland.Stream>; +var barStreamStream: Highland.Stream>; + var fooArrStream: Highland.Stream; var barArrStream: Highland.Stream; var fooStreamArr: Highland.Stream[]; var barStreamArr: Highland.Stream[]; -var fooStreamArr: Highland.Stream[]; -var barStreamArr: Highland.Stream[]; - var strFooArrMapStream: Highland.Stream; var strBarArrMapStream: Highland.Stream; @@ -184,13 +184,13 @@ strStream = _.keys(obj); anyArrStream = _.pairs(obj); anyArrStream = _.pairs(fooArr); -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - obj = _.extend(obj, obj); objCurObj = _.extend(obj); -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - x = _.get(str, obj); @@ -200,26 +200,26 @@ obj = _.set(str, foo, obj); objCurAny = _.set(str, foo); -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - _.log(str); _.log(str, num, foo); -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - f = _.wrapCallback(func); -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - num = _.add(num, num); numCurNum = _.add(num); -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // instance methods -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - fooStream.pause(); fooStream.resume(); @@ -323,6 +323,10 @@ fooStream = fooStream.flatFilter((x: Foo) => { return boolStream; }); +fooStream = fooStream.reject((x: Foo) => { + return bool; +}); + fooStream = fooStream.find((x: Foo) => { return bool; }); @@ -343,6 +347,7 @@ fooStream = fooStream.where(obj); fooStream = fooStream.zip(fooStream); fooStream = fooStream.zip([foo, foo]); +fooStream = fooStream.head(); fooStream = fooStream.take(num); fooStream = fooStream.last(); @@ -383,6 +388,10 @@ fooStream = fooStream.concat(fooArr); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +fooStream = fooStream.merge(fooStreamStream); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + barStream = fooStream.invoke(str, anyArr); fooStream = fooStream.throttle(num); @@ -393,4 +402,4 @@ fooStream = fooStream.debounce(num); fooStream = fooStream.latest(); -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/highland/highland.d.ts b/highland/highland.d.ts index 252c617ea..8760a5c2d 100644 --- a/highland/highland.d.ts +++ b/highland/highland.d.ts @@ -8,6 +8,7 @@ // TODO export the top-level functions // TODO figure out curry arguments +// TODO create more overloads for nested data, like streams-of-streams or streams-of-array-of-streams etc // TODO use externalised Thenable // TODO use externalised Readable/Writable (not node's) @@ -19,7 +20,6 @@ * Copyright (c) Caolan McMahon * */ - interface HighlandStatic { /** * The Stream constructor, accepts an array of values or a generator function @@ -320,8 +320,9 @@ interface HighlandStatic { * @api public */ add(a: number, b: number): number; - add(a: number): (b: number) => number; + + not(a: any): boolean; } declare module Highland { @@ -660,6 +661,21 @@ declare module Highland { */ flatFilter(f: (x: R) => Stream): Stream; + /** + * The inverse of [filter](#filter). + * + * @id reject + * @section Streams + * @name Stream.reject(f) + * @param {Function} f - the truth test function + * @api public + * + * var odds = _([1, 2, 3, 4]).reject(function (x) { + * return x % 2 === 0; + * }); + */ + reject(f: (x: R) => boolean): Stream; + /** * A convenient form of filter, which returns the first object from a * Stream that passes the provided truth test @@ -733,6 +749,18 @@ declare module Highland { */ take(n: number): Stream; + /** + * Creates a new Stream with only the first value from the source. + * + * @id head + * @section Streams + * @name Stream.head() + * @api public + * + * _([1, 2, 3, 4]).head() // => 1 + */ + head(): Stream; + /** * Drops all values from the Stream apart from the last one (if any). * @@ -871,6 +899,20 @@ declare module Highland { */ scan(memo: U, x: (memo: U, x: R) => U): Stream; + /** + * Same as [scan](#scan), but uses the first element as the initial + * state instead of passing in a `memo` value. + * + * @id scan1 + * @section Streams + * @name Stream.scan1(iterator) + * @param {Function} iterator - the function which reduces the values + * @api public + * + * _([1, 2, 3, 4]).scan1(add) // => 1, 3, 6, 10 + */ + scan1(memo: U, x: (memo: U, x: R) => U): Stream; + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /** @@ -889,6 +931,29 @@ declare module Highland { concat(ys: Stream): Stream; concat(ys: R[]): Stream; + /** + * Takes a Stream of Streams and merges their values and errors into a + * single new Stream. The merged stream ends when all source streams have + * ended. + * + * Note that no guarantee is made with respect to the order in which + * values for each stream end up in the merged stream. Values in the + * merged stream will, however, respect the order they were emitted from + * their respective streams. + * + * @id merge + * @section Streams + * @name Stream.merge() + * @api public + * + * var txt = _(['foo.txt', 'bar.txt']).map(readFile) + * var md = _(['baz.md']).map(readFile) + * + * _([txt, md]).merge(); + * // => contents of foo.txt, bar.txt and baz.txt in the order they were read + */ + merge (ys: Stream>): Stream; + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /**