Failure<A, E>The failure variant of Result. Wraps an error of type E.
Details
- Access the error via the
.failureproperty - Use isFailure to narrow a
ResulttoFailure - Create with fail
Example (Accessing the failure value)
import { Result } from "effect"
const failure = Result.fail("Network error")
if (Result.isFailure(failure)) {
console.log(failure.failure)
// Output: "Network error"
}export interface interface Failure<out A, out E>The failure variant of
Result
. Wraps an error of type E.
Details
- Access the error via the
.failure property
- Use
isFailure
to narrow a
Result to Failure
- Create with
fail
Example (Accessing the failure value)
import { Result } from "effect"
const failure = Result.fail("Network error")
if (Result.isFailure(failure)) {
console.log(failure.failure)
// Output: "Network error"
}
Failure<out function (type parameter) A in Failure<out A, out E>A, out function (type parameter) E in Failure<out A, out E>E> extends import PipeablePipeable, import InspectableInspectable {
readonly Failure<out A, out E>._tag: "Failure"_tag: "Failure"
readonly Failure<out A, out E>._op: "Failure"_op: "Failure"
readonly Failure<out A, out E>.failure: out Efailure: function (type parameter) E in Failure<out A, out E>E
readonly [const TypeId: "~effect/data/Result"TypeId]: {
readonly _A: Covariant<E>_A: type Covariant<A> = (_: never) => AFunction-type alias encoding covariant variance for a phantom type
parameter.
When to use
Use as a phantom field type to make a type parameter covariant in output
position.
Details
Covariant<A> is assignable to Covariant<B> when A extends B, following
the subtype direction.
Example (Defining a covariant phantom type)
import type { Types } from "effect"
interface Producer<T> {
readonly _phantom: Types.Covariant<T>
readonly get: () => T
}
Namespace for
Covariant
-related utilities.
When to use
Use when referring to type-level helpers nested under Covariant.
Covariant<function (type parameter) E in Failure<out A, out E>E>
readonly _E: Covariant<A>_E: type Covariant<A> = (_: never) => AFunction-type alias encoding covariant variance for a phantom type
parameter.
When to use
Use as a phantom field type to make a type parameter covariant in output
position.
Details
Covariant<A> is assignable to Covariant<B> when A extends B, following
the subtype direction.
Example (Defining a covariant phantom type)
import type { Types } from "effect"
interface Producer<T> {
readonly _phantom: Types.Covariant<T>
readonly get: () => T
}
Namespace for
Covariant
-related utilities.
When to use
Use when referring to type-level helpers nested under Covariant.
Covariant<function (type parameter) A in Failure<out A, out E>A>
}
[var Symbol: SymbolConstructorSymbol.SymbolConstructor.iterator: typeof Symbol.iteratorA method that returns the default iterator for an object. Called by the semantics of the
for-of statement.
iterator](): interface ResultIterator<T extends Result<any, any>>Iterator protocol used to yield a Result inside
gen
, returning the
success value type back to the generator.
When to use
Use when defining or typing [Symbol.iterator]() for Result values so
yield* can pass the success value type back into Result.gen.
ResultIterator<type Result<A, E = never> = Success<A, E> | Failure<A, E>A value that is either Success<A, E> or Failure<A, E>.
When to use
Use when both success and failure should remain available as data and
Option would lose failure information.
Details
- Use
succeed
/
fail
to construct
- Use
match
to fold both branches
- Use
isSuccess
/
isFailure
to narrow the type
E defaults to never, so Result<number> means a result that cannot fail.
Example (Creating and matching a Result)
import { Result } from "effect"
const success = Result.succeed(42)
const failure = Result.fail("something went wrong")
const message = Result.match(success, {
onSuccess: (value) => `Success: ${value}`,
onFailure: (error) => `Error: ${error}`
})
console.log(message)
// Output: "Success: 42"
Namespace containing type-level utilities for extracting the inner types
of a Result.
Example (Extracting inner types)
import type { Result } from "effect"
type R = Result.Result<number, string>
// number
type A = Result.Result.Success<R>
// string
type E = Result.Result.Failure<R>
Result<function (type parameter) A in Failure<out A, out E>A, function (type parameter) E in Failure<out A, out E>E>>
[import UnifyUnify.const typeSymbol: typeof Unify.typeSymbolDefines the unique symbol used to identify the type information for unification.
When to use
Use when you need a type-level protocol key that exposes the source type
read by Unify from a protocol-enabled data type.
Details
This symbol is a type-level protocol key. It stores the source type that
unification reads when widening protocol-enabled values.
The type of the typeSymbol.
When to use
Use to reference the type information property key in type-level protocol
definitions.
Details
This type represents the unique symbol used for storing type information
in types that support unification. It's used in type-level operations
to access and manipulate type information.
typeSymbol]?: unknown
[import UnifyUnify.const unifySymbol: typeof Unify.unifySymbolDefines the unique symbol used to identify unification behavior in Effect types.
When to use
Use to define the widened type produced by the Unify protocol for a custom
protocol-enabled data type.
Details
This symbol is a type-level protocol key. It describes how a protocol-enabled
type widens during unification and has no runtime behavior.
The type of the unifySymbol.
When to use
Use to reference the unification behavior property key in type-level
protocol definitions.
Details
This type represents the unique symbol used for identifying unification
behavior in Effect types. It's typically used in type-level operations
to enable automatic type unification.
unifySymbol]?: interface ResultUnify<T extends { [Unify.typeSymbol]?: any; }>Type-level utility for unifying Result types in generic contexts.
Details
This is an internal interface used by the Effect type system. You typically
do not need to reference it directly.
ResultUnify<this>
[import UnifyUnify.const ignoreSymbol: typeof Unify.ignoreSymbolDefines the unique symbol used to specify types that should be ignored during unification.
When to use
Use to hide helper protocol entries from Unify when they should not
contribute to the widened type.
Details
This symbol is a type-level protocol key. It lists protocol entries that
unification should ignore when computing the widened type.
The type of the ignoreSymbol.
When to use
Use to reference the ignored-property key in type-level protocol
definitions.
Details
This type represents the unique symbol used for marking types that should
be ignored during unification operations. It's used in type-level operations
to exclude specific types from the unification process.
ignoreSymbol]?: ResultUnifyIgnore
}