Task
Task:
object
Defined in: Core/Task.ts:59
Type Declaration
Section titled “Type Declaration”abortable
Section titled “abortable”abortable: <
A>(factory) =>object
Creates a Task paired with an abort handle. Calling abort() cancels the
current in-flight call immediately. Unlike a one-shot abort, calling task()
again after abort() starts a fresh call with a new signal.
Each invocation of task() automatically cancels the previous in-flight call,
making it safe to call repeatedly (e.g. on user input) without leaking promises.
If an outer signal is also present (passed at the call site), aborting it propagates into the internal controller.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”factory
Section titled “factory”(signal) => Thenable<A>
Returns
Section titled “Returns”object
abort: () =>
void
Returns
Section titled “Returns”void
task:
Task<A>
Example
Section titled “Example”all: <
T>(tasks,options?) =>Task<{ [K in string | number | symbol]: T[K] extends Task<A> ? A : never }>
Runs multiple Tasks in parallel and collects their results.
An optional concurrency option limits the number of tasks executing at any given time.
Type Parameters
Section titled “Type Parameters”T extends readonly Task<unknown>[]
Parameters
Section titled “Parameters”readonly [T]
options?
Section titled “options?”concurrency?
Section titled “concurrency?”number
Returns
Section titled “Returns”Task<{ [K in string | number | symbol]: T[K] extends Task<A> ? A : never }>
Task.sequential to run an array of Tasks one after another in order.
Example
Section titled “Example”apply: <
A>(arg) => <B>(task) =>Task<B>
Applies a function wrapped in a Task to a value wrapped in a Task. Both Tasks run in parallel.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”Task<A>
Returns
Section titled “Returns”<B>(task) => Task<B>
Task.all to run multiple independent Tasks in parallel.
Example
Section titled “Example”assign
Section titled “assign”assign: <
K,A,B>(key,transform) => (task) =>Task<A&{ [P in string]: B }>
Evaluates a new Task using the current accumulator and attaches the output to a new key.
Type Parameters
Section titled “Type Parameters”K extends string
A
B
Parameters
Section titled “Parameters”K
transform
Section titled “transform”(value) => Task<B>
Returns
Section titled “Returns”(task) => Task<A & { [P in string]: B }>
Example
Section titled “Example”assignTo
Section titled “assignTo”assignTo: <
K>(key) => <A>(task) =>Task<{ [P in string]: A }>
Converts a Task value into an object containing a single property. Initiates the pipeline accumulator record.
Type Parameters
Section titled “Type Parameters”K extends string
Parameters
Section titled “Parameters”K
Returns
Section titled “Returns”<A>(task) => Task<{ [P in string]: A }>
Example
Section titled “Example”chain: <
A,B>(transform) => (task) =>Task<B>
Chains Task computations. Passes the resolved value of the first Task to transform.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(value) => Task<B>
Returns
Section titled “Returns”(task) => Task<B>
Task.map to transform the resolved value without creating a new Task.
Example
Section titled “Example”delay: (
duration) => <A>(task) =>Task<A>
Delays the execution of a Task by the specified duration. Useful for debouncing or rate limiting.
Parameters
Section titled “Parameters”duration
Section titled “duration”Returns
Section titled “Returns”<A>(task) => Task<A>
Example
Section titled “Example”from:
object
from.sync
Section titled “from.sync”sync: <
A>(fn) =>Task<A> =syncTask
Creates a Task from a lazy synchronous thunk.
Unlike Task.make(f()), from.sync does not evaluate f until the Task is called.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”() => A
Returns
Section titled “Returns”Task<A>
Example
Section titled “Example”make: <
A>(value) =>Task<A> =makeTask
Creates a Task that immediately resolves to the given value.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”A
Returns
Section titled “Returns”Task<A>
Example
Section titled “Example”map: <
A,B>(transform) => (task) =>Task<B>
Transforms the value inside a Task.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(value) => B
Returns
Section titled “Returns”(task) => Task<B>
Task.chain to sequence operations that return a Task.
Example
Section titled “Example”Maybe:
object=TaskMaybe
Maybe.apply
Section titled “Maybe.apply”apply: <
A>(arg) => <B>(task) =>Maybe<B>
Applies a function wrapped in a Task.Maybe to a value wrapped in a Task.Maybe. Both Tasks run in parallel.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”Maybe<A>
Returns
Section titled “Returns”<B>(task) => Maybe<B>
Example
Section titled “Example”Maybe.assign
Section titled “Maybe.assign”assign: <
K,A,B>(key,transform) => (task) =>Maybe<A&{ [P in string]: B }>
Evaluates a new Task.Maybe using the current accumulator and attaches the output to a new key.
Type Parameters
Section titled “Type Parameters”K extends string
A
B
Parameters
Section titled “Parameters”K
transform
Section titled “transform”(value) => Maybe<B>
Returns
Section titled “Returns”(task) => Maybe<A & { [P in string]: B }>
Example
Section titled “Example”Maybe.assignTo
Section titled “Maybe.assignTo”assignTo: <
K>(key) => <A>(task) =>Maybe<{ [P in string]: A }>
Lifts a Task.Maybe value into an accumulator object.
Type Parameters
Section titled “Type Parameters”K extends string
Parameters
Section titled “Parameters”K
Returns
Section titled “Returns”<A>(task) => Maybe<{ [P in string]: A }>
Example
Section titled “Example”Maybe.chain
Section titled “Maybe.chain”chain: <
A,B>(transform) => (task) =>Maybe<B> =chainTaskMaybe
Chains Task.Maybe computations. If the first resolves to Some, passes the value to transform. If the first resolves to None, propagates None.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(value) => Maybe<B>
Returns
Section titled “Returns”(task) => Maybe<B>
Task.Maybe.map to transform the inner value without returning a new Task.Maybe.
Example
Section titled “Example”Maybe.filter
Section titled “Maybe.filter”filter: {<
A,B>(refinement): (task) =>Maybe<B>; <A>(predicate): (task) =>Maybe<A>; }
Filters the value inside a Task.Maybe. Returns None if the predicate fails.
Call Signature
Section titled “Call Signature”<
A,B>(refinement): (task) =>Maybe<B>
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”refinement
Section titled “refinement”(value) => value is B
Returns
Section titled “Returns”(task) => Maybe<B>
Call Signature
Section titled “Call Signature”<
A>(predicate): (task) =>Maybe<A>
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(value) => boolean
Returns
Section titled “Returns”(task) => Maybe<A>
Example
Section titled “Example”Maybe.from
Section titled “Maybe.from”from:
object
Maybe.from.Maybe
Section titled “Maybe.from.Maybe”Maybe: <
A>(maybe) =>Maybe<A>
Lifts a Maybe into a Task.Maybe.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”Maybe<A>
Returns
Section titled “Returns”Maybe<A>
Example
Section titled “Example”Maybe.from.nullable
Section titled “Maybe.from.nullable”nullable: <
A>(value) =>Maybe<A>
Creates a Task.Maybe from a nullable value. Returns Some if the value is not null or undefined, None otherwise.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”A | null | undefined
Returns
Section titled “Returns”Maybe<A>
Example
Section titled “Example”Maybe.from.Result
Section titled “Maybe.from.Result”Result: <
E,A>(result) =>Maybe<A>
Creates a Task.Maybe from a Result. Ok becomes Some, Error becomes None (the error value is discarded).
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”result
Section titled “result”Result<E, A>
Returns
Section titled “Returns”Maybe<A>
Example
Section titled “Example”Maybe.from.Task
Section titled “Maybe.from.Task”Task: <
A>(task) =>Maybe<A>
Lifts a Task into a Task.Maybe by wrapping its result in Some.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”Task<A>
Returns
Section titled “Returns”Maybe<A>
Example
Section titled “Example”Maybe.getOrElse
Section titled “Maybe.getOrElse”getOrElse: <
B>(fallback) => <A>(task) =>Task<B|A>
Returns the value or a default if the Task.Maybe resolves to None.
The default can be a different type, widening the result to Task<A | B>.
Type Parameters
Section titled “Type Parameters”B
Parameters
Section titled “Parameters”fallback
Section titled “fallback”() => B
Returns
Section titled “Returns”<A>(task) => Task<B | A>
Example
Section titled “Example”Maybe.make
Section titled “Maybe.make”make:
object
Wraps a value in a Some inside a Task.
Example
Section titled “Example”Maybe.make.none
Section titled “Maybe.make.none”none: <
A>() =>Maybe<A> =makeNone
Creates a Task.Maybe that resolves to None.
Type Parameters
Section titled “Type Parameters”A = never
Returns
Section titled “Returns”Maybe<A>
Example
Section titled “Example”Maybe.make.some
Section titled “Maybe.make.some”some: <
A>(value) =>Maybe<A> =makeSome
Creates a Task.Maybe that resolves to Some(value).
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”A
Returns
Section titled “Returns”Maybe<A>
Example
Section titled “Example”Maybe.map
Section titled “Maybe.map”map: <
A,B>(transform) => (task) =>Maybe<B> =mapTaskMaybe
Transforms the value inside a Task.Maybe.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(value) => B
Returns
Section titled “Returns”(task) => Maybe<B>
Task.Maybe.chain to sequence operations that themselves return a Task.Maybe.
Example
Section titled “Example”Maybe.match
Section titled “Maybe.match”match: <
A,B>(cases) => (task) =>Task<B>
Pattern matches on a Task.Maybe, returning a Task of the result.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”() => B
(value) => B
Returns
Section titled “Returns”(task) => Task<B>
Example
Section titled “Example”Maybe.memoize
Section titled “Maybe.memoize”memoize: <
A>(task) =>Maybe<A>
Creates a memoized version of a Task.Maybe. The task is executed at most once on first call, and its resolved Maybe is cached for all subsequent calls.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”Maybe<A>
Returns
Section titled “Returns”Maybe<A>
Example
Section titled “Example”Maybe.recover
Section titled “Maybe.recover”recover: <
B>(fallback) => <A>(task) =>Maybe<B|A>
Recovers from a None state by providing a fallback Task.Maybe.
Type Parameters
Section titled “Type Parameters”B
Parameters
Section titled “Parameters”fallback
Section titled “fallback”() => Maybe<B>
Returns
Section titled “Returns”<A>(task) => Maybe<B | A>
Example
Section titled “Example”Maybe.run
Section titled “Maybe.run”Executes a Task.Maybe with an optional signal, returning Deferred<Maybe<A>>.
Use as a terminal step in a pipe chain.
Parameters
Section titled “Parameters”signal?
Section titled “signal?”AbortSignal
Returns
Section titled “Returns”<A>(task) => Deferred<Maybe<A>>
Example
Section titled “Example”Maybe.struct
Section titled “Maybe.struct”struct: <
T>(fields) =>Maybe<{ [K in string | number | symbol]: T[K] extends Maybe<A> ? A : never }>
Combines a record of Task.Maybes into a single Task.Maybe of a record. Evaluates fields in parallel and returns None if any task resolves to None.
Type Parameters
Section titled “Type Parameters”T extends Record<string, Maybe<unknown>>
Parameters
Section titled “Parameters”fields
Section titled “fields”T
Returns
Section titled “Returns”Maybe<{ [K in string | number | symbol]: T[K] extends Maybe<A> ? A : never }>
Example
Section titled “Example”Maybe.tap
Section titled “Maybe.tap”tap: <
A>(sideEffect) => (task) =>Maybe<A>
Executes a side effect on the value without changing the Task.Maybe. Useful for logging or debugging.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”sideEffect
Section titled “sideEffect”(value) => void
Returns
Section titled “Returns”(task) => Maybe<A>
Example
Section titled “Example”Maybe.to
Section titled “Maybe.to”to:
object
Maybe.to.Result
Section titled “Maybe.to.Result”Result: <
E>(onNone) => <A>(task) =>Result<E,A>
Converts a Task.Maybe to a Task.Result, using onNone to produce the error value.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”onNone
Section titled “onNone”() => E
Returns
Section titled “Returns”<A>(task) => Result<E, A>
Example
Section titled “Example”Maybe.tryCatch
Section titled “Maybe.tryCatch”tryCatch: <
A>(fn) =>Maybe<A>
Creates a Task.Maybe from a Promise-returning function.
Returns Some if the promise resolves, None if it rejects.
The factory optionally receives an AbortSignal forwarded from the call site.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”(signal?) => Thenable<A>
Returns
Section titled “Returns”Maybe<A>
Example
Section titled “Example”memoize
Section titled “memoize”memoize: <
A>(task) =>Task<A>
Creates a memoized version of a Task. The task is executed at most once on first call, and its resolved value is cached for all subsequent calls.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”Task<A>
Returns
Section titled “Returns”Task<A>
Example
Section titled “Example”poll: <
A>(options) => (task) =>Task<A>
Polls a Task repeatedly until the result satisfies a predicate, returning that result.
An optional delay duration can be inserted between polling runs.
An optional attempts cap stops the loop after N calls — the last value is returned
regardless of whether the predicate was satisfied.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”options
Section titled “options”attempts?
Section titled “attempts?”number
delay?
Section titled “delay?”(value) => boolean
Returns
Section titled “Returns”(task) => Task<A>
Task.repeat to run a Task a fixed number of times.
Example
Section titled “Example”race: (<
T>(tasks) =>Task<T[number] extendsTask<A> ?A:never>) & (<A>(tasks) =>Task<A>) =raceTask
Resolves with the value of the first Task to complete. All Tasks start immediately. When one resolves, the other tasks are cancelled (aborted) downstream.
Example
Section titled “Example”repeat
Section titled “repeat”repeat: (
options) => <A>(task) =>Task<readonlyA[]>
Runs a Task a fixed number of times sequentially, collecting all results into an array. An optional delay duration can be inserted between runs.
Parameters
Section titled “Parameters”options
Section titled “options”delay?
Section titled “delay?”number
Returns
Section titled “Returns”<A>(task) => Task<readonly A[]>
Task.poll to repeatedly run a Task until a predicate is satisfied.
Example
Section titled “Example”Result
Section titled “Result”Result:
object=TaskResult
Result.allSettled
Section titled “Result.allSettled”allSettled: <
T>(tasks) =>Task<{ [K in string | number | symbol]: T[K] extends Result<E, A> ? Result<E, A> : never }>
Runs a list of fallible tasks in parallel and collects all outcomes (Ok and Err)
without short-circuiting on failure.
Type Parameters
Section titled “Type Parameters”T extends readonly Result<any, any>[]
Parameters
Section titled “Parameters”readonly [T]
Returns
Section titled “Returns”Task<{ [K in string | number | symbol]: T[K] extends Result<E, A> ? Result<E, A> : never }>
Example
Section titled “Example”Result.apply
Section titled “Result.apply”apply: <
E2,A>(arg) => <B,E1>(task) =>Result<E2|E1,B>
Applies a function wrapped in a Task.Result to a value wrapped in a Task.Result. Both Tasks run in parallel.
Type Parameters
Section titled “Type Parameters”E2 = never
A = unknown
Parameters
Section titled “Parameters”Result<E2, A>
Returns
Section titled “Returns”<B, E1>(task) => Result<E2 | E1, B>
Example
Section titled “Example”Result.assign
Section titled “Result.assign”assign: <
K,E2,A,B>(key,transform) => <E1>(task) =>Result<E2|E1,A&{ [P in string]: B }>
Evaluates a new Task.Result using the current accumulator and attaches the output to a new key.
Type Parameters
Section titled “Type Parameters”K extends string
E2
A
B
Parameters
Section titled “Parameters”K
transform
Section titled “transform”(value) => Result<E2, B>
Returns
Section titled “Returns”<E1>(task) => Result<E2 | E1, A & { [P in string]: B }>
Example
Section titled “Example”Result.assignTo
Section titled “Result.assignTo”assignTo: <
K>(key) => <E,A>(task) =>Result<E,{ [P in string]: A }>
Converts a Task.Result value into an object containing a single property. Initiates the pipeline accumulator record.
Type Parameters
Section titled “Type Parameters”K extends string
Parameters
Section titled “Parameters”K
Returns
Section titled “Returns”<E, A>(task) => Result<E, { [P in string]: A }>
Example
Section titled “Example”Result.bimap
Section titled “Result.bimap”bimap: <
E1,E2,A,B>(onErr,onOk) => (task) =>Result<E2,B>
Maps both the Err and Ok channels simultaneously.
Type Parameters
Section titled “Type Parameters”E1
E2
A
B
Parameters
Section titled “Parameters”(error) => E2
(value) => B
Returns
Section titled “Returns”(task) => Result<E2, B>
Example
Section titled “Example”Result.chain
Section titled “Result.chain”chain: <
E2,A,B>(transform) => <E1>(task) =>Result<E2|E1,B> =chainTaskResult
Chains Task.Result computations. If the first succeeds, passes the value to transform. If the first fails, propagates the error.
Type Parameters
Section titled “Type Parameters”E2
A
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(value) => Result<E2, B>
Returns
Section titled “Returns”<E1>(task) => Result<E2 | E1, B>
Task.Result.map to transform the inner value without returning a new Task.Result.
Example
Section titled “Example”Result.ensure
Section titled “Result.ensure”ensure: {<
A,B,E2>(refinement,onFail): <E1>(task) =>Result<E2|E1,B>; <A,E2>(predicate,onFail): <E1>(task) =>Result<E2|E1,A>; }
Narrows the Ok value with a predicate or type guard. If the predicate returns false, converts the value to an Err using onFail.
Call Signature
Section titled “Call Signature”<
A,B,E2>(refinement,onFail): <E1>(task) =>Result<E2|E1,B>
Type Parameters
Section titled “Type Parameters”A
B
E2
Parameters
Section titled “Parameters”refinement
Section titled “refinement”(value) => value is B
onFail
Section titled “onFail”(value) => E2
Returns
Section titled “Returns”<E1>(task) => Result<E2 | E1, B>
Call Signature
Section titled “Call Signature”<
A,E2>(predicate,onFail): <E1>(task) =>Result<E2|E1,A>
Type Parameters
Section titled “Type Parameters”A
E2
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(value) => boolean
onFail
Section titled “onFail”(value) => E2
Returns
Section titled “Returns”<E1>(task) => Result<E2 | E1, A>
Example
Section titled “Example”Result.from
Section titled “Result.from”from:
object
Result.from.Maybe
Section titled “Result.from.Maybe”Maybe: <
E>(onNone) => <A>(maybe) =>Result<E,A>
Creates a Task.Result from a Maybe. Some becomes Ok, None becomes err from onNone.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”onNone
Section titled “onNone”() => E
Returns
Section titled “Returns”<A>(maybe) => Result<E, A>
Example
Section titled “Example”Result.from.nullable
Section titled “Result.from.nullable”nullable: <
E>(onNull) => <A>(value) =>Result<E,A>
Creates a Task.Result from a nullable value. Returns Ok if the value is not null or undefined, err from onNull otherwise.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”onNull
Section titled “onNull”() => E
Returns
Section titled “Returns”<A>(value) => Result<E, A>
Example
Section titled “Example”Result.from.Result
Section titled “Result.from.Result”Result: <
E,A>(result) =>Result<E,A>
Lifts a Result into a Task.Result.
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”result
Section titled “result”Result<E, A>
Returns
Section titled “Returns”Result<E, A>
Example
Section titled “Example”Result.getOrElse
Section titled “Result.getOrElse”getOrElse: <
B>(fallback) => <A,E>(task) =>Task<B|A>
Returns the success value or a default value if the Task.Result is an error.
The default can be a different type, widening the result to Task<A | B>.
Type Parameters
Section titled “Type Parameters”B
Parameters
Section titled “Parameters”fallback
Section titled “fallback”() => B
Returns
Section titled “Returns”<A, E>(task) => Task<B | A>
Example
Section titled “Example”Result.make
Section titled “Result.make”make:
object
Result.make.err
Section titled “Result.make.err”err: <
E>(error) =>Result<E,never> =makeErr
Creates a failed Task.Result with the given error.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”E
Returns
Section titled “Returns”Result<E, never>
Example
Section titled “Example”Result.make.ok
Section titled “Result.make.ok”ok: <
A>(value) =>Result<never,A> =makeOk
Wraps a value in a successful Task.Result.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”A
Returns
Section titled “Returns”Result<never, A>
Example
Section titled “Example”Result.map
Section titled “Result.map”map: <
A,B>(transform) => <E>(task) =>Result<E,B> =mapTaskResult
Transforms the success value inside a Task.Result.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(value) => B
Returns
Section titled “Returns”<E>(task) => Result<E, B>
- Task.Result.chain to sequence operations that themselves return a Task.Result.
- Task.Result.mapError to transform the error value instead of the success value.
Example
Section titled “Example”Result.mapError
Section titled “Result.mapError”mapError: <
E,F>(transform) => <A>(task) =>Result<F,A>
Transforms the error value inside a Task.Result.
Type Parameters
Section titled “Type Parameters”E
F
Parameters
Section titled “Parameters”transform
Section titled “transform”(error) => F
Returns
Section titled “Returns”<A>(task) => Result<F, A>
Task.Result.map to transform the success value instead of the error value.
Example
Section titled “Example”Result.match
Section titled “Result.match”match: <
E,A,B>(cases) => (task) =>Task<B>
Pattern matches on a Task.Result, returning a Task of the result.
Type Parameters
Section titled “Type Parameters”E
A
B
Parameters
Section titled “Parameters”(error) => B
(value) => B
Returns
Section titled “Returns”(task) => Task<B>
Example
Section titled “Example”Result.memoize
Section titled “Result.memoize”memoize: <
E,A>(task) =>Result<E,A>
Creates a memoized version of a Task.Result. The task is executed at most once on first call, and its resolved Result is cached for all subsequent calls.
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”Result<E, A>
Returns
Section titled “Returns”Result<E, A>
Example
Section titled “Example”Result.recover
Section titled “Result.recover”recover: <
E1,E2,B>(fallback) => <A>(task) =>Result<E2,B|A>
Recovers from an error by providing a fallback Task.Result. The fallback can produce a different success type or resolve with a different error type.
Type Parameters
Section titled “Type Parameters”E1
E2
B
Parameters
Section titled “Parameters”fallback
Section titled “fallback”(error) => Result<E2, B>
Returns
Section titled “Returns”<A>(task) => Result<E2, B | A>
Task.Result.recoverUnless to conditionally recover based on the error value.
Example
Section titled “Example”Result.recoverUnless
Section titled “Result.recoverUnless”recoverUnless: <
E1,E2,B>(isBlocked,fallback) => <A>(task) =>Result<E1|E2,B|A>
Recovers from an error unless the predicate isBlocked returns true for that error.
The fallback can produce a different success type, widening the result to Task.Result<E1 | E2, A | B>.
Type Parameters
Section titled “Type Parameters”E1
E2
B
Parameters
Section titled “Parameters”isBlocked
Section titled “isBlocked”(error) => boolean
fallback
Section titled “fallback”(error) => Result<E2, B>
Returns
Section titled “Returns”<A>(task) => Result<E1 | E2, B | A>
Task.Result.recover for unconditional error recovery.
Example
Section titled “Example”Result.retry
Section titled “Result.retry”retry: <
E>(policy) => <E1,A>(task) =>Result<E1,A>
Retries a fallible Task.Result according to a RetryPolicy.
If the task succeeds, returns Ok immediately.
If the task fails, retries up to policy.attempts times with delays generated by policy.
Any optional when predicate or onRetry callback configured on the RetryPolicy
will filter retriable errors and emit telemetry events before each backoff delay.
Type Parameters
Section titled “Type Parameters”E = unknown
Parameters
Section titled “Parameters”policy
Section titled “policy”RetryPolicy<E>
Returns
Section titled “Returns”<E1, A>(task) => Result<E1, A>
Example
Section titled “Example”Result.run
Section titled “Result.run”Executes a Task.Result with an optional signal, returning Deferred<Result<E, A>>.
Use as a terminal step in a pipe chain.
Parameters
Section titled “Parameters”signal?
Section titled “signal?”AbortSignal
Returns
Section titled “Returns”<E, A>(task) => Deferred<Result<E, A>>
Example
Section titled “Example”Result.struct
Section titled “Result.struct”struct: <
T>(fields) =>Result<T[keyofT] extendsResult<E,unknown> ?E:never, { [K in string | number | symbol]: T[K] extends Result<unknown, A> ? A : never }>
Combines a record of Task.Results into a single Task.Result of a record. Evaluates all tasks in parallel, forwarding the AbortSignal down to each sub-task. Returns the first Err encountered in key order.
Type Parameters
Section titled “Type Parameters”T extends Record<string, Result<unknown, unknown>>
Parameters
Section titled “Parameters”fields
Section titled “fields”T
Returns
Section titled “Returns”Result<T[keyof T] extends Result<E, unknown> ? E : never, { [K in string | number | symbol]: T[K] extends Result<unknown, A> ? A : never }>
Example
Section titled “Example”Result.tap
Section titled “Result.tap”tap: <
A>(sideEffect) => <E>(task) =>Result<E,A>
Executes a side effect on the success value without changing the Task.Result. Useful for logging or debugging.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”sideEffect
Section titled “sideEffect”(value) => void
Returns
Section titled “Returns”<E>(task) => Result<E, A>
Task.Result.tapError to perform a side effect on the error value.
Example
Section titled “Example”Result.tapError
Section titled “Result.tapError”tapError: <
E>(sideEffect) => <A>(task) =>Result<E,A>
Executes a side effect on the error value without changing the Task.Result. Useful for logging or reporting async errors.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”sideEffect
Section titled “sideEffect”(error) => void
Returns
Section titled “Returns”<A>(task) => Result<E, A>
Task.Result.tap to perform a side effect on the success value.
Example
Section titled “Example”Result.timeout
Section titled “Result.timeout”timeout: <
E2>(options) => <E1,A>(task) =>Result<E2|E1,A>
Times out a fallible task, resolving to Err(onTimeout()) if the duration elapses
before the task completes.
Type Parameters
Section titled “Type Parameters”E2
Parameters
Section titled “Parameters”options
Section titled “options”duration
Section titled “duration”onTimeout
Section titled “onTimeout”() => E2
Returns
Section titled “Returns”<E1, A>(task) => Result<E2 | E1, A>
Example
Section titled “Example”Result.to
Section titled “Result.to”to:
object
Result.to.Maybe
Section titled “Result.to.Maybe”Maybe: <
E,A>(task) =>Maybe<A>
Converts a Task.Result to a Task.Maybe, dropping the error value on Err.
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”Result<E, A>
Returns
Section titled “Returns”Maybe<A>
Example
Section titled “Example”Result.tryCatch
Section titled “Result.tryCatch”tryCatch: <
E,A>(fn,options) =>Result<E,A>
Creates a Task.Result from a Promise-returning thunk that may throw or reject.
Catches any errors and transforms them using the onError function into an Err.
The thunk optionally receives an AbortSignal forwarded from the call site.
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”(signal?) => Thenable<A>
options
Section titled “options”onError
Section titled “onError”(error) => E
Returns
Section titled “Returns”Result<E, A>
Example
Section titled “Example”run: (
signal?) => <A>(task) =>Deferred<A>
Executes a task with an optional signal. Use as a terminal step in a pipe chain.
Parameters
Section titled “Parameters”signal?
Section titled “signal?”AbortSignal
Returns
Section titled “Returns”<A>(task) => Deferred<A>
Example
Section titled “Example”sequential
Section titled “sequential”sequential: <
T>(tasks) =>Task<{ [K in string | number | symbol]: T[K] extends Task<A> ? A : never }>
Runs an array or tuple of Tasks one at a time in order, collecting all results. Each Task starts only after the previous one resolves.
Type Parameters
Section titled “Type Parameters”T extends readonly Task<unknown>[]
Parameters
Section titled “Parameters”readonly [T]
Returns
Section titled “Returns”Task<{ [K in string | number | symbol]: T[K] extends Task<A> ? A : never }>
Task.all to run an array or tuple of tasks in parallel.
Example
Section titled “Example”tap: <
A>(sideEffect) => (task) =>Task<A>
Executes a side effect on the value without changing the Task. Useful for logging or debugging.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”sideEffect
Section titled “sideEffect”(value) => void
Returns
Section titled “Returns”(task) => Task<A>
Example
Section titled “Example”timeout
Section titled “timeout”Converts a Task<A> into a Task<Result<E, A>>, resolving to Err if the
Task does not complete within the given duration. The inner Task receives an
AbortSignal that fires when the deadline passes, so asynchronous operations
that accept a signal are cancelled rather than left dangling.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”options
Section titled “options”duration
Section titled “duration”onTimeout
Section titled “onTimeout”() => E
Returns
Section titled “Returns”<A>(task) => Task<Result<E, A>>
Example
Section titled “Example”tryCatch
Section titled “tryCatch”tryCatch: <
A,B>(fn,options) =>Task<A|B>
Wraps a Promise-returning thunk that may throw or reject,
trapping errors with a fallback function and returning a guaranteed Task<A>.
Type Parameters
Section titled “Type Parameters”A
B = A
Parameters
Section titled “Parameters”(signal?) => Thenable<A>
options
Section titled “options”onError
Section titled “onError”(error) => B
Returns
Section titled “Returns”Task<A | B>
Example
Section titled “Example”Validation
Section titled “Validation”Validation:
object=TaskValidation
Validation.apply
Section titled “Validation.apply”apply: <
E2,A>(arg) => <B,E1>(task) =>Validation<E2|E1,B>
Applies a function wrapped in a Task.Validation to a value wrapped in a Task.Validation. Both Tasks run in parallel and errors from both sides are accumulated.
Type Parameters
Section titled “Type Parameters”E2 = never
A = unknown
Parameters
Section titled “Parameters”Validation<E2, A>
Returns
Section titled “Returns”<B, E1>(task) => Validation<E2 | E1, B>
Task.Validation.struct to combine multiple validations into a record.
Example
Section titled “Example”Validation.from
Section titled “Validation.from”from:
object
Validation.from.Maybe
Section titled “Validation.from.Maybe”Maybe: <
E>(onNone) => <A>(maybe) =>Validation<E,A>
Creates a Task.Validation from a Maybe. Some becomes Passed, None becomes Failed with the error from onNone.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”onNone
Section titled “onNone”() => E
Returns
Section titled “Returns”<A>(maybe) => Validation<E, A>
Example
Section titled “Example”Validation.from.nullable
Section titled “Validation.from.nullable”nullable: <
E>(onNull) => <A>(value) =>Validation<E,NonNullable<A>>
Creates a Task.Validation from a nullable value. If the value is null or undefined, returns Failed with the error from onNull. Otherwise, returns Passed.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”onNull
Section titled “onNull”() => E
Returns
Section titled “Returns”<A>(value) => Validation<E, NonNullable<A>>
Example
Section titled “Example”Validation.from.Result
Section titled “Validation.from.Result”Result: <
E,A>(result) =>Validation<E,A>
Creates a Task.Validation from a Result. Ok becomes Passed, Err(e) becomes Failed([e]).
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”result
Section titled “result”Result<E, A>
Returns
Section titled “Returns”Validation<E, A>
Example
Section titled “Example”Validation.from.Validation
Section titled “Validation.from.Validation”Validation: <
E,A>(validation) =>Validation<E,A>
Lifts a Validation into a Task.Validation.
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”validation
Section titled “validation”Validation<E, A>
Returns
Section titled “Returns”Validation<E, A>
Example
Section titled “Example”Validation.getOrElse
Section titled “Validation.getOrElse”getOrElse: <
B>(fallback) => <A,E>(task) =>Task<B|A>
Returns the success value or a default value if the Task.Validation is failed.
The default can be a different type, widening the result to Task<A | B>.
Type Parameters
Section titled “Type Parameters”B
Parameters
Section titled “Parameters”fallback
Section titled “fallback”() => B
Returns
Section titled “Returns”<A, E>(task) => Task<B | A>
Example
Section titled “Example”Validation.make
Section titled “Validation.make”make:
object
Validation.make.failed
Section titled “Validation.make.failed”failed: <
E>(error) =>Validation<E,never> =makeFailed
Creates a failed Task.Validation with a single error.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”E
Returns
Section titled “Returns”Validation<E, never>
Example
Section titled “Example”Validation.make.failedAll
Section titled “Validation.make.failedAll”failedAll: <
E>(errors) =>Validation<E,never> =makeFailedAll
Creates a failed Task.Validation from multiple errors.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”errors
Section titled “errors”NonEmptyArr<E>
Returns
Section titled “Returns”Validation<E, never>
Example
Section titled “Example”Validation.make.passed
Section titled “Validation.make.passed”passed: <
A>(value) =>Validation<never,A> =makePassed
Wraps a value in a passed Task.Validation.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”A
Returns
Section titled “Returns”Validation<never, A>
Example
Section titled “Example”Validation.map
Section titled “Validation.map”map: <
A,B>(transform) => <E>(task) =>Validation<E,B>
Transforms the success value inside a Task.Validation.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(value) => B
Returns
Section titled “Returns”<E>(task) => Validation<E, B>
- Task.Validation.mapError to transform accumulated errors.
- Task.Validation.apply to combine multiple validations in parallel.
Example
Section titled “Example”Validation.mapError
Section titled “Validation.mapError”mapError: <
E,F>(transform) => <A>(task) =>Validation<F,A>
Transforms all accumulated errors inside a Task.Validation.
Type Parameters
Section titled “Type Parameters”E
F
Parameters
Section titled “Parameters”transform
Section titled “transform”(error) => F
Returns
Section titled “Returns”<A>(task) => Validation<F, A>
Task.Validation.map to transform the success value.
Example
Section titled “Example”Validation.match
Section titled “Validation.match”match: <
E,A,B>(cases) => (task) =>Task<B>
Pattern matches on a Task.Validation, returning a Task of the result.
Type Parameters
Section titled “Type Parameters”E
A
B
Parameters
Section titled “Parameters”failed
Section titled “failed”(errors) => B
passed
Section titled “passed”(value) => B
Returns
Section titled “Returns”(task) => Task<B>
Example
Section titled “Example”Validation.memoize
Section titled “Validation.memoize”memoize: <
E,A>(task) =>Validation<E,A>
Creates a memoized version of a Task.Validation. The task is executed at most once on first call, and its resolved Validation is cached for all subsequent calls.
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”Validation<E, A>
Returns
Section titled “Returns”Validation<E, A>
Example
Section titled “Example”Validation.recover
Section titled “Validation.recover”recover: <
E1,B,E2>(fallback) => <A>(task) =>Validation<E2,B|A>
Recovers from a Failed state by providing a fallback Task.Validation. The fallback receives the accumulated error list so callers can inspect which errors occurred. The fallback can produce a different success type or resolve with a different error type.
Type Parameters
Section titled “Type Parameters”E1
B
E2 = never
Parameters
Section titled “Parameters”fallback
Section titled “fallback”(errors) => Validation<E2, B>
Returns
Section titled “Returns”<A>(task) => Validation<E2, B | A>
Task.Validation.recoverUnless to conditionally recover based on accumulated errors.
Example
Section titled “Example”Validation.recoverUnless
Section titled “Validation.recoverUnless”recoverUnless: <
E1,B,E2>(isBlocked,fallback) => <A>(task) =>Validation<E1|E2,B|A>
Recovers from a Failed state unless the predicate isBlocked returns true for the accumulated errors.
The fallback receives the accumulated errors and can produce a different success type, widening the result to Task.Validation<E1 | E2, A | B>.
Type Parameters
Section titled “Type Parameters”E1
B
E2 = never
Parameters
Section titled “Parameters”isBlocked
Section titled “isBlocked”(errors) => boolean
fallback
Section titled “fallback”(errors) => Validation<E2, B>
Returns
Section titled “Returns”<A>(task) => Validation<E1 | E2, B | A>
Task.Validation.recover for unconditional error recovery.
Example
Section titled “Example”Validation.run
Section titled “Validation.run”run: (
signal?) => <E,A>(task) =>Deferred<Validation<E,A>>
Executes a Task.Validation with an optional signal, returning Deferred<Validation<E, A>>.
Use as a terminal step in a pipe chain.
Parameters
Section titled “Parameters”signal?
Section titled “signal?”AbortSignal
Returns
Section titled “Returns”<E, A>(task) => Deferred<Validation<E, A>>
Example
Section titled “Example”Validation.struct
Section titled “Validation.struct”struct: <
T>(fields) =>Validation<T[keyofT] extendsValidation<E,unknown> ?E:never, { [K in string | number | symbol]: T[K] extends Validation<unknown, A> ? A : never }>
Combines a record of Task.Validations into a single Task.Validation of a record. Evaluates fields in parallel and accumulates all validation errors.
Type Parameters
Section titled “Type Parameters”T extends Record<string, Validation<unknown, unknown>>
Parameters
Section titled “Parameters”fields
Section titled “fields”T
Returns
Section titled “Returns”Validation<T[keyof T] extends Validation<E, unknown> ? E : never, { [K in string | number | symbol]: T[K] extends Validation<unknown, A> ? A : never }>
Example
Section titled “Example”Validation.tap
Section titled “Validation.tap”tap: <
A>(sideEffect) => <E>(task) =>Validation<E,A>
Executes a side effect on the success value without changing the Task.Validation. Useful for logging or debugging.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”sideEffect
Section titled “sideEffect”(value) => void
Returns
Section titled “Returns”<E>(task) => Validation<E, A>
Task.Validation.tapError to perform a side effect on accumulated errors.
Example
Section titled “Example”Validation.tapError
Section titled “Validation.tapError”tapError: <
E>(sideEffect) => <A>(task) =>Validation<E,A>
Executes a side effect on the accumulated errors without changing the Task.Validation.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”sideEffect
Section titled “sideEffect”(errors) => void
Returns
Section titled “Returns”<A>(task) => Validation<E, A>
Task.Validation.tap to perform a side effect on the success value.
Example
Section titled “Example”Validation.to
Section titled “Validation.to”to:
object
Validation.to.Maybe
Section titled “Validation.to.Maybe”Maybe: <
E,A>(task) =>Maybe<A>
Converts a Task.Validation to a Task.Maybe.
Passed(a) becomes Some(a); Failed(errors) becomes None (errors are discarded).
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”Validation<E, A>
Returns
Section titled “Returns”Maybe<A>
Example
Section titled “Example”Validation.to.Result
Section titled “Validation.to.Result”Result: <
E1,E2>(combineErrors) => <A>(task) =>Result<E2,A>
Converts a Task.Validation to a Task.Result, combining accumulated errors using combineErrors.
Passed(a) becomes Ok(a); Failed(errors) becomes Err(combineErrors(errors)).
Type Parameters
Section titled “Type Parameters”E1
E2
Parameters
Section titled “Parameters”combineErrors
Section titled “combineErrors”(errors) => E2
Returns
Section titled “Returns”<A>(task) => Result<E2, A>
Example
Section titled “Example”Validation.tryCatch
Section titled “Validation.tryCatch”tryCatch: <
E,A>(fn,options) =>Validation<E,A>
Creates a Task.Validation from a Promise-returning thunk that may throw or reject.
Catches any errors and transforms them using the onError function into a Failed validation.
The thunk optionally receives an AbortSignal forwarded from the call site.
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”(signal?) => Thenable<A>
options
Section titled “options”onError
Section titled “onError”(error) => E
Returns
Section titled “Returns”Validation<E, A>
Example
Section titled “Example”withLabel
Section titled “withLabel”withLabel: <
L>(label) => <A>(task) =>LabeledTask<L,A>
Attaches a read-only .label property to a Task, preserving the literal string generic type for IDE tooltips.
Type Parameters
Section titled “Type Parameters”L extends string
Parameters
Section titled “Parameters”L
Returns
Section titled “Returns”<A>(task) => LabeledTask<L, A>
Example
Section titled “Example”withProgress
Section titled “withProgress”withProgress: (
onProgress) => <A>(task) =>Task<A>
Monitors progress of a Task by calling onProgress(0) before execution and onProgress(1) upon completion.
Parameters
Section titled “Parameters”onProgress
Section titled “onProgress”(ratio) => void
Returns
Section titled “Returns”<A>(task) => Task<A>