<B>(that: LazyArg<Option<B>>): <A>(
self: Option<A>
) => Option<Result<B, A>>
<A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<Result<B, A>>Returns the first available value and marks whether it came from the fallback.
When to use
Use when you need to know whether a present value came from the primary or
fallback Option.
Details
selfisSome→Some(Result.fail(value))(value from primary)selfisNone,that()isSome→Some(Result.succeed(value))(value from fallback)- Both
None→None
Example (Tracking value source)
import { Option } from "effect"
console.log(Option.orElseResult(Option.some("primary"), () => Option.some("fallback")))
// Output: { _id: 'Option', _tag: 'Some', value: { _tag: 'Failure', value: 'primary' } }
console.log(Option.orElseResult(Option.none(), () => Option.some("fallback")))
// Output: { _id: 'Option', _tag: 'Some', value: { _tag: 'Success', value: 'fallback' } }export const const orElseResult: {
<B>(that: LazyArg<Option<B>>): <A>(
self: Option<A>
) => Option<Result<B, A>>
<A, B>(
self: Option<A>,
that: LazyArg<Option<B>>
): Option<Result<B, A>>
}
Returns the first available value and marks whether it came from the fallback.
When to use
Use when you need to know whether a present value came from the primary or
fallback Option.
Details
self is Some → Some(Result.fail(value)) (value from primary)
self is None, that() is Some → Some(Result.succeed(value)) (value from fallback)
- Both
None → None
Example (Tracking value source)
import { Option } from "effect"
console.log(Option.orElseResult(Option.some("primary"), () => Option.some("fallback")))
// Output: { _id: 'Option', _tag: 'Some', value: { _tag: 'Failure', value: 'primary' } }
console.log(Option.orElseResult(Option.none(), () => Option.some("fallback")))
// Output: { _id: 'Option', _tag: 'Some', value: { _tag: 'Success', value: 'fallback' } }
orElseResult: {
<function (type parameter) B in <B>(that: LazyArg<Option<B>>): <A>(self: Option<A>) => Option<Result<B, A>>B>(that: LazyArg<Option<B>>that: import LazyArgLazyArg<type Option<A> = None<A> | Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<function (type parameter) B in <B>(that: LazyArg<Option<B>>): <A>(self: Option<A>) => Option<Result<B, A>>B>>): <function (type parameter) A in <A>(self: Option<A>): Option<Result<B, A>>A>(self: Option<A>self: type Option<A> = None<A> | Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<function (type parameter) A in <A>(self: Option<A>): Option<Result<B, A>>A>) => type Option<A> = None<A> | Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<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>(that: LazyArg<Option<B>>): <A>(self: Option<A>) => Option<Result<B, A>>B, function (type parameter) A in <A>(self: Option<A>): Option<Result<B, A>>A>>
<function (type parameter) A in <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<Result<B, A>>A, function (type parameter) B in <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<Result<B, A>>B>(self: Option<A>self: type Option<A> = None<A> | Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<function (type parameter) A in <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<Result<B, A>>A>, that: LazyArg<Option<B>>that: import LazyArgLazyArg<type Option<A> = None<A> | Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<function (type parameter) B in <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<Result<B, A>>B>>): type Option<A> = None<A> | Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<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>(self: Option<A>, that: LazyArg<Option<B>>): Option<Result<B, A>>B, function (type parameter) A in <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<Result<B, A>>A>>
} = import dualdual(
2,
<function (type parameter) A in <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<Result<B, A>>A, function (type parameter) B in <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<Result<B, A>>B>(self: Option<A>self: type Option<A> = None<A> | Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<function (type parameter) A in <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<Result<B, A>>A>, that: LazyArg<Option<B>>that: import LazyArgLazyArg<type Option<A> = None<A> | Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<function (type parameter) B in <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<Result<B, A>>B>>): type Option<A> = None<A> | Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<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>(self: Option<A>, that: LazyArg<Option<B>>): Option<Result<B, A>>B, function (type parameter) A in <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<Result<B, A>>A>> =>
const isNone: <A>(
self: Option<A>
) => self is None<A>
Checks whether an Option is None (absent).
When to use
Use when you need to branch on an absent Option before accessing .value.
Details
- Acts as a type guard, narrowing to
None<A>
Example (Checking for None)
import { Option } from "effect"
console.log(Option.isNone(Option.some(1)))
// Output: false
console.log(Option.isNone(Option.none()))
// Output: true
isNone(self: Option<A>self) ? const map: {
<A, B>(f: (a: A) => B): (
self: Option<A>
) => Option<B>
<A, B>(
self: Option<A>,
f: (a: A) => B
): Option<B>
}
map(that: LazyArg<Option<B>>that(), import resultresult.const succeed: <A>(
success: A
) => Result.Result<A>
succeed) : const map: {
<A, B>(f: (a: A) => B): (
self: Option<A>
) => Option<B>
<A, B>(
self: Option<A>,
f: (a: A) => B
): Option<B>
}
map(self: Option<A>(parameter) self: {
_tag: "Some";
_op: "Some";
value: A;
valueOrUndefined: A;
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;
}
self, import resultresult.const fail: <E>(
failure: E
) => Result.Result<never, E>
fail)
)