Op
Op:
object
Defined in: Core/Op.ts:113
Type Declaration
Section titled “Type Declaration”interpret
Section titled “interpret”interpret: <
Args,E,A,O>(op,options) =>InterpretResult<Args,E,A,O> =interpretFn
Creates a manager that runs an operation using the selected concurrency strategy.
Type Parameters
Section titled “Type Parameters”Args extends readonly unknown[]
E
A
O extends AllInterpretOptions<Args, E>
Parameters
Section titled “Parameters”Op<Args, E, A>
options
Section titled “options”O
Returns
Section titled “Returns”InterpretResult<Args, E, A, O>
Op.make to construct an Op blueprint.
Example
Section titled “Example”is:
object
is.idle
Section titled “is.idle”idle: <
E,A>(state) =>state is Idle=isIdle
Type guard that checks if an Op state is Idle.
Type Parameters
Section titled “Type Parameters”E = unknown
A = unknown
Parameters
Section titled “Parameters”State<E, A>
Returns
Section titled “Returns”state is Idle
- Op.is.pending to check if an Op is actively executing.
- Op.is.settled to check if an Op has completed execution.
Example
Section titled “Example”is.pending
Section titled “is.pending”pending: <
E,A>(state) =>state is Pending=isPending
Type guard that checks if an Op state is Pending (actively executing).
Type Parameters
Section titled “Type Parameters”E = unknown
A = unknown
Parameters
Section titled “Parameters”State<E, A>
Returns
Section titled “Returns”state is Pending
- Op.is.idle to check if an Op is waiting to execute.
- Op.is.settled to check if an Op has completed execution.
Example
Section titled “Example”is.queued
Section titled “is.queued”queued: <
E,A>(state) =>state is Queued=isQueued
Type guard that checks if an Op state is Queued (waiting in a concurrency queue).
Type Parameters
Section titled “Type Parameters”E = unknown
A = unknown
Parameters
Section titled “Parameters”State<E, A>
Returns
Section titled “Returns”state is Queued
Op.is.pending to check if an Op is actively executing.
Example
Section titled “Example”is.retrying
Section titled “is.retrying”retrying: <
E,A>(state) =>state is Retrying<E>=isRetrying
Type guard that checks if an Op state is Retrying after a failure.
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”State<E, A>
Returns
Section titled “Returns”state is Retrying<E>
Op.is.pending to check if an Op is actively executing.
Example
Section titled “Example”is.settled
Section titled “is.settled”settled: <
E,A>(state) =>state is Outcome<E, A>=isSettled
Type guard that checks if an Op state has settled into an outcome (Ok, Err, or Nil).
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”State<E, A>
Returns
Section titled “Returns”state is Outcome<E, A>
- Op.is.pending to check if an Op is actively executing.
- Op.is.idle to check if an Op has not yet run.
Example
Section titled “Example”make: <
Args,E,A>(task,options?) =>Op<Args,E,A> =makeFn
Turns a task factory into an operation blueprint.
The factory receives the arguments passed to manager.run(...) and returns a
Task.Result, so the error channel is already typed before Op sees it. Map raw
promises at the boundary with Task.Result.tryCatch; Op never inspects thrown values.
Type Parameters
Section titled “Type Parameters”Args extends readonly unknown[]
E
A
Parameters
Section titled “Parameters”(…args) => Result<E, A>
options?
Section titled “options?”string
Returns
Section titled “Returns”Op<Args, E, A>
Op.interpret to attach a concurrency strategy to the blueprint.
Example
Section titled “Example”Outcome
Section titled “Outcome”Outcome:
object=OpOutcome
Settled outcome value constructors, type guards, eliminators, and combinators.
Outcome.chain
Section titled “Outcome.chain”chain: <
A,B,E2>(transform) => <E1>(outcome) =>Outcome<E2|E1,B>
Sequences an operation that produces an Op.Outcome if the current outcome is Ok.
Type Parameters
Section titled “Type Parameters”A
B
E2 = never
Parameters
Section titled “Parameters”transform
Section titled “transform”(value) => Outcome<E2, B>
Returns
Section titled “Returns”<E1>(outcome) => Outcome<E2 | E1, B>
Op.Outcome.map to transform the inner value without returning a new Op.Outcome.
Example
Section titled “Example”Outcome.from
Section titled “Outcome.from”from:
object
Outcome.from.Maybe
Section titled “Outcome.from.Maybe”Maybe: <
A>(maybe,onNone?) =>Outcome<never,A>
Creates an Op.Outcome from a Maybe, mapping Some to OpOk and None to OpNil.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”Maybe<A>
The Maybe to convert.
onNone?
Section titled “onNone?”() => NilReason
Optional callback returning the cancellation or drop reason (defaults to “dropped”).
Returns
Section titled “Returns”Outcome<never, A>
Op.Outcome.to.Maybe to convert an outcome to a Maybe.
Example
Section titled “Example”Outcome.from.Result
Section titled “Outcome.from.Result”Result: <
E,A>(result) =>Outcome<E,A>
Creates an Op.Outcome from a Result, mapping Ok to OpOk and Err to OpErr.
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”result
Section titled “result”Result<E, A>
Returns
Section titled “Returns”Outcome<E, A>
Op.Outcome.to.Result to convert an outcome to a Result.
Example
Section titled “Example”Outcome.getOrElse
Section titled “Outcome.getOrElse”getOrElse: <
B>(fallback) => <E,A>(outcome) =>B|A
Returns the value if Ok, otherwise executes the fallback function and returns its result.
Type Parameters
Section titled “Type Parameters”B
Parameters
Section titled “Parameters”fallback
Section titled “fallback”() => B
Returns
Section titled “Returns”<E, A>(outcome) => B | A
Example
Section titled “Example”Outcome.is
Section titled “Outcome.is”is:
object
Outcome.is.err
Section titled “Outcome.is.err”err: <
E,A>(stateOrOutcome) =>stateOrOutcome is Err<E>=isErr
Type guard that checks if an Op state or outcome is Err.
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”stateOrOutcome
Section titled “stateOrOutcome”State<E, A>
Returns
Section titled “Returns”stateOrOutcome is Err<E>
- Op.Outcome.is.ok to check if an outcome or state is Ok.
- Op.Outcome.is.nil to check if an outcome or state is Nil.
Example
Section titled “Example”Outcome.is.nil
Section titled “Outcome.is.nil”nil: <
E,A>(stateOrOutcome) =>stateOrOutcome is Nil=isNil
Type guard that checks if an Op state or outcome is Nil.
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”stateOrOutcome
Section titled “stateOrOutcome”State<E, A>
Returns
Section titled “Returns”stateOrOutcome is Nil
- Op.Outcome.is.ok to check if an outcome or state is Ok.
- Op.Outcome.is.err to check if an outcome or state is Err.
Example
Section titled “Example”Outcome.is.ok
Section titled “Outcome.is.ok”ok: <
E,A>(stateOrOutcome) =>stateOrOutcome is Ok<A>=isOk
Type guard that checks if an Op state or outcome is Ok.
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”stateOrOutcome
Section titled “stateOrOutcome”State<E, A>
Returns
Section titled “Returns”stateOrOutcome is Ok<A>
- Op.Outcome.is.err to check if an outcome or state is Err.
- Op.Outcome.is.nil to check if an outcome or state is Nil.
Example
Section titled “Example”Outcome.make
Section titled “Outcome.make”make:
object
Outcome.make.err
Section titled “Outcome.make.err”err: <
E>(error) =>Err<E> =makeErr
Creates an Err outcome with the given error.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”E
Returns
Section titled “Returns”Err<E>
- Op.Outcome.make.ok to create an Ok outcome.
- Op.Outcome.make.nil to create a Nil outcome.
Example
Section titled “Example”Outcome.make.nil
Section titled “Outcome.make.nil”nil: (
reason) =>Nil=makeNil
Creates a Nil outcome with the given cancellation or drop reason.
Parameters
Section titled “Parameters”reason
Section titled “reason”Returns
Section titled “Returns”- Op.Outcome.make.ok to create an Ok outcome.
- Op.Outcome.make.err to create an Err outcome.
Example
Section titled “Example”Outcome.make.ok
Section titled “Outcome.make.ok”ok: <
A>(value) =>Ok<A> =makeOk
Creates an Ok outcome with the given value.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”A
Returns
Section titled “Returns”Ok<A>
- Op.Outcome.make.err to create an Err outcome.
- Op.Outcome.make.nil to create a Nil outcome.
Example
Section titled “Example”Outcome.map
Section titled “Outcome.map”map: <
A,B>(transform) => <E>(outcome) =>Outcome<E,B>
Transforms the value inside an Ok outcome using the provided function.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(value) => B
Returns
Section titled “Returns”<E>(outcome) => Outcome<E, B>
- Op.Outcome.chain to sequence operations that themselves return an Op.Outcome.
- Op.Outcome.mapError to transform the error inside an Err outcome.
Example
Section titled “Example”Outcome.mapError
Section titled “Outcome.mapError”mapError: <
E,F>(transform) => <A>(outcome) =>Outcome<F,A>
Transforms the error inside an Err outcome using the provided function.
Type Parameters
Section titled “Type Parameters”E
F
Parameters
Section titled “Parameters”transform
Section titled “transform”(error) => F
Returns
Section titled “Returns”<A>(outcome) => Outcome<F, A>
Op.Outcome.map to transform the value inside an Ok outcome.
Example
Section titled “Example”Outcome.match
Section titled “Outcome.match”match: <
E,A,B>(cases) => (outcome) =>B
Matches on an Op outcome by providing handlers for each variant.
Type Parameters
Section titled “Type Parameters”E
A
B
Parameters
Section titled “Parameters”(error) => B
(reason) => B
(value) => B
Returns
Section titled “Returns”(outcome) => B
Example
Section titled “Example”Outcome.recover
Section titled “Outcome.recover”recover: <
E1,B,E2>(handler) => <A>(outcome) =>Outcome<E2,B|A>
Recovers from an Err outcome by applying a recovery function that returns a new Op.Outcome.
Type Parameters
Section titled “Type Parameters”E1
B
E2 = never
Parameters
Section titled “Parameters”handler
Section titled “handler”(error) => Outcome<E2, B>
Returns
Section titled “Returns”<A>(outcome) => Outcome<E2, B | A>
Example
Section titled “Example”Outcome.tap
Section titled “Outcome.tap”tap: <
A>(sideEffect) => <E>(outcome) =>Outcome<E,A>
Executes a side effect if the outcome is Ok and returns the original outcome unchanged.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”sideEffect
Section titled “sideEffect”(value) => void
Returns
Section titled “Returns”<E>(outcome) => Outcome<E, A>
Op.Outcome.tapError to execute a side effect on Err outcomes.
Example
Section titled “Example”Outcome.tapError
Section titled “Outcome.tapError”tapError: <
E>(sideEffect) => <A>(outcome) =>Outcome<E,A>
Executes a side effect if the outcome is Err and returns the original outcome unchanged.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”sideEffect
Section titled “sideEffect”(error) => void
Returns
Section titled “Returns”<A>(outcome) => Outcome<E, A>
Op.Outcome.tap to execute a side effect on Ok outcomes.
Example
Section titled “Example”Outcome.to
Section titled “Outcome.to”to:
object
Outcome.to.Maybe
Section titled “Outcome.to.Maybe”Maybe: <
E,A>(outcome) =>Maybe<A>
Converts an Op.Outcome to a Maybe, mapping Ok to Some and both Err and Nil to None.
Type Parameters
Section titled “Type Parameters”E = never
A = never
Parameters
Section titled “Parameters”outcome
Section titled “outcome”Outcome<E, A>
Returns
Section titled “Returns”Maybe<A>
- Op.Outcome.to.Result to convert an outcome to a Result.
- Op.Outcome.from.Maybe to create an outcome from a Maybe.
Example
Section titled “Example”Outcome.to.Result
Section titled “Outcome.to.Result”Result: <
E2>(onNil) => <E1,A>(outcome) =>Result<E2|E1,A>
Converts an Op.Outcome to a Result.
Type Parameters
Section titled “Type Parameters”E2
Parameters
Section titled “Parameters”(reason) => E2
Returns
Section titled “Returns”<E1, A>(outcome) => Result<E2 | E1, A>
- Op.Outcome.to.Maybe to convert an outcome to a Maybe.
- Op.Outcome.from.Result to create an outcome from a Result.
Example
Section titled “Example”wire: <
Args,E,A,S>(source,sideEffect) => () =>void
Subscribes to an Op manager and executes a side-effect whenever the manager emits an Ok outcome. Returns an unsubscribe callback.
Type Parameters
Section titled “Type Parameters”Args extends readonly unknown[]
E
A
S extends State<E, A>
Parameters
Section titled “Parameters”source
Section titled “source”Manager<Args, E, A, S>
sideEffect
Section titled “sideEffect”(value) => void
Returns
Section titled “Returns”() => void