ResultIterator<T>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.
export interface 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<function (type parameter) T in ResultIterator<T extends Result<any, any>>T extends 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<any, any>> {
ResultIterator<T extends Result<any, any>>.next(...args: ReadonlyArray<any>): IteratorResult<T, Result.Success<T>>next(
...args: readonly any[]args: interface ReadonlyArray<T>ReadonlyArray<any>
): type IteratorResult<T, TReturn = any> =
| IteratorYieldResult<T>
| IteratorReturnResult<TReturn>
IteratorResult<function (type parameter) T in ResultIterator<T extends Result<any, any>>T, Result.type Result<A, E = never>.Success<T extends Result<any, any>> = [T] extends [Result<infer _A, infer _E>] ? _A : neverExtracts the success type A from Result<A, E>.
Success<function (type parameter) T in ResultIterator<T extends Result<any, any>>T>>
}