<A, B extends A, E>(
refinement: Refinement<A, B>,
orFailWith: (a: A) => E
): (a: A) => Result<B, E>
<B extends A, E, A = B>(
predicate: Predicate<A>,
orFailWith: (a: A) => E
): (a: B) => Result<B, E>
<A, E, B extends A>(
self: A,
refinement: Refinement<A, B>,
orFailWith: (a: A) => E
): Result<B, E>
<B extends A, E, A = B>(
self: B,
predicate: Predicate<A>,
orFailWith: (a: A) => E
): Result<B, E>Lifts a value into a Result based on a predicate or refinement.
When to use
Use to construct a Result from a raw value guarded by a predicate or
refinement.
Details
- If the predicate returns
true, the value becomesSuccess<A> - If the predicate returns
false,orFailWithproduces the error forFailure<E> - Also accepts a
Refinementto narrow the success type - Supports both data-first and data-last (piped) usage
Example (Validating a number)
import { pipe, Result } from "effect"
const ensurePositive = pipe(
5,
Result.liftPredicate(
(n: number) => n > 0,
(n) => `${n} is not positive`
)
)
console.log(ensurePositive)
// Output: { _tag: "Success", success: 5, ... }export const const liftPredicate: {
<A, B extends A, E>(
refinement: Refinement<A, B>,
orFailWith: (a: A) => E
): (a: A) => Result<B, E>
<B extends A, E, A = B>(
predicate: Predicate<A>,
orFailWith: (a: A) => E
): (a: B) => Result<B, E>
<A, E, B extends A>(
self: A,
refinement: Refinement<A, B>,
orFailWith: (a: A) => E
): Result<B, E>
<B extends A, E, A = B>(
self: B,
predicate: Predicate<A>,
orFailWith: (a: A) => E
): Result<B, E>
}
Lifts a value into a Result based on a predicate or refinement.
When to use
Use to construct a Result from a raw value guarded by a predicate or
refinement.
Details
- If the predicate returns
true, the value becomes Success<A>
- If the predicate returns
false, orFailWith produces the error for Failure<E>
- Also accepts a
Refinement to narrow the success type
- Supports both data-first and data-last (piped) usage
Example (Validating a number)
import { pipe, Result } from "effect"
const ensurePositive = pipe(
5,
Result.liftPredicate(
(n: number) => n > 0,
(n) => `${n} is not positive`
)
)
console.log(ensurePositive)
// Output: { _tag: "Success", success: 5, ... }
liftPredicate: {
<function (type parameter) A in <A, B extends A, E>(refinement: Refinement<A, B>, orFailWith: (a: A) => E): (a: A) => Result<B, E>A, function (type parameter) B in <A, B extends A, E>(refinement: Refinement<A, B>, orFailWith: (a: A) => E): (a: A) => Result<B, E>B extends function (type parameter) A in <A, B extends A, E>(refinement: Refinement<A, B>, orFailWith: (a: A) => E): (a: A) => Result<B, E>A, function (type parameter) E in <A, B extends A, E>(refinement: Refinement<A, B>, orFailWith: (a: A) => E): (a: A) => Result<B, E>E>(refinement: Refinement<A, B>refinement: import RefinementRefinement<function (type parameter) A in <A, B extends A, E>(refinement: Refinement<A, B>, orFailWith: (a: A) => E): (a: A) => Result<B, E>A, function (type parameter) B in <A, B extends A, E>(refinement: Refinement<A, B>, orFailWith: (a: A) => E): (a: A) => Result<B, E>B>, orFailWith: (a: A) => EorFailWith: (a: Aa: function (type parameter) A in <A, B extends A, E>(refinement: Refinement<A, B>, orFailWith: (a: A) => E): (a: A) => Result<B, E>A) => function (type parameter) E in <A, B extends A, E>(refinement: Refinement<A, B>, orFailWith: (a: A) => E): (a: A) => Result<B, E>E): (a: Aa: function (type parameter) A in <A, B extends A, E>(refinement: Refinement<A, B>, orFailWith: (a: A) => E): (a: A) => Result<B, E>A) => 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) B in <A, B extends A, E>(refinement: Refinement<A, B>, orFailWith: (a: A) => E): (a: A) => Result<B, E>B, function (type parameter) E in <A, B extends A, E>(refinement: Refinement<A, B>, orFailWith: (a: A) => E): (a: A) => Result<B, E>E>
<function (type parameter) B in <B extends A, E, A = B>(predicate: Predicate<A>, orFailWith: (a: A) => E): (a: B) => Result<B, E>B extends function (type parameter) A in <B extends A, E, A = B>(predicate: Predicate<A>, orFailWith: (a: A) => E): (a: B) => Result<B, E>A, function (type parameter) E in <B extends A, E, A = B>(predicate: Predicate<A>, orFailWith: (a: A) => E): (a: B) => Result<B, E>E, function (type parameter) A in <B extends A, E, A = B>(predicate: Predicate<A>, orFailWith: (a: A) => E): (a: B) => Result<B, E>A = function (type parameter) B in <B extends A, E, A = B>(predicate: Predicate<A>, orFailWith: (a: A) => E): (a: B) => Result<B, E>B>(
predicate: Predicate<A>predicate: import PredicatePredicate<function (type parameter) A in <B extends A, E, A = B>(predicate: Predicate<A>, orFailWith: (a: A) => E): (a: B) => Result<B, E>A>,
orFailWith: (a: A) => EorFailWith: (a: A = Ba: function (type parameter) A in <B extends A, E, A = B>(predicate: Predicate<A>, orFailWith: (a: A) => E): (a: B) => Result<B, E>A) => function (type parameter) E in <B extends A, E, A = B>(predicate: Predicate<A>, orFailWith: (a: A) => E): (a: B) => Result<B, E>E
): (a: B extends Aa: function (type parameter) B in <B extends A, E, A = B>(predicate: Predicate<A>, orFailWith: (a: A) => E): (a: B) => Result<B, E>B) => 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) B in <B extends A, E, A = B>(predicate: Predicate<A>, orFailWith: (a: A) => E): (a: B) => Result<B, E>B, function (type parameter) E in <B extends A, E, A = B>(predicate: Predicate<A>, orFailWith: (a: A) => E): (a: B) => Result<B, E>E>
<function (type parameter) A in <A, E, B extends A>(self: A, refinement: Refinement<A, B>, orFailWith: (a: A) => E): Result<B, E>A, function (type parameter) E in <A, E, B extends A>(self: A, refinement: Refinement<A, B>, orFailWith: (a: A) => E): Result<B, E>E, function (type parameter) B in <A, E, B extends A>(self: A, refinement: Refinement<A, B>, orFailWith: (a: A) => E): Result<B, E>B extends function (type parameter) A in <A, E, B extends A>(self: A, refinement: Refinement<A, B>, orFailWith: (a: A) => E): Result<B, E>A>(
self: Aself: function (type parameter) A in <A, E, B extends A>(self: A, refinement: Refinement<A, B>, orFailWith: (a: A) => E): Result<B, E>A,
refinement: Refinement<A, B>refinement: import RefinementRefinement<function (type parameter) A in <A, E, B extends A>(self: A, refinement: Refinement<A, B>, orFailWith: (a: A) => E): Result<B, E>A, function (type parameter) B in <A, E, B extends A>(self: A, refinement: Refinement<A, B>, orFailWith: (a: A) => E): Result<B, E>B>,
orFailWith: (a: A) => EorFailWith: (a: Aa: function (type parameter) A in <A, E, B extends A>(self: A, refinement: Refinement<A, B>, orFailWith: (a: A) => E): Result<B, E>A) => function (type parameter) E in <A, E, B extends A>(self: A, refinement: Refinement<A, B>, orFailWith: (a: A) => E): Result<B, E>E
): 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) B in <A, E, B extends A>(self: A, refinement: Refinement<A, B>, orFailWith: (a: A) => E): Result<B, E>B, function (type parameter) E in <A, E, B extends A>(self: A, refinement: Refinement<A, B>, orFailWith: (a: A) => E): Result<B, E>E>
<function (type parameter) B in <B extends A, E, A = B>(self: B, predicate: Predicate<A>, orFailWith: (a: A) => E): Result<B, E>B extends function (type parameter) A in <B extends A, E, A = B>(self: B, predicate: Predicate<A>, orFailWith: (a: A) => E): Result<B, E>A, function (type parameter) E in <B extends A, E, A = B>(self: B, predicate: Predicate<A>, orFailWith: (a: A) => E): Result<B, E>E, function (type parameter) A in <B extends A, E, A = B>(self: B, predicate: Predicate<A>, orFailWith: (a: A) => E): Result<B, E>A = function (type parameter) B in <B extends A, E, A = B>(self: B, predicate: Predicate<A>, orFailWith: (a: A) => E): Result<B, E>B>(
self: B extends Aself: function (type parameter) B in <B extends A, E, A = B>(self: B, predicate: Predicate<A>, orFailWith: (a: A) => E): Result<B, E>B,
predicate: Predicate<A>predicate: import PredicatePredicate<function (type parameter) A in <B extends A, E, A = B>(self: B, predicate: Predicate<A>, orFailWith: (a: A) => E): Result<B, E>A>,
orFailWith: (a: A) => EorFailWith: (a: A = Ba: function (type parameter) A in <B extends A, E, A = B>(self: B, predicate: Predicate<A>, orFailWith: (a: A) => E): Result<B, E>A) => function (type parameter) E in <B extends A, E, A = B>(self: B, predicate: Predicate<A>, orFailWith: (a: A) => E): Result<B, E>E
): 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) B in <B extends A, E, A = B>(self: B, predicate: Predicate<A>, orFailWith: (a: A) => E): Result<B, E>B, function (type parameter) E in <B extends A, E, A = B>(self: B, predicate: Predicate<A>, orFailWith: (a: A) => E): Result<B, E>E>
} = import dualdual(
3,
<function (type parameter) A in <A, E>(a: A, predicate: Predicate<A>, orFailWith: (a: A) => E): Result<A, E>A, function (type parameter) E in <A, E>(a: A, predicate: Predicate<A>, orFailWith: (a: A) => E): Result<A, E>E>(a: Aa: function (type parameter) A in <A, E>(a: A, predicate: Predicate<A>, orFailWith: (a: A) => E): Result<A, E>A, predicate: Predicate<A>predicate: import PredicatePredicate<function (type parameter) A in <A, E>(a: A, predicate: Predicate<A>, orFailWith: (a: A) => E): Result<A, E>A>, orFailWith: (a: A) => EorFailWith: (a: Aa: function (type parameter) A in <A, E>(a: A, predicate: Predicate<A>, orFailWith: (a: A) => E): Result<A, E>A) => function (type parameter) E in <A, E>(a: A, predicate: Predicate<A>, orFailWith: (a: A) => E): Result<A, E>E): 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 <A, E>(a: A, predicate: Predicate<A>, orFailWith: (a: A) => E): Result<A, E>A, function (type parameter) E in <A, E>(a: A, predicate: Predicate<A>, orFailWith: (a: A) => E): Result<A, E>E> =>
predicate: Predicate<A>predicate(a: Aa) ? const succeed: <A>(right: A) => Result<A>Creates a Result holding a Success value.
Details
- Use when you have a value and want to lift it into the
Result type
- The error type
E defaults to never
Example (Wrapping a value)
import { Result } from "effect"
const result = Result.succeed(42)
console.log(Result.isSuccess(result))
// Output: true
succeed(a: Aa) : const fail: <E>(
left: E
) => Result<never, E>
Creates a Result holding a Failure value.
When to use
Use to represent a failed Result with a typed failure value.
Details
- The success type
A defaults to never
Example (Creating a failure)
import { Result } from "effect"
const result = Result.fail("Something went wrong")
console.log(Result.isFailure(result))
// Output: true
fail(orFailWith: (a: A) => EorFailWith(a: Aa))
)