declare module 'fluture' { export interface RecoverFunction { (exception: Error): void } 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 ConcurrentFutureInstance { sequential: FutureInstance } export interface FutureInstance { /** Apply a function to this Future. See https://github.com/fluture-js/Fluture#pipe */ pipe(fn: (future: FutureInstance) => T): T /** Logical and for Futures. See https://github.com/fluture-js/Fluture#and */ and(right: FutureInstance): FutureInstance /** Logical or for Futures. See https://github.com/fluture-js/Fluture#alt */ alt(right: FutureInstance): FutureInstance /** Apply the function in this Future to the value in another. See https://github.com/fluture-js/Fluture#ap */ ap(this: FutureInstance B>, right: FutureInstance): FutureInstance /** 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): FutureInstance /** Wait for this Future and the given one in parallel. See https://github.com/fluture-js/Fluture#both */ both(right: FutureInstance): FutureInstance /** Use the resolution value in this Future to create the next Future. See https://github.com/fluture-js/Fluture#chain */ chain(mapper: (value: R) => FutureInstance): FutureInstance /** Use the rejection reason in this Future to create the next Future. See https://github.com/fluture-js/Fluture#chainrej */ chainRej(mapper: (reason: L) => FutureInstance): FutureInstance /** The Future constructor */ constructor: FutureTypeRep /** 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: FutureInstance): FutureInstance /** Fold both branches into the resolution branch. See https://github.com/fluture-js/Fluture#fold */ fold(lmapper: (reason: L) => RB, rmapper: (value: R) => RB): FutureInstance /** Fork the Future into the two given continuations. See https://github.com/fluture-js/Fluture#fork */ fork(reject: RejectFunction, resolve: ResolveFunction): Cancel /** Fork with exception recovery. See https://github.com/fluture-js/Fluture#forkCatch */ forkCatch(recover: RecoverFunction, 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: FutureInstance): FutureInstance /** Map over the resolution value in this Future. See https://github.com/fluture-js/Fluture#map */ map(mapper: (value: R) => RB): FutureInstance /** Map over the rejection reason in this Future. See https://github.com/fluture-js/Fluture#maprej */ mapRej(mapper: (reason: L) => LB): FutureInstance /** Logical or for Futures. See https://github.com/fluture-js/Fluture#alt */ or(right: FutureInstance): FutureInstance /** 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: FutureInstance): FutureInstance /** Swap the rejection reason and the resolotion value. See https://github.com/fluture-js/Fluture#swap */ swap(): FutureInstance /** Fork this Future into the given continuation. See https://github.com/fluture-js/Fluture#value */ value(this: FutureInstance, 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): FutureInstance export function after(duration: number): (value: R) => FutureInstance /** Logical and for Futures. See https://github.com/fluture-js/Fluture#and */ export function and(left: FutureInstance, right: FutureInstance): FutureInstance export function and(left: FutureInstance): (right: FutureInstance) => FutureInstance /** Logical or for Futures. See https://github.com/fluture-js/Fluture#alt */ export function alt(left: FutureInstance, right: FutureInstance): FutureInstance export function alt(left: FutureInstance): (right: FutureInstance) => FutureInstance /** Race two ConcurrentFutures. See https://github.com/fluture-js/Fluture#alt */ export function alt(left: ConcurrentFutureInstance, right: ConcurrentFutureInstance): ConcurrentFutureInstance export function alt(left: ConcurrentFutureInstance): (right: ConcurrentFutureInstance) => ConcurrentFutureInstance /** 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: FutureInstance RB>, value: FutureInstance): FutureInstance export function ap(apply: FutureInstance RB>): (value: FutureInstance) => FutureInstance /** 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: ConcurrentFutureInstance RB>, value: ConcurrentFutureInstance): ConcurrentFutureInstance export function ap(apply: ConcurrentFutureInstance RB>): (value: ConcurrentFutureInstance) => ConcurrentFutureInstance /** 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): FutureInstance /** 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: FutureInstance): FutureInstance export function bimap(lmapper: (reason: LA) => LB, rmapper: (value: RA) => RB): (source: FutureInstance) => FutureInstance export function bimap(lmapper: (reason: LA) => LB): (rmapper: (value: RA) => RB, source: FutureInstance) => FutureInstance export function bimap(lmapper: (reason: LA) => LB): (rmapper: (value: RA) => RB) => (source: FutureInstance) => FutureInstance /** Wait for both Futures to resolve in parallel. See https://github.com/fluture-js/Fluture#both */ export function both(left: FutureInstance, right: FutureInstance): FutureInstance export function both(left: FutureInstance): (right: FutureInstance) => FutureInstance /** Cache the outcome of the given Future. See https://github.com/fluture-js/Fluture#cache */ export function cache(source: FutureInstance): FutureInstance /** 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) => FutureInstance, source: FutureInstance): FutureInstance export function chain(mapper: (value: RA) => FutureInstance): (source: FutureInstance) => FutureInstance /** 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) => FutureInstance, source: FutureInstance): FutureInstance export function chainRej(mapper: (reason: LA) => FutureInstance): (source: FutureInstance) => FutureInstance /** Fork the given Future into a Node-style callback. See https://github.com/fluture-js/Fluture#done */ export function done(callback: Nodeback, source: FutureInstance): Cancel export function done(callback: Nodeback): (source: FutureInstance) => 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): FutureInstance export function encase(fn: (a: A) => R): (a: A) => FutureInstance /** 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): FutureInstance export function encase2(fn: (a: A, b: B) => R, a: A): (b: B) => FutureInstance 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): FutureInstance export function encase3(fn: (a: A, b: B, c: C) => R, a: A, b: B): (c: C) => FutureInstance 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): FutureInstance export function encaseN(fn: (a: A, callback: Nodeback) => void): (a: A) => FutureInstance /** 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): FutureInstance export function encaseN2(fn: (a: A, b: B, callback: Nodeback) => void, a: A): (b: B) => FutureInstance 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): FutureInstance export function encaseN3(fn: (a: A, b: B, c: C, callback: Nodeback) => void, a: A, b: B): (c: C) => FutureInstance 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): FutureInstance export function encaseP(fn: (a: A) => Promise): (a: A) => FutureInstance /** 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): FutureInstance export function encaseP2(fn: (a: A, b: B) => Promise, a: A): (b: B) => FutureInstance 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): FutureInstance export function encaseP3(fn: (a: A, b: B, c: C) => Promise, a: A, b: B): (c: C) => FutureInstance 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: FutureInstance): Array /** Attempt to extract the resolution value. See https://github.com/fluture-js/Fluture#extractright */ export function extractRight(source: FutureInstance): 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: FutureInstance): FutureInstance export function fold(lmapper: (left: LA) => RA, rmapper: (right: RA) => RB): (source: FutureInstance) => FutureInstance export function fold(lmapper: (left: LA) => RA): AwaitingTwo<(right: RA) => RB, FutureInstance, FutureInstance> /** Fork the given Future into the given continuations. See https://github.com/fluture-js/Fluture#fork */ export function fork(reject: RejectFunction, resolve: ResolveFunction, source: FutureInstance): Cancel export function fork(reject: RejectFunction, resolve: ResolveFunction): (source: FutureInstance) => Cancel export function fork(reject: RejectFunction): AwaitingTwo, FutureInstance, Cancel> /** Fork with exception recovery. See https://github.com/fluture-js/Fluture#forkCatch */ export function forkCatch(recover: RecoverFunction, reject: RejectFunction, resolve: ResolveFunction, source: FutureInstance): Cancel export function forkCatch(recover: RecoverFunction, reject: RejectFunction, resolve: ResolveFunction): (source: FutureInstance) => Cancel export function forkCatch(recover: RecoverFunction, reject: RejectFunction): AwaitingTwo, FutureInstance, Cancel> export function forkCatch(recover: RecoverFunction): AwaitingThree, ResolveFunction, FutureInstance, Cancel> /** Build a coroutine using Futures. See https://github.com/fluture-js/Fluture#go */ export function go(generator: Generator, R>): FutureInstance /** Manage resources before and after the computation that needs them. See https://github.com/fluture-js/Fluture#hook */ export function hook(acquire: FutureInstance, dispose: (handle: H) => FutureInstance, consume: (handle: H) => FutureInstance): FutureInstance export function hook(acquire: FutureInstance, dispose: (handle: H) => FutureInstance): (consume: (handle: H) => FutureInstance) => FutureInstance export function hook(acquire: FutureInstance): AwaitingTwo<(handle: H) => FutureInstance, (handle: H) => FutureInstance, FutureInstance> /** 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: FutureInstance, action: FutureInstance): FutureInstance export function lastly(cleanup: FutureInstance): (action: FutureInstance) => FutureInstance /** 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: FutureInstance): FutureInstance export function map(mapper: (value: RA) => RB): (source: FutureInstance) => FutureInstance /** 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: ConcurrentFutureInstance): ConcurrentFutureInstance export function map(mapper: (value: RA) => RB): (source: ConcurrentFutureInstance) => ConcurrentFutureInstance /** 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: FutureInstance): FutureInstance export function mapRej(mapper: (reason: LA) => LB): (source: FutureInstance) => FutureInstance /** A Future that never settles. See https://github.com/fluture-js/Fluture#never */ export var never: FutureInstance /** Create a Future using a provided Node-style callback. See https://github.com/fluture-js/Fluture#node */ export function node(fn: (done: Nodeback) => void): FutureInstance /** Create a Future with the given resolution value. See https://github.com/fluture-js/Fluture#of */ export function of(value: R): FutureInstance /** Create a Future with the given resolution value. See https://github.com/fluture-js/Fluture#of */ export function resolve(value: R): FutureInstance /** Logical or for Futures. See https://github.com/fluture-js/Fluture#alt */ export function or(left: FutureInstance, right: FutureInstance): FutureInstance export function or(left: FutureInstance): (right: FutureInstance) => FutureInstance /** 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>): FutureInstance> export function parallel(concurrency: number): (futures: Array>) => FutureInstance> /** Convert a Future to a Promise. See https://github.com/fluture-js/Fluture#promise */ export function promise(source: FutureInstance): Promise /** Race two Futures against one another. See https://github.com/fluture-js/Fluture#race */ export function race(left: FutureInstance, right: FutureInstance): FutureInstance export function race(left: FutureInstance): (right: FutureInstance) => FutureInstance /** Create a Future with the given rejection reason. See https://github.com/fluture-js/Fluture#reject */ export function reject(reason: L): FutureInstance /** 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): FutureInstance export function rejectAfter(duration: number): (reason: L) => FutureInstance /** Convert a ConcurrentFuture to a regular Future. See https://github.com/fluture-js/Fluture#concurrentfuture */ export function seq(source: ConcurrentFutureInstance): FutureInstance /** Swap the rejection reason and the resolution value. See https://github.com/fluture-js/Fluture#swap */ export function swap(source: FutureInstance): FutureInstance /** Convert a Promise-returning function to a Future. See https://github.com/fluture-js/Fluture#tryP */ export function tryP(fn: () => Promise): FutureInstance /** Fork the Future into the given continuation. See https://github.com/fluture-js/Fluture#value */ export function value(resolve: ResolveFunction, source: FutureInstance): Cancel export function value(resolve: ResolveFunction): (source: FutureInstance) => Cancel /** Enable or disable debug mode. See https://github.com/fluture-js/Fluture#debugmode */ export function debugMode(debug: boolean): void; export interface FutureTypeRep { /** Create a Future from a possibly cancellable computation. See https://github.com/fluture-js/Fluture#future */ (computation: ( reject: RejectFunction, resolve: ResolveFunction ) => Cancel | void): FutureInstance /** Create a Future from a possibly cancellable computation. See https://github.com/fluture-js/Fluture#future */ new (computation: ( reject: RejectFunction, resolve: ResolveFunction ) => Cancel | void): FutureInstance /** Implementation of Fantasy Land ChainRec. */ chainRec(iterator: (next: (value: I) => Next, done: (value: R) => Done, value: I) => FutureInstance | Done>, initial: I): FutureInstance ap: typeof ap alt: typeof alt bimap: typeof bimap chain: typeof chain map: typeof map of: typeof resolve resolve: typeof resolve reject: typeof reject '@@type': string } export var Future: FutureTypeRep export default Future export interface ConcurrentFutureTypeRep { /** Create a ConcurrentFuture using a Future. See https://github.com/fluture-js/Fluture#concurrentfuture */ (source: FutureInstance): ConcurrentFutureInstance of(value: R): ConcurrentFutureInstance zero(): ConcurrentFutureInstance ap: typeof ap map: typeof map alt: typeof alt '@@type': string } export var Par: ConcurrentFutureTypeRep }