/**
* ```ts
* interface Task {
* (): Promise
* }
* ```
*
* `Task` represents an asynchronous computation that yields a value of type `A` and **never fails**.
* If you want to represent an asynchronous computation that may fail, please see `TaskEither`.
*
* @since 2.0.0
*/
import { Applicative1 } from './Applicative'
import { Apply1 } from './Apply'
import { Chain1 } from './Chain'
import { FromIO1 } from './FromIO'
import { FromTask1 } from './FromTask'
import { Functor1 } from './Functor'
import { Monad1 } from './Monad'
import { MonadIO1 } from './MonadIO'
import { MonadTask1 } from './MonadTask'
import { Monoid } from './Monoid'
import { Pointed1 } from './Pointed'
import { ReadonlyNonEmptyArray } from './ReadonlyNonEmptyArray'
import { Semigroup } from './Semigroup'
import { IO } from './IO'
/**
* @category model
* @since 2.0.0
*/
export interface Task {
(): Promise
}
/**
* @category conversions
* @since 2.0.0
*/
export declare const fromIO: (fa: IO) => Task
/**
* Creates a task that will complete after a time delay
*
* @example
* import { sequenceT } from 'fp-ts/Apply'
* import * as T from 'fp-ts/Task'
* import { takeRight } from 'fp-ts/Array'
*
* async function test() {
* const log: Array = []
* const append = (message: string): T.Task =>
* T.fromIO(() => {
* log.push(message)
* })
* const fa = append('a')
* const fb = T.delay(20)(append('b'))
* const fc = T.delay(10)(append('c'))
* const fd = append('d')
* await sequenceT(T.ApplyPar)(fa, fb, fc, fd)()
* assert.deepStrictEqual(takeRight(2)(log), ['c', 'b'])
* }
*
* test()
*
* @since 2.0.0
*/
export declare function delay(millis: number): (ma: Task) => Task
/**
* `map` can be used to turn functions `(a: A) => B` into functions `(fa: F) => F` whose argument and return types
* use the type constructor `F` to represent some computational context.
*
* @category mapping
* @since 2.0.0
*/
export declare const map: (f: (a: A) => B) => (fa: Task) => Task
/**
* @since 2.0.0
*/
export declare const ap: (fa: Task) => (fab: Task<(a: A) => B>) => Task
/**
* @category constructors
* @since 2.0.0
*/
export declare const of: (a: A) => Task
/**
* Composes computations in sequence, using the return value of one computation to determine the next computation.
*
* @category sequencing
* @since 2.0.0
*/
export declare const chain: (f: (a: A) => Task) => (ma: Task) => Task
/**
* @category sequencing
* @since 2.0.0
*/
export declare const flatten: (mma: Task>) => Task
/**
* @category type lambdas
* @since 2.0.0
*/
export declare const URI = 'Task'
/**
* @category type lambdas
* @since 2.0.0
*/
export declare type URI = typeof URI
declare module './HKT' {
interface URItoKind {
readonly [URI]: Task
}
}
/**
* Monoid returning the first completed task.
*
* Note: uses `Promise.race` internally.
*
* @example
* import * as T from 'fp-ts/Task'
*
* async function test() {
* const S = T.getRaceMonoid()
* const fa = T.delay(20)(T.of('a'))
* const fb = T.delay(10)(T.of('b'))
* assert.deepStrictEqual(await S.concat(fa, fb)(), 'b')
* }
*
* test()
*
* @category instances
* @since 2.0.0
*/
export declare function getRaceMonoid(): Monoid>
/**
* @category instances
* @since 2.7.0
*/
export declare const Functor: Functor1
/**
* @category mapping
* @since 2.10.0
*/
export declare const flap: (a: A) => (fab: Task<(a: A) => B>) => Task
/**
* @category instances
* @since 2.10.0
*/
export declare const Pointed: Pointed1
/**
* Runs computations in parallel.
*
* @category instances
* @since 2.10.0
*/
export declare const ApplyPar: Apply1
/**
* Combine two effectful actions, keeping only the result of the first.
*
* @since 2.0.0
*/
export declare const apFirst: (second: Task) => (first: Task) => Task
/**
* Combine two effectful actions, keeping only the result of the second.
*
* @since 2.0.0
*/
export declare const apSecond: (second: Task) => (first: Task) => Task
/**
* Runs computations in parallel.
*
* @category instances
* @since 2.7.0
*/
export declare const ApplicativePar: Applicative1
/**
* Runs computations sequentially.
*
* @category instances
* @since 2.10.0
*/
export declare const ApplySeq: Apply1
/**
* Runs computations sequentially.
*
* @category instances
* @since 2.7.0
*/
export declare const ApplicativeSeq: Applicative1
/**
* @category instances
* @since 2.10.0
*/
export declare const Chain: Chain1
/**
* @category instances
* @since 2.10.0
*/
export declare const Monad: Monad1
/**
* @category instances
* @since 2.10.0
*/
export declare const MonadIO: MonadIO1
/**
* @category zone of death
* @since 2.7.0
* @deprecated
*/
export declare const fromTask: (fa: Task) => Task
/**
* @category instances
* @since 2.10.0
*/
export declare const MonadTask: MonadTask1
/**
* Composes computations in sequence, using the return value of one computation to determine the next computation and
* keeping only the result of the first.
*
* @category sequencing
* @since 2.0.0
*/
export declare const chainFirst: (f: (a: A) => Task) => (first: Task) => Task
/**
* @category instances
* @since 2.10.0
*/
export declare const FromIO: FromIO1
/**
* @category lifting
* @since 2.4.0
*/
export declare const fromIOK: , B>(f: (...a: A) => IO) => (...a: A) => Task
/**
* @category sequencing
* @since 2.4.0
*/
export declare const chainIOK: (f: (a: A) => IO) => (first: Task) => Task
/**
* @category sequencing
* @since 2.10.0
*/
export declare const chainFirstIOK: (f: (a: A) => IO) => (first: Task) => Task
/**
* @category instances
* @since 2.10.0
*/
export declare const FromTask: FromTask1
/**
* A `Task` that never completes.
*
* @since 2.0.0
*/
export declare const never: Task
/**
* @category do notation
* @since 2.9.0
*/
export declare const Do: Task<{}>
/**
* @category do notation
* @since 2.8.0
*/
export declare const bindTo: (name: N) => (fa: Task) => Task<{ readonly [K in N]: A }>
declare const let_: (
name: Exclude,
f: (a: A) => B
) => (fa: Task) => Task<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
export {
/**
* @category do notation
* @since 2.13.0
*/
let_ as let
}
/**
* @category do notation
* @since 2.8.0
*/
export declare const bind: (
name: Exclude,
f: (a: A) => Task
) => (ma: Task) => Task<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
/**
* @category do notation
* @since 2.8.0
*/
export declare const apS: (
name: Exclude,
fb: Task
) => (fa: Task) => Task<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
/**
* @since 2.11.0
*/
export declare const ApT: Task
/**
* Equivalent to `ReadonlyNonEmptyArray#traverseWithIndex(ApplicativePar)`.
*
* @category traversing
* @since 2.11.0
*/
export declare const traverseReadonlyNonEmptyArrayWithIndex: (
f: (index: number, a: A) => Task
) => (as: ReadonlyNonEmptyArray) => Task>
/**
* Equivalent to `ReadonlyArray#traverseWithIndex(ApplicativePar)`.
*
* @category traversing
* @since 2.11.0
*/
export declare const traverseReadonlyArrayWithIndex: (
f: (index: number, a: A) => Task
) => (as: readonly A[]) => Task
/**
* Equivalent to `ReadonlyNonEmptyArray#traverseWithIndex(ApplicativeSeq)`.
*
* @category traversing
* @since 2.11.0
*/
export declare const traverseReadonlyNonEmptyArrayWithIndexSeq: (
f: (index: number, a: A) => Task
) => (as: ReadonlyNonEmptyArray) => Task>
/**
* Equivalent to `ReadonlyArray#traverseWithIndex(ApplicativeSeq)`.
*
* @category traversing
* @since 2.11.0
*/
export declare const traverseReadonlyArrayWithIndexSeq: (
f: (index: number, a: A) => Task
) => (as: readonly A[]) => Task
/**
* Equivalent to `ReadonlyArray#traverseWithIndex(Applicative)`.
*
* @category traversing
* @since 2.9.0
*/
export declare const traverseArrayWithIndex: (
f: (index: number, a: A) => Task
) => (as: ReadonlyArray) => Task>
/**
* Equivalent to `ReadonlyArray#traverse(Applicative)`.
*
* @category traversing
* @since 2.9.0
*/
export declare const traverseArray: (f: (a: A) => Task) => (as: readonly A[]) => Task
/**
* Equivalent to `ReadonlyArray#sequence(Applicative)`.
*
* @category traversing
* @since 2.9.0
*/
export declare const sequenceArray: (arr: ReadonlyArray>) => Task>
/**
* Equivalent to `ReadonlyArray#traverseWithIndex(ApplicativeSeq)`.
*
* @category traversing
* @since 2.9.0
*/
export declare const traverseSeqArrayWithIndex: (
f: (index: number, a: A) => Task
) => (as: ReadonlyArray) => Task>
/**
* Equivalent to `ReadonlyArray#traverse(ApplicativeSeq)`.
*
* @category traversing
* @since 2.9.0
*/
export declare const traverseSeqArray: (f: (a: A) => Task) => (as: readonly A[]) => Task
/**
* Equivalent to `ReadonlyArray#sequence(ApplicativeSeq)`.
*
* @category traversing
* @since 2.9.0
*/
export declare const sequenceSeqArray: (arr: ReadonlyArray>) => Task>
/**
* This instance is deprecated, use small, specific instances instead.
* For example if a function needs a `Functor` instance, pass `T.Functor` instead of `T.task`
* (where `T` is from `import T from 'fp-ts/Task'`)
*
* @category zone of death
* @since 2.0.0
* @deprecated
*/
export declare const task: Monad1 & MonadTask1
/**
* This instance is deprecated, use small, specific instances instead.
* For example if a function needs a `Functor` instance, pass `T.Functor` instead of `T.taskSeq`
* (where `T` is from `import T from 'fp-ts/Task'`)
*
* @category zone of death
* @since 2.0.0
* @deprecated
*/
export declare const taskSeq: Monad1 & MonadTask1
/**
* Use [`getApplySemigroup`](./Apply.ts.html#getapplysemigroup) instead.
*
* @category zone of death
* @since 2.0.0
* @deprecated
*/
export declare const getSemigroup: (S: Semigroup) => Semigroup>
/**
* Use [`getApplicativeMonoid`](./Applicative.ts.html#getapplicativemonoid) instead.
*
* Lift a monoid into 'Task', the inner values are concatenated using the provided `Monoid`.
*
* @category zone of death
* @since 2.0.0
* @deprecated
*/
export declare const getMonoid: (M: Monoid) => Monoid>