(input: unknown): input is Result<unknown, unknown>Checks whether a value is a Result (either Success or Failure).
When to use
Use to validate unknown input before operating on it as a Result.
Details
- Returns
truefor bothSuccessandFailurevariants - Acts as a TypeScript type guard, narrowing to
Result<unknown, unknown>
Example (Checking if a value is a Result)
import { Result } from "effect"
console.log(Result.isResult(Result.succeed(1)))
// Output: true
console.log(Result.isResult({ value: 1 }))
// Output: falseexport const const isResult: (
input: unknown
) => input is Result<unknown, unknown>
Checks whether a value is a Result (either Success or Failure).
When to use
Use to validate unknown input before operating on it as a Result.
Details
- Returns
true for both Success and Failure variants
- Acts as a TypeScript type guard, narrowing to
Result<unknown, unknown>
Example (Checking if a value is a Result)
import { Result } from "effect"
console.log(Result.isResult(Result.succeed(1)))
// Output: true
console.log(Result.isResult({ value: 1 }))
// Output: false
isResult: (input: unknowninput: unknown) => input: unknowninput is 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<unknown, unknown> = import resultresult.const isResult: (
input: unknown
) => input is Result.Result<unknown, unknown>
isResult