<R0, L>(self: Iterable<Result<R0, L>>): Iterable<L>Returns a lazy iterable containing the failure values from an iterable of
Results, skipping successful results.
Example (Extracting failures)
import { Iterable, Result } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(
Array.from(
Iterable.getFailures([
Result.succeed(1),
Result.fail("err"),
Result.succeed(2)
])
),
["err"]
)export const const getFailures: <R0, L>(
self: Iterable<Result<R0, L>>
) => Iterable<L>
Returns a lazy iterable containing the failure values from an iterable of
Results, skipping successful results.
Example (Extracting failures)
import { Iterable, Result } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(
Array.from(
Iterable.getFailures([
Result.succeed(1),
Result.fail("err"),
Result.succeed(2)
])
),
["err"]
)
getFailures = <function (type parameter) R0 in <R0, L>(self: Iterable<Result<R0, L>>): Iterable<L>R0, function (type parameter) L in <R0, L>(self: Iterable<Result<R0, L>>): Iterable<L>L>(self: Iterable<Result<R0, L>>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<type Result<A, E = never> = R.Success<A, E> | R.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) R0 in <R0, L>(self: Iterable<Result<R0, L>>): Iterable<L>R0, function (type parameter) L in <R0, L>(self: Iterable<Result<R0, L>>): Iterable<L>L>>): interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) L in <R0, L>(self: Iterable<Result<R0, L>>): Iterable<L>L> => {
return {
[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]() {
const const iterator: Iterator<
Result<R0, L>,
any,
any
>
iterator = self: Iterable<Result<R0, L>>self[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]()
return {
Iterator<L, any, any>.next(...[value]: [] | [any]): IteratorResult<L, any>next() {
let let result: IteratorResult<
Result<R0, L>,
any
>
result = const iterator: Iterator<
Result<R0, L>,
any,
any
>
iterator.Iterator<Result<R0, L>, any, any>.next(...[value]: [] | [any]): IteratorResult<Result<R0, L>, any>next()
while (!let result: IteratorResult<
Result<R0, L>,
any
>
result.done?: boolean | undefineddone) {
if (import RR.const isFailure: <A, E>(
self: Result<A, E>
) => self is Failure<A, E>
Checks whether a Result is a Failure.
When to use
Use to narrow a known Result to the Failure variant.
Details
- Acts as a TypeScript type guard, narrowing to
Failure<A, E>
- After narrowing, you can access
.failure to read the error value
Example (Narrowing to failure)
import { Result } from "effect"
const result = Result.fail("oops")
if (Result.isFailure(result)) {
console.log(result.failure)
// Output: "oops"
}
isFailure(let result: IteratorYieldResult<
Result<R0, L>
>
result.IteratorYieldResult<Result<R0, L>>.value: Result<R0, L>value)) {
return { IteratorYieldResult<TYield>.done?: false | undefineddone: false, IteratorYieldResult<L>.value: Lvalue: let result: IteratorYieldResult<
Result<R0, L>
>
result.IteratorYieldResult<Result<R0, L>>.value: R.Failure<R0, L>(property) IteratorYieldResult<Result<R0, L>>.value: {
_tag: "Failure";
_op: "Failure";
failure: E;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
value.Failure<R0, L>.failure: Lfailure }
}
let result: IteratorResult<
Result<R0, L>,
any
>
result = const iterator: Iterator<
Result<R0, L>,
any,
any
>
iterator.Iterator<Result<R0, L>, any, any>.next(...[value]: [] | [any]): IteratorResult<Result<R0, L>, any>next()
}
return { IteratorReturnResult<TReturn>.done: truedone: true, IteratorReturnResult<any>.value: anyvalue: var undefinedundefined }
}
}
}
}
}