diff --git a/baconjs/baconjs-tests.ts b/baconjs/baconjs-tests.ts
new file mode 100644
index 0000000000..e542ef1c9f
--- /dev/null
+++ b/baconjs/baconjs-tests.ts
@@ -0,0 +1,386 @@
+///
+
+function CreatingStreams() {
+ $("#my-div").asEventStream("click");
+ $("#my-div").asEventStream("click", ".more-specific-selector");
+ $("#my-div").asEventStream("click", (event, args) => args[0]);
+ $("#my-div").asEventStream("click", ".more-specific-selector", (event, args) => args[0]);
+
+ Bacon.fromPromise($.ajax("https://baconjs.github.io/"));
+ Bacon.fromPromise(Promise.resolve(1));
+
+ Bacon.fromPromise($.ajax("https://baconjs.github.io/"), true);
+ Bacon.fromPromise(Promise.resolve(1), false);
+
+ Bacon.fromPromise($.ajax("https://baconjs.github.io/"), true, (n:string) => {
+ return [new Bacon.Next(n), new Bacon.Next(() => n), new Bacon.End()];
+ });
+ Bacon.fromPromise(Promise.resolve(1), false, n => {
+ return [new Bacon.Next(n), new Bacon.Next(() => n), new Bacon.End()];
+ });
+
+ Bacon.fromEvent(document.body, "click").onValue(() => {
+ alert("Bacon!");
+ });
+ Bacon.fromEvent(document.body, "click", (event:MouseEvent) => event.clientX).onValue(clientX => {
+ alert("Bacon!");
+ });
+ Bacon.fromEvent(process.stdin, "readable", () => {
+ alert("Bacon!");
+ });
+
+ // This would create a stream that outputs a single value "Bacon!" and ends after that. The use of setTimeout causes the value to be delayed by 1 second.
+ Bacon.fromCallback(callback => {
+ setTimeout(() => {
+ callback("Bacon!");
+ }, 1000);
+ });
+
+ // You can also give any number of arguments to `fromCallback`, which will be passed to the function. These arguments can be simple variables, Bacon EventStreams or Properties. For example the following will output "Bacon rules":
+ Bacon.fromCallback((a, b, callback) => {
+ callback(a + " " + b);
+ }, Bacon.constant("bacon"), "rules").log();
+
+ {
+ var fs = require("fs"),
+ read = Bacon.fromNodeCallback(fs.readFile, "input.txt");
+ read.onError(error => {
+ console.log("Reading failed: " + error);
+ });
+ read.onValue(value => {
+ console.log("Read contents: " + value);
+ });
+ }
+
+ Bacon.once(new Bacon.Error("fail"));
+
+ // The following would lead to `1,2,3,1,2,3...` to be repeated indefinitely:
+ Bacon.fromArray([1, new Bacon.Error("")]);
+
+ Bacon.repeatedly(10, [1, 2, 3]);
+
+ // The following will produce values `0,1,2`.
+ Bacon.repeat(i => {
+ if (i < 3) {
+ return Bacon.once(i);
+ } else {
+ return false;
+ }
+ }).log();
+
+ {
+ var stream = Bacon.fromBinder(sink => {
+ sink("first value");
+ sink([new Bacon.Next("2nd"), new Bacon.Next("3rd")]);
+ sink(new Bacon.Next(() => {
+ return "This one will be evaluated lazily"
+ }));
+ sink(new Bacon.Error("oops, an error"));
+ sink(new Bacon.End());
+ return () => {
+ // unsub functionality here, this one's a no-op
+ };
+ });
+ stream.log();
+ }
+
+ new Bacon.Next("value");
+ new Bacon.Next(() => "value");
+}
+
+function CommonMethodsInEventStreamsAndProperties() {
+ // Converting strings to integers, skipping empty values:
+ Bacon.once("").flatMap(text => {
+ return text != "" ? parseInt(text) : Bacon.never();
+ });
+
+ Bacon.sequentially(1, [1, 2, 3]).scan(0, (a, b) => a + b);
+
+ Bacon.sequentially(1, [1, 2, 3]).diff(0, (a, b) => Math.abs(b - a));
+
+ // If you have a EventStream `s` with a value sequence `1,2,3,4,5`, the respective values in `s.slidingWindow(2)` would be `[],[1],[1,2],[2,3],[3,4],[4,5]`:
+ Bacon.fromArray([1, 2, 3, 4, 5]).slidingWindow(2);
+ // The values of `s.slidingWindow(2,2)`would be `[1,2],[2,3],[3,4],[4,5]`:
+ Bacon.fromArray([1, 2, 3, 4, 5]).slidingWindow(2, 2);
+
+ {
+ var x = Bacon.fromArray([1, 2]), y = Bacon.fromArray([3, 4]);
+ x.zip(y, (x, y) => x + y);
+ }
+
+ {
+ var stream = Bacon.fromArray([1, 2]);
+ stream.log("New event in myStream");
+ stream.log();
+ }
+
+ Bacon.fromArray([1, 2, 3]).withStateMachine(0, (sum, event) => {
+ if (event.hasValue()) {
+ // had to cast to `number` because event:Bacon.Next|Bacon.Error<{}>
+ return [sum + event.value(), []];
+ }
+ else if (event.isEnd()) {
+ return [undefined, [new Bacon.Next(sum), event]];
+ }
+ else {
+ return [sum, [event]];
+ }
+ });
+
+ {
+ var property = Bacon.fromArray([1, 2, 3]).toProperty(),
+ who = Bacon.fromArray(["A", "B", "C"]).toProperty();
+ property.decode({1: "mike", 2: who});
+
+ property.decode({1: {type: "mike"}, 2: {type: "other", whoThen: who}});
+ }
+
+ {
+ // This is handy for keeping track whether we are currently awaiting an AJAX response:
+ var ajaxRequest = >{},
+ ajaxResponse = >{},
+ showAjaxIndicator = ajaxRequest.awaiting(ajaxResponse);
+ }
+
+ Bacon.fromArray([1, 2, -3, 3]).withHandler(function (event) {
+ if (event.hasValue() && event.value() < 0) {
+ this.push(new Bacon.Error("Value below zero"));
+ return this.push(new Bacon.End());
+ } else {
+ return this.push(event);
+ }
+ });
+
+ {
+ var src = Bacon.once(1),
+ obs = src.map(x => -x);
+ console.log(obs.toString()); // > "Bacon.once(1).map(function)"
+
+ obs.withDescription(src, "times", -1);
+ console.log(obs.toString()); // > "Bacon.once(1).times(-1)"
+ }
+
+ {
+ // Calculator for grouped consecutive values until group is cancelled:
+ var events = [
+ {id: 1, type: "add", val: 3},
+ {id: 2, type: "add", val: -1},
+ {id: 1, type: "add", val: 2},
+ {id: 2, type: "cancel"},
+ {id: 3, type: "add", val: 2},
+ {id: 3, type: "cancel"},
+ {id: 1, type: "add", val: 1},
+ {id: 1, type: "add", val: 2},
+ {id: 1, type: "cancel"}
+ ],
+ keyF = (event:{id:number}) => event.id,
+ limitF = (groupedStream:Bacon.EventStream) => {
+ var cancel = groupedStream.filter(x => x.type === "cancel").take(1),
+ adds = groupedStream.filter(x => x.type === "add");
+ return adds.takeUntil(cancel).map(x => x.val);
+ };
+
+ Bacon.sequentially(2, events)
+ .groupBy(keyF, limitF)
+ .flatMap(groupedStream => groupedStream.fold(0, (acc, x) => acc + x))
+ .onValue(sum => {
+ console.log(sum); // returns [-1, 2, 8] in an order
+ });
+ }
+}
+
+function EventStream() {
+ // This creates the stream which doesn't produce any events and never ends:
+ Bacon.interval(1e1, 0).last();
+
+ Bacon.fromArray([1, 2, 2, 1])
+ .skipDuplicates().log(); // > returns [1, 2, 1] in an order
+
+ // You might get two events containing [1,2,3,4] and [5,6,7] respectively, given that the flush occurs between numbers 4 and 5:
+ Bacon.fromArray([1, 2, 3, 4, 5, 6, 7]).bufferWithTime(0);
+
+ // Here's an equivalent to `stream.bufferWithTime(10)`:
+ {
+ var stream = Bacon.fromArray([1, 2, 3, 4, 5, 6, 7]);
+ stream.bufferWithTime(f => {
+ setTimeout(f, 10);
+ });
+ }
+
+ // You will get output events with values `[1, 2]`, `[3, 4]` and `[5]`.
+ Bacon.fromArray([1, 2, 3, 4, 5]).bufferWithCount(2);
+}
+
+function Property() {
+ // This creates the property which doesn't produce any events and never ends:
+ Bacon.interval(1e1, 0).toProperty().last();
+
+ {
+ var property = Bacon.fromArray([1, 2, 3, 4, 5]).toProperty();
+ // If you want to assign your Property to the "disabled" attribute of a JQuery object, you can do this:
+ property.assign($("#my-button"), "attr", "disabled");
+
+ // A simpler example would be to toggle the visibility of an element based on a Property:
+ property.assign($("#my-button"), "toggle");
+ }
+
+ Bacon.fromArray([1, 2, 2, 1]).toProperty()
+ .skipDuplicates().log(); // > returns [1, 2, 1] in an order
+}
+
+function CombiningMultipleStreamsAndProperties() {
+ {
+ var property = Bacon.constant(1),
+ stream = Bacon.once(2),
+ constant = 3;
+ Bacon.combineAsArray(property, stream, constant)
+ .log(); // > returns [1, 2, 3]
+ }
+
+ {
+ // To calculate the current sum of three numeric Properties, you can do:
+ var property = Bacon.constant(1),
+ stream = Bacon.once(2),
+ constant = 3;
+ // NOTE: had to explicitly specify the typing for `x:number, y:number, z:number`
+ Bacon.combineWith((x:number, y:number, z:number) => x + y + z, property, stream, constant);
+ }
+
+ {
+ // Assuming you've got streams or properties named `password`, `username`, `firstname` and `lastname`, you can do:
+ var password = Bacon.constant("easy"),
+ username = Bacon.constant("juha"),
+ firstname = Bacon.constant("juha"),
+ lastname = Bacon.constant("paananen"),
+ // NOTE: you should provide `combineTemplate` typing explicitly!
+ loginInfo = Bacon.combineTemplate({
+ magicNumber: 3,
+ userid: username,
+ passwd: password,
+ name: {first: firstname, last: lastname}
+ }).onValue(loginInfo => {
+ // and your new `loginInfo` property will combine values from all these streams using that template, whenever any of the streams/properties get a new value. It would yield a value:
+ console.log("`loginInfo` expected", {
+ magicNumber: 3,
+ userid: "juha",
+ passwd: "easy",
+ name: {first: "juha", last: "paananen"}
+ });
+ console.log("`loginInfo` actual", loginInfo);
+ });
+
+ // Note that all Bacon.combine* methods produce a `Property` instead of an `EventStream`. If you need the result as an `EventStream` you might want to use `property.changes()`:
+ Bacon.combineWith((firstname, lastname) => `${firstname} ${lastname}`, firstname, lastname).changes();
+ }
+
+ {
+ var x = Bacon.fromArray([1, 2, 3]),
+ y = Bacon.fromArray([10, 20, 30]),
+ z = Bacon.fromArray([100, 200, 300]);
+ Bacon.zipAsArray(x, y, z)
+ .log(); // > returns values `[1, 10, 100]`, `[2, 20, 200]` and `[3, 30, 300]`
+ }
+
+ // The following example would log the number 3.
+ // NOTE: had to explicitly specify the typing for `a:number, b:number`
+ Bacon.onValues(Bacon.constant(1), Bacon.constant(2), (a:number, b:number) => {
+ console.log(a + b);
+ });
+}
+
+function $Event() {
+ new Bacon.Next("value");
+ new Bacon.Next(() => "value");
+}
+
+function Errors() {
+ // In case you want to convert (some) value events into Error events, you may use `flatMap` like this:
+ // NOTE: had to explicitly specify the typing for `flatMap`
+ Bacon.fromArray([1, 2, 3, 4]).flatMap(x => {
+ return x > 2 ? new Bacon.Error("too big") : x;
+ });
+
+ // Conversely, if you want to convert some Error events into value events, you may use `flatMapError`:
+ Bacon.fromArray([1, 2, 3, 4]).flatMapError(error => {
+ var isNonCriticalError = (error:string) => Math.random() < .5,
+ handleNonCriticalError = (error:string) => 42;
+ return isNonCriticalError(error) ? handleNonCriticalError(error) : new Bacon.Error(error);
+ });
+
+ // Note also that Bacon.js combinators do not catch errors that are thrown. Especially `map` doesn't do so. If you want to map things and wrap caught errors into Error events, you can do the following:
+ Bacon.fromArray([1, 2, 3, 4]).flatMap(x => {
+ var dangerousFunction = (x:number) => {
+ throw new Error("dangerous function!");
+ };
+ try {
+ return dangerousFunction(x);
+ } catch (e) {
+ return new Bacon.Error(e);
+ }
+ });
+
+ Bacon.once("https://baconjs.github.io/").flatMap(url => {
+ // `ajaxCall` gives `Error`s on network or server `Error`s.
+ var ajaxCall = (url:string) => {
+ return Bacon.fromPromise($.ajax(url));
+ };
+ return Bacon.retry({
+ source: () => ajaxCall(url),
+ retries: 5,
+ isRetryable: (error:JQueryXHR) => error.status !== 404,
+ delay: context => 100 // Just use the same delay always
+ });
+ });
+}
+
+function JoinPatterns() {
+ {
+ // Consider implementing a game with discrete time ticks. We want to handle key-events synchronized on tick-events, with at most one key event handled per tick. If there are no key events, we want to just process a tick:
+ var tick = Bacon.interval(1e2, 0),
+ keyEvent = Bacon.fromEvent(document.body, "click", _ => Date.now()),
+ handleTick = (_:number) => `timestamp: NONE`,
+ handleKeyEvent = (timestamp:number) => `timestamp: ${timestamp}`;
+ Bacon.when(
+ [tick, keyEvent], (_:number, timestamp:number) => handleKeyEvent(timestamp),
+ [tick], handleTick
+ );
+ // Order is important here. If the [tick] patterns had been written first, this would have been tried first, and preferred at each tick.
+ }
+
+ {
+ // Join patterns are indeed a generalization of `zip`, and `zip` is equivalent to a single-rule join pattern. The following `Observable`s have the same output:
+ var a = Bacon.once("a"),
+ b = Bacon.once("b"),
+ c = Bacon.once("c"),
+ f = (a:string, b:string, c:string) => `a = ${a}; b = ${b}; c = ${c}.`;
+ Bacon.zipWith(f, a, b, c);
+ Bacon.when([a, b, c], f);
+ }
+ {
+ // The inputs to `Bacon.update` are defined like this:
+ var initial = 0,
+ x = Bacon.interval(1e3, 1),
+ y = Bacon.interval(2e3, 1),
+ z = Bacon.interval(1.5e3, 1);
+ // NOTE: had to explicitly specify the typing for `previous:number`
+ Bacon.update(initial,
+ [x, y, z], (previous:number, x:number, y:number, z:number) => previous + x + y + z,
+ [x, y], (previous:number, x:number, y:number) => previous + x + y
+ );
+ // As input, each function above will get the previous value of the `result` Property, along with values from the listed Observables. The value returned by the function will be used as the next value of `result`. Just like in `Bacon.when`, only EventStreams will trigger an update, while Properties will be just sampled. So, if you list a single EventStream and several Properties, the value will be updated only when an event occurs in the EventStream.
+ }
+ {
+ // Here's a simple gaming example:
+ var scoreMultiplier = Bacon.constant(1),
+ hitUfo = new Bacon.Bus(),
+ hitMotherShip = new Bacon.Bus(),
+ score = Bacon.update(0,
+ [hitUfo, scoreMultiplier], (score:number, _:number, multiplier:number) => score + 100 * multiplier,
+ [hitMotherShip], (score:number, _:number) => score + 2000
+ );
+ // In the example, the `score` property is updated when either `hitUfo` or `hitMotherShip` occur. The `scoreMultiplier` Property is sampled to take multiplier into account when `hitUfo` occurs.
+ }
+}
diff --git a/baconjs/baconjs.d.ts b/baconjs/baconjs.d.ts
new file mode 100644
index 0000000000..0e3f77c127
--- /dev/null
+++ b/baconjs/baconjs.d.ts
@@ -0,0 +1,2746 @@
+// Type definitions for Bacon.js 0.7.0
+// Project: https://baconjs.github.io/
+// Definitions by: Alexander Matsievsky
+// Definitions: https://github.com/borisyankov/DefinitelyTyped
+
+///
+///
+///
+
+interface JQuery {
+ /**
+ * @method
+ * @description Creates an [EventStream]{@link Bacon.EventStream} from events on a jQuery or Zepto.js object.
+ * @param {string} eventName
+ * @returns {EventStream}
+ * @example
+ * $("#my-div").asEventStream("click");
+ */
+ asEventStream(eventName:string):Bacon.EventStream;
+
+ /**
+ * @method
+ * @description Creates an [EventStream]{@link Bacon.EventStream} from events on a jQuery or Zepto.js object. You can pass an argument to add a jQuery live `selector`.
+ * @param {string} eventName
+ * @param {string} selector
+ * @returns {EventStream}
+ * @example
+ * $("#my-div").asEventStream("click", ".more-specific-selector");
+ */
+ asEventStream(eventName:string, selector:string):Bacon.EventStream;
+
+ /**
+ * @callback JQuery#asEventStream1~f
+ * @param {JQueryEventObject} event
+ * @param {*[]} args
+ * @returns {A}
+ */
+ /**
+ * @method JQuery#asEventStream1
+ * @description Creates an [EventStream]{@link Bacon.EventStream} from events on a jQuery or Zepto.js object. You can pass an argument to add a function `f` that processes the jQuery event and its parameters.
+ * @param {string} eventName
+ * @param {JQuery#asEventStream1~f} f
+ * @returns {EventStream}
+ * @example
+ * $("#my-div").asEventStream("click", (event, args) => args[0]);
+ */
+ asEventStream(eventName:string, f:(event:JQueryEventObject, args:any[]) => A):Bacon.EventStream;
+
+ /**
+ * @callback JQuery#asEventStream2~f
+ * @param {JQueryEventObject} event
+ * @param {*[]} args
+ * @returns {A}
+ */
+ /**
+ * @method JQuery#asEventStream2
+ * @description Creates an [EventStream]{@link Bacon.EventStream} from events on a jQuery or Zepto.js object. You can pass an argument to add a jQuery live `selector` and a function `f` that processes the jQuery event and its parameters.
+ * @param {string} eventName
+ * @param {string} selector
+ * @param {JQuery#asEventStream2~f} f
+ * @returns {Bacon.EventStream}
+ * @example
+ * $("#my-div").asEventStream("click", ".more-specific-selector", (event, args) => args[0]);
+ */
+ asEventStream(eventName:string, selector:string, f:(event:JQueryEventObject, args:any[]) => A):Bacon.EventStream;
+}
+
+/** @module Bacon */
+declare module Bacon {
+ /**
+ * @function
+ * @description Creates an [EventStream]{@link Bacon.EventStream} from a `promise` Promise object such as JQuery Ajax. This stream will contain a single value or an error, followed immediately by stream end. You can use the optional `abort` flag (i.e. ´Bacon.fromPromise(p, true)´ to have the `abort` method of the given promise be called when all subscribers have been removed from the created stream.
+ * @param {Promise|JQueryXHR} promise
+ * @param {boolean} [abort]
+ * @returns {EventStream}
+ * @example
+ * Bacon.fromPromise($.ajax("https://baconjs.github.io/"));
+ * Bacon.fromPromise(Promise.resolve(1));
+ * Bacon.fromPromise($.ajax("https://baconjs.github.io/"), true);
+ * Bacon.fromPromise(Promise.resolve(1), false);
+ */
+ function fromPromise(promise:Promise|JQueryXHR, abort?:boolean):EventStream;
+
+ /**
+ * @callback Bacon.fromPromise~eventTransformer
+ * @param {A} value
+ * @returns {(Initial|Next|End|Error)[]}
+ */
+ /**
+ * @function Bacon.fromPromise
+ * @description Creates an [EventStream]{@link Bacon.EventStream} from a `promise` Promise object such as JQuery Ajax. This stream will contain a single value or an error, followed immediately by stream end. You can use the `abort` flag (i.e. ´Bacon.fromPromise(p, true)´ to have the `abort` method of the given promise be called when all subscribers have been removed from the created stream, and also pass a function `eventTransformer` that transforms the promise value into Events. The default is to transform the value into `[new Bacon.Next(value), new Bacon.End()]`.
+ * @param {Promise|JQueryXHR} promise
+ * @param {boolean} abort
+ * @param {Bacon.fromPromise~eventTransformer} eventTransformer
+ * @returns {EventStream}
+ * @example
+ * Bacon.fromPromise($.ajax("https://baconjs.github.io/"), true, (n:string) => {
+ * return [new Bacon.Next(n), new Bacon.Next(() => n), new Bacon.End()];
+ * });
+ * Bacon.fromPromise(Promise.resolve(1), false, n => {
+ * return [new Bacon.Next(n), new Bacon.Next(() => n), new Bacon.End()];
+ * });
+ */
+ function fromPromise(promise:Promise|JQueryXHR, abort:boolean, eventTransformer:(value:A) => (Initial|Next|End|Error)[]):EventStream;
+
+ /**
+ * @function
+ * @description Creates an [EventStream]{@link Bacon.EventStream} from events on a DOM EventTarget or Node.JS EventEmitter object, or an object that supports event listeners using `on`/`off` methods.
+ * @param {EventTarget|NodeJS.EventEmitter} target
+ * @param {string} eventName
+ * @returns {EventStream}
+ * @example
+ * Bacon.fromEvent(document.body, "click").onValue(() => {
+ * alert("Bacon!");
+ * });
+ * Bacon.fromEvent(process.stdin, "readable", () => {
+ * alert("Bacon!");
+ * });
+ */
+ function fromEvent(target:EventTarget|NodeJS.EventEmitter, eventName:string):EventStream;
+
+ /**
+ * @callback Bacon.fromEvent~eventTransformer
+ * @param {A} event
+ * @returns {B}
+ */
+ /**
+ * @function Bacon.fromEvent
+ * @description Creates an [EventStream]{@link Bacon.EventStream} from events on a DOM EventTarget or Node.JS EventEmitter object, or an object that supports event listeners using `on`/`off` methods. You can pass a function `eventTransformer` that transforms the emitted events' parameters.
+ * @param {EventTarget|NodeJS.EventEmitter} target
+ * @param {string} eventName
+ * @param {Bacon.fromEvent~eventTransformer} eventTransformer
+ * @returns {EventStream}
+ * @example
+ * Bacon.fromEvent(document.body, "click", (event:MouseEvent) => event.clientX).onValue(clientX => {
+ * alert("Bacon!");
+ * });
+ */
+ function fromEvent(target:EventTarget|NodeJS.EventEmitter, eventName:string, eventTransformer:(event:A) => B):EventStream;
+
+ /**
+ * @callback Bacon.fromCallback1~f
+ * @param {Bacon.fromCallback1~callback} callback
+ * @returns {void}
+ */
+ /**
+ * @callback Bacon.fromCallback1~callback
+ * @param {...*} args
+ * @returns {void}
+ */
+ /**
+ * @function Bacon.fromCallback1
+ * @description Creates an [EventStream]{@link Bacon.EventStream} from a function `f` that accepts a `callback`. The function is supposed to call its callback just once.
+ * @param {Bacon.fromCallback1~f} f
+ * @returns {EventStream}
+ * @example
+ * // This would create a stream that outputs a single value "Bacon!" and ends after that. The use of setTimeout causes the value to be delayed by 1 second.
+ * Bacon.fromCallback(callback => {
+ * setTimeout(() => {
+ * callback("Bacon!");
+ * }, 1000);
+ * });
+ */
+ function fromCallback(f:(callback:(...args:any[]) => void) => void):EventStream;
+
+ /**
+ * @callback Bacon.fromCallback2~f
+ * @param {...*} args
+ * @returns {void}
+ */
+ /**
+ * @function Bacon.fromCallback2
+ * @description Creates an [EventStream]{@link Bacon.EventStream} from a function `f` that accepts a `callback`. The function is supposed to call its callback just once.
+ * @param {Bacon.fromCallback2~f} f
+ * @param {...*} args
+ * @returns {EventStream}
+ * @example
+ * // You can also give any number of arguments to `fromCallback`, which will be passed to the function. These arguments can be simple variables, Bacon EventStreams or Properties. For example the following will output "Bacon rules":
+ * Bacon.fromCallback((a, b, callback) => {
+ * callback(a + " " + b);
+ * }, Bacon.constant("bacon"), "rules").log();
+ */
+ function fromCallback(f:(...args:any[]) => void, ...args:any[]):EventStream;
+
+ /**
+ * @function
+ * @description Creates an [EventStream]{@link Bacon.EventStream} from a `methodName` method of a given `object`. The function is supposed to call its callback just once.
+ * @param {Object} object
+ * @param {string} methodName
+ * @param {...*} args
+ * @returns {EventStream}
+ */
+ function fromCallback(object:Object, methodName:string, ...args:any[]):EventStream;
+
+ /**
+ * @callback Bacon.fromNodeCallback~f
+ * @param {Bacon.fromNodeCallback~callback} callback
+ * @returns {void}
+ */
+ /**
+ * @callback Bacon.fromNodeCallback~callback
+ * @param {E} error
+ * @param {A} data
+ * @returns {void}
+ */
+ /**
+ * @function Bacon.fromNodeCallback
+ * @description Creates an [EventStream]{@link Bacon.EventStream} from a function `f` that accepts a Node.js `callback`: callback(error, data), where error is `null` if everything is fine. The function is supposed to call its callback just once.
+ * @param {Bacon.fromNodeCallback~f} f
+ * @param {...*} args
+ * @returns {EventStream}
+ * @example
+ * {
+ * let fs = require("fs"),
+ * read = Bacon.fromNodeCallback(fs.readFile, "input.txt");
+ * read.onError(error => {
+ * console.log("Reading failed: " + error);
+ * });
+ * read.onValue(value => {
+ * console.log("Read contents: " + value);
+ * });
+ * }
+ */
+ function fromNodeCallback(f:(callback:(error:E, data:A) => void) => void, ...args:any[]):EventStream;
+
+ /**
+ * @function
+ * @description Creates an [EventStream]{@link Bacon.EventStream} from a `methodName` method of a given `object`.
+ * @param {Object} object
+ * @param {string} methodName
+ * @param {...*} args
+ * @returns {EventStream}
+ */
+ function fromNodeCallback(object:Object, methodName:string, ...args:any[]):EventStream;
+
+ /**
+ * @callback Bacon.fromPoll~f
+ * @returns {Next|End}
+ */
+ /**
+ * @function Bacon.fromPoll
+ * @description Polls given function `f` with given `interval`. Function should return events: either [Next]{@link Bacon.Next} or [End]{@link Bacon.End}. Polling occurs only when there are subscribers to the stream. Polling ends permanently when `f` returns [End]{@link Bacon.End}.
+ * @param {number} interval
+ * @param {Bacon.fromPoll~f} f
+ * @returns {EventStream}
+ */
+ function fromPoll(interval:number, f:() => Next|End):EventStream;
+
+ /**
+ * @function Bacon.once
+ * @description Creates an [EventStream]{@link Bacon.EventStream} that delivers the given single `value` for the first subscriber. The stream will end immediately after this value. You can also send an [Error]{@link Bacon.Error} event instead of a `value`.
+ * @param {A|Error} value
+ * @returns {EventStream}
+ * @example
+ * Bacon.once(new Bacon.Error("fail"));
+ */
+ function once(value:A|Error):EventStream;
+
+ /**
+ * @function
+ * @description Creates an [EventStream]{@link Bacon.EventStream} that delivers the given series of `values` (given as array) to the first subscriber. The stream ends after these values have been delivered. You can also send [Error]{@link Bacon.Error} events, or any combination of pure values and error events.
+ * @param {(A|Error)[]} values
+ * @returns {EventStream}
+ * @example
+ * Bacon.fromArray([1, new Bacon.Error("")]);
+ */
+ function fromArray(values:(A|Error)[]):EventStream;
+
+ /**
+ * @function
+ * @description Repeats the single `value` indefinitely with the given `interval` (in milliseconds).
+ * @param {number} interval
+ * @param {A} value
+ * @returns {EventStream}
+ */
+ function interval(interval:number, value:A):EventStream;
+
+ /**
+ * @function
+ * @description Creates a [EventStream]{@link Bacon.EventStream} containing given `values` (given as array) with the given `interval` (in milliseconds).
+ * @param {number} interval
+ * @param {A[]} values
+ * @returns {EventStream}
+ */
+ function sequentially(interval:number, values:A[]):EventStream;
+
+ /**
+ * @function
+ * @description Repeats given `values` indefinitely with then given `interval` (in milliseconds).
+ * @param {number} interval
+ * @param {A[]} values
+ * @returns {EventStream}
+ * @example
+ * // The following would lead to `1,2,3,1,2,3...` to be repeated indefinitely:
+ * Bacon.fromArray([1, new Bacon.Error("")]);
+ */
+ function repeatedly(interval:number, values:A[]):EventStream;
+
+ /**
+ * @callback Bacon.repeat~f
+ * @param {number} iteration
+ * @returns {boolean|Observable}
+ */
+ /**
+ * @function Bacon.repeat
+ * @description Calls generator function `f` which is expected to return an [Observable]{@link Bacon.Observable}. The returned [EventStream]{@link Bacon.EventStream} contains values and errors from the spawned observable. When the spawned Observable ends, the generator `f` is called again to spawn a new Observable. This is repeated until the generator `f` returns a falsy value (such as `undefined` or `false`). The generator `f` is called with one argument — `iteration` number starting from `0`.
+ * @param {Bacon.repeat~f} f
+ * @returns {EventStream}
+ * @example
+ * // The following will produce values `0,1,2`.
+ * Bacon.repeat(i => {
+ * if (i < 3) {
+ * return Bacon.once(i);
+ * } else {
+ * return false;
+ * }
+ * }).log();
+ */
+ function repeat(f:(iteration:number) => boolean|Observable):EventStream;
+
+ /**
+ * @function Bacon.never
+ * @description Creates an [EventStream]{@link Bacon.EventStream} that immediately ends.
+ * @returns {EventStream}
+ */
+ function never():EventStream;
+
+ /**
+ * @function
+ * @description Creates a single-element [EventStream]{@link Bacon.EventStream} that produces given `value` after a given `delay` (in milliseconds).
+ * @param {number} delay
+ * @param {A} value
+ * @returns {EventStream}
+ */
+ function later(delay:number, value:A):EventStream;
+
+ /**
+ * @function
+ * @description Creates a constant [Property]{@link Bacon.Property} with value `x`.
+ * @param {A} x
+ * @returns {Property}
+ */
+ function constant(x:A):Property;
+
+ /**
+ * @callback Bacon.fromBinder~subscribe
+ * @param {Bacon.fromBinder~sink} sink
+ * @returns {Bacon.fromBinder~unsubscribe}
+ */
+ /**
+ * @callback Bacon.fromBinder~sink
+ * @param {More|NoMore|(A|Initial|Next|End|Error)|(A|Initial|Next|End|Error)[]} value
+ * @returns {void}
+ */
+ /**
+ * @callback Bacon.fromBinder~unsubscribe
+ * @returns {void}
+ */
+ /**
+ * @function Bacon.fromBinder
+ * @description Creates an [EventStream]{@link Bacon.EventStream} with the given [subscribe]{@link Bacon.fromBinder~subscribe} function. The parameter `subscribe` is a function that accepts a [sink]{@link Bacon.fromBinder~sink} which is a function that your `subscribe` function can "push" events to. You can push: a plain value, like `"first value"`; an [Event]{@link Bacon.Event} object including [Error]{@link Bacon.Error} (wraps an error) and [End]{@link Bacon.End} (indicates stream end); an array of event objects at once. The `subscribe` function must return a function. Let's call that function [unsubscribe]{@link Bacon.fromBinder~unsubscribe}. The returned function can be used by the subscriber (directly or indirectly) to unsubscribe from the EventStream. It should release all resources that the `subscribe` function reserved. The `sink` function may return [noMore]{@link Bacon.noMore} (as well as [more]{@link Bacon.more} or any other value). If it returns `noMore`, no further events will be consumed by the subscriber. The `subscribe` function may choose to clean up all resources at this point (e.g., by calling `unsubscribe`). This is usually not necessary, because further calls to `sink` are ignored, but doing so can increase performance in rare cases. The EventStream will wrap your `subscribe` function so that it will only be called when the first stream listener is added, and the `unsubscribe` function is called only after the last listener has been removed. The subscribe-unsubscribe cycle may of course be repeated indefinitely, so prepare for multiple calls to the `subscribe` function.
+ * @param {Bacon.fromBinder~subscribe} subscribe
+ * @returns {EventStream}
+ * @example
+ * let stream = Bacon.fromBinder(sink => {
+ * sink("first value");
+ * sink([new Bacon.Next("2nd"), new Bacon.Next("3rd")]);
+ * sink(new Bacon.Next(() => {
+ * return "This one will be evaluated lazily"
+ * }));
+ * sink(new Bacon.Error("oops, an error"));
+ * sink(new Bacon.End());
+ * return () => {
+ * // unsub functionality here, this one's a no-op
+ * };
+ * });
+ * stream.log();
+ */
+ function fromBinder(subscribe:(sink:(value:More|NoMore|(A|Initial|Next|End|Error)|(A|Initial|Next|End|Error)[]) => void) => (() => void)):EventStream;
+
+ /**
+ * @interface
+ * @see Bacon.more
+ */
+ interface More {
+ }
+ /**
+ * @property more
+ * @constant
+ * @description The opaque value `sink` function may return. See [Bacon.fromBinder]{@link Bacon.fromBinder}.
+ */
+ var more:More;
+
+ /**
+ * @interface
+ * @see Bacon.noMore
+ */
+ interface NoMore {
+ }
+ /**
+ * @property noMore
+ * @constant
+ * @description The opaque value `sink` function may return. See [Bacon.fromBinder]{@link Bacon.fromBinder}.
+ */
+ var noMore:NoMore;
+
+ /**
+ * @class Observable
+ * @description A superclass for [EventStream]{@link Bacon.EventStream} and [Property]{@link Bacon.Property}.
+ * */
+ interface Observable {
+ /**
+ * @callback Observable#onValue~f
+ * @param {A} value
+ * @returns {void}
+ */
+ /**
+ * @callback Observable#onValue~unsubscribe
+ * @returns {void}
+ */
+ /**
+ * @method Observable#onValue
+ * @description Subscribes a given handler function `f` to the [Observable]{@link Bacon.Observable}. Function will be called for each new value. This is the simplest way to assign a side-effect to an Observable. The difference to the [EventStream.subscribe]{@link Bacon.EventStream#subscribe} and [Property.subscribe]{@link Bacon.Property#subscribe} methods is that the actual stream `value`s are received, instead of [Event]{@link Bacon.Event} objects. [EventStream.onValue]{@link Bacon.EventStream#onValue} and [Property.onValue]{@link Bacon.Property#onValue} behave similarly, except that the latter also pushes the initial value of the Property, in case there is one.
+ * @param {Observable#onValue~f} f
+ * @returns {Observable#onValue~unsubscribe}
+ */
+ onValue(f:(value:A) => void):() => void;
+
+ /**
+ * @callback Observable#onError~f
+ * @param {E} error
+ * @returns {void}
+ */
+ /**
+ * @callback Observable#onError~unsubscribe
+ * @returns {void}
+ */
+ /**
+ * @method Observable#onError
+ * @description Subscribes a given handler function `f` to [Error]{@link Bacon.Error} events. The function `f` will be called for each error in the [Observable]{@link Bacon.Observable}.
+ * @param {Observable#onError~f} f
+ * @returns {Observable#onError~unsubscribe}
+ */
+ onError(f:(error:E) => void):() => void;
+
+ /**
+ * @callback Observable#onEnd~f
+ * @returns {void}
+ */
+ /**
+ * @callback Observable#onEnd~unsubscribe
+ * @returns {void}
+ */
+ /**
+ * @method Observable#onEnd
+ * @description Subscribes a given handler function `f` to [End]{@link Bacon.End} event. The function `f` will be called when the [Observable]{@link Bacon.Observable} ends. Just like [EventStream.subscribe]{@link Bacon.EventStream#subscribe} and [Property.subscribe]{@link Bacon.Property#subscribe}, this method returns a function for `unsubscribe`ing.
+ * @param {Observable#onEnd~f} f
+ * @returns {Observable#onEnd~unsubscribe}
+ */
+ onEnd(f:() => void):() => void;
+
+ /**
+ * @callback Observable#toPromise~promiseCtr
+ * @param {A} value
+ * @returns {Promise}
+ */
+ /**
+ * @method Observable#toPromise
+ * @description Returns a Promise which will be resolved with the last event coming from an [Observable]{@link Bacon.Observable}. The global ES6 promise implementation will be used unless a promise constructor `promiseCtr` is given. Use a shim if you need to support legacy browsers or platforms.
+ * @param {Observable#toPromise~promiseCtr} [promiseCtr]
+ * @returns {Promise}
+ */
+ toPromise(promiseCtr?:(value:A) => Promise):Promise;
+
+ /**
+ * @callback Observable#firstToPromise~promiseCtr
+ * @param {A} value
+ * @returns {Promise}
+ */
+ /**
+ * @method Observable#firstToPromise
+ * @description Returns a Promise which will be resolved with the first event coming from an [Observable]{@link Bacon.Observable}. Like [Observable.toPromise]{@link Bacon.Observable#toPromise}, the global ES6 promise implementation will be used unless a promise constructor `promiseCtr` is given.
+ * @param {Observable#firstToPromise~promiseCtr} [promiseCtr]
+ * @returns {Promise}
+ */
+ firstToPromise(promiseCtr?:(value:A) => Promise):Promise;
+
+ /**
+ * @method
+ * @description Throttles the [Observable]{@link Bacon.Observable} using a buffer so that at most one value event in `minimumInteval` is issued. Unlike [EventStream.throttle]{@link Bacon.EventStream#throttle} and [Property.throttle]{@link Bacon.Property#throttle}, it doesn't discard the excessive events but buffers them instead, outputting them with a rate of at most one value per `minimumInterval`.
+ * @param {number} minimumInterval
+ * @returns {EventStream}
+ */
+ bufferingThrottle(minimumInterval:number):EventStream;
+
+ /**
+ * @callback Observable#flatMap~f
+ * @param {A} value
+ * @returns {B|Initial|Next|End|Error|Observable}
+ */
+ /**
+ * @method Observable#flatMap
+ * @description For each element in the source [Observable]{@link Bacon.Observable}, spawn a new stream using the function `f`, and collect events from each of the spawned streams into the result [EventStream]{@link Bacon.EventStream}. The return value of function `f` can be either an Observable (EventStream/[Property]{@link Bacon.Property}) or a constant value. The result of [flatMap]{@link Bacon.Observable#flatMap} is always an EventStream. The "Function Construction rules" apply here. `flatMap` can be used conveniently with [Bacon.once]{@link Bacon.once} and [Bacon.never]{@link Bacon.never} for converting and filtering at the same time, including only some of the results.
+ * @param {Observable#flatMap~f} f
+ * @returns {EventStream}
+ * @example
+ * // Converting strings to integers, skipping empty values:
+ * Bacon.once("").flatMap(text => {
+ * return text != "" ? parseInt(text) : Bacon.never();
+ * });
+ */
+ flatMap(f:(value:A) => B|Initial|Next|End|Error|Observable):EventStream;
+
+ /**
+ * @callback Observable#flatMapLatest~f
+ * @param {A} value
+ * @returns {B|Initial|Next|End|Error|Observable}
+ */
+ /**
+ * @method Observable#flatMapLatest
+ * @description For each element in the source [Observable]{@link Bacon.Observable}, spawn a new stream using the function `f`, but instead of including events from all spawned streams, only includes them from the latest spawned stream into the result [EventStream]{@link Bacon.EventStream}. The return value of function `f` can be either an Observable (EventStream/[Property]{@link Bacon.Property}) or a constant value. The result of [flatMapLatest]{@link Bacon.Observable#flatMapLatest} is always an EventStream.
+ * @param {Observable#flatMapLatest~f} f
+ * @returns {EventStream}
+ */
+ flatMapLatest(f:(value:A) => B|Initial|Next|End|Error|Observable):EventStream;
+
+ /**
+ * @callback Observable#flatMapFirst~f
+ * @param {A} value
+ * @returns {B|Initial|Next|End|Error|Observable}
+ */
+ /**
+ * @method Observable#flatMapFirst
+ * @description For each element in the source [Observable]{@link Bacon.Observable}, spawn a new stream using the function `f` only if the previously spawned stream has ended, and collect events from each of the spawned streams into the result [EventStream]{@link Bacon.EventStream}. The return value of function `f` can be either an Observable (EventStream/[Property]{@link Bacon.Property}) or a constant value. The result of [flatMapFirst]{@link Bacon.Observable#flatMapFirst} is always an EventStream.
+ * @param {Observable#flatMapFirst~f} f
+ * @returns {EventStream}
+ */
+ flatMapFirst(f:(value:A) => B|Initial|Next|End|Error|Observable):EventStream;
+
+ /**
+ * @callback Observable#flatMapError~f
+ * @param {E} error
+ * @returns {B|Initial|Next|End|Error|Observable}
+ */
+ /**
+ * @method Observable#flatMapError
+ * @description For each [Error]{@link Bacon.Error} event in the source [Observable]{@link Bacon.Observable}, spawn a new stream using the function `f`, and collect events from each of the spawned streams into the result [EventStream]{@link Bacon.EventStream}. The return value of function `f` can be either an Observable (EventStream/[Property]{@link Bacon.Property}) or a constant value. The result of [flatMapError]{@link Bacon.Observable#flatMapError} is always an EventStream.
+ * @param {Observable#flatMapError~f} f
+ * @returns {EventStream}
+ */
+ flatMapError(f:(error:E) => B|Initial|Next|End|Error|Observable):EventStream;
+
+ /**
+ * @callback Observable#flatMapWithConcurrencyLimit~f
+ * @param {A} value
+ * @returns {B|Initial|Next|End|Error|Observable}
+ */
+ /**
+ * @method Observable#flatMapWithConcurrencyLimit
+ * @description For each element in the source [Observable]{@link Bacon.Observable}, spawn a new stream using the function `f`, and collect events from each of the spawned streams into the result [EventStream]{@link Bacon.EventStream}, but limit the number of open spawned streams and buffers incoming events by `limit` amount. The return value of function `f` can be either an Observable (EventStream/[Property]{@link Bacon.Property}) or a constant value. [flatMapConcat]{@link Bacon.Observable#flatMapConcat} is [flatMapWithConcurrencyLimit]{@link Bacon.Observable#flatMapWithConcurrencyLimit}(1) (only one input active), and [flatMap]{@link Bacon.Observable#flatMap} is [flatMapWithConcurrencyLimit]{@link Bacon.Observable#flatMapWithConcurrencyLimit}(∞) (all inputs are piped to output). The result of `flatMapWithConcurrencyLimit` is always an EventStream.
+ * @param {number} limit
+ * @param {Observable#flatMapWithConcurrencyLimit~f} f
+ * @returns {EventStream}
+ */
+ flatMapWithConcurrencyLimit(limit:number, f:(value:A) => B|Initial|Next|End|Error|Observable):EventStream;
+
+ /**
+ * @callback Observable#flatMapConcat~f
+ * @param {A} value
+ * @returns {B|Initial|Next|End|Error|Observable}
+ */
+ /**
+ * @method Observable#flatMapConcat
+ * @description For each element in the source [Observable]{@link Bacon.Observable}, spawn a new stream using the function `f`, and collect events from each of the spawned streams into the result [EventStream]{@link Bacon.EventStream}, but limit the number of open spawned streams and buffers incoming events to 1. The return value of function `f` can be either an Observable (EventStream/[Property]{@link Bacon.Property}) or a constant value. The result of `flatMapConcat` is always an EventStream.
+ * @param {Observable#flatMapConcat~f} f
+ * @returns {EventStream}
+ */
+ flatMapConcat(f:(value:A) => B|Initial|Next|End|Error|Observable):EventStream;
+
+ /**
+ * @callback Observable#scan~f
+ * @param {B} acc
+ * @param {A} next
+ * @returns {B}
+ */
+ /**
+ * @method Observable#scan
+ * @description Scans [Observable]{@link Bacon.Observable} with given `seed` value and accumulator function `f`, resulting to a [Property]{@link Bacon.Property}. For example, you might use zero as `seed` and a "plus" function as the accumulator to create an "integral" Property. When applied to a Property as in `r = p.scan(seed, f)`, there's a (hopefully insignificant) catch: the starting value for `r` depends on whether `p` has an initial value when `scan` is applied. If there's no initial value, this works identically to `[EventStream]{@link Bacon.EventStream}.scan`: the `seed` will be the initial value of `r`. However, if `r` already has a current/initial value `x`, the seed won't be output as is. Instead, the initial value of `r` will be `f(seed, x)`. This makes sense, because there can only be 1 initial value for a Property at a time.
+ * @param {B} seed
+ * @param {Observable#scan~f} f
+ * @returns {Property}
+ * @example
+ * Bacon.sequentially(1, [1, 2, 3]).scan(0, (a, b) => a + b);
+ */
+ scan(seed:B, f:(acc:B, next:A) => B):Property;
+
+ /**
+ * @callback Observable#fold~f
+ * @param {B} acc
+ * @param {A} next
+ * @returns {B}
+ */
+ /**
+ * @method Observable#fold
+ * @description Scans [Observable]{@link Bacon.Observable} with given `seed` value and accumulator function `f`, but only emits the final value, i.e. the value just before the Observable ends. Returns a [Property]{@link Bacon.Property}.
+ * @param {B} seed
+ * @param {Observable#fold~f} f
+ * @returns {Property}
+ */
+ fold(seed:B, f:(acc:B, next:A) => B):Property;
+
+ /**
+ * @callback Observable#reduce~f
+ * @param {B} acc
+ * @param {A} next
+ * @returns {B}
+ */
+ /**
+ * @method Observable#reduce
+ * @description Scans [Observable]{@link Bacon.Observable} with given `seed` value and accumulator function `f`, but only emits the final value, i.e. the value just before the Observable ends. Returns a [Property]{@link Bacon.Property}.
+ * @param {B} seed
+ * @param {Observable#reduce~f} f
+ * @returns {Property}
+ */
+ reduce(seed:B, f:(acc:B, next:A) => B):Property;
+
+ /**
+ * @callback Observable#diff~f
+ * @param {A} a
+ * @param {B} b
+ * @returns {B}
+ */
+ /**
+ * @method Observable#diff
+ * @description Returns a [Property]{@link Bacon.Property} that represents the result of a comparison `f` between the previous and current value of the [Observable]{@link Bacon.Observable}. For the initial value of the Observable, the previous value will be the given `start`.
+ * @param {A} start
+ * @param {Observable#diff~f} f
+ * @returns {Property}
+ * @example
+ * Bacon.sequentially(1, [1, 2, 3]).diff(0, (a, b) => Math.abs(b - a));
+ */
+ diff(start:A, f:(a:A, b:A) => B):Property;
+
+ /**
+ * @callback Observable#zip~f
+ * @param {A} a
+ * @param {B} b
+ * @returns {C}
+ */
+ /**
+ * @method Observable#zip
+ * @description Returns an [EventStream]{@link Bacon.EventStream} with elements pair-wise lined up with events from this and the `other` EventStream. A zipped EventStream will publish only when it has a value from each EventStream and will only produce values up to when any single EventStream ends. The given function `f` is used to create the result value from value in the two source EventStream. If no function `f` is given, the values are zipped into an array. Be careful not to have too much "drift" between streams. If one stream produces many more values than some other excessive buffering will occur inside the zipped observable.
+ * @param {EventStream} other
+ * @param {Observable#zip~f} f
+ * @returns {EventStream}
+ * @example
+ * {
+ * let x = Bacon.fromArray([1, 2]),
+ * y = Bacon.fromArray([3, 4]);
+ * x.zip(y, (x, y) => x + y);
+ * }
+ */
+ zip(other:EventStream, f:(a:A, b:B) => C):EventStream;
+
+ /**
+ * @method
+ * @description Returns a [Property]{@link Bacon.Property} that represents a "sliding window" into the history of the values of the [Observable]{@link Bacon.Observable}. The resulting Property will have a value that is an array containing the last `n` values of the original Observable, where `n` is at most the value of the `max` argument, and at least the value of the `min` argument. If the `min` argument is omitted, there's no lower limit of values.
+ * @param {number} max
+ * @param {number} [min]
+ * @returns {Property}
+ * @example
+ * // If you have a EventStream `s` with a value sequence `1,2,3,4,5`, the respective values in `s.slidingWindow(2)` would be `[],[1],[1,2],[2,3],[3,4],[4,5]`:
+ * Bacon.fromArray([1, 2, 3, 4, 5]).slidingWindow(2);
+ * // The values of `s.slidingWindow(2,2)`would be `[1,2],[2,3],[3,4],[4,5]`:
+ * Bacon.fromArray([1, 2, 3, 4, 5]).slidingWindow(2, 2);
+ */
+ slidingWindow(max:number, min?:number):Property;
+
+ /**
+ * @callback Observable#combine~f
+ * @param {A} a
+ * @param {B} b
+ * @returns {C}
+ */
+ /**
+ * @method Observable#combine
+ * @description Combines the latest values of the two [EventStream]{@link Bacon.EventStream}s or [Property]{@link Bacon.Property}s using a two-arg function `f`. The result is a Property.
+ * @param {Property} property2
+ * @param {Observable#combine~f} f
+ * @returns {Property}
+ */
+ combine(property2:Property, f:(a:A, b:B) => C):Property;
+
+ /**
+ * @callback Observable#withStateMachine~f
+ * @param {B} state
+ * @param {Initial|Next|End|Error} event
+ * @returns {[B, (Initial|Next|End|Error)[]]}
+ */
+ /**
+ * @method Observable#withStateMachine
+ * @description Lets you run a state machine on an [Observable]{@link Bacon.Observable}. Give it an initial state `initState` object and a state transformation function `f` that processes each incoming [Event]{@link Bacon.Event} and returns and array containing the next `state` and an array of output Event's.
+ * @param {B} initState
+ * @param {Observable#withStateMachine~f} f
+ * @returns {EventStream}
+ * @example
+ * // Calculate the total sum of all numbers in the stream and output the value on stream end:
+ * Bacon.fromArray([1, 2, 3]).withStateMachine(0, (sum, event) => {
+ * if (event.hasValue()) {
+ * had to cast to `number` because event:Bacon.Next|Bacon.Error<{}>
+ * return [sum + event.value(), []];
+ * } else if (event.isEnd()) {
+ * return [undefined, [new Bacon.Next(sum), event]];
+ * } else {
+ * return [sum, [event]];
+ * }
+ * });
+ */
+ withStateMachine(initState:B, f:(state:B, event:Initial|Next|End|Error) => [B, (Initial|Next|End|Error)[]]):EventStream;
+
+ /**
+ * @method
+ * @description Decodes input [Observable]{@link Bacon.Observable} using the given `mapping`. Is a bit like a switch-case or the decode function in Oracle SQL. The return value of `decode` is always a [Property]{@link Bacon.Property}.
+ * @param {Object} mapping
+ * @returns {Property}
+ * @example
+ * let property = Bacon.fromArray([1, 2, 3]).toProperty(),
+ * who = Bacon.fromArray(["A", "B", "C"]).toProperty();
+ * // The following would map the value 1 into the string "mike" and the value 2 into the value of the `who` property:
+ * property.decode({1: "mike", 2: who});
+ *
+ * // You can compose static and dynamic data quite freely, as in:
+ * property.decode({1: {type: "mike"}, 2: {type: "other", whoThen: who}});
+ */
+ decode(mapping:Object):Property;
+
+ /**
+ * @method
+ * @description Creates a [Property]{@link Bacon.Property} that indicates whether Observable is awaiting `otherObservable`, i.e. has produced a value after the latest value from `otherObservable`.
+ * @param {Observable} otherObservable
+ * @returns {Property}
+ * @example
+ * // This is handy for keeping track whether we are currently awaiting an AJAX response:
+ * let ajaxRequest = >{},
+ * ajaxResponse = >{},
+ * showAjaxIndicator = ajaxRequest.awaiting(ajaxResponse);
+ */
+ awaiting(otherObservable:Observable):Property;
+ }
+
+ /**
+ * @class EventStream
+ * @augments Bacon.Observable
+ * @description A stream of events.
+ * */
+ interface EventStream extends Observable {
+ /**
+ * @callback EventStream#map~f
+ * @param {A} value
+ * @returns {B}
+ */
+ /**
+ * @method EventStream#map
+ * @description Maps [EventStream]{@link Bacon.EventStream} values using given function `f`, returning a new EventStream. The `map` method, among many others, uses lazy evaluation.
+ * @param {EventStream#map~f} f
+ * @returns {EventStream}
+ * */
+ map(f:(value:A) => B):EventStream;
+
+ /**
+ * @method
+ * @description Maps [EventStream]{@link Bacon.EventStream} values using given `constant` value, returning a new EventStream. The `map` method, among many others, uses lazy evaluation.
+ * @param {B} constant
+ * @returns {EventStream}
+ * */
+ map(constant:B):EventStream;
+
+ /**
+ * @method
+ * @description Maps [EventStream]{@link Bacon.EventStream} values using given `propertyExtractor` string like ".keyCode", returning a new EventStream. So, if `propertyExtractor` is a string starting with a dot, the elements will be mapped to the corresponding field/function in the event value. For instance map(".keyCode") will pluck the keyCode field from the input values. If `keyCode` was a function, the result EventStream would contain the values returned by the function. The "Function Construction rules" apply here. The `map` method, among many others, uses lazy evaluation.
+ * @param {string} propertyExtractor
+ * @returns {EventStream}
+ * */
+ map(propertyExtractor:string):EventStream;
+
+ /**
+ * @method
+ * @description Maps [EventStream]{@link Bacon.EventStream} events to the current value of the given [Property]{@link Bacon.Property} `property`. This is equivalent to [Property.sampledBy]{@link Bacon.Property#sampledBy}.
+ * @param {Property} property
+ * @returns {EventStream