declare module 'fluture' { export interface RejectFunction { (error: L): void } export interface ResolveFunction { (value: R): void } export interface Cancel { (): void } export interface Nodeback { (err: E | null, value?: R): void } export interface Next { done: boolean value: T } export interface Done { done: boolean value: T } export interface Iterator { next(value?: N): Next | Done } export interface Generator { (): Iterator } /** The function is waiting for two more arguments. */ export interface AwaitingTwo { (a: A, b: B): R (a: A): (b: B) => R } /** The function is waiting for three more arguments. */ export interface AwaitingThree { (a: A, b: B, c: C): R (a: A, b: B): (c: C) => R (a: A): AwaitingTwo } export interface ConcurrentFuture { sequential: Future } export interface Future { /** Logical and for Futures. See https://github.com/fluture-js/Fluture#and */ and(right: Future): Future /** Apply the function in this Future to the value in another. See https://github.com/fluture-js/Fluture#ap */ ap(this: Future B>, right: Future): Future /** Map over both branches of the Future at once. See https://github.com/fluture-js/Fluture#bimap */ bimap(lmapper: (reason: L) => LB, rmapper: (value: R) => RB): Future /** Wait for this Future and the given one in parallel. See https://github.com/fluture-js/Fluture#both */ both(right: Future): Future /** Use the resolution value in this Future to create the next Future. See https://github.com/fluture-js/Fluture#chain */ chain(mapper: (value: R) => Future): Future /** Use the rejection reason in this Future to create the next Future. See https://github.com/fluture-js/Fluture#chainrej */ chainRej(mapper: (reason: L) => Future): Future /** The Future constructor */ constructor: Fluture /** Fork the Future into a Node-style callback. See https://github.com/fluture-js/Fluture#done */ done(callback: Nodeback): Cancel /** Attempt to extract the rejection reason. See https://github.com/fluture-js/Fluture#extractleft */ extractLeft(): Array /** Attempt to extract the resolution value. See https://github.com/fluture-js/Fluture#extractright */ extractRight(): Array /** Set up a cleanup Future to run after this one is done. See https://github.com/fluture-js/Fluture#finally */ finally(cleanup: Future): Future /** Fold both branches into the resolution branch. See https://github.com/fluture-js/Fluture#fold */ fold(lmapper: (reason: L) => RB, rmapper: (value: R) => RB): Future /** Fork the Future into the two given continuations. See https://github.com/fluture-js/Fluture#fork */ fork(reject: RejectFunction, resolve: ResolveFunction): Cancel /** Set up a cleanup Future to run after this one is done. See https://github.com/fluture-js/Fluture#finally */ lastly(cleanup: Future): Future /** Map over the resolution value in this Future. See https://github.com/fluture-js/Fluture#map */ map(mapper: (value: R) => RB): Future /** Map over the rejection reason in this Future. See https://github.com/fluture-js/Fluture#maprej */ mapRej(mapper: (reason: L) => LB): Future /** Logical or for Futures. See https://github.com/fluture-js/Fluture#or */ or(right: Future): Future /** Fork the Future into a Promise. See https://github.com/fluture-js/Fluture#promise */ promise(): Promise /** Race this Future against another one. See https://github.com/fluture-js/Fluture#race */ race(right: Future): Future /** Swap the rejection reason and the resolotion value. See https://github.com/fluture-js/Fluture#swap */ swap(): Future /** Fork this Future into the given continuation. See https://github.com/fluture-js/Fluture#value */ value(this: Future, resolve: ResolveFunction): Cancel } /** Creates a Future which resolves after the given duration with the given value. See https://github.com/fluture-js/Fluture#after */ export function after(duration: number, value: R): Future export function after(duration: number): (value: R) => Future /** Logical and for Futures. See https://github.com/fluture-js/Fluture#and */ export function and(left: Future, right: Future): Future export function and(left: Future): (right: Future) => Future /** Race two ConcurrentFutures. See https://github.com/fluture-js/Fluture#alt */ export function alt(left: ConcurrentFuture, right: ConcurrentFuture): ConcurrentFuture export function alt(left: ConcurrentFuture): (right: ConcurrentFuture) => ConcurrentFuture /** Apply the function in the left Future to the value in the right Future. See https://github.com/fluture-js/Fluture#ap */ export function ap(apply: Future RB>, value: Future): Future export function ap(apply: Future RB>): (value: Future) => Future /** Apply the function in the left ConcurrentFuture to the value in the right ConcurrentFuture. See https://github.com/fluture-js/Fluture#ap */ export function ap(apply: ConcurrentFuture RB>, value: ConcurrentFuture): ConcurrentFuture export function ap(apply: ConcurrentFuture RB>): (value: ConcurrentFuture) => ConcurrentFuture /** Create a Future which resolves with the return value of the given function, or rejects with the error it throws. See https://github.com/fluture-js/Fluture#try */ export function attempt(fn: () => R): Future /** Map over both branched of the given Bifunctor at once. See https://github.com/fluture-js/Fluture#bimap */ export function bimap(lmapper: (reason: LA) => LB, rmapper: (value: RA) => RB, source: Future): Future export function bimap(lmapper: (reason: LA) => LB, rmapper: (value: RA) => RB): (source: Future) => Future export function bimap(lmapper: (reason: LA) => LB): (rmapper: (value: RA) => RB, source: Future) => Future export function bimap(lmapper: (reason: LA) => LB): (rmapper: (value: RA) => RB) => (source: Future) => Future /** Wait for both Futures to resolve in parallel. See https://github.com/fluture-js/Fluture#both */ export function both(left: Future, right: Future): Future export function both(left: Future): (right: Future) => Future /** Cache the outcome of the given Future. See https://github.com/fluture-js/Fluture#cache */ export function cache(source: Future): Future /** Create a Future using the resolution value of the given Future. See https://github.com/fluture-js/Fluture#chain */ export function chain(mapper: (value: RA) => Future, source: Future): Future export function chain(mapper: (value: RA) => Future): (source: Future) => Future /** Create a Future using the rejection reason of the given Future. See https://github.com/fluture-js/Fluture#chain */ export function chainRej(mapper: (reason: LA) => Future, source: Future): Future export function chainRej(mapper: (reason: LA) => Future): (source: Future) => Future /** Fork the given Future into a Node-style callback. See https://github.com/fluture-js/Fluture#done */ export function done(callback: Nodeback, source: Future): Cancel export function done(callback: Nodeback): (source: Future) => Cancel /** Encase the given function such that it returns a Future of its return value. See https://github.com/fluture-js/Fluture#encase */ export function encase(fn: (a: A) => R, a: A): Future export function encase(fn: (a: A) => R): (a: A) => Future /** Encase the given function such that it returns a Future of its return value. See https://github.com/fluture-js/Fluture#encase */ export function encase2(fn: (a: A, b: B) => R, a: A, b: B): Future export function encase2(fn: (a: A, b: B) => R, a: A): (b: B) => Future export function encase2(fn: (a: A, b: B) => R): AwaitingTwo> /** Encase the given function such that it returns a Future of its return value. See https://github.com/fluture-js/Fluture#encase */ export function encase3(fn: (a: A, b: B, c: C) => R, a: A, b: B, c: C): Future export function encase3(fn: (a: A, b: B, c: C) => R, a: A, b: B): (c: C) => Future export function encase3(fn: (a: A, b: B, c: C) => R, a: A): AwaitingTwo> export function encase3(fn: (a: A, b: B, c: C) => R): AwaitingThree> /** Encase the given Node-style function such that it returns a Future of its result. See https://github.com/fluture-js/Fluture#encasen */ export function encaseN(fn: (a: A, callback: Nodeback) => void, a: A): Future export function encaseN(fn: (a: A, callback: Nodeback) => void): (a: A) => Future /** Encase the given Node-style function such that it returns a Future of its result. See https://github.com/fluture-js/Fluture#encasen */ export function encaseN2(fn: (a: A, b: B, callback: Nodeback) => void, a: A, b: B): Future export function encaseN2(fn: (a: A, b: B, callback: Nodeback) => void, a: A): (b: B) => Future export function encaseN2(fn: (a: A, b: B, callback: Nodeback) => void): AwaitingTwo> /** Encase the given Node-style function such that it returns a Future of its result. See https://github.com/fluture-js/Fluture#encasen */ export function encaseN3(fn: (a: A, b: B, c: C, callback: Nodeback) => void, a: A, b: B, c: C): Future export function encaseN3(fn: (a: A, b: B, c: C, callback: Nodeback) => void, a: A, b: B): (c: C) => Future export function encaseN3(fn: (a: A, b: B, c: C, callback: Nodeback) => void, a: A): AwaitingTwo> export function encaseN3(fn: (a: A, b: B, c: C, callback: Nodeback) => void): AwaitingThree> /** Encase the given Promise-returning function such that it returns a Future of its resolution value. See https://github.com/fluture-js/Fluture#encasep */ export function encaseP(fn: (a: A) => Promise, a: A): Future export function encaseP(fn: (a: A) => Promise): (a: A) => Future /** Encase the given Promise-returning function such that it returns a Future of its resolution value. See https://github.com/fluture-js/Fluture#encasep */ export function encaseP2(fn: (a: A, b: B) => Promise, a: A, b: B): Future export function encaseP2(fn: (a: A, b: B) => Promise, a: A): (b: B) => Future export function encaseP2(fn: (a: A, b: B) => Promise): AwaitingTwo> /** Encase the given Promise-returning function such that it returns a Future of its resolution value. See https://github.com/fluture-js/Fluture#encasep */ export function encaseP3(fn: (a: A, b: B, c: C) => Promise, a: A, b: B, c: C): Future export function encaseP3(fn: (a: A, b: B, c: C) => Promise, a: A, b: B): (c: C) => Future export function encaseP3(fn: (a: A, b: B, c: C) => Promise, a: A): AwaitingTwo> export function encaseP3(fn: (a: A, b: B, c: C) => Promise): AwaitingThree> /** Attempt to extract the rejection reason. See https://github.com/fluture-js/Fluture#extractleft */ export function extractLeft(source: Future): Array /** Attempt to extract the resolution value. See https://github.com/fluture-js/Fluture#extractright */ export function extractRight(source: Future): Array /** Fold both branches into the resolution branch. See https://github.com/fluture-js/Fluture#fold */ export function fold(lmapper: (left: LA) => RA, rmapper: (right: RA) => RB, source: Future): Future export function fold(lmapper: (left: LA) => RA, rmapper: (right: RA) => RB): (source: Future) => Future export function fold(lmapper: (left: LA) => RA): AwaitingTwo<(right: RA) => RB, Future, Future> /** Fork the given Future into the given continuations. See https://github.com/fluture-js/Fluture#fork */ export function fork(reject: RejectFunction, resolve: ResolveFunction, source: Future): Cancel export function fork(reject: RejectFunction, resolve: ResolveFunction): (source: Future) => Cancel export function fork(reject: RejectFunction): AwaitingTwo, Future, Cancel> /** Build a coroutine using Futures. See https://github.com/fluture-js/Fluture#go */ export function go(generator: Generator, R>): Future /** Manage resources before and after the computation that needs them. See https://github.com/fluture-js/Fluture#hook */ export function hook(acquire: Future, dispose: (handle: H) => Future, consume: (handle: H) => Future): Future export function hook(acquire: Future, dispose: (handle: H) => Future): (consume: (handle: H) => Future) => Future export function hook(acquire: Future): AwaitingTwo<(handle: H) => Future, (handle: H) => Future, Future> /** Returns true for Futures. See https://github.com/fluture-js/Fluture#isfuture */ export function isFuture(value: any): boolean /** Returns true for Futures that will certainly never settle. See https://github.com/fluture-js/Fluture#isnever */ export function isNever(value: any): boolean /** Set up a cleanup Future to run after the given action has settled. See https://github.com/fluture-js/Fluture#lastly */ export function lastly(cleanup: Future, action: Future): Future export function lastly(cleanup: Future): (action: Future) => Future /** Map over the resolution value of the given Future. See https://github.com/fluture-js/Fluture#map */ export function map(mapper: (value: RA) => RB, source: Future): Future export function map(mapper: (value: RA) => RB): (source: Future) => Future /** Map over the resolution value of the given ConcurrentFuture. See https://github.com/fluture-js/Fluture#map */ export function map(mapper: (value: RA) => RB, source: ConcurrentFuture): ConcurrentFuture export function map(mapper: (value: RA) => RB): (source: ConcurrentFuture) => ConcurrentFuture /** Map over the rejection reason of the given Future. See https://github.com/fluture-js/Fluture#maprej */ export function mapRej(mapper: (reason: LA) => LB, source: Future): Future export function mapRej(mapper: (reason: LA) => LB): (source: Future) => Future /** A Future that never settles. See https://github.com/fluture-js/Fluture#never */ export var never: Future /** Create a Future using a provided Node-style callback. See https://github.com/fluture-js/Fluture#node */ export function node(fn: (done: Nodeback) => void): Future /** Create a Future with the given resolution value. See https://github.com/fluture-js/Fluture#of */ export function of(value: R): Future /** Logical or for Futures. See https://github.com/fluture-js/Fluture#or */ export function or(left: Future, right: Future): Future export function or(left: Future): (right: Future) => Future /** Run an Array of Futures in parallel, under the given concurrency limit. See https://github.com/fluture-js/Fluture#parallel */ export function parallel(concurrency: number, futures: Array>): Future> export function parallel(concurrency: number): (futures: Array>) => Future> /** Convert a Future to a Promise. See https://github.com/fluture-js/Fluture#promise */ export function promise(source: Future): Promise /** Race two Futures against one another. See https://github.com/fluture-js/Fluture#race */ export function race(left: Future, right: Future): Future export function race(left: Future): (right: Future) => Future /** Create a Future with the given rejection reason. See https://github.com/fluture-js/Fluture#reject */ export function reject(reason: L): Future /** Creates a Future which rejects after the given duration with the given reason. See https://github.com/fluture-js/Fluture#rejectafter */ export function rejectAfter(duration: number, reason: L): Future export function rejectAfter(duration: number): (reason: L) => Future /** Convert a ConcurrentFuture to a regular Future. See https://github.com/fluture-js/Fluture#concurrentfuture */ export function seq(source: ConcurrentFuture): Future /** Swap the rejection reason and the resolution value. See https://github.com/fluture-js/Fluture#swap */ export function swap(source: Future): Future /** Convert a Promise-returning function to a Future. See https://github.com/fluture-js/Fluture#tryP */ export function tryP(fn: () => Promise): Future /** Fork the Future into the given continuation. See https://github.com/fluture-js/Fluture#value */ export function value(resolve: ResolveFunction, source: Future): Cancel export function value(resolve: ResolveFunction): (source: Future) => Cancel export interface Fluture { /** Create a Future from a possibly cancellable computation. See https://github.com/fluture-js/Fluture#future */ (computation: ( reject: RejectFunction, resolve: ResolveFunction ) => Cancel | void): Future /** Create a Future from a possibly cancellable computation. See https://github.com/fluture-js/Fluture#future */ new (computation: ( reject: RejectFunction, resolve: ResolveFunction ) => Cancel | void): Future /** Implementation of Fantasy Land ChainRec. */ chainRec(iterator: (next: (value: I) => Next, done: (value: R) => Done, value: I) => Future | Done>, initial: I): Future ap: typeof ap bimap: typeof bimap chain: typeof chain map: typeof map of: typeof of reject: typeof reject '@@type': string } export var Future: Fluture export default Future export interface Par { /** Create a ConcurrentFuture using a Future. See https://github.com/fluture-js/Fluture#concurrentfuture */ (source: Future): ConcurrentFuture of(value: R): ConcurrentFuture zero(): ConcurrentFuture ap: typeof ap map: typeof map alt: typeof alt '@@type': string } export var Par: Par }