/// /// 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 } declare const $T: unique symbol export interface Functor { [$T]: unknown 'fantasy-land/map'(mapper: (value: A) => B): Functor } type Mapped, B> = ReturnType<(F & { [$T]: B })['fantasy-land/map']> export interface ConcurrentFutureInstance extends Functor { sequential: FutureInstance 'fantasy-land/ap'(this: ConcurrentFutureInstance B>, right: ConcurrentFutureInstance): ConcurrentFutureInstance 'fantasy-land/map'(mapper: (value: R) => RB): ConcurrentFutureInstance 'fantasy-land/alt'(right: ConcurrentFutureInstance): ConcurrentFutureInstance } export interface FutureInstance extends Functor { /** The Future constructor */ constructor: FutureTypeRep /** Apply a function to this Future. See https://github.com/fluture-js/Fluture#pipe */ pipe(fn: (future: this) => T): T /** 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 'fantasy-land/ap'(this: FutureInstance B>, right: FutureInstance): FutureInstance 'fantasy-land/map'(mapper: (value: R) => RB): FutureInstance 'fantasy-land/alt'(right: FutureInstance): FutureInstance 'fantasy-land/bimap'(lmapper: (reason: L) => LB, rmapper: (value: R) => RB): FutureInstance 'fantasy-land/chain'(mapper: (value: R) => FutureInstance): FutureInstance } /** 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 /** Logical and for Futures. See https://github.com/fluture-js/Fluture#and */ 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 /** Race two ConcurrentFutures. See https://github.com/fluture-js/Fluture#alt */ export function alt(left: ConcurrentFutureInstance): (right: ConcurrentFutureInstance) => ConcurrentFutureInstance /** Apply the function in the right Future to the value in the left Future. See https://github.com/fluture-js/Fluture#ap */ export function ap(value: FutureInstance): (apply: FutureInstance RB>) => FutureInstance /** Apply the function in the right ConcurrentFuture to the value in the left ConcurrentFuture. See https://github.com/fluture-js/Fluture#ap */ export function ap(value: ConcurrentFutureInstance): (apply: ConcurrentFutureInstance RB>) => ConcurrentFutureInstance /** Apply the function in the right Future to the value in the left Future in parallel. See https://github.com/fluture-js/Fluture#pap */ export function pap(value: FutureInstance): (apply: FutureInstance RB>) => FutureInstance /** 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#attempt */ export function attempt(fn: () => R): FutureInstance /** Convert a Promise-returning function to a Future. See https://github.com/fluture-js/Fluture#attemptP */ export function attemptP(fn: () => Promise): FutureInstance /** Create a Future using the inner value of the given Future. See https://github.com/fluture-js/Fluture#bichain */ export function bichain(lmapper: (reason: LA) => FutureInstance): (rmapper: (value: RA) => FutureInstance) => (source: FutureInstance) => FutureInstance /** Map over both branches 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 /** Wait for both Futures to resolve in parallel. See https://github.com/fluture-js/Fluture#both */ 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 /** 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 /** 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 /** 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 /** 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 /** 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 /** Coalesce both branches into the resolution branch. See https://github.com/fluture-js/Fluture#coalesce */ export function coalesce(lmapper: (left: LA) => R): (rmapper: (right: RA) => R) => (source: 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 /** Fork with exception recovery. See https://github.com/fluture-js/Fluture#forkCatch */ export function forkCatch(recover: RecoverFunction): (reject: RejectFunction) => (resolve: ResolveFunction) => (source: FutureInstance) => Cancel /** Build a coroutine using Futures. See https://github.com/fluture-js/Fluture#go */ export function go(generator: () => Generator, R, any>): 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 /** 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 /** Map over the resolution value of the given Future or ConcurrentFuture. See https://github.com/fluture-js/Fluture#map */ export const map: { >(mapper: Functor extends F ? never : (a: F extends Functor ? A : never) => B): (source: F) => Mapped (mapper: (a: A) => B): >(source: F) => Mapped } /** 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 /** 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 resolve(value: R): 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> /** 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 /** 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 /** 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 /** Fork the Future into the given continuation. See https://github.com/fluture-js/Fluture#value */ 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): FutureInstance 'fantasy-land/chainRec'(iterator: (next: (value: I) => IteratorYieldResult, done: (value: R) => IteratorReturnResult, value: I) => FutureInstance>, initial: I): FutureInstance 'fantasy-land/of': typeof resolve '@@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 'fantasy-land/of'(value: R): ConcurrentFutureInstance 'fantasy-land/zero'(): ConcurrentFutureInstance '@@type': string } export var Par: ConcurrentFutureTypeRep