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) =>Task<{ [K in string | number | symbol]: T[K] extends Task<A> ? A : never }>
Runs multiple Tasks in parallel and collects their results.
Type Parameters
Section titled “Type Parameters”T extends readonly Task<unknown>[]
Parameters
Section titled “Parameters”T
Returns
Section titled “Returns”Task<{ [K in string | number | symbol]: T[K] extends Task<A> ? A : never }>
Example
Section titled “Example”ap: <
A>(arg) => <B>(data) =>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>(data) => Task<B>
Example
Section titled “Example”bind: <
K,A,B>(key,f) => (data) =>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
(a) => Task<B>
Returns
Section titled “Returns”(data) => Task<A & { [P in string]: B }>
Example
Section titled “Example”bindTo
Section titled “bindTo”bindTo: <
K>(key) => <A>(data) =>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>(data) => Task<{ [P in string]: A }>
Example
Section titled “Example”chain: <
A,B>(f) => (data) =>Task<B>
Chains Task computations. Passes the resolved value of the first Task to f.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”(a) => Task<B>
Returns
Section titled “Returns”(data) => Task<B>
Example
Section titled “Example”delay: (
duration) => <A>(data) =>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>(data) => Task<A>
Example
Section titled “Example”from:
object
from.sync
Section titled “from.sync”sync: <
A>(f) =>Task<A> =syncTask
Creates a Task from a lazy synchronous thunk.
Unlike Task.resolve(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”map: <
A,B>(f) => (data) =>Task<B>
Transforms the value inside a Task.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”(a) => B
Returns
Section titled “Returns”(data) => Task<B>
Example
Section titled “Example”Maybe:
object=TaskMaybe
Maybe.ap
Section titled “Maybe.ap”ap: <
A>(arg) => <B>(data) =>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>(data) => Maybe<B>
Maybe.bind
Section titled “Maybe.bind”bind: <
K,A,B>(key,f) => (data) =>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
(a) => Maybe<B>
Returns
Section titled “Returns”(data) => Maybe<A & { [P in string]: B }>
Example
Section titled “Example”Maybe.bindTo
Section titled “Maybe.bindTo”bindTo: <
K>(key) => <A>(data) =>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>(data) => Maybe<{ [P in string]: A }>
Example
Section titled “Example”Maybe.chain
Section titled “Maybe.chain”chain: <
A,B>(f) => (data) =>Maybe<B> =chainTaskMaybe
Chains Task.Maybe computations. If the first resolves to Some, passes the value to f. If the first resolves to None, propagates None.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”(a) => Maybe<B>
Returns
Section titled “Returns”(data) => Maybe<B>
Example
Section titled “Example”Maybe.filter
Section titled “Maybe.filter”filter: <
A>(predicate) => (data) =>Maybe<A>
Filters the value inside a Task.Maybe. Returns None if the predicate fails.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(a) => boolean
Returns
Section titled “Returns”(data) => Maybe<A>
Maybe.fold
Section titled “Maybe.fold”fold: <
A,B>(onNone,onSome) => (data) =>Task<B>
Extracts a value from a Task.Maybe by providing handlers for both cases.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”onNone
Section titled “onNone”() => B
onSome
Section titled “onSome”(a) => B
Returns
Section titled “Returns”(data) => Task<B>
Maybe.from
Section titled “Maybe.from”from:
object
Maybe.from.Maybe
Section titled “Maybe.from.Maybe”Maybe: <
A>(option) =>Maybe<A>
Lifts a Maybe into a Task.Maybe.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”option
Section titled “option”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>(defaultValue) => <A>(data) =>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”defaultValue
Section titled “defaultValue”() => B
Returns
Section titled “Returns”<A>(data) => Task<B | A>
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>(f) => (data) =>Maybe<B> =mapTaskMaybe
Transforms the value inside a Task.Maybe.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”(a) => B
Returns
Section titled “Returns”(data) => Maybe<B>
Maybe.match
Section titled “Maybe.match”match: <
A,B>(cases) => (data) =>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
(a) => B
Returns
Section titled “Returns”(data) => 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>(data) =>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>(data) => Maybe<B | A>
Example
Section titled “Example”Maybe.struct
Section titled “Maybe.struct”struct: <
R>(fields) =>Maybe<R>
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”R extends Record<string, any>
Parameters
Section titled “Parameters”fields
Section titled “fields”{ [K in string | number | symbol]: Maybe<R[K]> }
Returns
Section titled “Returns”Maybe<R>
Example
Section titled “Example”Maybe.tap
Section titled “Maybe.tap”tap: <
A>(f) => (data) =>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”(a) => void
Returns
Section titled “Returns”(data) => Maybe<A>
Maybe.to
Section titled “Maybe.to”to:
object
Maybe.to.Result
Section titled “Maybe.to.Result”Result: <
E>(onNone) => <A>(data) =>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>(data) => Result<E, A>
Example
Section titled “Example”Maybe.tryCatch
Section titled “Maybe.tryCatch”tryCatch: <
A>(f) =>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”race: <
A>(tasks) =>Task<A>
Resolves with the value of the first Task to complete. All Tasks start immediately. When one resolves, the other tasks are cancelled (aborted) downstream.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”readonly Task<A>[]
Returns
Section titled “Returns”Task<A>
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[]>
Example
Section titled “Example”repeatUntil
Section titled “repeatUntil”repeatUntil: <
A>(options) => (task) =>Task<A>
Runs a Task repeatedly until the result satisfies a predicate, returning that result.
An optional delay duration can be inserted between runs.
An optional maxAttempts 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”delay?
Section titled “delay?”maxAttempts?
Section titled “maxAttempts?”number
(a) => boolean
Returns
Section titled “Returns”(task) => Task<A>
Example
Section titled “Example”resolve
Section titled “resolve”resolve: <
A>(value) =>Task<A> =resolveTask
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”Result
Section titled “Result”Result:
object=TaskResult
Result.allSettled
Section titled “Result.allSettled”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”E
A
Parameters
Section titled “Parameters”readonly Result<E, A>[]
Returns
Section titled “Returns”Example
Section titled “Example”Result.ap
Section titled “Result.ap”ap: <
E,A>(arg) => <B>(data) =>Result<E,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”E
A
Parameters
Section titled “Parameters”Result<E, A>
Returns
Section titled “Returns”<B>(data) => Result<E, B>
Result.bind
Section titled “Result.bind”bind: <
K,E,A,B>(key,f) => (data) =>Result<E,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
E
A
B
Parameters
Section titled “Parameters”K
(a) => Result<E, B>
Returns
Section titled “Returns”(data) => Result<E, A & { [P in string]: B }>
Example
Section titled “Example”Result.bindTo
Section titled “Result.bindTo”bindTo: <
K>(key) => <E,A>(data) =>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>(data) => Result<E, { [P in string]: A }>
Example
Section titled “Example”Result.chain
Section titled “Result.chain”chain: <
E2,A,B>(f) => <E1>(data) =>Result<E2|E1,B> =chainTaskResult
Chains Task.Result computations. If the first succeeds, passes the value to f. If the first fails, propagates the error.
Type Parameters
Section titled “Type Parameters”E2
A
B
Parameters
Section titled “Parameters”(a) => Result<E2, B>
Returns
Section titled “Returns”<E1>(data) => Result<E2 | E1, B>
Result.fold
Section titled “Result.fold”fold: <
E,A,B>(onErr,onOk) => (data) =>Task<B>
Extracts the value from a Task.Result by providing handlers for both cases.
Type Parameters
Section titled “Type Parameters”E
A
B
Parameters
Section titled “Parameters”(e) => B
(a) => B
Returns
Section titled “Returns”(data) => Task<B>
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>(defaultValue) => <E,A>(data) =>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”defaultValue
Section titled “defaultValue”() => B
Returns
Section titled “Returns”<E, A>(data) => Task<B | A>
Result.make
Section titled “Result.make”make:
object
Result.make.err
Section titled “Result.make.err”err: <
E,A>(error) =>Result<E,A> =makeErr
Creates a failed Task.Result with the given error.
Type Parameters
Section titled “Type Parameters”E
A = never
Parameters
Section titled “Parameters”E
Returns
Section titled “Returns”Result<E, A>
Example
Section titled “Example”Result.make.ok
Section titled “Result.make.ok”ok: <
E,A>(value) =>Result<E,A> =makeOk
Wraps a value in a successful Task.Result.
Type Parameters
Section titled “Type Parameters”E = never
A = unknown
Parameters
Section titled “Parameters”A
Returns
Section titled “Returns”Result<E, A>
Example
Section titled “Example”Result.map
Section titled “Result.map”map: <
E,A,B>(f) => (data) =>Result<E,B> =mapTaskResult
Transforms the success value inside a Task.Result.
Type Parameters
Section titled “Type Parameters”E
A
B
Parameters
Section titled “Parameters”(a) => B
Returns
Section titled “Returns”(data) => Result<E, B>
Result.mapError
Section titled “Result.mapError”mapError: <
E,F,A>(f) => (data) =>Result<F,A>
Transforms the error value inside a Task.Result.
Type Parameters
Section titled “Type Parameters”E
F
A
Parameters
Section titled “Parameters”(e) => F
Returns
Section titled “Returns”(data) => Result<F, A>
Result.match
Section titled “Result.match”match: <
E,A,B>(cases) => (data) =>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”(e) => B
(a) => B
Returns
Section titled “Returns”(data) => Task<B>
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: <
E,B>(fallback) => <A>(data) =>Result<E,B|A>
Recovers from an error by providing a fallback Task.Result.
The fallback can produce a different success type, widening the result to Task.Result<E, A | B>.
Type Parameters
Section titled “Type Parameters”E
B
Parameters
Section titled “Parameters”fallback
Section titled “fallback”(e) => Result<E, B>
Returns
Section titled “Returns”<A>(data) => Result<E, B | A>
Result.recoverUnless
Section titled “Result.recoverUnless”recoverUnless: <
E,B>(isBlocked,fallback) => <A>(data) =>Result<E,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<E, A | B>.
Type Parameters
Section titled “Type Parameters”E
B
Parameters
Section titled “Parameters”isBlocked
Section titled “isBlocked”(e) => boolean
fallback
Section titled “fallback”(e) => Result<E, B>
Returns
Section titled “Returns”<A>(data) => Result<E, B | A>
Example
Section titled “Example”Result.retry
Section titled “Result.retry”retry: (
policy) => <E,A>(task) =>Result<E,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.
Parameters
Section titled “Parameters”policy
Section titled “policy”Returns
Section titled “Returns”<E, A>(task) => Result<E, A>
Example
Section titled “Example”Result.run
Section titled “Result.run”Executes a Task.Result with an optional signal, returning Promise<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: <
E,R>(fields) =>Result<E,R>
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”E
R extends Record<string, any>
Parameters
Section titled “Parameters”fields
Section titled “fields”{ [K in string | number | symbol]: Result<E, R[K]> }
Returns
Section titled “Returns”Result<E, R>
Example
Section titled “Example”Result.tap
Section titled “Result.tap”tap: <
E,A>(f) => (data) =>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”E
A
Parameters
Section titled “Parameters”(a) => void
Returns
Section titled “Returns”(data) => Result<E, A>
Result.tapError
Section titled “Result.tapError”tapError: <
E,A>(f) => (data) =>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
A
Parameters
Section titled “Parameters”(e) => void
Returns
Section titled “Returns”(data) => Result<E, A>
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>(data) =>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>(f,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”sequence
Section titled “sequence”sequence: <
A>(tasks) =>Task<readonlyA[]>
Runs an array of Tasks concurrently and collects their results in an array. Forward-propagates the call site’s AbortSignal to all subtasks concurrently.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”readonly Task<A>[]
Returns
Section titled “Returns”Task<readonly A[]>
Example
Section titled “Example”sequential
Section titled “sequential”sequential: <
A>(tasks) =>Task<readonlyA[]>
Runs an array 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”A
Parameters
Section titled “Parameters”readonly Task<A>[]
Returns
Section titled “Returns”Task<readonly A[]>
Example
Section titled “Example”tap: <
A>(f) => (data) =>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”(a) => void
Returns
Section titled “Returns”(data) => 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>(f,options) =>Task<A>
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
Parameters
Section titled “Parameters”(signal?) => Promise<A>
options
Section titled “options”onError
Section titled “onError”(error) => A
Returns
Section titled “Returns”Task<A>
Example
Section titled “Example”Validation
Section titled “Validation”Validation:
object=TaskValidation
Validation.ap
Section titled “Validation.ap”ap: <
E,A>(arg) => <B>(data) =>Validation<E,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”E
A
Parameters
Section titled “Parameters”Validation<E, A>
Returns
Section titled “Returns”<B>(data) => Validation<E, B>
Example
Section titled “Example”Validation.fold
Section titled “Validation.fold”fold: <
E,A,B>(onFailed,onPassed) => (data) =>Task<B>
Extracts a value from a Task.Validation by providing handlers for both cases.
Type Parameters
Section titled “Type Parameters”E
A
B
Parameters
Section titled “Parameters”onFailed
Section titled “onFailed”(errors) => B
onPassed
Section titled “onPassed”(a) => B
Returns
Section titled “Returns”(data) => Task<B>
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,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, 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>(defaultValue) => <E,A>(data) =>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”defaultValue
Section titled “defaultValue”() => B
Returns
Section titled “Returns”<E, A>(data) => Task<B | A>
Validation.make
Section titled “Validation.make”make:
object
Validation.make.failed
Section titled “Validation.make.failed”failed: <
E,A>(error) =>Validation<E,A> =makeFailed
Creates a failed Task.Validation with a single error.
Type Parameters
Section titled “Type Parameters”E
A = never
Parameters
Section titled “Parameters”E
Returns
Section titled “Returns”Validation<E, A>
Example
Section titled “Example”Validation.make.failedAll
Section titled “Validation.make.failedAll”failedAll: <
E,A>(errors) =>Validation<E,A> =makeFailedAll
Creates a failed Task.Validation from multiple errors.
Type Parameters
Section titled “Type Parameters”E
A = never
Parameters
Section titled “Parameters”errors
Section titled “errors”NonEmptyArr<E>
Returns
Section titled “Returns”Validation<E, A>
Example
Section titled “Example”Validation.make.passed
Section titled “Validation.make.passed”passed: <
E,A>(value) =>Validation<E,A> =makePassed
Wraps a value in a passed Task.Validation.
Type Parameters
Section titled “Type Parameters”E = never
A = unknown
Parameters
Section titled “Parameters”A
Returns
Section titled “Returns”Validation<E, A>
Example
Section titled “Example”Validation.map
Section titled “Validation.map”map: <
E,A,B>(f) => (data) =>Validation<E,B>
Transforms the success value inside a Task.Validation.
Type Parameters
Section titled “Type Parameters”E
A
B
Parameters
Section titled “Parameters”(a) => B
Returns
Section titled “Returns”(data) => Validation<E, B>
Validation.mapError
Section titled “Validation.mapError”mapError: <
E,F,A>(f) => (data) =>Validation<F,A>
Transforms all accumulated errors inside a Task.Validation.
Type Parameters
Section titled “Type Parameters”E
F
A
Parameters
Section titled “Parameters”(e) => F
Returns
Section titled “Returns”(data) => Validation<F, A>
Example
Section titled “Example”Validation.match
Section titled “Validation.match”match: <
E,A,B>(cases) => (data) =>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”(a) => B
Returns
Section titled “Returns”(data) => 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.product
Section titled “Validation.product”product: <
E,A,B>(first,second) =>Validation<E, readonly [A,B]>
Runs two Task.Validations concurrently and combines their results into a tuple. If both are Passed, returns Passed with both values. If either fails, accumulates errors from both sides.
Type Parameters
Section titled “Type Parameters”E
A
B
Parameters
Section titled “Parameters”Validation<E, A>
second
Section titled “second”Validation<E, B>
Returns
Section titled “Returns”Validation<E, readonly [A, B]>
Example
Section titled “Example”Validation.productAll
Section titled “Validation.productAll”productAll: <
E,A>(data) =>Validation<E, readonlyA[]>
Runs all Task.Validations concurrently and collects results. If all are Passed, returns Passed with all values as an array. If any fail, returns Failed with all accumulated errors.
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”NonEmptyArr<Validation<E, A>>
Returns
Section titled “Returns”Validation<E, readonly A[]>
Example
Section titled “Example”Validation.recover
Section titled “Validation.recover”recover: <
E,B>(fallback) => <A>(data) =>Validation<E,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, widening the result to Task.Validation<E, A | B>.
Type Parameters
Section titled “Type Parameters”E
B
Parameters
Section titled “Parameters”fallback
Section titled “fallback”(errors) => Validation<E, B>
Returns
Section titled “Returns”<A>(data) => Validation<E, B | A>
Validation.recoverUnless
Section titled “Validation.recoverUnless”recoverUnless: <
E,B>(isBlocked,fallback) => <A>(data) =>Validation<E,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<E, A | B>.
Type Parameters
Section titled “Type Parameters”E
B
Parameters
Section titled “Parameters”isBlocked
Section titled “isBlocked”(errors) => boolean
fallback
Section titled “fallback”(errors) => Validation<E, B>
Returns
Section titled “Returns”<A>(data) => Validation<E, B | A>
Example
Section titled “Example”Validation.struct
Section titled “Validation.struct”struct: <
E,R>(fields) =>Validation<E,R>
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”E
R extends Record<string, any>
Parameters
Section titled “Parameters”fields
Section titled “fields”{ [K in string | number | symbol]: Validation<E, R[K]> }
Returns
Section titled “Returns”Validation<E, R>
Example
Section titled “Example”Validation.tap
Section titled “Validation.tap”tap: <
E,A>(f) => (data) =>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”E
A
Parameters
Section titled “Parameters”(a) => void
Returns
Section titled “Returns”(data) => Validation<E, A>
Validation.tapError
Section titled “Validation.tapError”tapError: <
E,A>(f) => (data) =>Validation<E,A>
Executes a side effect on the accumulated errors without changing the Task.Validation.
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”(errors) => void
Returns
Section titled “Returns”(data) => Validation<E, A>
Example
Section titled “Example”Validation.to
Section titled “Validation.to”to:
object
Validation.to.Maybe
Section titled “Validation.to.Maybe”Maybe: <
E,A>(data) =>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,A>(combineErrors) => (data) =>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
A
Parameters
Section titled “Parameters”combineErrors
Section titled “combineErrors”(errors) => E2
Returns
Section titled “Returns”(data) => Result<E2, A>
Example
Section titled “Example”Validation.tryCatch
Section titled “Validation.tryCatch”tryCatch: <
E,A>(f,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: <
A>(onProgress) => (task) =>Task<A>
Monitors progress of a Task by calling onProgress(0) before execution and onProgress(1) upon completion.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”onProgress
Section titled “onProgress”(ratio) => void
Returns
Section titled “Returns”(task) => Task<A>