import { Monad } from "jabz/monad";
import { Observer } from "./frp-common";
import { Future } from "./future";
import { Stream } from "./stream";
/**
* A behavior is a value that changes over time. Conceptually it can
* be though of as a function from time to a value. I.e. `type
* Behavior = (t: Time) => A`.
*/
export declare abstract class Behavior implements Observer, Monad {
pushing: boolean;
last: A;
nrOfListeners: number;
child: Observer;
abstract push(a: any): void;
abstract pull(): A;
constructor();
map(fn: (a: A) => B): Behavior;
mapTo(v: A): Behavior;
static of(v: A): Behavior;
of(v: A): Behavior;
ap(f: Behavior<(a: A) => B>): Behavior;
lift(f: (t: T1) => R, m: Behavior): Behavior;
lift(f: (t: T1, u: T2) => R, m1: Behavior, m2: Behavior): Behavior;
lift(f: (t1: T1, t2: T2, t3: T3) => R, m1: Behavior, m2: Behavior, m3: Behavior): Behavior;
static multi: boolean;
multi: boolean;
chain(fn: (a: A) => Behavior): Behavior;
flatten: () => Behavior;
endPulling(): void;
beginPulling(): void;
subscribe(cb: (a: A) => void): Observer;
addListener(c: Observer): void;
removeListener(listener: Observer): void;
observe(push: (a: A) => void, beginPulling: () => void, endPulling: () => void): CbObserver;
at(): A;
}
export declare function at(b: Behavior): B;
/**
* Apply a function valued behavior to a value behavior.
*
* @param fnB behavior of functions from `A` to `B`
* @param valB A behavior of `A`
* @returns Behavior of the function in `fnB` applied to the value in `valB`
*/
export declare function ap(fnB: Behavior<(a: A) => B>, valB: Behavior): Behavior;
/**
* Creates a behavior for imperative impure pushing.
*/
export declare function sink(initialValue: A): Behavior;
/**
* A placeholder behavior is a behavior without any value. It is used
* to do value recursion in `./framework.ts`.
* @private
*/
export declare class PlaceholderBehavior extends Behavior {
private source;
constructor();
push(v: B): void;
pull(): B;
replaceWith(b: Behavior): void;
}
export declare function placeholder(): PlaceholderBehavior;
export declare function when(b: Behavior): Behavior>;
export declare function snapshotAt(b: Behavior, f: Future): Behavior>;
export declare function switchTo(init: Behavior, next: Future>): Behavior;
export declare function switcher(init: Behavior, stream: Stream>): Behavior>;
export declare function stepper(initial: B, steps: Stream): Behavior;
export declare function scan(fn: (a: A, b: B) => B, init: B, source: Stream): Behavior>;
export declare function toggle(initial: boolean, turnOn: Stream, turnOff: Stream): Behavior;
export declare function fromFunction(fn: () => B): Behavior;
export declare class CbObserver implements Observer {
private _push;
private _beginPulling;
private _endPulling;
private source;
constructor(_push: (a: A) => void, _beginPulling: () => void, _endPulling: () => void, source: Behavior);
push(a: A): void;
beginPulling(): void;
endPulling(): void;
}
/**
* Observe a behavior for the purpose of executing imperative actions
* based on the value of the behavior.
*/
export declare function observe(push: (a: A) => void, beginPulling: () => void, endPulling: () => void, b: Behavior): CbObserver;
/**
* Imperatively push a value into a behavior.
*/
export declare function publish(a: A, b: Behavior): void;
export declare function isBehavior(b: any): b is Behavior;
export declare type Time = number;
export declare const time: Behavior