Outcome (deprecated)
@pencroff-lab/kore / outcome
Monadic container for safe success/error propagation using tuple-first design.
Outcome<T> wraps a ResultTuple<T> — either [T, null] (success) or
[null, Err] (error) — and provides chainable transforms (map, flatMap,
pipe), combinators (all, any), and terminal operations (toTuple,
defaultTo, either).
Key concepts:
- Tuple-first —
toTuple()is the primary extraction; destructure as[val, err]. - Immutability — every transform returns a new
Outcome, never mutates. - map vs flatMap —
maptakes(T) => Uand cannot fail;flatMaptakes(T) => Outcome<U>and can. Tuple/Errreturns are data inmap, never control flow. - Value protocol — in
from/fromAsync,flatMap,mapErrandpipea returnedErris a failure, a returnedOutcomepasses through, and anything else is the success value. UseOutcome.ok(x)to carry anError anOutcomeas a value. - Tuple protocol —
fromTuple/fromTupleAsyncare the only entry points that read[value, error]as control flow; everywhere else a tuple is an ordinary array value. - Auto-catch —
from,fromTuple,map,flatMapandpipecatch thrown exceptions and wrap them asErr. - Combinators —
allcollects every error (non-short-circuit),anyshort-circuits on first success.
Deprecated since v0.7.0. The class tier is frozen from v0.7.0 onward; the
flow tier is the supported API. v0.7.0 itself changed this class — see the
changelog’s breaking changes before upgrading from v0.6.x. flow works on
the same ResultTuple with free functions, so migration is call-site local:
see the migration map in the README.
See
outcome.examples.test.ts for usage patterns
Classes
Outcome
Defined in: types/outcome.ts:60
A monadic container for handling success and error states.
Uses tuples as the primary interface; toTuple() is the sole extraction.
The container is immutable — every transform returns a new instance. The value
it carries is yours: it is never copied or frozen, so mutating it after
wrapping is visible through the Outcome. (Err.metadata is copied and frozen
because errors are a cold path; T is not.)
Deprecated
since v0.7.0 — superseded by the flow tier. The class stays
exported and its shape is frozen from v0.7.0 onward, but v0.7.0 is itself a
breaking release for it: removed accessors, the callback protocol split, and
nominal Err recognition. Check the changelog when upgrading from v0.6.x.
Move to the free functions over ResultTuple (ok, fail, map, flatMap,
mapErr, pipe, all, any, defaultTo, either); toTuple() is the bridge.
Type Parameters
T
T
The type of the success value
Methods
defaultTo()
Call Signature
defaultTo(
fallback):T
Defined in: types/outcome.ts:574
Extract the success value, or use a fallback value on error.
Parameters
fallback
T
The fallback value to use if in error state
Returns
T
The success value or the fallback
Throws
If the outcome is an error and computing fallback throws
Call Signature
defaultTo(
handler):T
Defined in: types/outcome.ts:583
Extract the success value, or compute a fallback from the error.
Parameters
handler
(error) => T
Function to compute fallback from error
Returns
T
The success value or computed fallback
Throws
If the handler throws, the exception propagates to the caller
Call Signature
defaultTo(
fallback,asValue):T
Defined in: types/outcome.ts:594
Extract the success value, or use the provided fallback value.
Use asValue: true when T is a function type to avoid treating it as a handler.
Parameters
fallback
T
The fallback value to use when error
asValue
true
Must be true to use this overload
Returns
T
The success value or the fallback
effect()
effect(
fn):Outcome<T>
Defined in: types/outcome.ts:534
Execute a side effect with access to the full tuple.
Returns this unchanged for chaining.
If the callback throws, the exception is caught and the Outcome becomes an error.
Parameters
fn
(tuple) => void
Side effect function receiving the tuple
Returns
Outcome
<T>
This Outcome (for chaining), or error Outcome if callback throws
See
effectAsync for the async version
effectAsync()
effectAsync(
fn):Promise<Outcome<T>>
Defined in: types/outcome.ts:551
Async version of effect().
Parameters
fn
(tuple) => Promise<void>
Async side effect function
Returns
Promise<Outcome
<T>>
Promise of this Outcome
See
effect for the synchronous version
either()
either<
U>(onOk,onErr):U
Defined in: types/outcome.ts:618
Transform the Outcome into a final value by handling both cases.
Type Parameters
U
U
Parameters
onOk
(value) => U
Function to transform success value into final result
onErr
(error) => U
Function to transform error into final result
Returns
U
The transformed value (not wrapped in Outcome)
Throws
If either callback throws, the exception propagates to the caller
flatMap()
Defined in: types/outcome.ts:444
Chain a callback that can fail, flattening the result.
Follows the value protocol: a returned Outcome is flattened, a returned
Err becomes the failure, anything else is the success value. Only called if
successful; errors pass through unchanged and a throw is caught and wrapped.
Type Parameters
R
R
Parameters
fn
(value) => R
Function receiving the success value, returning an Outcome
Returns
The Outcome returned by the callback, or the original error
See
- flatMapAsync for the async version
- map for a total callback whose return is never inspected
flatMapAsync()
Defined in: types/outcome.ts:462
Async version of flatMap().
Type Parameters
R
R
Parameters
fn
(value) => Promise<R>
Async function returning a Promise of an Outcome
Returns
Promise<Outcome
<ValueOf
<R>>>
Promise of the flattened Outcome
See
flatMap for the synchronous version
map()
map<
U>(fn):Outcome<U>
Defined in: types/outcome.ts:403
Transform the success value with a plain function.
The return value is carried as-is — a tuple, an Err, or null stays the
success value. Use flatMap
to return an Outcome that can fail.
Only called if successful. Errors pass through unchanged. If the callback throws, the exception is caught and wrapped.
Type Parameters
U
U
Parameters
fn
(value) => U
Transformation function receiving the success value
Returns
Outcome
<U>
New Outcome with the transformed value, or the original error
See
- mapAsync for the async version
- flatMap for callbacks that return an Outcome
- mapErr for transforming or recovering from errors
mapAsync()
mapAsync<
U>(fn):Promise<Outcome<U>>
Defined in: types/outcome.ts:421
Async version of map().
Type Parameters
U
U
Parameters
fn
(value) => Promise<U>
Async transformation function
Returns
Promise<Outcome
<U>>
Promise of new Outcome
See
map for the synchronous version
mapErr()
Defined in: types/outcome.ts:487
Transform or recover from an error using a callback.
Follows the value protocol, so returning an Err re-fails and returning
anything else recovers. Only called if in error state; success passes through
unchanged.
Type Parameters
R
R
Parameters
fn
(error) => R
Function receiving the error
Returns
New Outcome with transformed error or recovered value
See
- mapErrAsync for the async version
- map for transforming success values
mapErrAsync()
Defined in: types/outcome.ts:506
Async version of mapErr().
Type Parameters
R
R
Parameters
fn
(error) => Promise<R>
Async function receiving the error
Returns
Promise<Outcome
<T | ValueOf
<R>>>
Promise of new Outcome
See
mapErr for the synchronous version
pipe()
Call Signature
pipe<
A>(f1):Outcome<A>
Defined in: types/outcome.ts:638
Chain synchronous transformations using tuple-based predicates.
Each predicate receives ResultTuple<T> and returns CallbackReturn<U>,
enabling mid-chain recovery or conditional transformations.
Type Parameters
A
A
Parameters
f1
PipeFn
<T, A>
Returns
Outcome
<A>
See
- pipeAsync for async transformations
- map for simple success-only transformation
- mapErr for error-only transformation
Call Signature
pipe<
A,B>(f1,f2):Outcome<B>
Defined in: types/outcome.ts:639
Chain synchronous transformations using tuple-based predicates.
Each predicate receives ResultTuple<T> and returns CallbackReturn<U>,
enabling mid-chain recovery or conditional transformations.
Type Parameters
A
A
B
B
Parameters
f1
PipeFn
<T, A>
f2
PipeFn
<A, B>
Returns
Outcome
<B>
See
- pipeAsync for async transformations
- map for simple success-only transformation
- mapErr for error-only transformation
Call Signature
pipe<
A,B,C>(f1,f2,f3):Outcome<C>
Defined in: types/outcome.ts:640
Chain synchronous transformations using tuple-based predicates.
Each predicate receives ResultTuple<T> and returns CallbackReturn<U>,
enabling mid-chain recovery or conditional transformations.
Type Parameters
A
A
B
B
C
C
Parameters
f1
PipeFn
<T, A>
f2
PipeFn
<A, B>
f3
PipeFn
<B, C>
Returns
Outcome
<C>
See
- pipeAsync for async transformations
- map for simple success-only transformation
- mapErr for error-only transformation
Call Signature
pipe<
A,B,C,D>(f1,f2,f3,f4):Outcome<D>
Defined in: types/outcome.ts:645
Chain synchronous transformations using tuple-based predicates.
Each predicate receives ResultTuple<T> and returns CallbackReturn<U>,
enabling mid-chain recovery or conditional transformations.
Type Parameters
A
A
B
B
C
C
D
D
Parameters
f1
PipeFn
<T, A>
f2
PipeFn
<A, B>
f3
PipeFn
<B, C>
f4
PipeFn
<C, D>
Returns
Outcome
<D>
See
- pipeAsync for async transformations
- map for simple success-only transformation
- mapErr for error-only transformation
Call Signature
pipe<
A,B,C,D,E>(f1,f2,f3,f4,f5):Outcome<E>
Defined in: types/outcome.ts:651
Chain synchronous transformations using tuple-based predicates.
Each predicate receives ResultTuple<T> and returns CallbackReturn<U>,
enabling mid-chain recovery or conditional transformations.
Type Parameters
A
A
B
B
C
C
D
D
E
E
Parameters
f1
PipeFn
<T, A>
f2
PipeFn
<A, B>
f3
PipeFn
<B, C>
f4
PipeFn
<C, D>
f5
PipeFn
<D, E>
Returns
Outcome
<E>
See
- pipeAsync for async transformations
- map for simple success-only transformation
- mapErr for error-only transformation
Call Signature
pipe<
A,B,C,D,E,F>(f1,f2,f3,f4,f5,f6):Outcome<F>
Defined in: types/outcome.ts:658
Chain synchronous transformations using tuple-based predicates.
Each predicate receives ResultTuple<T> and returns CallbackReturn<U>,
enabling mid-chain recovery or conditional transformations.
Type Parameters
A
A
B
B
C
C
D
D
E
E
F
F
Parameters
f1
PipeFn
<T, A>
f2
PipeFn
<A, B>
f3
PipeFn
<B, C>
f4
PipeFn
<C, D>
f5
PipeFn
<D, E>
f6
PipeFn
<E, F>
Returns
Outcome
<F>
See
- pipeAsync for async transformations
- map for simple success-only transformation
- mapErr for error-only transformation
Call Signature
pipe<
A,B,C,D,E,F,G>(f1,f2,f3,f4,f5,f6,f7):Outcome<G>
Defined in: types/outcome.ts:666
Chain synchronous transformations using tuple-based predicates.
Each predicate receives ResultTuple<T> and returns CallbackReturn<U>,
enabling mid-chain recovery or conditional transformations.
Type Parameters
A
A
B
B
C
C
D
D
E
E
F
F
G
G
Parameters
f1
PipeFn
<T, A>
f2
PipeFn
<A, B>
f3
PipeFn
<B, C>
f4
PipeFn
<C, D>
f5
PipeFn
<D, E>
f6
PipeFn
<E, F>
f7
PipeFn
<F, G>
Returns
Outcome
<G>
See
- pipeAsync for async transformations
- map for simple success-only transformation
- mapErr for error-only transformation
Call Signature
pipe<
A,B,C,D,E,F,G,H>(f1,f2,f3,f4,f5,f6,f7,f8):Outcome<H>
Defined in: types/outcome.ts:675
Chain synchronous transformations using tuple-based predicates.
Each predicate receives ResultTuple<T> and returns CallbackReturn<U>,
enabling mid-chain recovery or conditional transformations.
Type Parameters
A
A
B
B
C
C
D
D
E
E
F
F
G
G
H
H
Parameters
f1
PipeFn
<T, A>
f2
PipeFn
<A, B>
f3
PipeFn
<B, C>
f4
PipeFn
<C, D>
f5
PipeFn
<D, E>
f6
PipeFn
<E, F>
f7
PipeFn
<F, G>
f8
PipeFn
<G, H>
Returns
Outcome
<H>
See
- pipeAsync for async transformations
- map for simple success-only transformation
- mapErr for error-only transformation
Call Signature
pipe<
A,B,C,D,E,F,G,H,I>(f1,f2,f3,f4,f5,f6,f7,f8,f9):Outcome<I>
Defined in: types/outcome.ts:685
Chain synchronous transformations using tuple-based predicates.
Each predicate receives ResultTuple<T> and returns CallbackReturn<U>,
enabling mid-chain recovery or conditional transformations.
Type Parameters
A
A
B
B
C
C
D
D
E
E
F
F
G
G
H
H
I
I
Parameters
f1
PipeFn
<T, A>
f2
PipeFn
<A, B>
f3
PipeFn
<B, C>
f4
PipeFn
<C, D>
f5
PipeFn
<D, E>
f6
PipeFn
<E, F>
f7
PipeFn
<F, G>
f8
PipeFn
<G, H>
f9
PipeFn
<H, I>
Returns
Outcome
<I>
See
- pipeAsync for async transformations
- map for simple success-only transformation
- mapErr for error-only transformation
Call Signature
pipe<
A,B,C,D,E,F,G,H,I,J>(f1,f2,f3,f4,f5,f6,f7,f8,f9,f10):Outcome<J>
Defined in: types/outcome.ts:696
Chain synchronous transformations using tuple-based predicates.
Each predicate receives ResultTuple<T> and returns CallbackReturn<U>,
enabling mid-chain recovery or conditional transformations.
Type Parameters
A
A
B
B
C
C
D
D
E
E
F
F
G
G
H
H
I
I
J
J
Parameters
f1
PipeFn
<T, A>
f2
PipeFn
<A, B>
f3
PipeFn
<B, C>
f4
PipeFn
<C, D>
f5
PipeFn
<D, E>
f6
PipeFn
<E, F>
f7
PipeFn
<F, G>
f8
PipeFn
<G, H>
f9
PipeFn
<H, I>
f10
PipeFn
<I, J>
Returns
Outcome
<J>
See
- pipeAsync for async transformations
- map for simple success-only transformation
- mapErr for error-only transformation
pipeAsync()
Call Signature
pipeAsync<
A>(f1):Promise<Outcome<A>>
Defined in: types/outcome.ts:737
Chain asynchronous transformations using tuple-based predicates.
Predicates are executed sequentially, each awaiting the previous result.
Type Parameters
A
A
Parameters
f1
PipeFnAsync
<T, A>
Returns
Promise<Outcome
<A>>
See
- pipe for synchronous transformations
- mapAsync for simple async success-only transformation
- mapErrAsync for async error-only transformation
Call Signature
pipeAsync<
A,B>(f1,f2):Promise<Outcome<B>>
Defined in: types/outcome.ts:738
Chain asynchronous transformations using tuple-based predicates.
Predicates are executed sequentially, each awaiting the previous result.
Type Parameters
A
A
B
B
Parameters
f1
PipeFnAsync
<T, A>
f2
PipeFnAsync
<A, B>
Returns
Promise<Outcome
<B>>
See
- pipe for synchronous transformations
- mapAsync for simple async success-only transformation
- mapErrAsync for async error-only transformation
Call Signature
pipeAsync<
A,B,C>(f1,f2,f3):Promise<Outcome<C>>
Defined in: types/outcome.ts:742
Chain asynchronous transformations using tuple-based predicates.
Predicates are executed sequentially, each awaiting the previous result.
Type Parameters
A
A
B
B
C
C
Parameters
f1
PipeFnAsync
<T, A>
f2
PipeFnAsync
<A, B>
f3
PipeFnAsync
<B, C>
Returns
Promise<Outcome
<C>>
See
- pipe for synchronous transformations
- mapAsync for simple async success-only transformation
- mapErrAsync for async error-only transformation
Call Signature
pipeAsync<
A,B,C,D>(f1,f2,f3,f4):Promise<Outcome<D>>
Defined in: types/outcome.ts:747
Chain asynchronous transformations using tuple-based predicates.
Predicates are executed sequentially, each awaiting the previous result.
Type Parameters
A
A
B
B
C
C
D
D
Parameters
f1
PipeFnAsync
<T, A>
f2
PipeFnAsync
<A, B>
f3
PipeFnAsync
<B, C>
f4
PipeFnAsync
<C, D>
Returns
Promise<Outcome
<D>>
See
- pipe for synchronous transformations
- mapAsync for simple async success-only transformation
- mapErrAsync for async error-only transformation
Call Signature
pipeAsync<
A,B,C,D,E>(f1,f2,f3,f4,f5):Promise<Outcome<E>>
Defined in: types/outcome.ts:753
Chain asynchronous transformations using tuple-based predicates.
Predicates are executed sequentially, each awaiting the previous result.
Type Parameters
A
A
B
B
C
C
D
D
E
E
Parameters
f1
PipeFnAsync
<T, A>
f2
PipeFnAsync
<A, B>
f3
PipeFnAsync
<B, C>
f4
PipeFnAsync
<C, D>
f5
PipeFnAsync
<D, E>
Returns
Promise<Outcome
<E>>
See
- pipe for synchronous transformations
- mapAsync for simple async success-only transformation
- mapErrAsync for async error-only transformation
Call Signature
pipeAsync<
A,B,C,D,E,F>(f1,f2,f3,f4,f5,f6):Promise<Outcome<F>>
Defined in: types/outcome.ts:760
Chain asynchronous transformations using tuple-based predicates.
Predicates are executed sequentially, each awaiting the previous result.
Type Parameters
A
A
B
B
C
C
D
D
E
E
F
F
Parameters
f1
PipeFnAsync
<T, A>
f2
PipeFnAsync
<A, B>
f3
PipeFnAsync
<B, C>
f4
PipeFnAsync
<C, D>
f5
PipeFnAsync
<D, E>
f6
PipeFnAsync
<E, F>
Returns
Promise<Outcome
<F>>
See
- pipe for synchronous transformations
- mapAsync for simple async success-only transformation
- mapErrAsync for async error-only transformation
Call Signature
pipeAsync<
A,B,C,D,E,F,G>(f1,f2,f3,f4,f5,f6,f7):Promise<Outcome<G>>
Defined in: types/outcome.ts:768
Chain asynchronous transformations using tuple-based predicates.
Predicates are executed sequentially, each awaiting the previous result.
Type Parameters
A
A
B
B
C
C
D
D
E
E
F
F
G
G
Parameters
f1
PipeFnAsync
<T, A>
f2
PipeFnAsync
<A, B>
f3
PipeFnAsync
<B, C>
f4
PipeFnAsync
<C, D>
f5
PipeFnAsync
<D, E>
f6
PipeFnAsync
<E, F>
f7
PipeFnAsync
<F, G>
Returns
Promise<Outcome
<G>>
See
- pipe for synchronous transformations
- mapAsync for simple async success-only transformation
- mapErrAsync for async error-only transformation
Call Signature
pipeAsync<
A,B,C,D,E,F,G,H>(f1,f2,f3,f4,f5,f6,f7,f8):Promise<Outcome<H>>
Defined in: types/outcome.ts:777
Chain asynchronous transformations using tuple-based predicates.
Predicates are executed sequentially, each awaiting the previous result.
Type Parameters
A
A
B
B
C
C
D
D
E
E
F
F
G
G
H
H
Parameters
f1
PipeFnAsync
<T, A>
f2
PipeFnAsync
<A, B>
f3
PipeFnAsync
<B, C>
f4
PipeFnAsync
<C, D>
f5
PipeFnAsync
<D, E>
f6
PipeFnAsync
<E, F>
f7
PipeFnAsync
<F, G>
f8
PipeFnAsync
<G, H>
Returns
Promise<Outcome
<H>>
See
- pipe for synchronous transformations
- mapAsync for simple async success-only transformation
- mapErrAsync for async error-only transformation
Call Signature
pipeAsync<
A,B,C,D,E,F,G,H,I>(f1,f2,f3,f4,f5,f6,f7,f8,f9):Promise<Outcome<I>>
Defined in: types/outcome.ts:787
Chain asynchronous transformations using tuple-based predicates.
Predicates are executed sequentially, each awaiting the previous result.
Type Parameters
A
A
B
B
C
C
D
D
E
E
F
F
G
G
H
H
I
I
Parameters
f1
PipeFnAsync
<T, A>
f2
PipeFnAsync
<A, B>
f3
PipeFnAsync
<B, C>
f4
PipeFnAsync
<C, D>
f5
PipeFnAsync
<D, E>
f6
PipeFnAsync
<E, F>
f7
PipeFnAsync
<F, G>
f8
PipeFnAsync
<G, H>
f9
PipeFnAsync
<H, I>
Returns
Promise<Outcome
<I>>
See
- pipe for synchronous transformations
- mapAsync for simple async success-only transformation
- mapErrAsync for async error-only transformation
Call Signature
pipeAsync<
A,B,C,D,E,F,G,H,I,J>(f1,f2,f3,f4,f5,f6,f7,f8,f9,f10):Promise<Outcome<J>>
Defined in: types/outcome.ts:798
Chain asynchronous transformations using tuple-based predicates.
Predicates are executed sequentially, each awaiting the previous result.
Type Parameters
A
A
B
B
C
C
D
D
E
E
F
F
G
G
H
H
I
I
J
J
Parameters
f1
PipeFnAsync
<T, A>
f2
PipeFnAsync
<A, B>
f3
PipeFnAsync
<B, C>
f4
PipeFnAsync
<C, D>
f5
PipeFnAsync
<D, E>
f6
PipeFnAsync
<E, F>
f7
PipeFnAsync
<F, G>
f8
PipeFnAsync
<G, H>
f9
PipeFnAsync
<H, I>
f10
PipeFnAsync
<I, J>
Returns
Promise<Outcome
<J>>
See
- pipe for synchronous transformations
- mapAsync for simple async success-only transformation
- mapErrAsync for async error-only transformation
toJSON()
toJSON(): [
T,null] | [null,ErrJSON]
Defined in: types/outcome.ts:852
Convert to JSON-serializable tuple.
Returns
[T, null] | [null, ErrJSON
]
JSON-serializable representation
See
fromJSON for deserializing an Outcome from JSON
toString()
toString():
string
Defined in: types/outcome.ts:864
Convert to a human-readable string.
Returns
string
String representation
toTuple()
toTuple():
ResultTuple<T>
Defined in: types/outcome.ts:841
Extract the internal tuple.
Returns
ResultTuple
<T>
The internal ResultTuple
See
fromTuple for creating an Outcome from a tuple
all()
staticall<T>(outcomes):Outcome<T[]>
Defined in: types/outcome.ts:305
Combines multiple Outcomes, succeeding if all succeed with an array of values.
Non-short-circuiting: collects all errors via addAll().
For empty arrays, returns Outcome.ok([]).
Type Parameters
T
T
Parameters
outcomes
Outcome
<T>[]
Array of Outcomes to combine
Returns
Outcome
<T[]>
Outcome containing array of all success values, or aggregate error
any()
staticany<T>(outcomes):Outcome<T>
Defined in: types/outcome.ts:335
Return the first successful Outcome from an array.
Short-circuits on first success. Returns an aggregate error if all fail.
For empty arrays, returns an error with code EMPTY_INPUT.
Type Parameters
T
T
Parameters
outcomes
Outcome
<T>[]
Array of Outcomes to check
Returns
Outcome
<T>
First successful Outcome, or aggregate of all errors
err()
Call Signature
staticerr<T>(error):Outcome<T>
Defined in: types/outcome.ts:121
Create an error Outcome from an existing Err.
Type Parameters
T
T = never
Success type to claim, so the result chains (defaults to never)
Parameters
error
The Err instance
Returns
Outcome
<T>
Outcome in error state
Call Signature
staticerr<T>(message,code?):Outcome<T>
Defined in: types/outcome.ts:130
Create an error Outcome from a message with optional code.
Type Parameters
T
T = never
Parameters
message
string
Error message
code?
string
Optional error code
Returns
Outcome
<T>
Outcome in error state
Call Signature
staticerr<T>(message,options):Outcome<T>
Defined in: types/outcome.ts:139
Create an error Outcome from a message with options.
Type Parameters
T
T = never
Parameters
message
string
Error message
options
Error options (code, metadata)
Returns
Outcome
<T>
Outcome in error state
Call Signature
staticerr<T>(message,error,options?):Outcome<T>
Defined in: types/outcome.ts:149
Create an error Outcome by wrapping another error.
Type Parameters
T
T = never
Parameters
message
string
Context message
error
Original error to wrap
Err
| Error
options?
Optional additional options
Returns
Outcome
<T>
Outcome in error state with wrapped cause
from()
Defined in: types/outcome.ts:195
Create an Outcome from a callback, under the value protocol.
An Err-valued success cannot be expressed here: from(() => someErr) is a
failure typed Outcome<never>. Use Outcome.ok(someErr) instead.
Type Parameters
R
R
Parameters
fn
() => R
Callback returning the success value, an Err or an Outcome
Returns
Outcome carrying the resolved success value
See
- fromAsync for the async version
- fromTuple
for callbacks returning a
[value, error]tuple - err for an unconditional failure
fromAsync()
Defined in: types/outcome.ts:211
Create an Outcome from an async callback, under the value protocol.
Type Parameters
R
R
Parameters
fn
() => Promise<R>
Async callback returning the success value, an Err or an Outcome
Returns
Promise<Outcome
<ValueOf
<R>>>
Promise of an Outcome carrying the resolved success value
See
- from for the synchronous version
- fromTupleAsync
for callbacks returning a
[value, error]tuple
fromJSON()
staticfromJSON<T>(payload):Outcome<T>
Defined in: types/outcome.ts:273
Create an Outcome from a JSON tuple produced by toJSON().
Invalid payloads return an error Outcome rather than throwing.
Type Parameters
T
T
Parameters
payload
JSON tuple from Outcome.toJSON()
[null, ErrJSON
] | [T, null]
Returns
Outcome
<T>
Outcome
See
toJSON for serializing an Outcome to JSON
fromTuple()
staticfromTuple<T>(src):Outcome<T>
Defined in: types/outcome.ts:232
Create an Outcome from a ResultTuple, or from a callback producing one.
This is the only entry point that reads [value, error] as control flow. The
callback form runs inside try/catch, so a throw becomes an error Outcome.
Type Parameters
T
T
Parameters
src
A ResultTuple
ResultTuple
<T> | () => ResultTuple
<T>
Returns
Outcome
<T>
Outcome
See
fromTupleAsync()
staticfromTupleAsync<T>(src):Promise<Outcome<T>>
Defined in: types/outcome.ts:253
Async counterpart of fromTuple().
Type Parameters
T
T
Parameters
src
A Promise of a ResultTuple
Promise<ResultTuple
<T>> | () => Promise<ResultTuple
<T>>
Returns
Promise<Outcome
<T>>
Promise<Outcome
See
fromTuple for the synchronous version
ok()
Call Signature
staticok():Outcome<void>
Defined in: types/outcome.ts:91
Create a success Outcome with no value (void success).
Returns
Outcome
<void>
Outcomeundefined
Call Signature
staticok(value):Outcome<null>
Defined in: types/outcome.ts:99
Create a success Outcome carrying an explicit null value.
Parameters
value
null
The literal null
Returns
Outcome
<null>
Outcome
Call Signature
staticok<T>(value):Outcome<T>
Defined in: types/outcome.ts:107
Create a success Outcome with the given value.
Type Parameters
T
T
Parameters
value
T
The success value
Returns
Outcome
<T>
Outcome containing the success value
Type Aliases
CallbackReturn
Defined in: types/outcome.types.ts:16
Callback return under the value protocol.
Err: failureOutcome<T>: passed through unchanged- anything else: the success value
Type Parameters
T
T
PipeFn()
PipeFn<
In,Out> = (tuple) =>CallbackReturn<Out>
Defined in: types/outcome.types.ts:38
Synchronous pipe function type. Receives a ResultTuple and returns a value-protocol result.
Type Parameters
In
In
Input value type
Out
Out
Output value type
Parameters
tuple
ResultTuple
<In>
Returns
CallbackReturn
<Out>
PipeFnAsync()
PipeFnAsync<
In,Out> = (tuple) =>Promise<CallbackReturn<Out>>
Defined in: types/outcome.types.ts:47
Asynchronous pipe function type. Receives a ResultTuple and returns a Promise of a value-protocol result.
Type Parameters
In
In
Input value type
Out
Out
Output value type
Parameters
tuple
ResultTuple
<In>
Returns
Promise<CallbackReturn
<Out>>
ValueOf
ValueOf<
R> =RextendsErr?never:RextendsOutcome<infer V> ?V:R
Defined in: types/outcome.types.ts:23
Success value a value-protocol callback return resolves to.
Distributes over unions, so 42 | Err resolves to 42.
Type Parameters
R
R
References
ResultTuple
Re-exports ResultTuple